ELF 格式的可重定位符号(汇编语言)
我们正在为客户端架构开发 GNU 汇编器的端口。 现在面临的问题是:
如果一条指令的立即操作数是一个涉及多个可重定位符号的表达式,那么在elf格式的输出文件中如何处理它。 这种情况下会产生什么搬迁信息呢?
例如:
j label1 + label2
在可重定位节中定义 label1 和 label2 的情况下,它们可能是相同的节或不同的可重定位节。
We are developing a port of the GNU Assembler for a client architecture.
Now the problem being faced is that:
If an immediate operand to an instruction is an expression involving more than one relocatable symbols, how is it handled in output file in elf format. What will be the relocation information produced in such a case?
For example:
j label1 + label2
where label1 and label2 are defined in relocatable sections, they might be the same sections or different relocatable sections.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我希望每条需要重定位的指令的每个地址都有一个条目。
Objdump 也许能够显示可执行文件或目标文件的重定位表,但我不知道这些标志。
我的建议是尝试挖掘 x86(或其他 CISC)指令,该指令的功能与您的客户端架构类似,并查看当您组装/链接它时会生成哪些重定位。
I would expect one entry per address for every instruction that needs relocation.
Objdump might be able to display the relocation table of an executable or object file, but I don't know the flags offhand.
My suggestion is to try to dig up an x86 (or other CISC) instruction that does something similar to what your client arch does, and see what relocations are generated when you assemble/link it.
我了解 Jack 关于 ELF 的知识,并且只了解一点关于链接的知识,但是...
我希望每个操作数的处理方式与只有一个操作数时的处理方式相同。
OTOH 问题可能是
j
的格式会根据标签的位置而改变? 如果是这样,我认为你已经陷入困境,因为链接器不够聪明,无法做这类事情(ADA 构建系统 IIRC 可能比大多数系统更聪明,所以你可以看看它。)I know jack about ELF and only a little more about linking but...
I would expect that each operand is handled the same way that it would be if there was only one.
OTOH might the issue be that the format for
j
alters depending on where the labels are? If so, I think you're sunk as linkers aren't smart enough to do that sort of thing (the ADA build system IIRC might be smarter than most so you might look at it.)ELF 本身并不了解指令。 它知道指令内符号偏移的特定编码。 在汇编器中,您需要输出两个重定位记录,每个重定位记录都有相应的[地址,类型,符号]三元组,以正确修补指令的该部分。 链接器甚至不一定知道这两个记录指向同一指令。
ELF 重定位类型完全依赖于 CPU(或者更准确地说,依赖于 ISA),因此您可以自由定义新架构所需的任何重定位。
如果没有指令编码的细节,就很难更具体。
ELF doesn't know about instructions, per se. It knows about particular encodings of symbol offsets within instructions. In the assembler, you would need to output two relocation records, each with the corresponding [address,type,symbol] triplet to properly patch that portion of the instruction. The linker wouldn't necessarily even know that these two records point to the same instruction.
The ELF relocation types are completely CPU-dependent (or, to be more precise, ISA-dependent), so you are free to define whatever relocations you need for a new architecture.
It's hard to be more specific without details of the instruction encoding.