Go语言,gobuild ,Mac中-ldflags “-s -w”无效,以及相应背景

来源:互联网 发布:java中的out是什么意思 编辑:程序博客网 时间:2024/06/05 00:57

Go语言,gobuild ,Mac中-ldflags “-s -w”无效,以及相应背景

https://blog.filippo.io/shrink-your-go-binaries-with-this-one-weird-trick/

https://news.ycombinator.com/item?id=11515612

https://rednaga.io/2016/09/21/reversing_go_binaries_like_a_pro/

https://jamescun.com/golang/binary-size/

http://www.grdtechs.com/2016/10/23/go-build-small-exec/

事情是这样的

我在mac中按默认去编译go程序,比如go build
然后拿hopper disassembler反编译,发现能看到函数名
我希望看不到

然后我就上网搜golang disassembly

然后搜着搜着就发现了strip

经过测试是这样的

只有在我的mac上,
go build -ldflags “-s -w”
中的-s 无效,起不到去除符号表的作用,

在windows上完全没问题

在mac上用
GOOS=darwin GOARCH=amd64 go build -o hello-stripped -ldflags “-s -w” main.go
也不行

但是在mac上用
GOOS=linux GOARCH=386 go build -o hello-stripped -ldflags “-s” main.go
就行

和GOARCH无关

最后,我发现只要用strip命令,后面接要去除符号表的程序,比如刚编译好的程序

符号表就没了
然而,这样又运行不了了。。

在linux上来编译成Mach-O文件,也不行,去不掉符号表

所以可能就是-s没法针对mac的文件起作用罢了

所以,只要不在mac上发布程序就ok

https://groups.google.com/forum/#!topic/golang-nuts/l85r332mKZU
也讨论了这个问题

阅读全文
0 0