避免在golang上调试信息 [英] Avoid debugging information on golang

查看:561
本文介绍了避免在golang上调试信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为gc默认包含调试信息。但是,我想避免反编译。

如何在编译go代码时删除调试信息?



<注意:
使用gccgo并不能解决问题。如果我没有使用'-g'进行编译,那么可执行文件被破坏并且只输出:

ELF可执行文件中没有调试信息errno -1
致命错误:在ELF可执行文件中没有调试信息

运行时栈:
在ELF可执行文件中没有调试信息errno -1
在恐慌期间发生混乱

解决方案

go链接器有一个标志 -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 -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.

这篇关于避免在golang上调试信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆