Next: As Sections, Previous: Secs Background, Up: Sections
ld
deals with just four kinds of sections, summarized below.
ld
treat them as
separate but equal sections. Anything you can say of one section is
true of another.
When the program is running, however, it is
customary for the text section to be unalterable. The
text section is often shared among processes: it contains
instructions, constants and the like. The data section of a running
program is usually alterable: for example, C variables would be stored
in the data section.
ld
must
not change when relocating. In this sense we speak of absolute
addresses being “unrelocatable”: they do not change during relocation.
An idealized example of three relocatable sections follows. The example uses the traditional section names `.text' and `.data'. Memory addresses are on the horizontal axis.
+-----+----+--+ partial program # 1: |ttttt|dddd|00| +-----+----+--+ text data bss seg. seg. seg. +---+---+---+ partial program # 2: |TTT|DDD|000| +---+---+---+ +--+---+-----+--+----+---+-----+~~ linked program: | |TTT|ttttt| |dddd|DDD|00000| +--+---+-----+--+----+---+-----+~~ addresses: 0 ...