Initially reported by Dennis Schridde in https://bugs.gentoo.org/803173 as a systemd-249.1 build failure when linked with ld.gold. Here is ane xtracted example (needs systemtap header) that illustrates the failure on x86_64: $ cat bug.c #include <sys/sdt.h> void f(void *dev) { STAP_PROBE("foo", "foo"); } int main(){} ld.gold fails: $ x86_64-pc-linux-gnu-gcc -O2 -fno-PIE -fno-stack-protector -o b.o -c bug.c $ x86_64-pc-linux-gnu-gcc -O2 -fno-PIE -fno-stack-protector -Wl,--gc-sections -Wl,-O1 -fuse-ld=gold b.o -o bug b.o(.note.stapsdt+0x14): error: relocation refers to local symbol "" [2], which is defined in a discarded section collect2: error: ld returned 1 exit status ld.bfd succeeds: $ x86_64-pc-linux-gnu-gcc -O2 -fno-PIE -fno-stack-protector -Wl,--gc-sections -Wl,-O1 -fuse-ld=bfd b.o -o bug Looks like -Wl,--gc-sections does too much for ld.gols. Which one is wrong here?
Created attachment 13567 [details] b.o b.o is a binary generated on my system.
Created attachment 13568 [details] preprocessed.c Attached preprocessed file extracted as: $ x86_64-pc-linux-gnu-gcc -O2 -fno-PIE -fno-stack-protector -o preprocessed.c -E bug.c
BFD linker has /* Start at sections marked with SEC_KEEP (ref _bfd_elf_gc_keep). Also treat note sections as a root, if the section is not part of a group. We must keep all PREINIT_ARRAY, INIT_ARRAY as well as FINI_ARRAY sections for ld -r. */