[hjl@gnu-cfl-2 testsuite]$ `echo g++ -fcf-protection -W -Wall -Wstack-usage=262144 -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fmerge-constants -g -O2 -fno-use-linker-plugin -o plugin_test_1 | sed -e 's/\([^ ]*\)\(.*\)/\1 -Bgcctestdir\/\2/' -e 's/-Wp,-D_FORTIFY_SOURCE=[0-9][0-9]*//'` -Wl,--no-demangle,--emit-relocs,--plugin,"./plugin_test.so",--plugin-opt,"_Z4f13iv" two_file_test_main.o two_file_test_1.o.syms two_file_test_1b.o.syms two_file_test_2.o.syms empty.o.syms -Wl,--gc-sections API version: 1 gold version: 116 option: _Z4f13iv Number of wrap symbols = 0 /usr/lib/gcc/x86_64-redhat-linux/10/../../../../lib64/crt1.o: claim file hook called (offset = 0, size = 10584) gcctestdir/collect-ld: internal error in do_layout, at /export/gnu/import/git/gitlab/x86-binutils/gold/object.cc:1933 cleanup hook called collect2: error: ld returned 1 exit status [hjl@gnu-cfl-2 testsuite]$
--emit-relocs + (--gc-sections || --icf) triggers an assertion failure. --emit-relocs --icf failure is reported as PR18845. % echo 'void foo(){}' | gcc -xc - -c -o a.o % gold --emit-relocs --gc-sections a.o gold: internal error in do_layout, at ../../gold/object.cc:1939 Simply commenting out the assert will lead to a segfault along the road. diff --git i/gold/object.cc w/gold/object.cc index fe2494d3c41..9ba444f79d0 100644 --- i/gold/object.cc +++ w/gold/object.cc @@ -1936,7 +1936,7 @@ Sized_relobj_file<size, big_endian>::do_layout(Symbol_table* symtab, if (emit_relocs) this->size_relocatable_relocs(); - gold_assert(!is_two_pass || reloc_sections.empty()); + //gold_assert(!is_two_pass || reloc_sections.empty()); for (std::vector<unsigned int>::const_iterator p = reloc_sections.begin(); p != reloc_sections.end(); (gdb) up #1 0x0000555555b7c8bd in gold::Layout::layout_reloc<64, false> (this=0x7fffffff32d0, shdr=..., data_section=0x1, rr=0x555555d80630) at ../../../gold/layout.cc:1341 1341 name += data_section->name(); (gdb) p data_section $1 = (gold::Output_section *) 0x1 (gdb) bt #0 0x0000555555965b78 in gold::Output_section::name (this=0x1) at ../../../gold/output.h:3258 #1 0x0000555555b7c8bd in gold::Layout::layout_reloc<64, false> (this=0x7fffffff32d0, shdr=..., data_section=0x1, rr=0x555555d80630) at ../../../gold/layout.cc:1341 #2 0x0000555555bb9236 in gold::Sized_relobj_file<64, false>::do_layout (this=0x555555d90490, symtab=0x7fffffff37b0, layout=0x7fffffff32d0, sd=0x555555d906c0) at ../../../gold/object.cc:1982 #3 0x0000555555ab58bc in gold::Object::layout (this=0x555555d90490, symtab=0x7fffffff37b0, layout=0x7fffffff32d0, sd=0x555555d906c0) at ../../../gold/object.h:696 #4 0x0000555555c5d3c8 in gold::Add_symbols::run (this=0x555555d7ffe0) at ../../../gold/readsyms.cc:634 #5 0x0000555555ceb27b in gold::Workqueue::find_and_run_task (this=0x7fffffff3cb0, thread_number=0) at ../../../gold/workqueue.cc:319 #6 0x0000555555ceb8b1 in gold::Workqueue::process (this=0x7fffffff3cb0, thread_number=0) at ../../../gold/workqueue.cc:495 #7 0x00005555557e6a80 in main (argc=4, argv=0x7fffffffd5d8) at ../../../gold/main.cc:252 (gdb)
*** Bug 27741 has been marked as a duplicate of this bug. ***
See https://github.com/llvm/llvm-project/issues/57545 for a llvm-project/bolt --emit-relocs link issue due to this gold bug.