This depends on https://sourceware.org/bugzilla/show_bug.cgi?id=24526 (Generalize GC support for SHF_LINK_ORDER) # a.script SECTIONS { /DISCARD/ : { *(.foo) } } # a.s .section .foo,"a" .quad 0 .section .bar,"ao",@progbits,.foo # "o" is llvm-mc specific syntax that sets SHF_LINK_ORDER and sh_link .quad 0 .section .zed,"ao",@progbits,.foo .quad 0 .section .moo,"ao",@progbits,.zed .quad 0 GNU ld issues an error % llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o % ld.bfd -T a.script a.o ld.bfd: a.out: sh_link of section `.bar' points to discarded section `.foo' of `a.o' ld.bfd: final link failed: bad value In lld, .bar is considered a dependent section of .foo When /DISCARD/ discards .foo, it discards .bar as well. Transitively, .zed and .moo are discarded. This rule can be seen as a generalization of SHT_RELA or SHT_ARM_EXIDX. % ld.lld -T a.script a.o ld.lld: warning: cannot find entry symbol _start; defaulting to 0x0
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9b538ba71fc7dbab65371e3e4e5f7e093ff25023 commit 9b538ba71fc7dbab65371e3e4e5f7e093ff25023 Author: H.J. Lu <hjl.tools@gmail.com> Date: Thu Feb 6 19:42:52 2020 -0800 ELF: Discard a section if any of its linked-to sections has been discarded Add ldelf_before_place_orphans to call before lang_place_orphans to discard a section if any of its linked-to sections has been discarded. PR ld/25022 * emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Add before_place_orphans_default. * emultempl/armcoff.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/beos.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/linux.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/msp430.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/pe.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/pep.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/ticoff.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/vanilla.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Use ldelf_before_place_orphans. * ldelf.c (ldelf_before_place_orphans): New. * ldelf.h (ldelf_before_place_orphans): Likewise. * ldemul.c (ldemul_before_place_orphans): Likewise. (before_place_orphans_default): Likewise. * ldemul.h (ldemul_before_place_orphans): Likewise. (before_place_orphans_default): Likewise. (ld_emulation_xfer_struct): Add before_place_orphans. * ldlang.c (lang_process): Call ldemul_before_place_orphans before lang_place_orphans. * testsuite/ld-elf/pr25022.d: New file. * testsuite/ld-elf/pr25022.s: Likewise. * testsuite/ld-elf/pr25022.t: Likewise.
Fixed for 2.35.
(In reply to H.J. Lu from comment #2) > Fixed for 2.35. Not quite: Checking Binutils in: dlx-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: frv-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: d30v-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: mn10200-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: ms1-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: mt-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: xgate-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: fr30-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: ft32-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: iq2000-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: pj-elf ... LD REGRESSION: ld-elf/pr25022 Checking Binutils in: s12z-elf ... LD REGRESSION: ld-elf/pr25022 Could you have a look please ? Cheers Nick
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=adb8754e48d53b219ddaa9e8368e4b1acb9db53a commit adb8754e48d53b219ddaa9e8368e4b1acb9db53a Author: H.J. Lu <hjl.tools@gmail.com> Date: Fri Feb 7 05:08:16 2020 -0800 pr25022.d: Xfail more targets without ldelf_before_place_orphans PR ld/25022 * testsuite/ld-elf/pr25022.d: Xfail more targets which don't use ldelf_before_place_orphans.
(In reply to Nick Clifton from comment #3) > (In reply to H.J. Lu from comment #2) > > Fixed for 2.35. > > Not quite: > > Checking Binutils in: dlx-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: frv-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: d30v-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: mn10200-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: ms1-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: mt-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: xgate-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: fr30-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: ft32-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: iq2000-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: pj-elf ... LD REGRESSION: ld-elf/pr25022 > Checking Binutils in: s12z-elf ... LD REGRESSION: ld-elf/pr25022 > > Could you have a look please ? > Should be fixed now.