ELF 针对本地部分重新定位
我正在尝试创建自己的 ELF .o 文件,在其中我想写出指向其他内存条的内存条。我不想给每个条带一个名称,所以我只是跟踪它们相对于它们所在部分的开头的位置。
因此我创建了一个以下形式的重定位条目:
000000000a50 00090000000b R_X86_64_32S 0000000000000000 .section + a70
位于 a50我们使用 64 位全局指针引用 .section + a70 处的对象。该部分的定义如下:
9: 0000000000000000 0 SECTION LOCAL DEFAULT 6
之前的输出来自 readelf,它实际上假装一切都很好......直到我通过 LD 拉取它,这只是段错误。
我发现,如果我使用 WEAK 类型,它可以工作......但它似乎使用它在所有链接的 .o 文件中找到的第一部分符号作为这种情况下所有重定位的目标。我真的希望它是本地的,所以它应该是本地的。
到目前为止,我的替代方案是在包含此类对象的每个部分的开头创建一个 OBJECT 符号,但这看起来很愚蠢......我做错了什么,还是 LD 中存在错误?
I'm trying to create my own ELF .o files in which I want to write out strips of memory that point at other strips of memory. I don't want to give every strip a name, so I just keep track of their position relative to the start of the section they are in.
So I create a relocation-entry in the form of:
000000000a50 00090000000b R_X86_64_32S 0000000000000000 .section + a70
where at a50 we refer to an object at .section + a70, using a 64bit global pointer. The section is defined using:
9: 0000000000000000 0 SECTION LOCAL DEFAULT 6
The previous output is from readelf and it actually pretends that everything is fine ... until I pull this through LD, which just segfaults.
I found out that if I use a WEAK type that it sorta works... but it seems like it uses the first section symbol it finds in all linked .o files as the target for ALL relocations in that case. I really want it to be local, so LOCAL it should be.
The alternative I have until now is just creating an OBJECT symbol at the beginning of each section that has such objects, but that just seems silly... Am I doing something wrong, or is there a bug in LD?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然我在符号表的
sh_info
字段中有一个 off-by-1 。我在 GOLD 的帮助下弄清楚了这一点,它不仅提供了段错误,还提供了更多信息:or
这帮助我识别出我的本地符号最终出现在“外部符号”中(意味着在“第一个符号的索引之后”)非本地符号”,存储在
sh_info
中)Apparently I had an off-by-1 in the
sh_info
field of the symbol table. I figured it out with the help of GOLD, which is a bit more informative by not just segfaulting but also giving:or
This helped me identify that my local symbols ended up in the "external symbols" (meaning after the "index of the first non-local symbol", stored in
sh_info
)