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

cmd/objdump: TestDisasmExtld fails on darwin/arm64 #49700

Closed
jsshapiro opened this issue Nov 20, 2021 · 9 comments
Closed

cmd/objdump: TestDisasmExtld fails on darwin/arm64 #49700

jsshapiro opened this issue Nov 20, 2021 · 9 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin
Milestone

Comments

@jsshapiro
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.17.2 darwin/arm64

Does this issue reproduce with the latest release?

Yes

This appears to be recent, as I don't recall seeing it when I built master a week ago. Could be a real bug, or could be a valid fix where the reference output didn't get updated. This has me temporarily stuck trying to build locally using go generics.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/shap/Library/Caches/go-build"
GOENV="/Users/shap/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/shap/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/shap/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.17.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.17.2/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/go-build2009238581=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.17.2 darwin/arm64
GOROOT/bin/go tool compile -V: compile version go1.17.2
uname -v: Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:01 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T6000
ProductName:	macOS
ProductVersion:	12.0.1
BuildVersion:	21A559
lldb --version: lldb-1300.0.32.4
Swift version 5.5.1-dev

What did you do?

git clone from repo (tried both github and origin)
git checkout master
cd src
./all.bash

Currently have go version go1.17.2 darwin/arm64, which was probably used for very early bootstrap.

What did you expect to see?

Successful unit tests completed.

What did you see instead?

--- FAIL: TestDisasmExtld (2.93s)
objdump_test.go:156: Running [/Users/shap/Dev/Personal/go-generics/bin/go build -o /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-b8671a8435298d43c67d864e10c70b6b.exe -ldflags=-linkmode=external fmthello.go]
objdump_test.go:209: Running [/var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/testobjdump.exe -s main.main /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-b8671a8435298d43c67d864e10c70b6b.exe]
objdump_test.go:220: disassembly missing 'fmthello.go:6'
objdump_test.go:232: full disassembly:
TEXT main.main(SB)
:0 0x1000883a0 f9400b90 MOVD 16(R28), R16
:0 0x1000883a4 910003f1 MOVD RSP, R17
:0 0x1000883a8 eb10023f CMP R16, R17
:0 0x1000883ac 540002c9 BLS 22(PC)
:0 0x1000883b0 f81e0ffe MOVD.W R30, -32(RSP)
:0 0x1000883b4 f81f83fd MOVD R29, -8(RSP)
:0 0x1000883b8 d10023fd SUB $8, RSP, R29
:0 0x1000883bc d0000000 ADRP 8192(PC), R0
:0 0x1000883c0 91085c00 ADD $535, R0, R0
:0 0x1000883c4 b27e07e1 ORR $12, ZR, R1
:0 0x1000883c8 94000012 CALL main.Println(SB)
:0 0x1000883cc d00006c2 ADRP 892928(PC), R2
:0 0x1000883d0 91290442 ADD $2625, R2, R2
:0 0x1000883d4 39400042 MOVBU (R2), R2
:0 0x1000883d8 b40000c2 CBZ R2, 6(PC)
:0 0x1000883dc b0000000 ADRP 4096(PC), R0
:0 0x1000883e0 911c9400 ADD $1829, R0, R0
:0 0x1000883e4 b27d03e1 ORR $8, ZR, R1
:0 0x1000883e8 9400000a CALL main.Println(SB)
:0 0x1000883ec 14000004 JMP 4(PC)
:0 0x1000883f0 f85f83fd MOVD -8(RSP), R29
:0 0x1000883f4 f84207fe MOVD.P 32(RSP), R30
:0 0x1000883f8 d65f03c0 RET
:0 0x1000883fc d503201f NOOP
:0 0x100088400 17ffffff JMP -1(PC)
:0 0x100088404 aa1e03e3 MOVD R30, R3
:0 0x100088408 97ff3f82 CALL runtime.morestack_noctxt.abi0(SB)
:0 0x10008840c 17ffffe5 JMP main.main(SB)
--- FAIL: TestDisasmGnuAsm (4.07s)
objdump_test.go:156: Running [/Users/shap/Dev/Personal/go-generics/bin/go build -o /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-a2fdf6fa5e30e7eb2b8d7d63be13b362.exe fmthello.go]
objdump_test.go:209: Running [/var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/testobjdump.exe -gnu -s main.main /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-a2fdf6fa5e30e7eb2b8d7d63be13b362.exe]
objdump_test.go:156: Running [/Users/shap/Dev/Personal/go-generics/bin/go build -o /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-739d837da95c25909d2915651b14619d.exe fmthellocgo.go]
objdump_test.go:209: Running [/var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/testobjdump.exe -gnu -s main.main /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-739d837da95c25909d2915651b14619d.exe]
objdump_test.go:220: disassembly missing 'fmthellocgo.go:6'
objdump_test.go:232: full disassembly:
TEXT main.main(SB)
:0 0x1000884d0 f9400b90 MOVD 16(R28), R16 // ldr x16, [x28,#16]
:0 0x1000884d4 910003f1 MOVD RSP, R17 // mov x17, sp
:0 0x1000884d8 eb10023f CMP R16, R17 // cmp x17, x16
:0 0x1000884dc 540002c9 BLS 22(PC) // b.ls .+0x58
:0 0x1000884e0 f81e0ffe MOVD.W R30, -32(RSP) // str x30, [sp,#-32]!
:0 0x1000884e4 f81f83fd MOVD R29, -8(RSP) // stur x29, [sp,#-8]
:0 0x1000884e8 d10023fd SUB $8, RSP, R29 // sub x29, sp, #0x8
:0 0x1000884ec d0000000 ADRP 8192(PC), R0 // adrp x0, .+0x2000
:0 0x1000884f0 9108d800 ADD $566, R0, R0 // add x0, x0, #0x236
:0 0x1000884f4 b27e07e1 ORR $12, ZR, R1 // orr x1, xzr, #0xc
:0 0x1000884f8 94000012 CALL main.Println(SB) // bl .+0x48
:0 0x1000884fc d00006c2 ADRP 892928(PC), R2 // adrp x2, .+0xda000
:0 0x100088500 912a0442 ADD $2689, R2, R2 // add x2, x2, #0xa81
:0 0x100088504 39400042 MOVBU (R2), R2 // ldrb w2, [x2]
:0 0x100088508 b40000c2 CBZ R2, 6(PC) // cbz x2, .+0x18
:0 0x10008850c b0000000 ADRP 4096(PC), R0 // adrp x0, .+0x1000
:0 0x100088510 911d1000 ADD $1860, R0, R0 // add x0, x0, #0x744
:0 0x100088514 b27d03e1 ORR $8, ZR, R1 // orr x1, xzr, #0x8
:0 0x100088518 9400000a CALL main.Println(SB) // bl .+0x28
:0 0x10008851c 14000004 JMP 4(PC) // b .+0x10
:0 0x100088520 f85f83fd MOVD -8(RSP), R29 // ldur x29, [sp,#-8]
:0 0x100088524 f84207fe MOVD.P 32(RSP), R30 // ldr x30, [sp],#32
:0 0x100088528 d65f03c0 RET // ret
:0 0x10008852c d503201f NOOP // nop
:0 0x100088530 17ffffff JMP -1(PC) // b .+0xfffffffffffffffc
:0 0x100088534 aa1e03e3 MOVD R30, R3 // mov x3, x30
:0 0x100088538 97ff3f9e CALL runtime.morestack_noctxt.abi0(SB) // bl .+0xfffffffffffcfe78
:0 0x10008853c 17ffffe5 JMP main.main(SB) // b .+0xffffffffffffff94
--- FAIL: TestDisasm (4.08s)
objdump_test.go:156: Running [/Users/shap/Dev/Personal/go-generics/bin/go build -o /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-ea6f791f716c96f8441f99ba474a41f0.exe fmthello.go]
objdump_test.go:209: Running [/var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/testobjdump.exe -s main.main /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-ea6f791f716c96f8441f99ba474a41f0.exe]
objdump_test.go:156: Running [/Users/shap/Dev/Personal/go-generics/bin/go build -o /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-a6acfb7e9d32782fea9814ad1314bef1.exe fmthellocgo.go]
objdump_test.go:209: Running [/var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/testobjdump.exe -s main.main /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-a6acfb7e9d32782fea9814ad1314bef1.exe]
objdump_test.go:220: disassembly missing 'fmthellocgo.go:6'
objdump_test.go:232: full disassembly:
TEXT main.main(SB)
:0 0x1000884d0 f9400b90 MOVD 16(R28), R16
:0 0x1000884d4 910003f1 MOVD RSP, R17
:0 0x1000884d8 eb10023f CMP R16, R17
:0 0x1000884dc 540002c9 BLS 22(PC)
:0 0x1000884e0 f81e0ffe MOVD.W R30, -32(RSP)
:0 0x1000884e4 f81f83fd MOVD R29, -8(RSP)
:0 0x1000884e8 d10023fd SUB $8, RSP, R29
:0 0x1000884ec d0000000 ADRP 8192(PC), R0
:0 0x1000884f0 9108d800 ADD $566, R0, R0
:0 0x1000884f4 b27e07e1 ORR $12, ZR, R1
:0 0x1000884f8 94000012 CALL main.Println(SB)
:0 0x1000884fc d00006c2 ADRP 892928(PC), R2
:0 0x100088500 912a0442 ADD $2689, R2, R2
:0 0x100088504 39400042 MOVBU (R2), R2
:0 0x100088508 b40000c2 CBZ R2, 6(PC)
:0 0x10008850c b0000000 ADRP 4096(PC), R0
:0 0x100088510 911d1000 ADD $1860, R0, R0
:0 0x100088514 b27d03e1 ORR $8, ZR, R1
:0 0x100088518 9400000a CALL main.Println(SB)
:0 0x10008851c 14000004 JMP 4(PC)
:0 0x100088520 f85f83fd MOVD -8(RSP), R29
:0 0x100088524 f84207fe MOVD.P 32(RSP), R30
:0 0x100088528 d65f03c0 RET
:0 0x10008852c d503201f NOOP
:0 0x100088530 17ffffff JMP -1(PC)
:0 0x100088534 aa1e03e3 MOVD R30, R3
:0 0x100088538 97ff3f9e CALL runtime.morestack_noctxt.abi0(SB)
:0 0x10008853c 17ffffe5 JMP main.main(SB)
--- FAIL: TestDisasmCode (4.30s)
objdump_test.go:156: Running [/Users/shap/Dev/Personal/go-generics/bin/go build -o /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-7f184b50e2cba293836d4b2309588185.exe fmthello.go]
objdump_test.go:209: Running [/var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/testobjdump.exe -S -s main.main /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-7f184b50e2cba293836d4b2309588185.exe]
objdump_test.go:156: Running [/Users/shap/Dev/Personal/go-generics/bin/go build -o /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-50c34f7265eea30b52665e483079b0c1.exe fmthellocgo.go]
objdump_test.go:209: Running [/var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/testobjdump.exe -S -s main.main /var/folders/tv/wzbzy7hd6fl95qfv0vxd8q700000gn/T/TestObjDump3987775514/hello-50c34f7265eea30b52665e483079b0c1.exe]
objdump_test.go:220: disassembly missing ' Println("hello, world")'
objdump_test.go:232: full disassembly:
TEXT main.main(SB)
0x1000884d0 f9400b90 MOVD 16(R28), R16
0x1000884d4 910003f1 MOVD RSP, R17
0x1000884d8 eb10023f CMP R16, R17
0x1000884dc 540002c9 BLS 22(PC)
0x1000884e0 f81e0ffe MOVD.W R30, -32(RSP)
0x1000884e4 f81f83fd MOVD R29, -8(RSP)
0x1000884e8 d10023fd SUB $8, RSP, R29
0x1000884ec d0000000 ADRP 8192(PC), R0
0x1000884f0 9108d800 ADD $566, R0, R0
0x1000884f4 b27e07e1 ORR $12, ZR, R1
0x1000884f8 94000012 CALL main.Println(SB)
0x1000884fc d00006c2 ADRP 892928(PC), R2
0x100088500 912a0442 ADD $2689, R2, R2
0x100088504 39400042 MOVBU (R2), R2
0x100088508 b40000c2 CBZ R2, 6(PC)
0x10008850c b0000000 ADRP 4096(PC), R0
0x100088510 911d1000 ADD $1860, R0, R0
0x100088514 b27d03e1 ORR $8, ZR, R1
0x100088518 9400000a CALL main.Println(SB)
0x10008851c 14000004 JMP 4(PC)
0x100088520 f85f83fd MOVD -8(RSP), R29
0x100088524 f84207fe MOVD.P 32(RSP), R30
0x100088528 d65f03c0 RET
0x10008852c d503201f NOOP
0x100088530 17ffffff JMP -1(PC)
0x100088534 aa1e03e3 MOVD R30, R3
0x100088538 97ff3f9e CALL runtime.morestack_noctxt.abi0(SB)
0x10008853c 17ffffe5 JMP main.main(SB)
FAIL
FAIL cmd/objdump 6.838s

@jsshapiro jsshapiro changed the title Master 762c61 regression failure on darwin/arm64 Go compiler Master 762c61 regression failure on darwin/arm64 Nov 20, 2021
@cherrymui cherrymui changed the title Go compiler Master 762c61 regression failure on darwin/arm64 cmd/objdump: TestDisasmExtld fails on darwin/arm64 Nov 22, 2021
@cherrymui
Copy link
Member

@jsshapiro thanks for the report. What version of the system linker do you have? What is the output of ld -v ?

I have one machine with ld64-609.8 and it doesn't fail, and another machine with ld64-711 and it fails even with Go 1.17. Our builders seem to have ld64-609.8 and it passes.

@heschi heschi added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 22, 2021
@heschi heschi added this to the Go1.18 milestone Nov 22, 2021
@jsshapiro
Copy link
Author

jsshapiro commented Nov 22, 2021 via email

@jsshapiro
Copy link
Author

If you have a patch you want tested, feel free to let me know.

@rhysh
Copy link
Contributor

rhysh commented Nov 23, 2021

Is it related to the macOS version? (Broken on Monterey, not broken before Monterey?)

On the macOS machines I can access, I see ./all.bash pass at go1.17.3 and go1.18-91abe4be0e (commit 91abe4be0e8f3329bd891838fc047d83a5762c61 ends in 762c61, from the original issue title) on both amd64 and arm64:

  1. MacBook Air (M1, 2020) with macOS Big Sur / 11.6.1 (20G224). ld -v reports ld64-711, uname -r reports 20.6.0, ./all.bash passes at both go1.17.3 and go1.18-91abe4be0e.
  2. MacBook Pro (Retina, 13-inch, Mid 2014) with macOS BigSur / 11.6.1 (20G224). ld -v reports ld64-711, uname -r reports 20.6.0, ./all.bash passes at both go1.17.3 and go1.18-91abe4be0e.

@cherrymui
Copy link
Member

Thanks for the information. It seems this is specific to ARM64 using newer system ld (at least ld64-711).

I think this is what happening: our PC-line table (for which our objdump uses) contains PCs to functions. On Darwin/ARM64 the binaries are PIE, so the dynamic linker rewrites the binary at load time by applying dynamic relocations. Objdump, being static, just reads the static content from the binary. With the old version of the darwin linker, the static content contains the right PCs that match the functions in the binary. The new version of the darwin linker seems to generate a different kind of dynamic relocations and leaves the static content not matching the function addresses, so objdump couldn't find the line number from the PCs.

In general, objdump on PIE binaries needs more work. #17883 may be related. I'll see if there is anything simple we could do. Otherwise for the short term (1.18) we may skip the tests and revisit in the next cycle.

@cherrymui
Copy link
Member

@rhysh Interesting! it does look like OS-dependent. If I pass -extldflags=-Wl,-macos_version_min,11.0 to the linker it doesn't generate the new relocations and objdump works fine.

@jsshapiro
Copy link
Author

jsshapiro commented Nov 23, 2021 via email

@gopherbot
Copy link

Change https://golang.org/cl/366695 mentions this issue: cmd/internal/objfile, debug/gosym: use the address of runtime.text as textStart

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 10, 2022
@gopherbot
Copy link

Change https://go.dev/cl/405474 mentions this issue: [release-branch.go1.17] skip TestDisasm* on darwin-arm64

gopherbot pushed a commit that referenced this issue May 10, 2022
The macOS 12 builders have an incompatible version of XCode installed.
We fixed the bug on 1.18 but not 1.17.

Updates #49700.

Change-Id: Id356786aad351568ba6665430f093f5f78bb4357
Reviewed-on: https://go-review.googlesource.com/c/go/+/405474
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
@golang golang locked and limited conversation to collaborators May 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin
Projects
None yet
Development

No branches or pull requests

6 participants