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.
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.