构建不带调试信息的Go二进制文件

huangapple go评论69阅读模式
英文:

Building Go binaries without debugging info

问题

是否有可能构建一个Go二进制文件,以便在发生panic时不显示堆栈跟踪,并且不包含任何源代码路径等?

我目前正在使用ld-flags的"-w"和"-s",但生成的二进制文件仍然包含一些不必要的路径,并在发生panic时显示不必要的堆栈跟踪。

关于这个问题有一个问题(https://code.google.com/p/go/issues/detail?id=3467),但它已经很久没有更新了(而且我对其中一个问题评论中的"patching runtime"一词一窍不通)。

英文:

Is it possible to build go binary so that it doesn't show stack-trace on panic and doesn't contain any source code paths etc?

I'm currently using ld-flags "-w" and "-s" but resulting binary still contains some unneeded paths and shows unneeded stack trace on panic.

There is a issue about this thing (https://code.google.com/p/go/issues/detail?id=3467) but it is old and hasn't been updated for a while (and I don't have slightest idea what "patching runtime" in one of issues comments means).

答案1

得分: 4

不,目前没有任何方法可以做到这一点。

关于修补运行时的评论意味着目前只有这种方法可以禁用该输出。运行时是打印 panic 的堆栈跟踪和段错误地址的部分,你需要编写一个补丁来禁用这种行为。

英文:

No, there isn't any way to do this right now.

The comment about patching the runtime means that is currently the only way to disable that output. The runtime is what prints the stack traces on panic, and the segfault addresses; and you'd have to write a patch to disable that behavior.

答案2

得分: 0

自Go 1.11版本开始,可以通过添加"-trimpath"标志来使用该功能。

英文:

It is available since go 1.11, with adding -trimpath flag build command.

huangapple
  • 本文由 发表于 2014年11月16日 01:02:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/26948331.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定