Home > Back-end >  ELF section identification
ELF section identification

Time:02-25

In an ELF executable file, I over-wrote all the section names by zero-valued bytes. Even then, the file can be linked and executed correctly. How does the OS identify various sections like the symbols-table, etc. in the file? I was under the impression that the section names serve this purpose. A related question is that what is the use of section names then?

CodePudding user response:

I over-wrote all the section names ...

... the file can be linked ... correctly.

Unlike the object files used in 32-bit Windows, the section names in ELF object files are ignored if no linker script is used.

Each "PROGBITS" section contains flags that specify if the section is writeable, executable and/or not even part of the image (debug information).

(Actually, the object files used by Windows also have such flags, but they are typically set to 0 and the section name is used to distinguish between code and data sections.)

For other section types (such as symbol tables) it is clear how they have to be handled anyway.

... the file can be ... executed correctly.

For executable files and shared libraries, the sections are ignored anyway. Instead, the "program headers" of the file are used.

A "program header" tells the OS that a certain address range in the file must be loaded to memory. A "program header" may cover multiple sections. And "program headers" don't have names.

Example:

Sections:
    Name       Address    Offset in file    Length
    .text      0x10100    0x100             0x30    read-only
    .rodata    0x10130    0x130             0x20    read-only
    .data      0x20250    0x150             0x10    read-write
    .sdata     0x20260    0x160             0x10    read-write

Program headers:
    Address    Offset in file     Length
    0x10100    0x100              0x50     read-only
    0x20250    0x150              0x20     read-write
  • Related