I think that gc includes debugging information by default. However, I want to avoid decompilation.
How can I remove the debugging information when compiling go code
The go linker has a flag -w
which disables DWARF debugging information generation. You can supply linker flags to go tool build commands as follows:
go build -ldflags '-w'
Another approach on Linux/Unix platforms is using command strip
against the compiled binary. This seems to produce smaller binaries than the above linker option.
I recommend usage of -ldflags="-s -w"
which removes symbol table and debugging information.
As a bonus with Go 1.13 -trimpath
can be used to reduce length of file paths stored in the file