Go to main content

Oracle® Solaris 11.4 Linkers and Libraries Guide

Exit Print View

Updated: March 2019
 
 

Section Compression

The SHF_COMPRESSED section flag identifies a section containing compressed data. SHF_COMPRESSED applies only to non-allocable sections, and cannot be used in conjunction with SHF_ALLOC. In addition, SHF_COMPRESSED cannot be applied to sections of type SHT_NOBITS.

Any relocations that must be applied to a compressed section specify offsets to the uncompressed section data. It is therefore necessary to uncompress section data before relocations can be applied. Each compressed section specifies the algorithm independently. Different sections in a given ELF object can employ different compression algorithms.

Compressed sections start with a compression header structure that identifies the compression algorithm.

typedef struct {
        Elf32_Word      ch_type;
        Elf32_Word      ch_size;
        Elf32_Word      ch_addralign;
} Elf32_Chdr;

typedef struct {
        Elf64_Word      ch_type;
        Elf64_Word      ch_reserved;
        Elf64_Xword     ch_size;
        Elf64_Xword     ch_addralign;
} Elf64_Chdr;
ch_type

Specifies the compression algorithm. Supported algorithms and their descriptions are listed in Figure 21, Table 21, ELF Compression Types, ch_type.

ch_size

The size in bytes of the uncompressed data. See sh_size.

ch_addralign

Required alignment for the uncompressed data. See sh_addralign.

The sh_size and sh_addralign fields of the section header for a compressed section reflect the requirements of the compressed section. The ch_size and ch_addralign fields of the compression header provide the corresponding values for the uncompressed data, thereby supplying the values that sh_size and sh_addralign would have if the section had not been compressed.

The layout and interpretation of the data that follows the compression header is specific to each algorithm. This layout may contain algorithm specific parameters and alignment padding in addition to compressed data bytes.

A compression header's ch_type member specifies the compression algorithm employed, as shown in the following table.

Table 21  ELF Compression Types, ch_type
Name
Value
ELFCOMPRESS_ZLIB
1
ELFCOMPRESS_LOOS
0x60000000
ELFCOMPRESS_HIOS
0x6fffffff
ELFCOMPRESS_LOPROC
0x70000000
ELFCOMPRESS_HIPROC
0x7fffffff
ELFCOMPRESS_ZLIB

The section data is compressed with the ZLIB compression algorithm. The compressed ZLIB data bytes begin with the byte immediately following the compression header, and extend to the end of the section. Documentation for ZLIB may be found at http://www.zlib.net/.

ELFCOMPRESS_LOOS - ELFCOMPRESS_HIOS

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

ELFCOMPRESS_LOPROC - ELFCOMPRESS_HIPROC

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

GNU-Style Section Compression

In addition to the compression format discussed previously, the Oracle Solaris link-editor understands an alternative format used by the GNU tool chain. This format does not employ a section flag to indicate compression. Instead, a section name that starts with the .zdebug prefix identifies a section containing compressed data. GNU-style compressed sections start with the following compression header structure.

typedef struct {
        uchar_t         gch_magic[4];
        uchar_t         gch_size[8];
} Chdr_GNU;
gch_magic

A 4-byte magic number identifying the compression algorithm. At this time, only ZLIB compression is supported. The values of gch_magic for ZLIB compression is as listed in Figure 22, Table 22, GNU ZLIB Compression, gch_magic.

gch_size

The size in bytes of the uncompressed data, encoded as a 64-bit ELFDATA2MSB big endian integer value.

Table 22  GNU ZLIB Compression, gch_magic
Name
Value
gch_magic[0]
'Z'
gch_magic[1]
'L'
gch_magic[2]
'I'
gch_magic[3]
'B'