Linker and Libraries Guide

Dynamic Section

If an object file participates in dynamic linking, its program header table will have an element of type PT_DYNAMIC. This segment contains the .dynamic section. A special symbol, _DYNAMIC, labels the section, which contains an array of the following structures (defined in sys/link.h):


typedef struct {
        Elf32_Sword d_tag;
        union {
                Elf32_Word      d_val;
                Elf32_Addr      d_ptr;
                Elf32_Off       d_off;
        } d_un;
} Elf32_Dyn;

typedef struct {
        Elf64_Xword d_tag;
        union {
                Elf64_Xword     d_val;
                Elf64_Addr      d_ptr;
        } d_un;
} Elf64_Dyn;

For each object with this type, d_tag controls the interpretation of d_un.

d_val

These objects represent integer values with various interpretations.

d_ptr

These objects represent program virtual addresses. As mentioned previously, a file's virtual addresses might not match the memory virtual addresses during execution. When interpreting addresses contained in the dynamic structure, the runtime linker computes actual addresses, based on the original file value and the memory base address. For consistency, files do not contain relocation entries to correct addresses in the dynamic structure.

To make it simpler for tools to interpret the contents of dynamic section entries, the value of each tag, except for those in two special compatibility ranges, will determine the interpretation of the d_un union. A tag whose value is an even number indicates a dynamic section entry that uses d_ptr. A tag whose value is an odd number indicates a dynamic section entry that uses d_val or that uses neither d_ptr nor d_val. Tags whose values are less than the special value DT_ENCODING and tags whose values fall between DT_HIOS and DT_LOPROC do not follow these rules.

The following table summarizes the tag requirements for executable and shared object files. If a tag is marked mandatory, then the dynamic linking array must have an entry of that type. Likewise, optional means an entry for the tag can appear but is not required.

Table 7-43 Dynamic Array Tags, d_tag

Name 

Value 

d_un 

Executable 

Shared Object 

DT_NULL

0

Ignored 

Mandatory 

Mandatory 

DT_NEEDED

1

d_val

Optional 

Optional 

DT_PLTRELSZ

2

d_val

Optional 

Optional 

DT_PLTGOT

3

d_ptr

Optional 

Optional  

DT_HASH

4

d_ptr

Mandatory 

Mandatory 

DT_STRTAB

5

d_ptr

Mandatory 

Mandatory 

DT_SYMTAB

6

d_ptr

Mandatory 

Mandatory 

DT_RELA

7

d_ptr

Mandatory 

Optional 

DT_RELASZ

8

d_val

Mandatory 

Optional  

DT_RELAENT

9

d_val

Mandatory 

Optional 

DT_STRSZ

10

d_val

Mandatory 

Mandatory 

DT_SYMENT

11

d_val

Mandatory 

Mandatory 

DT_INIT

12

d_ptr

Optional 

Optional 

DT_FINI

13

d_ptr

Optional 

Optional  

DT_SONAME

14

d_val

Ignored 

Optional 

DT_RPATH

15

d_val

Optional 

Optional 

DT_SYMBOLIC

16

Ignored 

Ignored 

Optional 

DT_REL

17

d_ptr

Mandatory 

Optional 

DT_RELSZ

18

d_val

Mandatory 

Optional 

DT_RELENT

19

d_val

Mandatory 

Optional 

DT_PLTREL

20

d_val

Optional 

Optional  

DT_DEBUG

21

d_ptr

Optional 

Ignored 

DT_TEXTREL

22

Ignored 

Optional 

Optional  

DT_JMPREL

23

d_ptr

Optional 

Optional 

DT_BIND_NOW

24

Ignored 

Optional 

Optional 

DT_INIT_ARRAY

25

d_ptr

Optional 

Optional 

DT_FINI_ARRAY

26

d_ptr

Optional 

Optional 

DT_INIT_ARRAYSZ

27

d_val

Optional 

Optional 

DT_FINI_ARRAYSZ

28

d_val

Optional 

Optional 

DT_RUNPATH

29

d_val

Optional 

Optional 

DT_FLAGS

30

d_val

Optional 

Optional 

DT_ENCODINGS

32

Unspecified 

Unspecified 

Unspecified 

DT_PREINIT_ARRAY

32

d_ptr

Optional 

Optional 

DT_PREINIT_ARRAYSZ

33

d_val

Optional 

Optional 

DT_LOOS

0x6000000d

Unspecified 

Unspecified 

Unspecified 

DT_HIOS

0x6ffff000

Unspecified 

Unspecified 

Unspecified 

DT_VALRNGLO

0x6ffffd00

Unspecified 

Unspecified 

Unspecified 

DT_CHECKSUM

0x6ffffdf8

d_val

Optional 

Optional 

DT_PLTPADSZ

0x6ffffdf9

d_val

Optional 

Optional 

DT_MOVEENT

0x6ffffdfa

d_val

Optional 

Optional 

DT_MOVESZ

0x6ffffdfb

d_val

Optional 

Optional 

DT_FEATURE

0x6ffffdfc

d_val

Optional 

Optional 

DT_POSFLAG_1

0x6ffffdfd

d_val

Optional 

Optional 

DT_SYMINSZ

0x6ffffdfe

d_val

Optional 

Optional 

DT_SYMINENT

0x6ffffdff

d_val

Optional 

Optional 

DT_VALRNGHI

0x6ffffdff

Unspecified 

Unspecified 

Unspecified 

DT_ADDRRNGLO

0x6ffffe00

Unspecified 

Unspecified 

Unspecified 

DT_CONFIG

0x6ffffefa

d_ptr

Optional 

Optional 

DT_DEPAUDIT

0x6ffffefb

d_ptr

Optional 

Optional 

DT_AUDIT

0x6ffffefc

d_ptr

Optional 

Optional 

DT_PLTPAD

0x6ffffefd

d_ptr

Optional 

Optional 

DT_MOVETAB

0x6ffffefe

d_ptr

Optional 

Optional 

DT_SYMINFO

0x6ffffeff

d_ptr

Optional 

Optional  

DT_ADDRRNGHI

0x6ffffeff

Unspecified 

Unspecified 

Unspecified 

DT_RELACOUNT

0x6ffffff9

d_val

Optional 

Optional 

DT_RELCOUNT

0x6ffffffa

d_val

Optional 

Optional 

DT_FLAGS_1

0x6ffffffb

d_val

Optional 

Optional 

DT_VERDEF

0x6ffffffc

d_ptr

Optional 

Optional 

DT_VERDEFNUM

0x6ffffffd

d_val

Optional 

Optional 

DT_VERNEED

0x6ffffffe

d_ptr

Optional 

Optional 

DT_VERNEEDNUM

0x6fffffff

d_val

Optional 

Optional 

DT_AUXILIARY

0x7ffffffd

d_val

Unspecified 

Optional 

DT_USED

0x7ffffffe

d_val

Optional 

Optional 

DT_FILTER

0x7fffffff

d_val

Unspecified 

Optional 

DT_LOPROC

0x70000000

Unspecified 

Unspecified 

Unspecified  

DT_SPARC_REGISTER

0x70000001

d_val

Optional 

Optional 

DT_HIPROC

0x7fffffff

Unspecified 

Unspecified 

Unspecified 

DT_NULL

An entry with a DT_NULL tag marks the end of the _DYNAMIC array.

DT_NEEDED

This element holds the string table offset of a null-terminated string, giving the name of a needed dependency. The offset is an index into the table recorded in the DT_STRTAB entry. See "Shared Object Dependencies" for more information about these names. The dynamic array can contain multiple entries with this type. These entries' relative order is significant, though their relation to entries of other types is not.

DT_PLTRELSZ

This element holds the total size, in bytes, of the relocation entries associated with the procedure linkage table. If an entry of type DT_JMPREL is present, a DT_PLTRELSZ must accompany it.

DT_PLTGOT

This element holds an address associated with the procedure linkage table and/or the global offset table.

DT_HASH

This element points to the symbol hash table, described in "Hash Table". This hash table refers to the symbol table indicated by the DT_SYMTAB element.

DT_STRTAB

This element holds the address of the string table, described in the first part of this chapter. Symbol names, dependency names, and other strings required by the runtime linker reside in this table.

DT_SYMTAB

This element holds the address of the symbol table, described in the first part of this chapter, with Elf32_Sym entries for the 32-bit class of files, or Elf64_Sym entries for the 64-bit class of files.

DT_RELA

This element holds the address of a relocation table, described in the first part of this chapter. Entries in the table have explicit addends, such as Elf32_Rela for the 32-bit file class, or Elf64_Rela for the 64-bit file class.

An object file can have multiple relocation sections. When creating the relocation table for an executable or shared object file, the link-editor catenates those sections to form a single table. Although the sections remain independent in the object file, the runtime linker sees a single table. When the runtime linker creates the process image for an executable file or adds a shared object to the process image, it reads the relocation table and performs the associated actions.

If this element is present, the dynamic structure must also have DT_RELASZ and DT_RELAENT elements. When relocation is mandatory for a file, either DT_RELA or DT_REL can occur (both are permitted but not required).

DT_RELASZ

This element holds the total size, in bytes, of the DT_RELA relocation table.

DT_RELAENT

This element holds the size, in bytes, of the DT_RELA relocation entry.

DT_STRSZ

This element holds the size, in bytes, of the string table.

DT_SYMENT

This element holds the size, in bytes, of a symbol table entry.

DT_INIT

This element holds the address of the initialization function, discussed in "Initialization and Termination Functions".

DT_FINI

This element holds the address of the termination function, discussed in "Initialization and Termination Functions".

DT_SONAME

This element holds the string table offset of a null-terminated string, giving the name of the shared object. The offset is an index into the table recorded in the DT_STRTAB entry. See "Shared Object Dependencies" for more information about these names.

DT_RPATH

This element holds the string table offset of a null-terminated search library search path string, discussed in "Shared Objects With Dependencies". The offset is an index into the table recorded in the DT_STRTAB entry. Its use has been superseded by DT_RUNPATH.

DT_SYMBOLIC

This element flags that the object contains symbolic bindings that were applied during its link-edit. See also "The Use of -Bsymbolic". Its use has been superseded by the DF_SYMBOLIC flag.

DT_REL

This element is similar to DT_RELA, except its table has implicit addends, such as Elf32_Rel for the 32-bit file class. If this element is present, the dynamic structure must also have DT_RELSZ and DT_RELENT elements.

DT_RELSZ

This element holds the total size, in bytes, of the DT_REL relocation table.

DT_RELENT

This element holds the size, in bytes, of the DT_REL relocation entry.

DT_PLTREL

This member specifies the type of relocation entry to which the procedure linkage table refers. The d_val member holds DT_REL or DT_RELA, as appropriate. All relocations in a procedure linkage table must use the same relocation.

DT_DEBUG

This member is used for debugging.

DT_TEXTREL

This member's absence signifies that no relocation entry should cause a modification to a non-writable segment, as specified by the segment permissions in the program header table. If this member is present, one or more relocation entries might request modifications to a non-writable segment, and the runtime linker can prepare accordingly. Its use has been superseded by the DF_TEXTREL flag.

DT_JMPREL

If present, this entry's d_ptr member holds the address of relocation entries associated solely with the procedure linkage table. Separating these relocation entries lets the runtime linker ignore them during process initialization, if lazy binding is enabled. If this entry is present, the related entries of types DT_PLTRELSZ and DT_PLTREL must also be present.

DT_POSFLAG_1

If present, this entry's d_val member holds various state flags. These flags are to be applied to the immediately following DT_* entry in the .dynamic section.

DT_BIND_NOW

If present in a shared object or executable, this entry instructs the runtime linker to process all relocations for the object containing this entry before transferring control to the program. The presence of this entry takes precedence over a directive to use lazy binding for this object when specified through the environment or via dlopen(3DL). Its use has been superseded by the DF_BIND_NOW flag.

DT_INIT_ARRAY

This element holds the address of the array of pointers to initialization functions, discussed in "Initialization and Termination Functions".

DT_FINI_ARRAY

This element holds the address of the array of pointers to termination functions, discussed in "Initialization and Termination Functions".

DT_RUNPATH

This element holds the string table offset of a null-terminated search library search path string, discussed in "Shared Objects With Dependencies". The offset is an index into the table recorded in the DT_STRTAB entry.

DT_FLAGS

This element holds flag values specific to the object being loaded. Each flag value will have the name DF_flag_name. Defined values and their meanings are described below. All other values are reserved.

DT_ENCODING

Values greater than or equal to DT_ENCODING and less than DT_LOOS follow the rules for the interpretation of the d_un union described above.

DT_PREINIT_ARRAY

This element holds the address of the array of pointers to pre-initialization functions, discussed in "Initialization and Termination Functions". The DT_PREINIT_ARRAY table is processed only in an executable file; it is ignored if contained in a shared object.

DT_PREINIT_ARRAYSZ

This element holds the size in bytes of the array of pre-initialization functions pointed to by the DT_PREINIT_ARRAY entry. If an object has a DT_PREINIT_ARRAY entry, it must also have a DT_PREINIT_ARRAYSZ entry. As with DT_PREINIT_ARRAY, this entry is ignored if it appears in a shared object.

DT_LOOS - DT_HIOS

Values in this inclusive range are reserved for operating system-specific semantics. All such values follow the rules for the interpretation of the d_un union described above.

DT_SYMINFO

This element holds the address of the SHT_SUNW_syminfo section.

DT_SYMINENT

This element holds the size, in bytes, of a SHT_SUNW_syminfo table entry.

DT_SYMINSZ

This element holds the size, in bytes, of a SHT_SUNW_syminfo section.

DT_VERDEF

Holds the address of the version definition table, described in the first part of this chapter, with Elf32_Verdef entries for the 32-bit class of files, or Elf64_Verdef entries for the 64-bit class of files. See section "Version Definition Section" for more information. Elements within these entries contain indexes into the table recorded in the DT_STRTAB entry.

DT_VERDEFNUM

This element specifies the number of entries in the version definition table.

DT_VERNEED

Holds the address of the version dependency table, described in the first part of this chapter, with Elf32_Verneed entries for the 32-bit class of files, or Elf64_Verneed entries for the 64-bit class of files. See section "Version Dependency Section" for more information. Elements within these entries contain indexes into the table recorded in the DT_STRTAB entry.

DT_VERNEEDNUM

This element specifies the number of entries in the version dependency table.

DT_RELACOUNT

All Elf32_Rela (or Elf64_Rela) R_*_RELATIVE relocations have been placed into a single block and this entry specifies the number of entries in that block. This permits the runtime linker to streamline the processing of RELATIVE relocations.

DT_RELCOUNT

All Elf32_Rel R_*_RELATIVE relocations have been placed into a single block and this entry specifies the number of entries in that block. This permits the runtime linker to streamline the processing of RELATIVE relocations.

DT_AUXILIARY

Holds the string table offset of a null-terminated string that names an object. The offset is an index into the table recorded in the DT_STRTAB entry. Symbols in the auxiliary object will be used in preference to the symbols within this object.

DT_FILTER

Holds the string table offset of a null-terminated string that names an object. The offset is an index into the table recorded in the DT_STRTAB entry. The symbol table of this object acts as a filter for the symbol table of the named object.

DT_CHECKSUM

This element holds a simple checksum of selected sections of the object. See gelf_checksum(3ELF).

DT_MOVEENT

This element holds the total size of the section defined by SHT_SUNW_move. See "Move Section".

DT_MOVESZ

This element holds the size, in bytes, of the DT_MOVETAB move entry.

DT_MOVETAB

This element holds the address of a move table, described in the first part of this chapter. Entries in the table have Elf32_Move entries for the 32-bit class of files, or Elf64_Move entries for the 64-bit class of files.

DT_CONFIG

This element holds the string table offset of a null-terminated string defining a configuration file. The offset is an index into the table recorded in the DT_STRTAB entry. The configuration file may provide search path, directory cache or alternative objects, typically unique to the application specifying the DT_CONFIG entry. See crle(1) and the link-editors' -c option.

DT_DEPAUDIT

This element holds the string table offset of a null-terminated string defining one or more audit libraries. The offset is an index into the table recorded in the DT_STRTAB entry. The audit libraries are used to audit the explicit dependencies of this object at runtime. See the link-editors' -P option.

DT_AUDIT

This element holds the string table offset of a null-terminated string defining one or more audit libraries. The offset is an index into the table recorded in the DT_STRTAB entry. The audit libraries are used to audit this object at runtime. See the link-editors' -p option.

DT_FLAGS_1

If present, this entry's d_val member holds various state flags. See Table 7-45.

DT_FEATURE_1

If present, this entry's d_val member holds DTF_1_* flags defining runtime feature requirements. The function _check_rtld_feature() can be called at runtime, typically from compiler supplied start-up code, to verify the required features exist. See "The Feature Checker" and Table 7-47.

DT_VALRNGLO - DT_VALRNGHI

Values in this inclusive range use the d_un.d_val field of the dynamic structure.

DT_ADDRRNGLO - DT_ADDRRNGHI

Values in this inclusive range use the d_un.d_ptr field of the dynamic structure. If any adjustment is made to the ELF object after it has been built these entries must be updated accordingly.

DT_SPARC_REGISTER

This element contains the index of an STT_SPARC_REGISTER symbol. There is one of these entries for every STT_SPARC_REGISTER symbol table entry in the symbol table.

DT_LOPROC - DT_HIPROC

Values in this inclusive range are reserved for processor-specific semantics.

Except for the DT_NULL element at the end of the dynamic array and the relative order of DT_NEEDED and DT_POSFLAG_1 elements, entries can appear in any order. Tag values not appearing in the table are reserved.

The dynamic state flags DT_FLAGS that are presently available are shown in the following table.

Table 7-44 Dynamic Tags, DT_FLAGS

Name 

Value 

Meaning 

DF_ORIGIN

0x1

$ORIGIN processing required

DF_SYMBOLIC

0x2

symbolic symbol resolution required 

DF_TEXTREL

0x4

text relocations exist 

DF_BIND_NOW

0x8

non-lazy binding required 

DF_ORIGIN

Indicates that the object requires $ORIGIN processing. See "Locating Associated Dependencies".

DF_SYMBOLIC

Indicates that the object contains symbolic bindings that were applied during its link-edit. See also "The Use of -Bsymbolic".

DF_TEXTREL

This flags's absence signifies that no relocation entry should cause a modification to a non-writable segment, as specified by the segment permissions in the program header table. If this flag is present, one or more relocation entries might request modifications to a non-writable segment, and the runtime linker can prepare accordingly.

DF_BIND_NOW

If set in a shared object or executable, this flag instructs the dynamic linker to process all relocations for the object containing this entry before transferring control to the program. The presence of this entry takes precedence over a directive to use lazy binding for this object when specified through the environment or via dlopen(3DL). This state is recorded in the object using the link-editors' -znow option.

The dynamic state flags DT_FLAGS_1 that are presently available are shown in the following table.

Table 7-45 Dynamic Tags, DT_FLAGS_1

Name 

Value 

Meaning  

DF_1_NOW

0x1

Perform complete relocation processing 

DF_1_GLOBAL

0x2

Unused 

DF_1_GROUP

0x4

Indicate object is a member of a group 

DF_1_NODELETE

0x8

Object cannot be deleted from a process 

DF_1_LOADFLTR

0x10

Ensure immediate loading of filtee(s) 

DF_1_INITFIRST

0x20

Run objects' initialization first 

DF_1_NOOPEN

0x40

Object can not be used with dlopen(3DL)

DF_1_ORIGIN

0x80

$ORIGIN processing required

DF_1_DIRECT

0x100

Direct bindings enabled 

DF_1_INTERPOSE

0x400

Object is an interposer 

DF_1_NODEFLIB

0x800

Ignore default library search path 

DF_1_NODUMP

0x1000

Object can not be dumped with dldump(3DL)

DF_1_CONFALT

0x2000

Object is a configuration alternative 

DF_1_ENDFILTEE

0x4000

Filtee terminates filters search 

DF_1_DISPRELDNE

0x8000

Displacement relocation done 

DF_1_DISPRELPND

0x10000

Displacement relocation pending 

DF_1_NOW

When the object is loaded, all relocation processing is completed; see "When Relocations Are Performed". This state is recorded in the object using the link-editors' -znow option.

DF_1_GROUP

Indicates that the object is a member of a group; see "Symbol Lookup". This state is recorded in the object using the link-editors' -Bgroup option.

DF_1_NODELETE

Indicates that the object cannot be deleted from a process. Thus, if the object is loaded in a process, either directly or as a dependency, with dlopen(3DL), it cannot be unloaded with dlclose(3DL). This state is recorded in the object using the link-editors' -znodelete option.

DF_1_LOADFLTR

This state is only meaningful for filters (see "Shared Objects as Filters"). When the filter is loaded, all associated filtees are immediately processed; see "Filtee Processing". This state is recorded in the object using the link-editors' -zloadfltr option.

DF_1_INITFIRST

When the object is loaded, its initialization section is run before any other objects loaded with it; see "Debugging Aids". This specialized state is intended for libthread.so.1. This state is recorded in the object using the link-editors' -zinitfirst option.

DF_1_NOOPEN

Indicates that the object cannot be added to a running process with dlopen(3DL). This state is recorded in the object using the link-editors' -znodlopen option.

DF_1_ORIGIN

Indicates that the object requires $ORIGIN processing. See "Locating Associated Dependencies".

DF_1_DIRECT

Object has direct bindings information. See "Direct Binding".

DF_1_INTERPOSE

The objects symbol table is to interpose before all symbols but the primary executable. This is enabled with the link-editors' -zinterpose option. See "Direct Binding".

DF_1_NODEFLIB

The search for dependencies of this object will ignore any default library search paths; see "Directories Searched by the Runtime Linker". This state is recorded in the object using the link-editors' -znodefaultlib option.

DF_1_NODUMP

This object will not be dumped by dldump(3DL). Candidates for this option include filters such as libdl.so.1 which may get included when generating a configuration file using crle(1). This state is recorded in the object using the link-editors' -znodump option.

DF_1_CONFALT

Indicates that this is a configuration alternative object generated by crle(1). This state triggers the runtime linker to search for a configuration file $ORIGIN/ld.config.app-name.

DF_1_ENDFILTEE

This state is only meaningful for filtees (see "Shared Objects as Filters"). This flag terminates a filters search for any further filtees; see "Reducing Auxiliary Searches". This state is recorded in the object using the link-editors' -zendfiltee option.

DF_1_DISPRELDNE

Indicates that this object has displacement relocations applied. The relocation records no longer exist within the object as they were discarded once the relocation was applied. See "Displacement Relocations".

DF_1_DISPRELPND

Indicates that this object has displacement relocations pending. The relocation records exits within the object so they can be completed at runtime. See "Displacement Relocations".

Table 7-46 Dynamic Tags, DT_POSFLAG_1

Name 

Value 

Meaning  

DF_P1_LAZYLOAD

0x1

The following object is to be lazily loaded 

DF_P1_GROUPPERM

0x2

The following object is to be loaded with group permissions 

DF_P1_LAZYLOAD

The following DT_* entry identifies an object to be loaded. The loading of this object is to be delayed until a symbol binding identified by a Syminfo table entry specifically references this object. This state is recorded in the object using the link-editors' -zlazyload option.

DF_P1_GROUPPERM

The following DT_* entry identifies an object to be loaded. The symbols in this object are not available for general symbol resolution, instead they are only available to the object(s) that caused it to be loaded. This state is recorded in the object using the link-editors' -zgroupperm option.

The dynamic feature flags that are presently available are shown in the following table.

Table 7-47 Dynamic Feature Flags, DT_FEATURE

Name 

Value 

Meaning  

DTF_1_PARINIT

0x1

The partially initialization feature is required. 

DTF_1_CONFEXP

0x2

A configuration file is expected (set by crle(1) for alternative objects; same affect as DF_1_CONFALT)