Skip to content

Commit

Permalink
linker.ld: Use explict program headers
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
josephlr authored and rbradford committed Nov 6, 2019
1 parent ade010a commit 5c1cb64
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions layout.ld
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
ENTRY(_start)

PHDRS
{
rodata PT_LOAD FILEHDR PHDRS ;
data PT_LOAD ;
text PT_LOAD ;
}

SECTIONS
{
. = 1M ;
start_of_data = . ;
.rodata : { *(.rodata .rodata.*) }
.data : { *(.data .data.*) }
.bss : { *(COMMON) *(.bss .bss.*) }
end_of_data = . ;

start_of_text = . ;
.text : { *(.text .text.*) }
end_of_text = . ;
_start_of_file = . ;

/* Mapping in the program headers makes it easier to mmap the whole file. */
. += SIZEOF_HEADERS ;

.rodata : { *(.rodata .rodata.*) } :rodata
.data : { *(.data .data.*) } :data
.bss : { *(.bss .bss.*) } :data
.text : { *(.text .text.*) } :text

_end_of_file = . ;

/* Match edk2's GccBase.lds DISCARD section */
/DISCARD/ : {
*(.note.GNU-stack)
*(.gnu_debuglink)
*(.interp)
*(.dynsym)
*(.dynstr)
*(.dynamic)
*(.hash .gnu.hash)
*(.comment)
*(COMMON)
}
}

0 comments on commit 5c1cb64

Please sign in to comment.