$ ./ld-new -o tmpdir/cross1 -T /home/alan/src/binutils-virgin/ld/testsuite/ld-scripts/cross1.t tmpdir/cross1.o tmpdir/cross2.o ./ld-new: final link failed: bad value The fail is from bfd_set_section_contents returning false on attempting to write contents past the end of the output section. elf_fixup_link_order causes that by reordering .IA_64.unwind later. .IA_64.unwind has alignment of 8 and the new order happens to require more alignment padding. I know that ia64 is marked obsolete, but the same situation may arise with other targets.
Created attachment 13103 [details] cross1.o
Created attachment 13104 [details] cross2.o
A patch is posted at https://sourceware.org/pipermail/binutils/2021-January/114821.html
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b1b29aa51a6a67d5e35391ad31a80765839d6eb4 commit b1b29aa51a6a67d5e35391ad31a80765839d6eb4 Author: H.J. Lu <hjl.tools@gmail.com> Date: Fri Jan 8 21:38:39 2021 -0800 elf: Verify section size for mixed ordered/unordered inputs When fixing up SHF_LINK_ORDER, issue a fatal error if the output section size is increased. Otherwise, bfd_set_section_contents will fail later when attempting to write contents past the end of the output section. PR ld/26256 PR ld/27160 * elflink.c (elf_fixup_link_order): Verify that fixing up SHF_LINK_ORDER doesn't increase the output section size.
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b209b5a6b8a4433be961a0f016439f381de65bfc commit b209b5a6b8a4433be961a0f016439f381de65bfc Author: Alan Modra <amodra@gmail.com> Date: Wed Jan 13 13:33:34 2021 +1030 SHF_LINK_ORDER fixup_link_order in ld This moves the SHF_LINK_ORDER sorting from bfd_elf_final_link to the linker which means generic ELF targets now support SHF_LINK_ORDER and we cope with odd cases that require resizing of output sections. The patch also fixes two bugs in the current implementation, introduced by commit cd6d537c48fa. The pattern test used by that commit meant that sections matching something like "*(.IA_64.unwind* .gnu.linkonce.ia64unw.*)" would not properly sort a mix of sections matching the two wildcards. That commit also assumed a stable qsort. bfd/ PR 27160 * section.c (struct bfd_section): Remove pattern field. (BFD_FAKE_SECTION): Adjust to suit. * bfd-in2.h: Regenerate. * elflink.c (compare_link_order, elf_fixup_link_order): Delete. (bfd_elf_final_link): Don't call elf_fixup_link_order. ld/ PR 27160 * ldlang.h (lang_output_section_statement_type): Add data field. (lang_input_section_type, lang_section_bst_type): Add pattern field. (statement_list): Declare. (lang_add_section): Adjust prototype. * emultempl/aarch64elf.em: Adjust lang_add_section calls. * emultempl/armelf.em: Likewise. * emultempl/beos.em: Likewise. * emultempl/cskyelf.em: Likewise. * emultempl/hppaelf.em: Likewise. * emultempl/m68hc1xelf.em: Likewise. * emultempl/metagelf.em: Likewise. * emultempl/mipself.em: Likewise. * emultempl/mmo.em: Likewise. * emultempl/msp430.em: Likewise. * emultempl/nios2elf.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/pep.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/spuelf.em: Likewise. * emultempl/vms.em: Likewise. * ldelf.c: Likewise. * ldelfgen.c: Include ldctor.h. (struct os_sections): New. (add_link_order_input_section, link_order_scan): New functions. (compare_link_order, fixup_link_order): New functions. (ldelf_map_segments): Call link_order_scan and fixup_link_order. * ldlang.c (statement_list): Make global. (output_section_callback_fast): Save pattern in tree node. (lang_add_section): Add pattern parameter, save in lang_input_section. (output_section_callback_tree_to_list): Adjust lang_add_section calls. (lang_insert_orphan, output_section_callback): Likewise. (ldlang_place_orphan): Likewise. (gc_section_callback): Don't set section->pattern * testsuite/ld-elf/pr26256-2a.d: Don't xfail generic. * testsuite/ld-elf/pr26256-3b.d: Likewise. * testsuite/ld-elf/pr26256-2b.d: Likewise. notarget xgate.
Fixed
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4120e4885bd80ac66fb6c643ecc9d15adec92a14 commit 4120e4885bd80ac66fb6c643ecc9d15adec92a14 Author: Alan Modra <amodra@gmail.com> Date: Thu Jan 14 08:48:49 2021 +1030 Re: SHF_LINK_ORDER fixup_link_order in ld PR 27160 * ldelfgen.c (compare_link_order): Protect access of ELF section data. (add_link_order_input_section): Remove redundant NULL check. Use bfd_get_flavour. (ldelf_map_segments): Use bfd_get_flavour.