Oracle® Solaris 11.2 链接程序和库指南

退出打印视图

更新时间: 2014 年 7 月
 
 

预定义段和入口条件的 mapfile 指令

链接编辑器提供一组预定义的输出段描述符和入口条件,如预定义段中所述。链接编辑器已经知道这些节,因此创建这些节无需 mapfile 指令。所显示的可用于生成它们的 mapfile 指令仅为提供说明,并作为相对复杂的 mapfile 规范的一个示例。可以使用 mapfile 段指令修改或扩充这些内置定义。

通常,节到段的分配可在单个段指令中完成。但是,预定义节具有更复杂的要求,即要求按照不同于段在内存中的布局顺序处理这些节的入口条件。为此可以使用两个过程,第一个用于按照所需顺序定义所有段,第二个用于按照实现所需结果的顺序建立入口条件。用户 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;
        };