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.
A relocatable object file holds sections containing code and data. This file is suitable to be linked with other relocatable object files to create dynamic executable files, shared object files, or another relocatable object. A dynamic executable file holds a program that is ready to execute.
ELF sections and the AREA directive In assembly source code, you use the AREA directive to mark the start of a section. ELF sections are independent, named, indivisible sequences of code or data. A single code section is the minimum required to produce an application.
This chapter describes the object file format, called ELF (Executable and Linking Format). There are three main types of object files. A relocatable file holds code and data suitable for linking with other object files to create an executable or a shared object file.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With