简体   繁体   English

链接器(ld)ELF问题

[英]Linker (ld) ELF Questions

I have an issue with an ELF file generated by the GNU linker ld. 我对GNU链接器ld生成的ELF文件有问题。

The result is that the data section (.data) gets corrupted when the executable is loaded into memory. 结果是,将可执行文件加载到内存中时,数据节(.data)损坏。 The corruption to the .data section occurs when the loader performs the relocation on the .eh_frame section using the relocation data (.rela.eh_frame). 当加载程序使用重定位数据(.rela.eh_frame)对.eh_frame节执行重定位时,.data节将发生损坏。

What happens is that this relocation causes seven writes that are beyond the .eh_frame section and over-write the correct contents of the .data section which is adjacent to the top of the .eh_frame section. 发生的情况是,此重定位导致七次超出.eh_frame节的写入,并覆盖了与.eh_frame节顶部相邻的.​​data节的正确内容。

After some investigation, I believe the loader is behaving correctly, but the ELF file it has been given contains an error. 经过一番调查,我相信加载程序的运行情况正确,但是给出的ELF文件包含错误。

But I could be wrong and wanted to check what I've found so far. 但是我可能错了,想要检查到目前为止我发现的内容。

Using readelf on the ELF file, it can be seen that seven of the entries in the .rela.eh_frame section contain offsets that are outside (above) the range given by readelf for the .eh_frame section. 在ELF文件上使用readelf,可以看到.rela.eh_frame节中的七个条目包含的偏移量超出了readelf为.eh_frame节指定的范围。 ie The seven offsets in .rela.eh_frame are greater than the length given for .eh_frame. 即.rela.eh_frame中的七个偏移量大于为.eh_frame指定的长度。 When these seven offsets are applied in the relocation, they corrupt the .data section. 在重定位中应用这七个偏移量后,它们将破坏.data节。

So my questions are: 所以我的问题是:

(1) Is my deduction that relocation offsets should not be greater than the length of the section to which they apply? (1)我是否推断搬迁补偿不应该大于其适用部分的长度? And therefore the ELF file that has been generated is in error? 因此,已生成的ELF文件有错误吗?

(2) What are people's opinions on the best way of proceeding to diagnose the cause of the incorrect ELF file? (2)人们对继续诊断错误ELF文件原因的最佳方法有何看法? Are there any options to ld that will help, or any options that will remove/fix the .eh_frame and it's relocation counterpart .rela.eh_frame? 是否有ld的任何选项会有所帮助,或者是否有任何选项会删除/修复.eh_frame及其相对应的.rela.eh_frame?

(3) How would I discover what linker script is being used when the ELF file is generated? (3)生成ELF文件时,如何发现正在使用的链接描述文件?

(4) Is there a specific forum where I might find a whole pile of linker experts who would be able to help. (4)是否有一个特定的论坛,在这里我可以找到一大堆可以提供帮助的链接专家。 I appreciate this is a highly technical question and that many people may not have a clue what I'm talking about! 我赞赏这是一个高度技术性的问题,很多人可能不知道我在说什么!

Thanks for any help! 谢谢你的帮助!

The .eh_frame section is not supposed to have any run-time relocations. .eh_frame节不应具有任何运行时重定位。 All offsets are fixed when the link editor is run (because the object layout is completely known at this point) and the ET_EXEC or ET_DYN object is created. 运行链接编辑器时,所有偏移量都是固定的(因为此时完全了解对象布局)并创建了ET_EXECET_DYN对象。 Only ET_REL objects have relocations in that section, and those are never seen by the dynamic linker. 在该部分中只有ET_REL对象具有重定位,并且动态链接程序从不会看到这些重定位。 So something odd most be going on. 所以最奇怪的事情正在发生。

You can ask such questions on the binutils list or the libc-help list (if you use the GNU toolchain). 您可以在binutils列表或libc-help列表中提出此类问题(如果使用GNU工具链)。

EDIT It seems that you are using a toolchain configured for ZCX exceptions with a target which expects SJLJ exceptions. 编辑似乎您正在使用为ZCX异常配置的工具链,并且其目标期望为SJLJ异常。 AdaCore has some documentation about his: AdaCore有一些有关他的文档:

It doesn't quite say how t switch to the SJLJ-based VxWorks 5 toolchain. 并没有说如何切换到基于SJLJ的VxWorks 5工具链。 It is definitely not a matter of using the correct linker script. 绝对不是使用正确的链接程序脚本的问题。 The choice of exception handling style affects code generation, too. 异常处理方式的选择也会影响代码生成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM