Example: Predefined Section Modification
The following mapfile
example manipulates the predefined text
and data segments, header options and section within segment ordering.
Example 10-2 Predefined Section Manipulation and Section to Segment Assignment
1 $mapfile_version 2 2 HDR_NOALLOC; 3 4 LOAD_SEGMENT text { 5 VADDR=0xf0004000; 6 FLAGS=READ EXECUTE; 7 OS_ORDER=.text .rodata; 9 ASSIGN_SECTION { 10 TYPE=PROGBITS; 11 FLAGS=ALLOC !WRITE; 12 }; 13 }; 14 15 LOAD_SEGMENT data { 16 FLAGS=READ WRITE EXECUTE; 17 ALIGN=0x1000; 18 ROUND=0x1000; 19 };
As always, the first line declares the mapfile
language version
to be used. The HDR_NOALLOC
directive (line 2) specifies that the
resulting object should not include the ELF header or program
header array within the first allocable segment in the object, which is the
predefined text segment.
The segment directive on lines 4-13 set a virtual address and permission flags for
the text segment. This directive also specifies that sections named
.text
sections should be placed at the head of the segment,
followed by any sections named .rodata
, and that all other
sections will follow these. Finally, allocable, non-writable
PROGBITS
sections are assigned to the segment.
The segment directive on lines 15-19 specifies that the data segment must be aligned on a boundary of 0x1000. This has the effect of aligning the first section within the segment at the same alignment. The length of the segment is to be rounded up to a multiple of the same value as the alignment. The segment permissions are set to read, write, and execute.