golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.13k stars 17.56k forks source link

build: debug_* sections are missing from toolchain binaries in Go 1.21 #61714

Open laboger opened 1 year ago

laboger commented 1 year ago

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

go 1.21rc4

$ go version

Does this issue reproduce with the latest release?

No

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

ppc64le, but same result on x86

go env Output
$ go env

What did you do?

I tried to use the GNU objdump -DlS on the go binary from a toolchain I built from the Go 1.21 branch, but the source statement information did not appear. On further inspection I found that the debug_* sections were missing from the go binary and all binaries found under pkg/tool/linux_ppc64le. When building a toolchain from the master branch all these binaries have the debug sections, and likewise on earlier releases such as the Go 1.20 branch.

[boger@ltcd97-lp2 bin]$ file ~/golang/base/go/bin/go
/home/boger/golang/base/go/bin/go: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), statically linked, Go BuildID=yEBM_x29Vtmmv5mU7ibv/fQLYk1huGo5MrnaLT7cs/UABCXJ-zG0lDIV6nnPTB/lP5zvxbwOH1d-gjeKVWj, with debug_info, not stripped
[boger@ltcd97-lp2 bin]$ file ~/golang/base/go/pkg/tool/linux_ppc64le/compile
/home/boger/golang/base/go/pkg/tool/linux_ppc64le/compile: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), statically linked, Go BuildID=NEnWUHq4dHMg58fMsP2C/HzKcDIEHHQ2d8XRwW2wM/hVRUaEN2h5tH_gBuJgi3/Fd9-7WFy0d_3nglhJ1Wn, with debug_info, not stripped

[boger@ltcd97-lp2 bin]$ file ~/golang/go1.21/go/bin/go
/home/boger/golang/go1.21/go/bin/go: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), statically linked, Go BuildID=Ipj_J0quvipW6G1VJUv5/Z8dFndgoIFi-DjK_MBs5/Yo-_THqt0OgmXGm3gyEv/DwCPGEf0IzGsTtYqTLQd, not stripped
[boger@ltcd97-lp2 bin]$ file ~/golang/go1.21/go/pkg/tool/linux_ppc64le/compile 
/home/boger/golang/go1.21/go/pkg/tool/linux_ppc64le/compile: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), statically linked, Go BuildID=L5yz1CZ290PRDTFeR0Cq/-R4MnzVYRXvc8oT1olkg/SlvsKpKgea9wlhrCM9fX/IFuvxzMaydYb-mjbrIpz, not stripped

What did you expect to see?

The debug_* sections in the Go 1.21 toolchain binaries such as go and those found in pkg/tool/linux_ppc64le so that debug tools will work when debugging the toolchain.

What did you see instead?

No debuginfo in the Go 1.21 toolchain binaries and debugging tools less effective.

If this was a planned change, I didn't see anything in the git log that explicitly mentions the removal of the debug_* sections and didn't find anything in the release notes that mentions the diffference.

dmitshur commented 1 year ago

There've been some changes to reduce the size of the release toolchains as part of work for #57001, but I'm not sure if this issue is working is intended. CL 475378 may be relevant here.

laboger commented 1 year ago

OK it looks like that CL is what did this. Is there a place where the value for the GO_LDFLAGS option to generate the dwarf sections is documented?

dmitshur commented 1 year ago

CC @rsc, @ianlancetaylor.

cherrymui commented 1 year ago

The linker -w flag is documented at https://pkg.go.dev/cmd/link .

I think the expectation is that most user won't debug a toolchain binary. And for toolchain developers who do want to debug a toolchain binary, one can build it with go install cmd/compile (or link etc.).

laboger commented 1 year ago

The linker -w flag is documented at https://pkg.go.dev/cmd/link .

My point is that the only way to know that the release binaries in the toolchain are not built with debug information is to search the log and find the change. Then you'd know to use -w=0 to generate them. I was expecting to see this in at least the release notes but if you don't think this is a difference that warrants being mentioned then feel free to close it.