This is an attempt to fix the https://bugs.llvm.org//show_bug.cgi?id=37212.
The issue is about code like:
.section .text.foo,"axG",@progbits,bar,comdat .Lfoo: .section .debug_info,"",@progbits .quad .Lfoo
llvm-mc -filetype=obj -triple=x86_64-pc-linux t.s -o t.o ld t.o t.o -o ld.out
LLD currently ignores the relocations to discarded COMDAT sections and hence out output is different from GNU linkers output.
What LLD do is valid from the spec point of view (https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter7-11598/index.html),
but unfortunately, modern compilers produce technically incorrect ELF and this patch is an attempt
to work around it. It is a bit hacky but seems to be more or less isolated.
Unfortunately I don't think that this will work on all targets. For example with --target=armv7a-linux-gnueabihf clang puts the exception table information (.ARM.exdix.name_of_function> and .rel.ARM.exidx.text.name_of_function) in the same group as name_of_function. I think it will be possible to select _a_ candidate section for these groups by choosing the section with SHF_EXECINSTR.