如何彻底剥离可执行文件

发布于 2024-10-01 21:56:10 字数 202 浏览 5 评论 0原文

我想尽可能多地剥离 - 在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

时光暖心i 2024-10-08 21:56:10

如果其他一切都失败了,您可以阅读文档,从 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.

别再吹冷风 2024-10-08 21:56:10

使用 -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.

晚风撩人 2024-10-08 21:56:10

我会查看这篇很棒的文章,该文章深入探讨了如何使 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

·深蓝 2024-10-08 21:56:10
strip -R .comment
gcc -Os elf.c

这两个可能会有所帮助。

strip -R .comment
gcc -Os elf.c

Those two might help.

A君 2024-10-08 21:56:10

要删除所有符号,请使用 -s--strip-all

to strip all symbols, use -s or --strip-all

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文