Linker and Libraries Guide

Move Section

Typically, within ELF files, initialized data variables are maintained within the object file. Thus if a data variable is very large and only contains a small number of initialized (nonzero) elements, the entire variable is still maintained in the object file.

Objects that contain large partially initialized data variables (like FORTRAN COMMON blocks) can result in a significant disk space overhead. The SHT_SUNW_move section provides a mechanism of compressing these data variables and thus reducing the disk size of the associated object.

The SHT_SUNW_move section contains multiple entries of the type ELF32_Move or Elf64_Move. These entries allow data variables to be defined as tentative items (.bss), thus they occupy no space in the object file but contribute to the object's memory image at runtime. The move records establish how the memory image is initialized with data to construct the complete data variable.

ELF32_Move and Elf64_Move entries are defined as follows:


typedef struct {
        Elf32_Lword       m_value;
        Elf32_Word        m_info;
        Elf32_Word        m_poffset;
        Elf32_Half        m_repeat;
        Elf32_Half        m_stride;
} Elf32_Move;

#define ELF32_M_SYM(info)       ((info)>>8)
#define ELF32_M_SIZE(info)      ((unsigned char)(info))
#define ELF32_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))

typedef struct {
        Elf64_Lword       m_value;
        Elf64_Xword       m_info;
        Elf64_Xword       m_poffset;
        Elf64_Half        m_repeat;
        Elf64_Half        m_stride;
} Elf64_Move;

#define ELF64_M_SYM(info)       ((info)>>8)
#define ELF64_M_SIZE(info)      ((unsigned char)(info))
#define ELF64_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))

m_value

This member provides the initialization value (the value that will be moved into the memory image).

m_info

This member provides both the symbol table index, with respect to which the initialization is applied, together with the size, in bytes, of the offset being initialized. The lower 8 bits of the member define the size, which can be 1, 2, 4 or 8. The upper bytes define the symbol index.

m_poffset

This member provides the offset, relative to the associated symbol, to which the initialization is applied.

m_repeat

This member provides a repetition count.

m_stride

This member provides the stride count. This value indicates the number of units that should be skipped when performing a repetitive initialization. A unit is the size of an initialization object as defined by m_info. An m_stride value of 0 indicates that the initialization be performed contiguously for m_repeat units.

The following data definition would typically consume 0x8000 bytes within an object file:


typedef struct {
        int     one;
        char    two;
} Data

Data move[0x1000] = {
        {0, 0},
        {1, '1'},
        {0, 0},
        {0xf, 'F'}, {0xf, 'F'},
        {0, 0},
        {0xe, 'E'},
        {0, 0},
        {0xe, 'E'}
};

Using an SHT_SUNW_move section the data item can be moved to the .bss section and initialized with the associated move entries:


% elfdump -s data | fgrep move
      [17]  0x00020868 0x00008000  OBJT GLOB 0   .bss       move
% elfdump -m data
Move Section: .SUNW_move
        offset  ndx     size    repeat  stride  value   with respect to
        0x8     0x17    4       1       0       0x1     foo
        0xc     0x17    1       1       0       0x31    foo
        0x18    0x17    4       2       2       0xf     foo
        0x1c    0x17    1       2       8       0x46    foo
        0x28    0x17    4       2       4       0xe     foo
        0x2c    0x17    1       2       16      0x45    foo