From b30ed75e694d951f530342bb44fe8911001cbb81 Mon Sep 17 00:00:00 2001 From: occheung Date: Fri, 20 Aug 2021 16:03:21 +0800 Subject: [PATCH] kernel.ld: load elf header and prog headers ld.lld has a habit of not putting the headers under any load sections. However, the headers are needed by libunwind to handle exception raised by the kernel. Creating PT_LOAD section with FILEHDR and PHDRS solves this issue. Other PHDRS are also specified as linkers (not limited to ld.lld) will not create additional unspecified headers even when necessary. --- artiq/compiler/kernel.ld | 62 ++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/artiq/compiler/kernel.ld b/artiq/compiler/kernel.ld index 4147026a2..6523d631a 100644 --- a/artiq/compiler/kernel.ld +++ b/artiq/compiler/kernel.ld @@ -1,9 +1,53 @@ -SECTIONS { - .bss ALIGN(4) : - { - __bss_start = .; - *(.sbss .sbss.* .bss .bss.*); - . = ALIGN(4); - _end = .; - } -} \ No newline at end of file +/* Force ld to make the ELF header as loadable. */ +PHDRS +{ + headers PT_LOAD FILEHDR PHDRS ; + text PT_LOAD ; + data PT_LOAD ; + dynamic PT_DYNAMIC ; + eh_frame PT_GNU_EH_FRAME ; +} + +SECTIONS +{ + /* Push back .text section enough so that ld.lld not complain */ + . = SIZEOF_HEADERS; + + .text : + { + *(.text .text.*) + } : text + + .rodata : + { + *(.rodata .rodata.*) + } + + .eh_frame : + { + KEEP(*(.eh_frame)) + } : text + + .eh_frame_hdr : + { + KEEP(*(.eh_frame_hdr)) + } : text : eh_frame + + .data : + { + *(.data) + } : data + + .dynamic : + { + *(.dynamic) + } : data : dynamic + + .bss (NOLOAD) : ALIGN(4) + { + __bss_start = .; + *(.sbss .sbss.* .bss .bss.*); + . = ALIGN(4); + _end = .; + } +}