<div dir="ltr">What's the error handling case you mention? Presumably it works for multiple debug_types sections, so perhaps that support could be generalized to multiple debug_info sections as well? Then this failure could be restricted to only multiple debug_info sections when using gdb-index?<br><br>That way DWARF5 type units (that use debug_info sections) would just work? (except when using gdb-index)<br><br>It seems strange to me that the linker would special case the debug_* sections (& that that special casing would limit how they can be used) given the discussion we were having about the linker wanting to treat debug info as just normal sections.<br><br><div class="gmail_quote"><div dir="ltr">On Thu, Dec 7, 2017 at 4:39 AM George Rimar via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">grimar created this revision.<br>
Herald added subscribers: JDevlieghere, aprantl, emaste.<br>
<br>
It is based on discussions in "[llvm-dev] [RFC] - Deduplication of debug information in linkers (LLD)." thread.<br>
DWARF5 specification (<a href="http://dwarfstd.org/doc/DWARF5.pdf" rel="noreferrer" target="_blank">http://dwarfstd.org/doc/DWARF5.pdf</a>) mentions it can be one or more of debug sections.<br>
For example:<br>
<br>
1. p366 says objects may have multiple .debug_abrev, .debug_info, .debug_line sections for DWARF elimination.<br>
2. p376 says multiple .debug_info section could be used for deduplication of type units.<br>
<br>
In both cases LLD would work incorrectly now (as we do not expect multiple of above sections) for cases when we are<br>
trying to work with DWARF sections. It is error reporting case and --gdb-index generation case.<br>
So for both safety and simplicity of implementation I suggest to error out when LLDDwarfObj meets object with<br>
any multiple debug sections with the same name.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D40950" rel="noreferrer" target="_blank">https://reviews.llvm.org/D40950</a><br>
<br>
Files:<br>
  ELF/GdbIndex.cpp<br>
  ELF/GdbIndex.h<br>
  test/ELF/multiple-debug-sections.s<br>
<br>
<br>
Index: test/ELF/multiple-debug-sections.s<br>
===================================================================<br>
--- test/ELF/multiple-debug-sections.s<br>
+++ test/ELF/multiple-debug-sections.s<br>
@@ -0,0 +1,24 @@<br>
+# REQUIRES: x86<br>
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o<br>
+# RUN: not ld.lld --gdb-index %t1.o -o %t 2>&1 | FileCheck %s<br>
+# CHECK: error: {{.*}}.o: multiple .debug_info sections are not supported<br>
+# CHECK: error: {{.*}}.o: multiple .debug_abbrev sections are not supported<br>
+# CHECK: error: {{.*}}.o: multiple .debug_line sections are not supported<br>
+<br>
+.section  .debug_info,"",@progbits<br>
+.quad 0<br>
+<br>
+.section  .debug_info,"G",@progbits,foo,comdat<br>
+.quad 0<br>
+<br>
+.section  .debug_abbrev,"",@progbits<br>
+.quad 0<br>
+<br>
+.section  .debug_abbrev,"G",@progbits,foo,comdat<br>
+.quad 0<br>
+<br>
+.section  .debug_line,"",@progbits<br>
+.quad 0<br>
+<br>
+.section  .debug_line,"G",@progbits,foo,comdat<br>
+.quad 0<br>
Index: ELF/GdbIndex.h<br>
===================================================================<br>
--- ELF/GdbIndex.h<br>
+++ ELF/GdbIndex.h<br>
@@ -36,6 +36,8 @@<br>
   llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &Sec,<br>
                                                uint64_t Pos,<br>
                                                ArrayRef<RelTy> Rels) const;<br>
+  // Used to detect multiple debug sections with the same name.<br>
+  llvm::StringSet<> Seen;<br>
<br>
 public:<br>
   explicit LLDDwarfObj(ObjFile<ELFT> *Obj);<br>
Index: ELF/GdbIndex.cpp<br>
===================================================================<br>
--- ELF/GdbIndex.cpp<br>
+++ ELF/GdbIndex.cpp<br>
@@ -26,8 +26,13 @@<br>
<br>
 template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *Obj) {<br>
   for (InputSectionBase *Sec : Obj->getSections()) {<br>
-    if (!Sec)<br>
+    if (!Sec || !Sec->Name.startswith(".debug"))<br>
       continue;<br>
+<br>
+    if (!Seen.insert(Sec->Name).second)<br>
+      error(toString(Obj) + ": multiple " + Sec->Name +<br>
+            " sections are not supported");<br>
+<br>
     if (LLDDWARFSection *M = StringSwitch<LLDDWARFSection *>(Sec->Name)<br>
                                  .Case(".debug_info", &InfoSection)<br>
                                  .Case(".debug_ranges", &RangeSection)<br>
<br>
<br>
</blockquote></div></div>