Linker and Libraries Guide

Generating the Output Image

After all input file processing and symbol resolution is completed with no fatal errors, the link-editor can start generating the output file image. The link-editor establishes what additional sections must be generated to complete the output file image. These include the symbol tables that contain local symbol definitions from the input files, together with the global and weak symbol information that has been collected in its internal symbol table.

Also included are any output relocation and dynamic information sections required by the runtime linker. After all the output section information has been established, the total output file size is calculated and the output file image is created accordingly.

When building a dynamic executable or shared object, two symbol tables are usually generated. The .dynsym, and its associated string table .dynstr, contains only global, weak, and section symbols. These sections become part of the text segment that is mapped as part of the process image at runtime. This allows the runtime linker to read these sections and perform any necessary relocations.

The .symtab, and its associated string table .strtab, contain all the symbols collected from the input file processing. These sections are not mapped as part of the process image, and can even be stripped from the image using the link-editor's -s option, or after the link-edit using strip(1).

During the generation of the symbol tables, reserved symbols are created. These have special meaning to the linking process and should not be defined in your code:

_etext

The first location after the text segment.

_edata

The first location after initialized data.

_end

The first location after all data.

_DYNAMIC

The address of the dynamic information section (the .dynamic section).

_END_

The same as _end, but the symbol has local scope (see _START_).

_GLOBAL_OFFSET_TABLE_

The position-independent reference to a link-editor supplied table of addresses (the .got section). This table is constructed from position-independent data references occurring in objects that have been compiled with the -K pic option (see "Position-Independent Code" for more information).

_PROCEDURE_LINKAGE_TABLE_

The position-independent reference to a link-editor supplied table of addresses (the .plt section). This table is constructed from position-independent function references occurring in objects that have been compiled with the -K pic option (see "Position-Independent Code" for more information).

_START_

The first location within the text segment. The symbol has local scope, and together with _END_, provides a means of establishing an objects address range.

If the link-editor is generating an executable, it looks for additional symbols to define the executable's entry point. If a symbol was specified using the link-editor's -e option, it is used. Otherwise the link-editor looks for the reserved symbol names _start, and then main. If none of these symbols exists, the first address of the text segment is used.

Having created the output file, all data sections from the input files are copied to the new image. Any relocations specified in the input files are applied to the output image. Any new relocation information that must be generated, together with all the other link-editor generated information, is also written to the new image.