What sections can be present in ELF files?
- .text stores machine instructions.
- .rodata stores read only data.
- .data stores initialized global variables.
- .bss stores readable and writable global variables, initialized to zero. There is no need to dump their contents into an object file as they are all filled with zeros anyway. Instead, a total section size is stored. An operating system may know faster ways of initializing such memory than zeroing it manually. In assembly, you can put data here by placing
resb
,resw
, and similar directives after the section .bss. - .rel.text stores relocation table for the .text section. It is used to memorize places where a linker should modify .text after choosing the loading address for this specific object file.
- .rel.data stores a relocation table for data referenced in module.
- .debug stores a symbol table used to debug program. If the program was written in C or C++, it will store information not only about global variables (as .symtab does) but also about local variables.
- .line defines correspondence with pieces of code and line numbers in source code. We need it because the correspondence between lines of source code in higher-level languages and assembly instructions is not straightforward. This information allows one to debug a program in a higher-level language line by line.
- .strtab stores character strings. It is like an array of strings. Other sections, such, as .symtab and .debug, use not immediate strings but their indices in .strtab.
- .symtab stores a symbol table. Whenever a programmer defines a label, NASM will create a symbol for it.