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"
It allows you to build, edit, and debug programs. If you use VS Code to run your Go code and have the official Go extension installed on the editor, you can debug your code by pressing F5 or Run and Debug on your computer.
GoLand is a Go IDE from JetBrains, available from the JetBrains website. GoLand uses the Delve debugger internally to support time travel debugging.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With