Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relocatable symbols in ELF format (assembly language)

Tags:

assembly

gnu

elf

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.

like image 803
gagneet Avatar asked Dec 06 '08 18:12

gagneet


People also ask

What is relocatable load format?

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.

What is ELF in assembly?

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.

Is an object file an ELF file?

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.


1 Answers

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.

like image 103
user43983 Avatar answered Nov 28 '22 12:11

user43983