Wiki

Clone wiki

chocos / ELF sekcje

Info about ELF format.

Wykorzystywane przez nas

.text

kod (instrukcje) programu

.data

zmienne globalne RAM zainicjalizowane

.bss

zmienne globalne RAM zerowe lub niezainicjalizowane

.rodata

zmienne stałe - TODO: dlaczego nie używamy tego? Stałe są w sekcji .text?

.got

Global Offset Table

Wykorzystywane przez nas niestandardowe

.syscalls

TBD

.header

TBD

static const oC_Program_Header_t ProgramHeader __attribute__ ((section (".header"))) = {
                .HeaderSize                  = sizeof(oC_Program_Header_t) ,
                .SectionsDefinitionSize      = sizeof(oC_Program_Sections_t) ,
                .SystemCallDefinitionSize    = sizeof(oC_SystemCall_t) ,
                .MagicString                 = PROGRAM_HEADER_MAGIC_STRING ,
                .Version                     = oC_VERSION ,
                .MachineName                 = TO_STRING(MACHINE_NAME) ,
                .SystemCalls                 = SystemCalls ,
                .NumberOfSystemCalls         = oC_ARRAY_SIZE(SystemCalls) ,
                .ProgramRegistration = {
                    .Name              = TO_STRING(oC_PROGRAM_NAME) ,
                                                                             .Priority          = 0 ,
                                                                             .MainFunction      = MainFunction ,
                                                                             .StdInName         = TO_STRING(oC_STDIN),
                                                                             .StdOutName        = TO_STRING(oC_STDOUT),
                                                                             .StdErrName        = TO_STRING(oC_STDERR),
                                                                             .HeapMapSize       = HEAP_MAP_SIZE,
                                                                             .ThreadStackSize   = PROCESS_STACK_SIZE,
                    #ifdef ALLOCATION_LIMIT
                                                                             .AllocationLimit   = ALLOCATION_LIMIT,
                    #else
                                                                             .AllocationLimit   = 0 ,
                    #endif
                    #ifdef TRACK_ALLOCATION
                                                                             .TrackAllocations  = true,
                    #else
                                                                             .TrackAllocations  = false,
                    #endif
                    #ifdef ARGUMENTS_FORMAT_FILE
                                                                             .ArgumentsFormatFilePath = TO_STRING(ARGUMENTS_FORMAT_FILE),
                    #else
                                                                             .ArgumentsFormatFilePath = NULL,
                    #endif
                } ,
};

.sections

eeeee.png

Niewykorzystywane przez nas

Relocation table

Tablica relokacji jest tworzona przed linkowaniem i uzupełniana w trakcie linkowania. Tablic relokacji może być więcej niż 1 i jest zawsze ściśle powiązana z inną sekcją (np. rel.text). Są oznaczone w headerze typem SHT_REL

Składa się ona z wpisów o strukturze:

uint32_t offset  // offset od początku sekcji, ale też może być offset w GOT
uint32_t info    // W jednej zmiennej 2 dane: typ + indeks w symbol table (symtab)

Po zbudowaniu takiego kodu (Źródło) :

int global_linkage_file_scope_var = 1;
extern int extern_file_scope_var;
static int static_file_scope_defined_var = 3;

extern int extern_function(int p1);

int main(){
        int local_var = extern_function( extern_file_scope_var) + extern_function(static_file_scope_defined_var);
        return local_var;
}
Odczyt pliku obiektowego (arm-none-eabi-readelf -r main11.o) pokaże wynik:

Relocation section '.rel.text' at offset 0x288 contains 4 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0000000c  00000d0a R_ARM_THM_CALL    00000000   extern_function
00000018  00000d0a R_ARM_THM_CALL    00000000   extern_function
0000002c  00000e02 R_ARM_ABS32       00000000   extern_file_scope_var
00000030  00000302 R_ARM_ABS32       00000000   .data

Type jest wyciągany z uint32_t info z tej struktury.

.plt

plt dynamic linker.png

.stab & .stabstr

Symbole debuggera i tego typu informacje

.strtab

.symtab

Struktura identyczna jak sekcji .dynsym:

ffffffff.png ggggg.png W powyższym przykładzie st_shndx wskazuje indeks sekcji z tablicy hederów sekcji, która zawiera offset sekcji (tu konkretnie .data). st_value zawiera offset w tej sekcji.

.dynstr

Nazwy symboli z sekcji .dynsym - tablica stringów (NULL-terminated)

.dynsym

typedef struct
{
    oC_Elf_Word_t       NameIndex;                          //!< Index of symbol name into the object file symbol string table
    oC_Elf_Addr_t       Value;                              //!< This member gives the value of the associated symbol
    oC_Elf_Word_t       Size;                               //!< Number of bytes contained in the object
    uint8_t             Info;                               //!< Symbol type and binding attributes
    uint8_t             Other;                              //!< Reserved for future use
    oC_Elf_Half_t       Index;                              //!< Every symbol table entry is defined in relation for some section. This member holds the relevant section header table index
} oC_Elf_SymbolTableEntry_t;
NameIndex - indeks nazwy z .dynstr

Value - wartość powiązana lub zero

Other - jest zerowe - nie ma zdefiniowanego znaczenia

Index - sekcja :

cccc.png

ddddd.png

Updated