golang/go
View on GitHubcmd/objdump: symbolization of global variable doesn't work for shared objects
Open
#24,712 opened on Apr 5, 2018
NeedsInvestigationcompiler/runtimehelp wanted
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
What operating system and processor architecture are you using (go env)?
darwin/amd64
What did you do?
package main
var X int
//go:noinline
func F() { X = 5 }
func main() { F() }
$ go build p
$ go tool objdump -s "\.F$" p
TEXT main.F(SB) /tmp/p2/src/p/p.go
p.go:6 0x104b3a0 48c7050553070005000000 MOVQ $0x5, main.X(SB)
p.go:6 0x104b3ab c3 RET
:-1 0x104b3ac cc INT $0x3
:-1 0x104b3ad cc INT $0x3
:-1 0x104b3ae cc INT $0x3
:-1 0x104b3af cc INT $0x3
The address of global variable is symbolized (main.X(SB)), which is nice.
But this is not correct for shared objects, e.g. plugin:
$ go build -buildmode=plugin p
$ go tool objdump -s "\.F$" p.so
TEXT _p.F(SB) /tmp/p2/src/p/p.go
p.go:6 0x44670 4c8b3dc1090000 MOVQ __cgo_yield+200(SB), R15
p.go:6 0x44677 49c70705000000 MOVQ $0x5, 0(R15)
p.go:6 0x4467e c3 RET
:-1 0x4467f cc INT $0x3
Note the __cgo_yield+200(SB), which should actually be X in the GOT, like what compile -S prints
0x0000 00000 (/tmp/p2/src/p/p.go:6) MOVQ "".X@GOT(SB), R15
0x0007 00007 (/tmp/p2/src/p/p.go:6) MOVQ $5, (R15)
cc @aarzilli