Quote:
Originally Posted by ngpbalaji
can u explain me for any of one particular platform ?
This is for the Un*x platforms; it's a bit of a simplification but here goes:
when your linker links one or more compiled translation units (.o or .obj files)
it divides it all up in a bunch of segments:
1) the 'text' segment(s) where the actual machine code is stored; the loader
relocates all relative addresses to real memory addresses.
2) the 'data' segment; this segment has all the initialized global data in it; again
the loader takes care that every pointer or whatever points to the initialized stuff
points to the correct location in memory.
3) the 'rodata' segment (optionally): this segment contains all data that is supposed
to be 'ro' (read only).
4) the 'bss' segment (block started by symbol); this segment contains all
uninitialized data and logically speaking this segment contains all 0s (zeros).
This segment can be large and is usually not present in the linked file, i.e.
just a block of zeros in memory will be created by the loader.
5) the 'stack' segment; optionally the linked file specifies the size of the stack.
This was very important in the old days where memory was not present by the
giga bytes. Nowadays a stack can grow without limitation.
6) the 'reloc' (relocation) segments; these segments tell the loader which addresses
to adjust from relative addresses to real memory addresses. If the executable
for is dynamically linkable (.so or .dll file) these segments also contain the relative
addresses of the objects (data and code) that have exported linkage, (can be
called as a .so or .dll object.
7) the 'heap'; this segment is just like the stack not physically present in the
executable file. Just like the stack segment it can optionally specify the size
of the heap in memory.
All these segments (and a bit more) make up an executable file. The format of
those files is standardized as either a coff (common object file format) file or
an elf (extensible link format) file. I think (not sure though) that Microsoft uses
the coff format or their proprietary variation thereof.
kind regards,
Jos