Description:
Where does each variable go? Four C globals, three sections.
int a = 5 goes to .data
int b = 0 goes to .bss
const int c = 7 goes to .rodata
char d[] = "hi" goes to .data
.data holds initialized, writable globals, so the value is stored in the executable. .bss holds zero-initialized globals: the file only records the size and the loader provides zeroed memory, so it takes no file space. .rodata holds read-only data such as const globals and string literals. char d[] is a writable array initialized from the literal, so it lives in .data.
Checked with nm -S and objdump -t on linked x86-64 ELF executables: GCC 14.2 and Clang 19.1.7, -O0 to -Os, PIE and non-PIE (20 builds, same result).
References:
GCC code generation options: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html
ELF gABI special sections: https://www.sco.com/developers/gabi/latest/ch4.sheader.html
elf(5) man page: https://man7.org/linux/man-pages/man5/elf.5.html
Follow @cypherlarp for daily dev and crypto Shorts.
Support cypherlarp: https://buymeacoffee.com/cypherlarp
#c #clang #gcc #linux #embedded #programming #compilers #shorts #reels
Share this link via
Or copy link























