diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index c33ff0f66f758..1fddf40f5b22a 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -418,6 +418,14 @@ elf::ObjectFile::createInputSection(const Elf_Shdr &Sec, if (Config->Strip != StripPolicy::None && Name.startswith(".debug")) return &InputSection::Discarded; + // The linkonce feature is a sort of proto-comdat. Some glibc i386 object + // files contain definitions of symbol "__x86.get_pc_thunk.bx" in linkonce + // sections. Drop those sections to avoid duplicate symbol errors. + // FIXME: This is glibc PR20543, we should remove this hack once that has been + // fixed for a while. + if (Name.startswith(".gnu.linkonce.")) + return &InputSection::Discarded; + // The linker merges EH (exception handling) frames and creates a // .eh_frame_hdr section for runtime. So we handle them with a special // class. For relocatable outputs, they are just passed through. diff --git a/lld/test/ELF/comdat-linkonce.s b/lld/test/ELF/comdat-linkonce.s new file mode 100644 index 0000000000000..78611b4a9f262 --- /dev/null +++ b/lld/test/ELF/comdat-linkonce.s @@ -0,0 +1,9 @@ +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/comdat.s -o %t2.o +// RUN: ld.lld -shared %t.o %t2.o -o %t +// RUN: ld.lld -shared %t2.o %t.o -o %t + +.section .gnu.linkonce.t.zed +.globl abc +abc: +nop