[lld] r342299 - Rename GdbIndex.{cpp,h} -> DWARF.{cpp,h}.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 14 16:51:05 PDT 2018


Author: ruiu
Date: Fri Sep 14 16:51:05 2018
New Revision: 342299

URL: http://llvm.org/viewvc/llvm-project?rev=342299&view=rev
Log:
Rename GdbIndex.{cpp,h} -> DWARF.{cpp,h}.

These files used to contain classes and functions for .gdb_index,
but they are moved to SyntheticSections.{cpp,h}, so the name is now
irrelevant.

Added:
    lld/trunk/ELF/DWARF.cpp
    lld/trunk/ELF/DWARF.h
Removed:
    lld/trunk/ELF/GdbIndex.cpp
    lld/trunk/ELF/GdbIndex.h
Modified:
    lld/trunk/ELF/CMakeLists.txt
    lld/trunk/ELF/SyntheticSections.h

Modified: lld/trunk/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/CMakeLists.txt?rev=342299&r1=342298&r2=342299&view=diff
==============================================================================
--- lld/trunk/ELF/CMakeLists.txt (original)
+++ lld/trunk/ELF/CMakeLists.txt Fri Sep 14 16:51:05 2018
@@ -22,11 +22,11 @@ add_lld_library(lldELF
   Arch/X86.cpp
   Arch/X86_64.cpp
   CallGraphSort.cpp
+  DWARF.cpp
   Driver.cpp
   DriverUtils.cpp
   EhFrame.cpp
   Filesystem.cpp
-  GdbIndex.cpp
   ICF.cpp
   InputFiles.cpp
   InputSection.cpp

Added: lld/trunk/ELF/DWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DWARF.cpp?rev=342299&view=auto
==============================================================================
--- lld/trunk/ELF/DWARF.cpp (added)
+++ lld/trunk/ELF/DWARF.cpp Fri Sep 14 16:51:05 2018
@@ -0,0 +1,101 @@
+//===- DWARF.cpp ----------------------------------------------------------===//
+//
+//                             The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// The -gdb-index option instructs the linker to emit a .gdb_index section.
+// The section contains information to make gdb startup faster.
+// The format of the section is described at
+// https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html.
+//
+//===----------------------------------------------------------------------===//
+
+#include "DWARF.h"
+#include "Symbols.h"
+#include "lld/Common/Memory.h"
+#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
+#include "llvm/Object/ELFObjectFile.h"
+
+using namespace llvm;
+using namespace llvm::object;
+using namespace lld;
+using namespace lld::elf;
+
+template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *Obj) {
+  for (InputSectionBase *Sec : Obj->getSections()) {
+    if (!Sec)
+      continue;
+    if (LLDDWARFSection *M = StringSwitch<LLDDWARFSection *>(Sec->Name)
+                                 .Case(".debug_info", &InfoSection)
+                                 .Case(".debug_ranges", &RangeSection)
+                                 .Case(".debug_line", &LineSection)
+                                 .Default(nullptr)) {
+      Sec->maybeDecompress();
+      M->Data = toStringRef(Sec->Data);
+      M->Sec = Sec;
+      continue;
+    }
+    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);
+  }
+}
+
+// Find if there is a relocation at Pos in Sec.  The code is a bit
+// more complicated than usual because we need to pass a section index
+// to llvm since it has no idea about InputSection.
+template <class ELFT>
+template <class RelTy>
+Optional<RelocAddrEntry>
+LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
+                           ArrayRef<RelTy> Rels) const {
+  auto It = std::lower_bound(
+      Rels.begin(), Rels.end(), Pos,
+      [](const RelTy &A, uint64_t B) { return A.r_offset < B; });
+  if (It == Rels.end() || It->r_offset != Pos)
+    return None;
+  const RelTy &Rel = *It;
+
+  const ObjFile<ELFT> *File = Sec.getFile<ELFT>();
+  uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
+  const typename ELFT::Sym &Sym = File->getELFSyms()[SymIndex];
+  uint32_t SecIndex = File->getSectionIndex(Sym);
+
+  // Broken debug info can point to a non-Defined symbol.
+  auto *DR = dyn_cast<Defined>(&File->getRelocTargetSym(Rel));
+  if (!DR) {
+    error("unsupported relocation target while parsing debug info");
+    return None;
+  }
+  uint64_t Val = DR->Value + getAddend<ELFT>(Rel);
+
+  // FIXME: We should be consistent about always adding the file
+  // offset or not.
+  if (DR->Section->Flags & ELF::SHF_ALLOC)
+    Val += cast<InputSection>(DR->Section)->getOffsetInFile();
+
+  return RelocAddrEntry{SecIndex, Val};
+}
+
+template <class ELFT>
+Optional<RelocAddrEntry> LLDDwarfObj<ELFT>::find(const llvm::DWARFSection &S,
+                                                 uint64_t Pos) const {
+  auto &Sec = static_cast<const LLDDWARFSection &>(S);
+  if (Sec.Sec->AreRelocsRela)
+    return findAux(*Sec.Sec, Pos, Sec.Sec->template relas<ELFT>());
+  return findAux(*Sec.Sec, Pos, Sec.Sec->template rels<ELFT>());
+}
+
+template class elf::LLDDwarfObj<ELF32LE>;
+template class elf::LLDDwarfObj<ELF32BE>;
+template class elf::LLDDwarfObj<ELF64LE>;
+template class elf::LLDDwarfObj<ELF64BE>;

Added: lld/trunk/ELF/DWARF.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DWARF.h?rev=342299&view=auto
==============================================================================
--- lld/trunk/ELF/DWARF.h (added)
+++ lld/trunk/ELF/DWARF.h Fri Sep 14 16:51:05 2018
@@ -0,0 +1,70 @@
+//===- DWARF.h -----------------------------------------------*- C++ -*-===//
+//
+//                             The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===-------------------------------------------------------------------===//
+
+#ifndef LLD_ELF_DWARF_H
+#define LLD_ELF_DWARF_H
+
+#include "InputFiles.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
+#include "llvm/Object/ELF.h"
+
+namespace lld {
+namespace elf {
+
+class InputSection;
+
+struct LLDDWARFSection final : public llvm::DWARFSection {
+  InputSectionBase *Sec = nullptr;
+};
+
+template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject {
+  LLDDWARFSection InfoSection;
+  LLDDWARFSection RangeSection;
+  LLDDWARFSection LineSection;
+  StringRef AbbrevSection;
+  StringRef GnuPubNamesSection;
+  StringRef GnuPubTypesSection;
+  StringRef StrSection;
+
+  template <class RelTy>
+  llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &Sec,
+                                               uint64_t Pos,
+                                               ArrayRef<RelTy> Rels) const;
+
+public:
+  explicit LLDDwarfObj(ObjFile<ELFT> *Obj);
+  const llvm::DWARFSection &getInfoSection() const override {
+    return InfoSection;
+  }
+  const llvm::DWARFSection &getRangeSection() const override {
+    return RangeSection;
+  }
+  const llvm::DWARFSection &getLineSection() const override {
+    return LineSection;
+  }
+  StringRef getFileName() const override { return ""; }
+  StringRef getAbbrevSection() const override { return AbbrevSection; }
+  StringRef getStringSection() const override { return StrSection; }
+  StringRef getGnuPubNamesSection() const override {
+    return GnuPubNamesSection;
+  }
+  StringRef getGnuPubTypesSection() const override {
+    return GnuPubTypesSection;
+  }
+  bool isLittleEndian() const override {
+    return ELFT::TargetEndianness == llvm::support::little;
+  }
+  llvm::Optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &Sec,
+                                            uint64_t Pos) const override;
+};
+
+} // namespace elf
+} // namespace lld
+
+#endif

Removed: lld/trunk/ELF/GdbIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/GdbIndex.cpp?rev=342298&view=auto
==============================================================================
--- lld/trunk/ELF/GdbIndex.cpp (original)
+++ lld/trunk/ELF/GdbIndex.cpp (removed)
@@ -1,101 +0,0 @@
-//===- GdbIndex.cpp -------------------------------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// The -gdb-index option instructs the linker to emit a .gdb_index section.
-// The section contains information to make gdb startup faster.
-// The format of the section is described at
-// https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html.
-//
-//===----------------------------------------------------------------------===//
-
-#include "GdbIndex.h"
-#include "Symbols.h"
-#include "lld/Common/Memory.h"
-#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
-#include "llvm/Object/ELFObjectFile.h"
-
-using namespace llvm;
-using namespace llvm::object;
-using namespace lld;
-using namespace lld::elf;
-
-template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *Obj) {
-  for (InputSectionBase *Sec : Obj->getSections()) {
-    if (!Sec)
-      continue;
-    if (LLDDWARFSection *M = StringSwitch<LLDDWARFSection *>(Sec->Name)
-                                 .Case(".debug_info", &InfoSection)
-                                 .Case(".debug_ranges", &RangeSection)
-                                 .Case(".debug_line", &LineSection)
-                                 .Default(nullptr)) {
-      Sec->maybeDecompress();
-      M->Data = toStringRef(Sec->Data);
-      M->Sec = Sec;
-      continue;
-    }
-    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);
-  }
-}
-
-// Find if there is a relocation at Pos in Sec.  The code is a bit
-// more complicated than usual because we need to pass a section index
-// to llvm since it has no idea about InputSection.
-template <class ELFT>
-template <class RelTy>
-Optional<RelocAddrEntry>
-LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
-                           ArrayRef<RelTy> Rels) const {
-  auto It = std::lower_bound(
-      Rels.begin(), Rels.end(), Pos,
-      [](const RelTy &A, uint64_t B) { return A.r_offset < B; });
-  if (It == Rels.end() || It->r_offset != Pos)
-    return None;
-  const RelTy &Rel = *It;
-
-  const ObjFile<ELFT> *File = Sec.getFile<ELFT>();
-  uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
-  const typename ELFT::Sym &Sym = File->getELFSyms()[SymIndex];
-  uint32_t SecIndex = File->getSectionIndex(Sym);
-
-  // Broken debug info can point to a non-Defined symbol.
-  auto *DR = dyn_cast<Defined>(&File->getRelocTargetSym(Rel));
-  if (!DR) {
-    error("unsupported relocation target while parsing debug info");
-    return None;
-  }
-  uint64_t Val = DR->Value + getAddend<ELFT>(Rel);
-
-  // FIXME: We should be consistent about always adding the file
-  // offset or not.
-  if (DR->Section->Flags & ELF::SHF_ALLOC)
-    Val += cast<InputSection>(DR->Section)->getOffsetInFile();
-
-  return RelocAddrEntry{SecIndex, Val};
-}
-
-template <class ELFT>
-Optional<RelocAddrEntry> LLDDwarfObj<ELFT>::find(const llvm::DWARFSection &S,
-                                                 uint64_t Pos) const {
-  auto &Sec = static_cast<const LLDDWARFSection &>(S);
-  if (Sec.Sec->AreRelocsRela)
-    return findAux(*Sec.Sec, Pos, Sec.Sec->template relas<ELFT>());
-  return findAux(*Sec.Sec, Pos, Sec.Sec->template rels<ELFT>());
-}
-
-template class elf::LLDDwarfObj<ELF32LE>;
-template class elf::LLDDwarfObj<ELF32BE>;
-template class elf::LLDDwarfObj<ELF64LE>;
-template class elf::LLDDwarfObj<ELF64BE>;

Removed: lld/trunk/ELF/GdbIndex.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/GdbIndex.h?rev=342298&view=auto
==============================================================================
--- lld/trunk/ELF/GdbIndex.h (original)
+++ lld/trunk/ELF/GdbIndex.h (removed)
@@ -1,70 +0,0 @@
-//===- GdbIndex.h --------------------------------------------*- C++ -*-===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===-------------------------------------------------------------------===//
-
-#ifndef LLD_ELF_GDB_INDEX_H
-#define LLD_ELF_GDB_INDEX_H
-
-#include "InputFiles.h"
-#include "llvm/DebugInfo/DWARF/DWARFContext.h"
-#include "llvm/Object/ELF.h"
-
-namespace lld {
-namespace elf {
-
-class InputSection;
-
-struct LLDDWARFSection final : public llvm::DWARFSection {
-  InputSectionBase *Sec = nullptr;
-};
-
-template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject {
-  LLDDWARFSection InfoSection;
-  LLDDWARFSection RangeSection;
-  LLDDWARFSection LineSection;
-  StringRef AbbrevSection;
-  StringRef GnuPubNamesSection;
-  StringRef GnuPubTypesSection;
-  StringRef StrSection;
-
-  template <class RelTy>
-  llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &Sec,
-                                               uint64_t Pos,
-                                               ArrayRef<RelTy> Rels) const;
-
-public:
-  explicit LLDDwarfObj(ObjFile<ELFT> *Obj);
-  const llvm::DWARFSection &getInfoSection() const override {
-    return InfoSection;
-  }
-  const llvm::DWARFSection &getRangeSection() const override {
-    return RangeSection;
-  }
-  const llvm::DWARFSection &getLineSection() const override {
-    return LineSection;
-  }
-  StringRef getFileName() const override { return ""; }
-  StringRef getAbbrevSection() const override { return AbbrevSection; }
-  StringRef getStringSection() const override { return StrSection; }
-  StringRef getGnuPubNamesSection() const override {
-    return GnuPubNamesSection;
-  }
-  StringRef getGnuPubTypesSection() const override {
-    return GnuPubTypesSection;
-  }
-  bool isLittleEndian() const override {
-    return ELFT::TargetEndianness == llvm::support::little;
-  }
-  llvm::Optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &Sec,
-                                            uint64_t Pos) const override;
-};
-
-} // namespace elf
-} // namespace lld
-
-#endif

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=342299&r1=342298&r2=342299&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Fri Sep 14 16:51:05 2018
@@ -21,8 +21,8 @@
 #ifndef LLD_ELF_SYNTHETIC_SECTION_H
 #define LLD_ELF_SYNTHETIC_SECTION_H
 
+#include "DWARF.h"
 #include "EhFrame.h"
-#include "GdbIndex.h"
 #include "InputSection.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/MC/StringTableBuilder.h"




More information about the llvm-commits mailing list