查询 -ffunction-section &gcc 的 -fdata-sections 选项 [英] Query on -ffunction-section & -fdata-sections options of gcc

查看:22
本文介绍了查询 -ffunction-section &gcc 的 -fdata-sections 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下在 GCC 页面中提到的函数节和数据节选项:

<块引用>

-ffunction-sections-fdata-sections

如果目标支持任意部分,则将每个函数或数据项放入输出文件中自己的部分.函数的名称或数据项的名称决定了输出文件中部分的名称.在链接器可以执行优化以改进指令空间中引用的局部性的系统上使用这些选项.大多数使用 ELF 对象格式和运行 Solaris 2 的 SPARC 处理器的系统都具有具有此类优化的链接器.AIX 将来可能会有这些优化.

仅当这样做有显着好处时才使用这些选项.当您指定这些选项时,汇编器和链接器将创建更大的目标文件和可执行文件,而且速度也会变慢.指定此选项,如果同时指定此选项和 ​​-g,则调试可能会出现问题.

我的印象是这些选项将有助于减小可执行文件的大小.为什么这个页面说它会创建更大的可执行文件?我错过了什么吗?

解决方案

当使用这些编译器选项时,您可以添加链接器选项 -Wl,--gc-sections 将删除所有未使用的代码.

The below mentioned in the GCC Page for the function sections and data sections options:

-ffunction-sections
-fdata-sections

Place each function or data item into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section's name in the output file. Use these options on systems where the linker can perform optimizations to improve locality of reference in the instruction space. Most systems using the ELF object format and SPARC processors running Solaris 2 have linkers with such optimizations. AIX may have these optimizations in the future.

Only use these options when there are significant benefits from doing so. When you specify these options, the assembler and linker will create larger object and executable files and will also be slower. You will not be able to use gprof on all systems if you specify this option and you may have problems with debugging if you specify both this option and -g.

I was under the impression that these options will help in reducing the executable file size. Why does this page say that it will create larger executable files? Am I missing something?

解决方案

When using those compiler options, you can add the linker option -Wl,--gc-sections that will remove all unused code.

这篇关于查询 -ffunction-section &amp;gcc 的 -fdata-sections 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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