On Fri, Sep 16, 2022 at 12:13 PM Ramon Rüttimann <ramon.ruettim...@gmail.com> wrote: > > I am currently looking into what a built Go binary may contain and have found > some confusing things around the `.gopclntab` ELF section, also known as the > PCLN table. > > At first, I assumed that the PCLN table is present in all binaries, no matter > how they are built. I've done some tests with stripped, trimmed and CGo > binaries and have found it to be present. > However, this article contains an interesting statement: > > For ordinary unstripped Go binaries, this debugging information is in the > .gopclntab and .gosymtab ELF sections of the binary, and can be read out with > debug/elf/File.Section() and Section.Data(). Unfortunately, Go binaries that > use cgo do not have these Go ELF sections. As mentioned in Building a better > Go linker: > > For “cgo” binaries, which may make arbitrary use of C libraries, the Go > linker links all of the Go code into a single native object file and then > invokes the system linker to produce the final binary. > > This linkage obliterates .gopclntab and .gosymtab as separate ELF sections. I > believe that their data is still there in the final binary, but I don't know > how to extract them. > > I have also found such binaries in the wild, like the `containerd` binary or > some tools from Docker as well. I've tried to decipher how the containerd > binary is being built (based on this Makefile), but I am not really familiar > enough with Make to decipher this. > > This S/O post has asked the same question, but the answer doesn't match what > I've seen and also what that article claims. > > Can someone shed some lights on how one can build CGo binaries without the > `.pclntab` section? Also, what happens to stacktraces in such a case?
I believe that at least as of Go 1.19 the .gopclntab section exists even if the binary is built with cgo, and the .gosymtab section is empty in any case. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcU2VUXA4fwuMuSrv9VTk%3DsEytXoL6H%2Bki2XQ%2B%2BJ9kpYTA%40mail.gmail.com.