Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问怎么主要找到 m_tls 的具体定义呢? #57

Open
fbwfbi opened this issue Dec 1, 2021 · 1 comment
Open

请问怎么主要找到 m_tls 的具体定义呢? #57

fbwfbi opened this issue Dec 1, 2021 · 1 comment

Comments

@fbwfbi
Copy link

fbwfbi commented Dec 1, 2021

在分析 golang 启动过程时,经常会提到这么一行
LEAQ runtime·m0+m_tls(SB), DI

意思是将m0.tls的地址存入DI寄存器,查看源码时有不少地方用到 m_tls,比如如下:

#ifdef GOOS_windows
	CMPQ	BX, $0
	JNE	settls
	MOVQ	$0, 0x28(GS)
	RET
settls:
	MOVQ	g_m(BX), AX
	LEAQ	m_tls(AX), AX
	MOVQ	AX, 0x28(GS)
#endif
	get_tls(CX)
	MOVQ	BX, g(CX)
	RET

我感觉应该也是类似 get_tls (src/runtime/go_tls.h) 这样一个宏,但是翻遍 golang 源码里面好像找不到具体的定义

@cch123
Copy link
Owner

cch123 commented Dec 2, 2021

这种 runtime 自己的特殊 hack 太多了,这里的 m_tls 编译完成后会变成偏移量,

我猜是链接的时候做的替换:

https://github.com/golang/go/blob/72b6a89ca5cd3c3bfd13b9b17be976e8feb91ecc/src/cmd/internal/objabi/reloctype.go#L68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants