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 with gc?
Note: Using gccgo doesn't solve the problem. If I don't compile with '-g' the executable is broken and only outputs:
no debug info in ELF executable errno -1 fatal error: no debug info in ELF executable
runtime stack: no debug info in ELF executable errno -1 panic during panic"
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.