[lld] r346616 - [ELF] Change GnuPub{Names, Types}Section from StringRef to LLDDWARFSection

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 11 10:57:35 PST 2018


Author: maskray
Date: Sun Nov 11 10:57:35 2018
New Revision: 346616

URL: http://llvm.org/viewvc/llvm-project?rev=346616&view=rev
Log:
[ELF] Change GnuPub{Names,Types}Section from StringRef to LLDDWARFSection

Summary:
The debug_info_offset value may be relocated.

This is lld side change of D54375.

Reviewers: ruiu, dblaikie, grimar, espindola

Subscribers: emaste, arichardson, JDevlieghere, llvm-commits

Differential Revision: https://reviews.llvm.org/D54376

Modified:
    lld/trunk/ELF/DWARF.cpp
    lld/trunk/ELF/DWARF.h
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/DWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DWARF.cpp?rev=346616&r1=346615&r2=346616&view=diff
==============================================================================
--- lld/trunk/ELF/DWARF.cpp (original)
+++ lld/trunk/ELF/DWARF.cpp Sun Nov 11 10:57:35 2018
@@ -31,11 +31,14 @@ template <class ELFT> LLDDwarfObj<ELFT>:
     if (!Sec)
       continue;
 
-    if (LLDDWARFSection *M = StringSwitch<LLDDWARFSection *>(Sec->Name)
-                                 .Case(".debug_info", &InfoSection)
-                                 .Case(".debug_ranges", &RangeSection)
-                                 .Case(".debug_line", &LineSection)
-                                 .Default(nullptr)) {
+    if (LLDDWARFSection *M =
+            StringSwitch<LLDDWARFSection *>(Sec->Name)
+                .Case(".debug_gnu_pubnames", &GnuPubNamesSection)
+                .Case(".debug_gnu_pubtypes", &GnuPubTypesSection)
+                .Case(".debug_info", &InfoSection)
+                .Case(".debug_ranges", &RangeSection)
+                .Case(".debug_line", &LineSection)
+                .Default(nullptr)) {
       M->Data = toStringRef(Sec->data());
       M->Sec = Sec;
       continue;
@@ -43,10 +46,6 @@ template <class ELFT> LLDDwarfObj<ELFT>:
 
     if (Sec->Name == ".debug_abbrev")
       AbbrevSection = toStringRef(Sec->data());
-    else if (Sec->Name == ".debug_gnu_pubnames")
-      GnuPubNamesSection = toStringRef(Sec->data());
-    else if (Sec->Name == ".debug_gnu_pubtypes")
-      GnuPubTypesSection = toStringRef(Sec->data());
     else if (Sec->Name == ".debug_str")
       StrSection = toStringRef(Sec->data());
     else if (Sec->Name == ".debug_line_str")

Modified: lld/trunk/ELF/DWARF.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DWARF.h?rev=346616&r1=346615&r2=346616&view=diff
==============================================================================
--- lld/trunk/ELF/DWARF.h (original)
+++ lld/trunk/ELF/DWARF.h Sun Nov 11 10:57:35 2018
@@ -41,19 +41,19 @@ public:
     return LineSection;
   }
 
-  StringRef getFileName() const override { return ""; }
-  StringRef getAbbrevSection() const override { return AbbrevSection; }
-  StringRef getStringSection() const override { return StrSection; }
-  StringRef getLineStringSection() const override { return LineStringSection; }
-
-  StringRef getGnuPubNamesSection() const override {
+  const llvm::DWARFSection &getGnuPubNamesSection() const override {
     return GnuPubNamesSection;
   }
 
-  StringRef getGnuPubTypesSection() const override {
+  const llvm::DWARFSection &getGnuPubTypesSection() const override {
     return GnuPubTypesSection;
   }
 
+  StringRef getFileName() const override { return ""; }
+  StringRef getAbbrevSection() const override { return AbbrevSection; }
+  StringRef getStringSection() const override { return StrSection; }
+  StringRef getLineStringSection() const override { return LineStringSection; }
+
   bool isLittleEndian() const override {
     return ELFT::TargetEndianness == llvm::support::little;
   }
@@ -67,13 +67,13 @@ private:
                                                uint64_t Pos,
                                                ArrayRef<RelTy> Rels) const;
 
+  LLDDWARFSection GnuPubNamesSection;
+  LLDDWARFSection GnuPubTypesSection;
   LLDDWARFSection InfoSection;
   LLDDWARFSection RangeSection;
   LLDDWARFSection LineSection;
 
   StringRef AbbrevSection;
-  StringRef GnuPubNamesSection;
-  StringRef GnuPubTypesSection;
   StringRef StrSection;
   StringRef LineStringSection;
 };

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=346616&r1=346615&r2=346616&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Sun Nov 11 10:57:35 2018
@@ -2412,14 +2412,16 @@ readAddressAreas(DWARFContext &Dwarf, In
   return Ret;
 }
 
+template <class ELFT>
 static std::vector<GdbIndexSection::NameTypeEntry>
 readPubNamesAndTypes(DWARFContext &Dwarf, uint32_t Idx) {
-  StringRef Sec1 = Dwarf.getDWARFObj().getGnuPubNamesSection();
-  StringRef Sec2 = Dwarf.getDWARFObj().getGnuPubTypesSection();
+  auto &Obj = static_cast<const LLDDwarfObj<ELFT> &>(Dwarf.getDWARFObj());
+  const DWARFSection &PubNames = Obj.getGnuPubNamesSection();
+  const DWARFSection &PubTypes = Obj.getGnuPubTypesSection();
 
   std::vector<GdbIndexSection::NameTypeEntry> Ret;
-  for (StringRef Sec : {Sec1, Sec2}) {
-    DWARFDebugPubTable Table(Sec, Config->IsLE, true);
+  for (const DWARFSection *Pub : {&PubNames, &PubTypes}) {
+    DWARFDebugPubTable Table(Obj, *Pub, Config->IsLE, true);
     for (const DWARFDebugPubTable::Set &Set : Table.getData())
       for (const DWARFDebugPubTable::Entry &Ent : Set.Entries)
         Ret.push_back({{Ent.Name, computeGdbHash(Ent.Name)},
@@ -2517,7 +2519,7 @@ template <class ELFT> GdbIndexSection *G
     Chunks[I].Sec = Sections[I];
     Chunks[I].CompilationUnits = readCuList(Dwarf);
     Chunks[I].AddressAreas = readAddressAreas(Dwarf, Sections[I]);
-    NameTypes[I] = readPubNamesAndTypes(Dwarf, I);
+    NameTypes[I] = readPubNamesAndTypes<ELFT>(Dwarf, I);
   });
 
   auto *Ret = make<GdbIndexSection>();




More information about the llvm-commits mailing list