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

查看:38
本文介绍了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 和/或 <代码>--print-map-discarded?

Perhaps --gc-sections together with --print-gc-sections and/or --print-map-discarded?

如果所有内容都在单独的部分中,那么您将所有部分作为输入,以及丢弃部分的列表.然后简单的脚本将生成使用部分的列表、它们的大小和文件映射.

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天全站免登陆