Index: ELF/GdbIndex.h =================================================================== --- ELF/GdbIndex.h +++ ELF/GdbIndex.h @@ -36,6 +36,8 @@ llvm::Optional findAux(const InputSectionBase &Sec, uint64_t Pos, ArrayRef Rels) const; + // Used to detect multiple debug sections with the same name. + llvm::StringSet<> Seen; public: explicit LLDDwarfObj(ObjFile *Obj); Index: ELF/GdbIndex.cpp =================================================================== --- ELF/GdbIndex.cpp +++ ELF/GdbIndex.cpp @@ -26,8 +26,13 @@ template LLDDwarfObj::LLDDwarfObj(ObjFile *Obj) { for (InputSectionBase *Sec : Obj->getSections()) { - if (!Sec) + if (!Sec || !Sec->Name.startswith(".debug")) continue; + + if (!Seen.insert(Sec->Name).second) + error(toString(Obj) + ": multiple " + Sec->Name + + " sections are not supported"); + if (LLDDWARFSection *M = StringSwitch(Sec->Name) .Case(".debug_info", &InfoSection) .Case(".debug_ranges", &RangeSection) Index: test/ELF/multiple-debug-sections.s =================================================================== --- test/ELF/multiple-debug-sections.s +++ test/ELF/multiple-debug-sections.s @@ -0,0 +1,24 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: not ld.lld --gdb-index %t1.o -o %t 2>&1 | FileCheck %s +# CHECK: error: {{.*}}.o: multiple .debug_info sections are not supported +# CHECK: error: {{.*}}.o: multiple .debug_abbrev sections are not supported +# CHECK: error: {{.*}}.o: multiple .debug_line sections are not supported + +.section .debug_info,"",@progbits +.quad 0 + +.section .debug_info,"G",@progbits,foo,comdat +.quad 0 + +.section .debug_abbrev,"",@progbits +.quad 0 + +.section .debug_abbrev,"G",@progbits,foo,comdat +.quad 0 + +.section .debug_line,"",@progbits +.quad 0 + +.section .debug_line,"G",@progbits,foo,comdat +.quad 0