Elf sections

Just covering some findings on the usage of elf sections in AMD64 machine code stored in well, elf's. While you can call a section almost anything you want, there are some standard sections a compiler/linker uses. A complete description of all sections doesn't exist according to search engines, but GNU readelf appears to at least partly document all default sections.

Where did this desire to know more come from? Well, someone on irc was wondering if an elf was statically or dynamically linked, despite being built as static, since some tools reported it as static, and some reported as it containing dynamic sections. As it turns out, it seems that the compiler/linker decided to use the .dynamic section (as it felt like it), despite that section name really being intended for setting for the usage of dynamic library.

Running the program and checking strace did show that the elf was indeed static, so that section name was misleading. This left me with a desire to know what the standard section names and usage was. My findings are below:

Section name Type
.interp PROGBITS - Appears to be machine code.
.note.ABI-tag NOTE - A note for some ABI version.
.gnu.hash GNU_HASH - Contains a version string with gnu in the name.
.dynsym DYNSYM - An offset into .dynstr, where the name of external symbols can be found. Not used in static elfs.
.dynstr STRTAB - Strings of external symbols. Not used in static elfs.
.gnu.version VERSYM - Another version string with GNU in the name.
.gnu.version_r VERNEED - Needed version of something.
.rela.dyn RELA.
.rela.plt RELA.
.init PROGBITS - Machine code for init?
.plt PROGBITS.
.plt.got PROGBITS.
.text PROGBITS - Where the main program is located, containing _start, main and any other function.
.fini PROGBITS - Execute on finishing program execution?
.rodata PROGBITS - Initialised data that is read only.
.eh_frame_hdr PROGBITS - A header of .eh_frame?
.eh_frame PROGBITS - Appears to contain exception unwinding and source language information.
.init_array INIT_ARRAY - The init array.
.fini_array FINI_ARRAY - The finish(?) array whatever that is.
.dynamic DYNAMIC - Contains refrences to .dynstr via .dynsym, which the dynamic loader interprets to find which libraries to load. May be used by static elfs for some other unknown purpose.
.got PROGBITS.
.got.plt PROGBITS.
.data PROGBITS - Contains initalized data for reading and writing. Jmp here for execution if you dare.
.bss NOBITS - Contains allocated uninitalised data.
.comment PROGBITS - Probably something for debugging.
.symtab SYMTAB - A listing of the available functions.
.strtab STRTAB.
.shstrtab STRTAB.