Avoid debugging information on golang

后端 未结 2 1446
一向
一向 2020-12-24 03:12

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

相关标签:
2条回答
  • 2020-12-24 03:44

    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.

    0 讨论(0)
  • 2020-12-24 03:58

    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

    0 讨论(0)
提交回复
热议问题