Go to main content

Oracle® Solaris 11.4 Linkers and Libraries Guide

Exit Print View

Updated: October 2019
 
 

Section Merging

The SHF_MERGE section flag can be used to mark SHT_PROGBITS sections within relocatable objects. See Figure 18, Table 18, ELF Section Attribute Flags. This flag indicates that the section can be merged with compatible sections from other objects. Such merging has the potential to reduce the size of any dynamic object that is built from these relocatable objects. This size reduction can also have a positive effect on the runtime performance of the resulting object.

A SHF_MERGE flagged section indicates that the section adheres to the following characteristics.

  • The section is read-only. It must not be possible for a program containing this section to alter the section data at runtime.

  • Every item in the section is accessed from an individual relocation record. The program code must not make any assumptions about the relative position of items in the section when generating the code that accesses the items.

  • If the section also has the SHF_STRINGS flag set, then the section can only contain null terminated strings. Null characters are only allowed as string terminators, and null characters must not appear within the middle of any string.

SHF_MERGE is an optional flag indicating a possible optimization. The link-editor is allowed to perform the optimization, or to ignore the optimization. The link-editor creates a valid output object in either case. The link-editor currently implements section merging only for sections containing string data marked with the SHF_STRINGS flag.

When the SHF_STRINGS section flag is set in conjunction with the SHF_MERGE flag, the strings in the section are available to be merged with strings from other compatible sections. The link-editor merges such sections using the same string compression algorithm as used to compress the SHT_STRTAB string tables, .strtab and .dynstr.

  • Duplicate strings are reduced to a single copy.

  • Tail strings are eliminated. For example, if input sections contain the strings "bigdog" and "dog", then the smaller "dog" string is eliminated, and the tail of the larger string is used to represent the smaller string.

The link-editor currently implements string merging only for strings that consist of byte sized characters that do not have special alignment constraints. Specifically, the following section characteristics are required.

  • sh_entsize must be 0, or 1. Sections containing wide characters are not supported.

  • Only sections where sh_addralign is 0, or a power of 2, are merged.


Note -  Any string table compression can be suppressed with the link-editors –z nocompstrtab option.