We are developing a port of the GNU Assembler for a client architecture. Now the problem being faced is that:
我们正在为客户端架构开发GNU Assembler的端口。现在面临的问题是:
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?
如果指令的立即操作数是涉及多个可重定位符号的表达式,那么如何在elf格式的输出文件中处理它。在这种情况下产生的搬迁信息是什么?
For example:
j label1 + label2
where label1 and label2 are defined in relocatable sections, they might be the same sections or different relocatable sections.
其中label1和label2在可重定位部分中定义,它们可能是相同的部分或不同的可重定位部分。
3 个解决方案
#1
7
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.
ELF本身并不了解说明。它知道指令中符号偏移的特定编码。在汇编程序中,您需要输出两个重定位记录,每个记录具有相应的[地址,类型,符号]三元组,以正确修补指令的该部分。链接器甚至不一定知道这两个记录指向同一条指令。
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.
ELF重定位类型完全取决于CPU(或者更确切地说,取决于ISA),因此您可以*定义新架构所需的任何重定位。
It's hard to be more specific without details of the instruction encoding.
没有指令编码的细节,很难更具体。
#2
0
I know jack about ELF and only a little more about linking but...
我知道关于ELF的杰克和关于链接的更多信息......
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.)
OTOH的问题可能是j的格式会根据标签的位置而改变吗?如果是这样的话,我认为你已经沉没了,因为连接器不够聪明,不能做那种事情(ADA构建系统IIRC可能比大多数人更智能,所以你可能会看到它。)
#3
0
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.
Objdump可能能够显示可执行文件或目标文件的重定位表,但我不知道标记。
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.
我的建议是尝试挖掘x86(或其他CISC)指令,该指令执行类似于客户端arch所做的操作,并查看汇编/链接时生成的重定位。
#1
7
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.
ELF本身并不了解说明。它知道指令中符号偏移的特定编码。在汇编程序中,您需要输出两个重定位记录,每个记录具有相应的[地址,类型,符号]三元组,以正确修补指令的该部分。链接器甚至不一定知道这两个记录指向同一条指令。
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.
ELF重定位类型完全取决于CPU(或者更确切地说,取决于ISA),因此您可以*定义新架构所需的任何重定位。
It's hard to be more specific without details of the instruction encoding.
没有指令编码的细节,很难更具体。
#2
0
I know jack about ELF and only a little more about linking but...
我知道关于ELF的杰克和关于链接的更多信息......
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.)
OTOH的问题可能是j的格式会根据标签的位置而改变吗?如果是这样的话,我认为你已经沉没了,因为连接器不够聪明,不能做那种事情(ADA构建系统IIRC可能比大多数人更智能,所以你可能会看到它。)
#3
0
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.
Objdump可能能够显示可执行文件或目标文件的重定位表,但我不知道标记。
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.
我的建议是尝试挖掘x86(或其他CISC)指令,该指令执行类似于客户端arch所做的操作,并查看汇编/链接时生成的重定位。