Summary: -------- Linking a 64-bit EFI app (U-Boot) results in a SEGV. Overview: --------- Trying to build an custodian u-boot tree. https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/efi-working Commit fa89e29c4392dd526274f073067cd3268f22552a works around --whole-archive just to continue the process, but with a bad link result. Steps to reproduce: ------------------- Build tree. Back out --whole-archive workaround. Actual results: --------------- Program received signal SIGSEGV, Segmentation fault. 0x00005555555d1a8f in elf_x86_64_finish_dynamic_sections (output_bfd=0x5555557fefa0, info=0x5555557fa140 <link_info>) at /src/binutils/bfd/elf64-x86-64.c:4676 4676 ->this_hdr.sh_entsize = htab->plt.plt_entry_size; (gdb) bt #0 0x00005555555d1a8f in elf_x86_64_finish_dynamic_sections (output_bfd=0x5555557fefa0, info=0x5555557fa140 <link_info>) at /src/binutils/bfd/elf64-x86-64.c:4676 #1 0x00005555556093ec in bfd_elf_final_link (abfd=<optimized out>, info=<optimized out>) at /src/binutils/bfd/elflink.c:13116 #2 0x00005555555a4dd6 in ldwrite () at /src/binutils/ld/ldwrite.c:545 #3 0x000055555558c8f0 in main (argc=<optimized out>, argv=<optimized out>) at /src/binutils/ld/ldmain.c:513 (gdb) p (struct bfd_elf_section_data *)(htab->elf.splt->output_section)->used_by_bfd $3 = (struct bfd_elf_section_data *) 0x0 This happens with earlier toolchains and ld.bfd versions too. Expected results: ----------------- Could be misuse, but ld shouldn't SEGV? Additional information: ----------------------- Found elf_i386_fake_section handling the COFF reloc object but no similar function for x86_64. Am I missing something here? I tried adding a fake section handling for x86_64, but that didn't help.
Please provide precise steps and config files to reproduce the issue.
Linker shouldn't crash. But 64-bit u-boot.lds is wrong. Please compare it against 32-bit u-boot.lds which is correct.
[hjl@gnu-cfl-2 tmp]$ cat foo.s .text .globl foo foo: jmp bar@PLT [hjl@gnu-cfl-2 tmp]$ gcc -c foo.s [hjl@gnu-cfl-2 tmp]$ ld -shared -T pr28597.t foo.o Segmentation fault (core dumped) [hjl@gnu-cfl-2 tmp]$ cat pr28597.t SECTIONS { .text : { *(.text .text.*) } /DISCARD/ : { *(.dynsym) } /DISCARD/ : { *(.dynstr*) } /DISCARD/ : { *(.dynamic*) } /DISCARD/ : { *(.plt*) } /DISCARD/ : { *(.interp*) } /DISCARD/ : { *(.gnu*) } /DISCARD/ : { *(.note.gnu.property) } } [hjl@gnu-cfl-2 tmp]$
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7c80aab93666727965c2d5d6e17b1338d88293e0 commit 7c80aab93666727965c2d5d6e17b1338d88293e0 Author: H.J. Lu <hjl.tools@gmail.com> Date: Thu Nov 18 07:54:34 2021 -0800 elf/x86: Issue an error on discarded output .plt section Issue an error, instead of crash, on discarded output .plt section. bfd/ PR ld/28597 * elf32-i386.c (elf_i386_finish_dynamic_sections): Issue an error on discarded output .plt section. * elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Likewise. ld/ PR ld/28597 * testsuite/ld-elf/pr28597.d: New file. * testsuite/ld-elf/pr28597.s: Likewise. * testsuite/ld-elf/pr28597.t: Likewise.
Fixed for 2.38.
(In reply to H.J. Lu from comment #2) > Linker shouldn't crash. But 64-bit u-boot.lds is wrong. Please > compare it against 32-bit u-boot.lds which is correct. Thanks. You're right. Found the culprit in U-boot.