ELF 针对本地部分重新定位

发布于 2024-11-27 00:24:51 字数 585 浏览 1 评论 0原文

我正在尝试创建自己的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洛阳烟雨空心柳 2024-12-04 00:24:51

显然我在符号表的 sh_info 字段中有一个 off-by-1 。我在 GOLD 的帮助下弄清楚了这一点,它不仅提供了段错误,还提供了更多信息:

    gold: internal error in do_layout, at ../../gold/object.cc:1493

or

    gold: error: invalid STB_LOCAL symbol in external symbols
    gold: error: unsupported symbol binding 0
    gold: error: invalid STB_LOCAL symbol in external symbols
    gold: error: unsupported symbol binding 0
    gold: error: test.o: multiple definition of ''
    gold: test.o: previous definition here

这帮助我识别出我的本地符号最终出现在“外部符号”中(意味着在“第一个符号的索引之后”)非本地符号”,存储在 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:

    gold: internal error in do_layout, at ../../gold/object.cc:1493

or

    gold: error: invalid STB_LOCAL symbol in external symbols
    gold: error: unsupported symbol binding 0
    gold: error: invalid STB_LOCAL symbol in external symbols
    gold: error: unsupported symbol binding 0
    gold: error: test.o: multiple definition of ''
    gold: test.o: previous definition here

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文