リンカーには、定義済みセグメントで説明されているように、定義済みの出力セグメント記述子とエントランス基準のセットが提供されています。リンカーはこれらのセクションについて認識しているため、mapfile 指令でこれらを作成する必要はありません。これらの作成に使用できる mapfile 指令は、説明のため、または比較的複雑な mapfile を指定する例として示されています。mapfile セグメント指令は、これらの組み込み定義を変更または拡張するために使用できます。
通常、セクションからセグメントへの割り当ては、単一のセグメント指令の内部で行われます。しかし、定義済みのセクションにはより複雑な要件があるため、セグメントがメモリーに展開されている順序と異なる順序でエントランス基準を処理する必要があります。これを実現するには 2 つの方法が使用されます。1 つ目は、すべてのセグメントを望ましい順序で定義する方法、2 つ目は、望ましい結果が得られる順序でエントランス基準を設定する方法です。ユーザーの mapfile でこの方法が必要になることはまれです。
# Predefined segments and entrance criteria for the Oracle Solaris
# link-editor
$mapfile_version 2
# The lrodata and ldata segments only apply to x86-64 objects.
# Establish amd64 as a convenient token for conditional input
$if _ELF64 && _x86
$add amd64
$endif
# Pass 1: Define the segments and their attributes, but
# defer the entrance criteria details to the 2nd pass.
LOAD_SEGMENT text {
FLAGS = READ EXECUTE;
};
LOAD_SEGMENT data {
FLAGS = READ WRITE EXECUTE;
};
LOAD_SEGMENT bss {
DISABLE;
FLAGS=DATA;
};
$if amd64
LOAD_SEGMENT lrodata {
FLAGS = READ
};
LOAD_SEGMENT ldata {
FLAGS = READ WRITE;
};
$endif
NOTE_SEGMENT note;
NULL_SEGMENT extra;
# Pass 2: Define ASSIGN_SECTION attributes for the segments defined
# above, in the order the link-editor should evaluate them.
# All SHT_NOTE sections go to the note segment
NOTE_SEGMENT note {
ASSIGN_SECTION {
TYPE = NOTE;
};
};
$if amd64
# Medium/large model x86-64 readonly sections to lrodata
LOAD_SEGMENT lrodata {
ASSIGN_SECTION {
FLAGS = ALLOC AMD64_LARGE;
};
};
$endif
# text receives all readonly allocable sections
LOAD_SEGMENT text {
ASSIGN_SECTION {
FLAGS = ALLOC !WRITE;
};
};
# If bss is enabled, it takes the writable NOBITS sections
# that would otherwise end up in ldata or data.
LOAD_SEGMENT bss {
DISABLE;
ASSIGN_SECTION {
FLAGS = ALLOC WRITE;
TYPE = NOBITS;
};
};
$if amd64
# Medium/large model x86-64 writable sections to ldata
LOAD_SEGMENT ldata {
ASSIGN_SECTION {
FLAGS = ALLOC WRITE AMD64_LARGE;
};
ASSIGN_SECTION {
TYPE = NOBITS;
FLAGS = AMD64_LARGE
};
};
$endif
# Any writable allocable sections not taken above go to data
LOAD_SEGMENT data {
ASSIGN_SECTION {
FLAGS = ALLOC WRITE;
};
};
# Any section that makes it to this point ends up at the
# end of the object file in the extra segment. This accounts
# for the bulk of non-allocable sections.
NULL_SEGMENT extra {
ASSIGN_SECTION;
};