将节注入到GNU ld脚本中; binutils版本之间的脚本兼容性. [英] Injecting sections into GNU ld script; script compatibility between versions of binutils.

查看:83
本文介绍了将节注入到GNU ld脚本中; binutils版本之间的脚本兼容性.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建类似问题

I'm building something like in the question How to collect data from different .a files into one array? How to keep sections in .a files with ld script?, i.e. arrays composed during link-time out of elements from different object files.

在我的情况下,有几个数组,每个数组都进入其自己的部分.ld_comp_array_ *,其中*与该数组的名称匹配.然后,我使用ld --verbose获取默认的链接描述文件,并通过将所有这些部分(已排序,以便不同数组的元素不会混合)放入输出部分进行修改:

In my case, there are several arrays, each one going into its own section, .ld_comp_array_*, where * matches the name of the array. Then I take the default linker script using ld --verbose and modify it by putting all these sections (sorted, so that elements of different arrays don't get mixed) into an output section:

KEEP (*(SORT_BY_NAME(.ld_comp_array*)))

一切正常.

然后事情变得有点复杂,因为使用此功能的应用程序可能针对各种平台构建-到目前为止,我已经成功地尝试将AVR Xmega用作目标平台,以及Windows 32位和Linux 32位和64位用于单元测试,并且列表是开放的(不久的将来可能会添加新的平台).

Then things get a tiny bit more complicated, because application(s) using this feature may be built for various platforms - so far, I've successfully tried AVR Xmega as target platform, as well as Windows 32-bit and Linux 32- and 64-bit for unit testing, and the list is open (new platforms are likely to be added in near future).

但是,对于每个特定平台,默认的链接程序脚本与在其他平台上不同,并且当前我手动插入.ld_comp_array *部分-是否可以自动进行?我想到的唯一解决方案是解析默认脚本并粘贴上面的输入节描述,但这似乎太繁琐了.

However, for each particular platform the default linker scripts is different than on other platforms, and currently I insert the .ld_comp_array* sections manually - would it be possible to do it somehow automatically? The only solution I thought of was parsing the default script and pasting the above input section description, but this seems way too heavy.

如果没有相对简单的解决方案,我可以手动完成,但是我不确定从本地版本ld获得的默认脚本是否会在不同版本的binutils上中断.任何人都可以澄清这是否安全吗?

I could keep it done manually if there's no relatively simple solution, but I'm not sure if the default scripts obtained from a local version of ld may break on different version of binutils. Can anyone clarify whether this is safe or not?

如果可以自动完成,假设数组应该是不可变的",是否总是将输入节规范始终直接注入" .text节中可以吗?

In case it can be done automatically, is it ok to "inject" the input section specification always directly into .text section, assuming arrays are supposed to be "immutable"?

推荐答案

我找到了一个令人满意的解决方案. GNU ld具有INSERT选项,该选项使外部支持的脚本不会覆盖默认脚本,而只是在相对于默认脚本中存在的某些部分的位置添加新部分.

I found a satisfying solution for that problem. GNU ld has the INSERT option which makes the externally supported script not override the default script, but simply add new section at position relative to some section that exists in the default script.

因此,就我而言,传递给链接器的脚本可能很简单:

So in my case, the script passed to the linker may be as simple as:

SECTIONS
{
  .rodata.ld_comp_array :
  {
    *(SORT_BY_NAME(.ld_comp_array*))
  }
}
INSERT AFTER .rodata;

有关INSERT选项的更多信息: http://sourceware. org/binutils/docs/ld/Miscellaneous-Commands.html#Miscellaneous-Commands

More on the INSERT option: http://sourceware.org/binutils/docs/ld/Miscellaneous-Commands.html#Miscellaneous-Commands

这篇关于将节注入到GNU ld脚本中; binutils版本之间的脚本兼容性.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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