Example: Redirecting Sections

Normally, the link-editor copies input sections to the output object, creating output sections with the same names as the input. The LOAD_SEGMENT directive allows the use of MATCH and MATCHREF to match sections by name, and optionally to redirect them to differently named output sections. The following mapfile redirects all non-writable allocable sections with a name staring with the string ".appXtext.", and redirects each section to an output section named by replacing this prefix with ".text.".

        $mapfile_version 2

        LOAD_SEGMENT text {
                ASSIGN_SECTION apptext {
                        IS_NAME = MATCH(r/^\.appXtext\.(.*)$/);
                        FLAGS = ALLOC !WRITE;
                        OUTPUT_SECTION {
                                NAME = MATCHREF(/.text.${n1}/);
                        };
                };
        };