Skip to content

Commit 5c1cb64

Browse files
josephlrrbradford
authored andcommitted
linker.ld: Use explict program headers
This maps the file headers into readonly data, while preventing any other sections from being generated. It also makes the file 8% smaller. We also replace the marker symbols for {begin|end}_of_{text|data} with symbols denoting the begining/end of the file itself. Finally, we make an explict DISCARD section (based off of EDK2's GccBase.lds to prevent any additional data from entering our binary). Signed-off-by: Joe Richey <[email protected]>
1 parent ade010a commit 5c1cb64

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

layout.ld

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
ENTRY(_start)
22

3+
PHDRS
4+
{
5+
rodata PT_LOAD FILEHDR PHDRS ;
6+
data PT_LOAD ;
7+
text PT_LOAD ;
8+
}
9+
310
SECTIONS
411
{
512
. = 1M ;
6-
start_of_data = . ;
7-
.rodata : { *(.rodata .rodata.*) }
8-
.data : { *(.data .data.*) }
9-
.bss : { *(COMMON) *(.bss .bss.*) }
10-
end_of_data = . ;
11-
12-
start_of_text = . ;
13-
.text : { *(.text .text.*) }
14-
end_of_text = . ;
13+
_start_of_file = . ;
14+
15+
/* Mapping in the program headers makes it easier to mmap the whole file. */
16+
. += SIZEOF_HEADERS ;
17+
18+
.rodata : { *(.rodata .rodata.*) } :rodata
19+
.data : { *(.data .data.*) } :data
20+
.bss : { *(.bss .bss.*) } :data
21+
.text : { *(.text .text.*) } :text
22+
23+
_end_of_file = . ;
24+
25+
/* Match edk2's GccBase.lds DISCARD section */
26+
/DISCARD/ : {
27+
*(.note.GNU-stack)
28+
*(.gnu_debuglink)
29+
*(.interp)
30+
*(.dynsym)
31+
*(.dynstr)
32+
*(.dynamic)
33+
*(.hash .gnu.hash)
34+
*(.comment)
35+
*(COMMON)
36+
}
1537
}

0 commit comments

Comments
 (0)