过程用于降低可执行文件的大小 [英] Process for reducing the size of a executable

查看:155
本文介绍了过程用于降低可执行文件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我产生一个十六进制文件上,我想保持低于32K的ARM处理器上运行。这是目前比大了很多,我想知道,如果有人可能对什么是苗条的最佳方法一些建议下来?

I'm producing a hex file to run on an ARM processor which I want to keep below 32K. It's currently a lot larger than that and I wondered if someone might have some advice on what's the best approach to slim it down?

下面就是我迄今所做


  1. 所以,我跑'大小'它来确定十六进制文件有多大。

  2. 然后'大小'再看看有多大的每个目标文件是链接创建十六进制文件。看来大多数的大小来自外部库。

  3. 然后我用'readelf',看看哪些函数占用的内存最多。

  4. 我寻遍code来看看我是否能对这些函数的调用。

下面就是我遇到问题,有一些功能,我不直接调用(如_vfprintf),我找不到什么叫,所以我可以删除通话(因为我觉得我并不需要它)。

Here's where I get stuck, there's some functions which I don't call directly (e.g. _vfprintf) and I can't find what calls it so I can remove the call (as I think I don't need it).

那么,什么是下一个步骤是什么?

So what are the next steps?

感谢您的帮助。

应对答案:


  • 正如我可以看到有函数被调用它占用了大量的内存。我却无法找到什么调用它。

  • 我要忽略这些功能(如果可能),但我找不到什么称他们!可以从任意数量的库函数我想被调用。

  • 链接器工作根据需要,我想,这不仅包括相关的库文件。你怎么知道,如果正在仅包括相关的功能呢?你可以设置标志或东西是什么?

  • 我使用GCC

推荐答案

常规列表:


  • 确保您有编译器和连接调试选项禁用

  • 编译并与所有大小选项链接打开(-Os在GCC)

  • 运行上的可执行文件

  • 生成映射文件,并检查你的函数的大小。你可以让你的链接器生成地图文件( -M 当使用LD),也可以在最终的可执行文件使用objdump的(请注意,这只会在一个工作剥开可执行!)事实上这并不会解决问题,但它会让你知道最坏的罪犯。

  • 使用纳米来调查,是根据每个目标文件被称为符号。这将有助于找到谁在呼叫功能,你不想被调用。

  • Make sure that you have the compiler and linker debug options disabled
  • Compile and link with all size options turned on (-Os in gcc)
  • Run strip on the executable
  • Generate a map file and check your function sizes. You can either get your linker to generate your map file (-M when using ld), or you can use objdump on the final executable (note that this will only work on an unstripped executable!) This won't actually fix the problem, but it will let you know of the worst offenders.
  • Use nm to investigate the symbols that are called from each of your object files. This should help in finding who's calling functions that you don't want called.

在原来的问题是关于包括唯一的相关功能的子问题。 GCC 将包括用于每个对象文件中的所有功能。以另外一种方式,如果你有一个包含10种功能的目标文件,所有10个功能都包含在可执行文件中,即使一个1实际上是所谓的。

In the original question was a sub-question about including only relevant functions. gcc will include all functions within every object file that is used. To put that another way, if you have an object file that contains 10 functions, all 10 functions are included in your executable even if one 1 is actually called.

标准库(如libc中)将分割功能为许多独立的目标文件,然后将其存档。该可执行文件,然后对存档联系。
通过分割成许多对象文件链接器能够以仅包括实际调用的函数。 (这里假设你静态链接)

The standard libraries (eg. libc) will split functions into many separate object files, which are then archived. The executable is then linked against the archive. By splitting into many object files the linker is able to include only the functions that are actually called. (this assumes that you're statically linking)

有没有理由,你为什么不能做同样的伎俩。当然,你可能会说,如果功能不叫你也许可以删除它们自己。

There is no reason why you can't do the same trick. Of course, you could argue that if the functions aren't called the you can probably remove them yourself.

如果你对静态其他库链接,你可以运行在它们上面列出的工具,也确保他们遵循类似的规则。

If you're statically linking against other libraries you can run the tools listed above over them too to make sure that they're following similar rules.

这篇关于过程用于降低可执行文件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆