GCC链接器:如何在输出节中生成每个文件贡献的报告 [英] GCC Linker : how to generate a report of per file contribution on output sections

查看:39
本文介绍了GCC链接器:如何在输出节中生成每个文件贡献的报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我在尝试链接程序时遇到问题.它报告 .text 无法放入指定的内存区域.显然,源代码太大了,无法链接到有限的内存区域.

Recently I meet a problem when trying to link my program. It report .text can't fit in specified memory region. Obviously the source code grows too large to be linked in limited memory region.

我现在要做的是分析哪个文件对".text"部分的贡献最大,以便可以执行后续代码优化.我尝试了很多方法,但没有成功.

What I want to do now is to analyze which file contribute most significantly to the ".text" section so that follow up code optimization can be performed. I tried many ways but don't make it.

  • nm -s output.elf 给出每个符号的大小,但不要在每个源文件下将符号分组.
  • nm -s file.obj 无法遍历每个目标文件,因为 -fdata-section -ffunction-section -Wl ,所以并非目标文件中的所有内容都将链接到最终输出
  • readelf -s output.elf 给出了文件之间的信息,但是仅列出了每个文件下的符号及其大小.可以编写脚本来求和文件下所有大小的总和,但是总值似乎是错误的,这里的一个明显错误是某些符号可能指向同一内存位置,因此同一内存区域可能要计算多次.
  • nm -s output.elf gives size of each symbol, but don't group the symbol under each source file.
  • nm -s file.obj go through every object file don't work because -fdata-section -ffunction-section -Wl are specified, so not all content in an object file will get linked to final output
  • readelf -s output.elf gives information from file to file, but it simply list symbols under each file and their size. A script can be written to sum all the size under a file, but the total value seems wrong, an obvious error here is some symbols may point to the same memory location, so the same memory region may be calculated many times.

当gcc链接开始工作时,它应该知道从目标文件中提取的内容的所有详细信息,并将其放在输出部分,但似乎没有提供生成详细报告的开关(或者我错过了)什么?)

When gcc link do its work, it should know all the details of what is extracted from a object file and put to the output section, but seems it don't provide a switch to generate a detail report (Or am I missing something?)

有没有可以完成这项工作的工具?

Is there any tool which can do this job?

推荐答案

也许-gc-sections 以及-print-gc-sections 和/或<代码>-放弃打印地图?

如果所有内容都在单独的部分中,则将所有部分作为输入,并列出废弃部分.然后,简单的脚本将生成已用节的列表,它们的大小和文件映射.

If everything is in separate sections, then you have all your sections as input, and list of discarded sections. Then simple script shall produce list of used sections, their size and file mapping.

这篇关于GCC链接器:如何在输出节中生成每个文件贡献的报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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