Relocatable Object Files

Fig: Typical ELF relocatable object file
Components of ROF:
-
ELF header:
- begins with 16-byte sequence that descries word size and byte ordering of the system that's generating the file
- the rest contains information that allows the linker to parse and interpret the object file like size of ELF header, the type of object file, the machine type and the offset of #^0cb667.
-
Section Header Table
- Location and sizes of various sections are described here.
- Everything else is sandwiched between ELF header and this.
-
.text
-Machine code of the compiled program
-
.rodata:
-Read only data like format strings in printf statements and jump tables for switch statements.
-
.data:
- Initialized global and static C variables.
- NOTE: Local C vars are mainitaied at run time on the stack and do not appear in either .data or .bss section.
-
.bss:
- Contains all uninitialized global and static variables along with any that are initialized to zero.
- Occupies no actual place and is just a place holder
- At runtime these stuff are initialized to zero
-
.symtab:
- It's a table with info about functions and global vars that are defined and referenced in the program.
- Every Relocatable Object Files has it by default don't need -g for this to appear, unless u do STRIP command to remove it
- Does not contain
-
.rel. text:
- list of locations in .text section that needs to be modified when linker combines this object file with others i.e any instructions that call on external function or references some global variables
- NOT needed for local function and not put in Executable Object Files
-
.rel. data:
- Relocation info for any any global vars that are referenced or defined by this module
-
.debug:
- debugging symbol table for local vars and typedefs defined in the program and original C source file.
- need -g to enable this
-
.line:
- Mapping between the line numbers in original C source program and machine code instructions in .text section.
- need to invoke compiler driver with -g for this
-
.strtab:
- A sequence of null terminated character strings.
- A string table fro symbols table in the .symtab and .debug section.
- ALso has section names in section headers.