diff --git a/.cargo/config b/.cargo/config index 927b8ca..18cd625 100644 --- a/.cargo/config +++ b/.cargo/config @@ -4,4 +4,10 @@ rustflags = [ "-C", "relocation-model=pic", "-C", "link-args=-Wl,--sort-section=alignment -nostartfiles", "-C", "link-self-contained=no", + "-C", "link-arg=-Tlink.script", + + # Using GNU ld on Fedora 34 produces this assertion: + # = note: /usr/bin/ld: BFD version 2.35.2-3.fc34 assertion fail elf.c:6278 + # collect2: error: ld returned 1 exit status + #"-C", "link-arg=-fuse-ld=lld", ] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 81d1097..b10abd8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,8 @@ jobs: with: toolchain: ${{ matrix.toolchain }} override: true + - name: Install lld + run: sudo apt install lld - uses: actions-rs/cargo@v1 with: command: build diff --git a/link.script b/link.script new file mode 100644 index 0000000..600f516 --- /dev/null +++ b/link.script @@ -0,0 +1,58 @@ +ENTRY(_start) + +PHDRS { + preamble PT_LOAD FILEHDR PHDRS; + text PT_LOAD; + rodata PT_LOAD; + data PT_LOAD; + + dynamic PT_DYNAMIC; + note PT_NOTE; + + frame 0x6474e550; /* GNU_EH_FRAME */ + stack 0x6474e551 FLAGS(6); /* GNU_STACK */ + relro 0x6474e552 FLAGS(4); /* GNU_RELRO */ +} + +SECTIONS { + . = SIZEOF_HEADERS; + + . = ALIGN(CONSTANT(MAXPAGESIZE)); + .interp : { *(.interp) } :preamble + .note.gnu.build-id : { *(.note.gnu.build-id) } :preamble :note + .hash : { *(.hash) } :preamble + .gnu.hash : { *(.gnu.hash) } :preamble + .dynsym : { *(.dynsym) } :preamble + .dynstr : { *(.dynstr) } :preamble + .gnu.version : { *(.gnu.version) } :preamble + .gnu.version_d : { *(.gnu.version_d) } :preamble + .gnu.version_r : { *(.gnu.version_r) } :preamble + .rela.dyn : { *(.rela.*) } :preamble + .rela.plt : { *(.rela.plt) *(.rela.iplt) } :preamble + + . = ALIGN(CONSTANT(MAXPAGESIZE)); + .init : { KEEP (*(SORT_NONE(.init))) } :text + .fini : { KEEP (*(SORT_NONE(.fini))) } :text + .text : { *(.text .text.*) } :text + .plt : { *(.plt) *(.iplt) } :text + .plt.got : { *(.plt.got) } :text + .plt.sec : { *(.plt.sec) } :text + + . = ALIGN(CONSTANT(MAXPAGESIZE)); + .rodata : { *(.rodata .rodata.*) } :rodata + .rodata1 : { *(.rodata1) } :rodata + .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) } :rodata :frame + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) } :rodata + + . = ALIGN(CONSTANT(MAXPAGESIZE)); + .data.rel.ro : { *(.data.rel.ro .data.rel.ro.*) } :data :relro + .dynamic : { *(.dynamic) } :data :relro :dynamic + .got : { *(.got) } :data :relro + .got.plt : { *(.got.plt) } :data :relro + + . = ALIGN(CONSTANT(MAXPAGESIZE)); /* Align here? New section? */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } :data + .data : { *(.data .data.*) } :data + .data1 : { *(.data1) } :data + .bss : { *(.bss .bss.*) } :data +}