问题描述
我认为gc默认包含调试信息。但是,我想避免反编译。
如何在编译go代码时删除调试信息?
使用gccgo并不能解决问题。如果我没有使用'-g'进行编译,那么可执行文件被破坏并且只输出:
ELF可执行文件中没有调试信息errno -1
致命错误:在ELF可执行文件中没有调试信息
运行时栈:
在ELF可执行文件中没有调试信息errno -1
在恐慌期间发生混乱
-w
,它会禁用DWARF调试信息生成。提供链接器标志以执行工具构建命令,如下所示: go build -ldflags'-w'
在Linux / Unix平台上的另一种方法是使用命令 strip
。这似乎产生比上面的链接器选项更小的二进制文件。
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 -1fatal error: no debug info in ELF executable
runtime stack:no debug info in ELF executable errno -1panic 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.
这篇关于避免在golang上调试信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!