如何彻底剥离可执行文件
我想尽可能多地剥离 - 在 Linux 上:一个 ELF。我只想要运行它所需的东西。
我尝试使用 strip
:
strip --strip-all elf
但它似乎效果不佳:nm
仍然显示很多内容,并且二进制文件仍然很大。
我应该怎么办?
I'd like to strip as much as I can - on Linux: an ELF. I only want in there the stuff I need to run it.
I tried using strip
:
strip --strip-all elf
But it doesn't seem to do a good job: nm
still displays lots of stuff, and the binary is still big.
What should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果其他一切都失败了,您可以阅读文档,从
man strip
开始。说真的,也许您的应用程序有很多符号和代码。在一种极端情况下,最大的尺寸减少将是 rm elf ,但随后您的程序将不再运行。这完全取决于您的程序以及您在其中编写的代码。
作为一个具体的例子,我最近使用了一个大型 C++ 库,其中没有进一步参数的
strip
将大小从 400+mb 减少到大约 28 mb。但随后您无法再链接到它(在其他共享库的上下文中),使其变得有些无用。但是,当使用
strip --strip-unneeded
时,它将大小从 400+ mb 更改为 55 mb,这仍然是相当大的,但允许从其他共享库访问该库。简而言之,我信任
strip
。如果不更改代码,也许您的应用程序无法进一步减少。If everything else fails, you could read the documentation, starting with
man strip
.Seriously, maybe your application has a lot of symbols and code. At one extreme, the biggest size reduction would be
rm elf
but then your program won't run anymore. It all depends on your program and what you coded into it.As a concrete example, I recently worked with a large C++ library where
strip
without further arguments reduced the size from 400+mb to about 28 mb. But then you could not link anymore against it (in the context of other shared libraries), rendering it somewhat useless.But when using
strip --strip-unneeded
, it changed the size from 400+ mb to 55 mb which is still considerable, yet allowed the library to be accessed from other shared libraries.In short, I'd trust
strip
. Maybe your application cannot be reduced any further without code changes.使用 -R 选项进行剥离,您可以剥离所有不需要的部分。另请参阅有关最小 ELF 可执行文件的此。
Using the -R option to strip, you can strip away all sections you don't need. Also look at this regarding minimal ELF executables.
我会查看这篇很棒的文章,该文章深入探讨了如何使 ELF 可执行文件尽可能小。也许它有可以提供帮助的信息!
http://www.muppetlabs.com/~breadbox/software/tiny/teensy .html
I would check out this great article that goes into depth on making an ELF executable as small as possible. Maybe it has info that could help!
http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
这两个可能会有所帮助。
Those two might help.
要删除所有符号,请使用
-s
或--strip-all
to strip all symbols, use
-s
or--strip-all