Go program debug rt0_go extrance issue about get_tls Macro

Hi
I’m debugging go program with delve,and my env is

GO111MODULE="on"
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/xielei.xielei/goworkspace"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.google.cn"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/xielei.xielei/goworkspace/src/awesomeProject/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1187616538=/tmp/go-build -gno-record-gcc-switches"

I set a breakpoint at runtime.rt0_g0,and when i reach the code in the file /usr/local/go/src/runtime/asm_amd64.s:189

	LEAQ	runtime·m0+m_tls(SB), DI
	CALL	runtime·settls(SB)

	// store through it, to make sure it works
	get_tls(BX)
	MOVQ	$0x123, g(BX)
	MOVQ	runtime·m0+m_tls(SB), AX
	CMPQ	AX, $0x123
	JEQ 2(PC)
	CALL	runtime·abort(SB)

I have some question about the get_tls macro define in go_tls.h

#ifdef GOARCH_amd64
#define	get_tls(r)	MOVQ TLS, r
#define	g(r)	0(r)(TLS*1)
#endif

I found after get_tls(BX) is executed, the register BX is not modified

Before Rbx = 0x0000000005080800
After Rbx = 0x0000000005080800

while the Fs_base register hold the point to m0.tls[1] after line

CALL	runtime·settls(SB)

So i wonder if

   185:		get_tls(BX)
   186:		MOVQ	$0x123, g(BX)

line 185 did nothing under my environment(linux amd64), and line 186 will mov 0x123 to -8(Fs_base),correct me if i’m wrong

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.