There is this output of objdump on some object file:
$ objdump -h main.o
main.o: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000000b 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .data 00000000 00000000 00000000 00000040 2**2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000040 2**2
ALLOC
3 .note.GNU-stack 00000000 00000000 00000000 00000040 2**0
CONTENTS, READONLY, CODE
What do these flags CONTENTS, ALLOC, LOAD and so on mean?
What you see is the interpretation of the combination of ELF segment flags, section type and section flags for each section in the object file.
LOADmeans that the section resides in a loadable segment, i.e. its content could be read from the file into memory when a process is createdSection flags are well documented in the Chapter 4 of the System V Application Binary Interface, although under slightly different names from what
objdumpshows.CODEmeans that the section contains executable code; it is indicated by theSHF_EXECINSTRflag in the section headerDATAmeans that the section is not executable but is writable, indicated by the presence of theSHF_WRITEflagREADONLYmeans that the section is neither executable nor writtable and should be placed in read-only memory pagesALLOCmeans that the section occupies memory, e.g. memory pages are actually allocated to hold the section content when a process is created, indicated by theSHF_ALLOCflag. Some sections, e.g. those containing debug information, are not read into memory during normal program execution and are not marked asALLOCto save memory.Sections of type
SHT_PROGBITShave corresponding content in the file and are shown asCONTENTS. Some sections does not have corresponding content in the file, e.g. the.bsssection, which is of typeSHT_NOBITS.The
.textsection contains the program executable code. It is show asCONTENTSsince it is of typeSHT_PROGBITS. Memory should be reserved for this section since it isALLOCand its contents should be loaded from the file since it is placed in aLOAD-able segment. Program code is generally non-modifiable and hence the section is placed in read-only memory. It contains instructions that are to be executed and hence theCODEflag.Initialised variables with static storage class go into the
.datasection. Their initial values are stored in the file and read from there as the process is created. In C/C++ these are global variables, static local variables and C++ static member variables that are initialised appropriately, e.g.static int a = 10;. Fortran places initialisedSAVE-d variables andCOMMONblocks, which are given intiial value with a blockDATAstatement there.The
.bsssection (historic name, abbreviation from Block Started by Symbol) is the most simple one. It holds uninitialised variables with static storage class. It is a section of typeSHT_NOBITSand takes no space in the file. Memory isALLOC-ated for it but nothing is read from the file to prepopulate the memory – it just stays all zeroes as delivered by the kernel memory allocator.Constants usually go into the
.rodatasection (not present in your example), which looks like.databut is not marked as writable and is thus shown asREADONLY.