首頁 > 後端開發 > Golang > 如何從編譯的 Go 程式碼中去除調試資訊?

如何從編譯的 Go 程式碼中去除調試資訊?

Susan Sarandon
發布: 2024-11-15 07:31:02
原創
971 人瀏覽過

How to Strip Debugging Information from Compiled Go Code?

Stripping Debugging Information from Go Compiled Code

Debugging information is frequently included in Go code compiled using gc by default. While it can be helpful for debugging purposes, it also increases the size of the executable and makes it susceptible to decompilation.

Removing Debugging Information

To eliminate debugging information during compilation with gc, specify the "-ldflags" flag along with the "-s" and "-w" options. The following command demonstrates this:

go build -ldflags="-s -w"
登入後複製

The "-s" option removes the symbol table, while the "-w" option suppresses DWARF debug information. This effectively removes all debugging information from the compiled executable.

Note on gccgo

Using gccgo does not resolve this issue. Compiling without the "-g" flag will result in a broken executable that outputs errors related to missing debug information.

Additional Option in Go 1.13

With the introduction of Go 1.13, the "-trimpath" flag can be used to reduce the length of file paths stored in the executable. This further minimizes the size of the compiled code.

以上是如何從編譯的 Go 程式碼中去除調試資訊?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板