How can I strip the .gopclntab and (optionally) the .gosymtab sections of my Go binary?

Viewed 351

I program on Linux x86_64. I run readelf -S ./mybinary and I see that the Go compiler places these two sections called .gopclntab and .gosymtab in the binary. It seems that at least .gopclntab is not necessary at runtime. I happened to find this article which confirms that:

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.

So apparently these are not strictly necessary for the program to run properly. However, the strip utility doesn't strip them, likely because it is not aware of these Go-specific sections. Note that even if I use go build -ldflags="-s -w", these sections still exist.

Is there a way to strip them aside from using cgo?

0 Answers
Related