[PATCH] D40950: [ELF] - Fail when multiple .debug_* sections are used in a single object.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 04:39:47 PST 2017


grimar created this revision.
Herald added subscribers: JDevlieghere, aprantl, emaste.

It is based on discussions in "[llvm-dev] [RFC] - Deduplication of debug information in linkers (LLD)." thread.
DWARF5 specification (http://dwarfstd.org/doc/DWARF5.pdf) mentions it can be one or more of debug sections.
For example:

1. p366 says objects may have multiple .debug_abrev, .debug_info, .debug_line sections for DWARF elimination.
2. p376 says multiple .debug_info section could be used for deduplication of type units.

In both cases LLD would work incorrectly now (as we do not expect multiple of above sections) for cases when we are 
trying to work with DWARF sections. It is error reporting case and --gdb-index generation case.
So for both safety and simplicity of implementation I suggest to error out when LLDDwarfObj meets object with
any multiple debug sections with the same name.


https://reviews.llvm.org/D40950

Files:
  ELF/GdbIndex.cpp
  ELF/GdbIndex.h
  test/ELF/multiple-debug-sections.s


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,"", at progbits
+.quad 0
+
+.section  .debug_info,"G", at progbits,foo,comdat
+.quad 0
+
+.section  .debug_abbrev,"", at progbits
+.quad 0
+
+.section  .debug_abbrev,"G", at progbits,foo,comdat
+.quad 0
+
+.section  .debug_line,"", at progbits
+.quad 0
+
+.section  .debug_line,"G", at progbits,foo,comdat
+.quad 0
Index: ELF/GdbIndex.h
===================================================================
--- ELF/GdbIndex.h
+++ ELF/GdbIndex.h
@@ -36,6 +36,8 @@
   llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &Sec,
                                                uint64_t Pos,
                                                ArrayRef<RelTy> Rels) const;
+  // Used to detect multiple debug sections with the same name.
+  llvm::StringSet<> Seen;
 
 public:
   explicit LLDDwarfObj(ObjFile<ELFT> *Obj);
Index: ELF/GdbIndex.cpp
===================================================================
--- ELF/GdbIndex.cpp
+++ ELF/GdbIndex.cpp
@@ -26,8 +26,13 @@
 
 template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *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<LLDDWARFSection *>(Sec->Name)
                                  .Case(".debug_info", &InfoSection)
                                  .Case(".debug_ranges", &RangeSection)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40950.125930.patch
Type: text/x-patch
Size: 2138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171207/ca897b66/attachment.bin>


More information about the llvm-commits mailing list