upxupx -9本例中的程序是golang写的一个自用的ssh tunnel代理及端口转发程序
本例中用到的主要编译选项说明如下:
-ldflags 'flag list'
- '-s -w': 压缩编译后的体积
- -s: 去掉符号表
- -w: 去掉调试信息,不能gdb调试了
- -trimpath:删除Go编译文档的GOPATH信息
- 编译选项及文件大小
CGO_ENABLED=0 GOARCH=amd64 go build -v -a -ldflags -s -installsuffix cgo -trimpathCGO_ENABLED=0 GOARCH=amd64 go build -v -a -ldflags "-s -w" -installsuffix cgo -trimpath-ldflags "-s -w"-ldflags -supx-ldflags -s -wupx- 运行内存占用大小
- 不压缩情况下初始启动内存占用大小17.1m
- upx压缩后内存占用28.5m,观察了一段时间内存并没有降下来
- 总结
在我的机器上(mac mini 2020 m1 16G)上的运行情况看,压缩确实可以大大减小文件大小,但是内存占用高了许多。对于我来说,比起文件大小占用的硬盘空间,我更在乎运行时的内存占用,你呢?
-ldflags "-s -w" upx63302 segmentation fault /path/to/your/app