From 27ead2f20bc0cd824c2aeafbfd372b048c5e3b2c Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 4 Jun 2017 17:46:03 -0500 Subject: [PATCH] linker.ld: Make sure all ELF sections are page-aligned --- src/arch/x86_64/linker.ld | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/arch/x86_64/linker.ld b/src/arch/x86_64/linker.ld index afee66c..4d73e18 100644 --- a/src/arch/x86_64/linker.ld +++ b/src/arch/x86_64/linker.ld @@ -3,21 +3,51 @@ ENTRY(start) SECTIONS { . = 1M; /* load the kernel at 1MiB above 0x0 */ - .boot : { + /* Merged section for both the multiboot header and .rodata, + so we don't waste a page on the multiboot header */ + .rodata : { /* ensure the multiboot header is at the start of the binary */ KEEP(*(.multiboot_header)) + + /* ensure small fragments in .rodata and .rel.ro are linked together */ + *(.rodata .rodata.*) + + . = ALIGN(4K); } .text : { /* Kernel code */ *(.text .text.*) /* .text.* ensures that all small .text fragments are linked together */ + . = ALIGN(4K); } - /* ensure small fragments in .rodata and .rel.ro are linked together */ - .rodata : { - *(.rodata .rodata.*) + .data : { + *(.data .data.*) + . = ALIGN(4K); + } + + .bss : { + *(.bss .bss.*) + . = ALIGN(4K); } - .data.rel.ro : { + + .got : { + *(.got) + . = ALIGN(4K); + } + + .got.plt : { + *(.got.plt) + . = ALIGN(4K); + } + + .data.rel.ro : ALIGN(4K) { *(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*) + . = ALIGN(4K); + } + + .gcc_except_table : ALIGN(4K) { + *(.gcc_except_table) + . = ALIGN(4K); } }