[llvm] r259317 - [dsymutil] Allow debug map mappings with no object file address. NFC

Frederic Riss via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 30 20:29:22 PST 2016


Author: friss
Date: Sat Jan 30 22:29:22 2016
New Revision: 259317

URL: http://llvm.org/viewvc/llvm-project?rev=259317&view=rev
Log:
[dsymutil] Allow debug map mappings with no object file address. NFC

This change just changes the data structure that ties symbol names,
object file address and linked binary addresses to accept mappings
with no object file address. Such symbol mappings are not fed into
the debug map yet, so this patch is NFC.
A subsequent patch will make use of this functionality for common
symbols.

Modified:
    llvm/trunk/tools/dsymutil/DebugMap.cpp
    llvm/trunk/tools/dsymutil/DebugMap.h
    llvm/trunk/tools/dsymutil/DwarfLinker.cpp
    llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp

Modified: llvm/trunk/tools/dsymutil/DebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.cpp?rev=259317&r1=259316&r2=259317&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.cpp (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.cpp Sat Jan 30 22:29:22 2016
@@ -24,13 +24,13 @@ DebugMapObject::DebugMapObject(StringRef
                                sys::TimeValue Timestamp)
     : Filename(ObjectFilename), Timestamp(Timestamp) {}
 
-bool DebugMapObject::addSymbol(StringRef Name, uint64_t ObjectAddress,
+bool DebugMapObject::addSymbol(StringRef Name, Optional<uint64_t> ObjectAddress,
                                uint64_t LinkedAddress, uint32_t Size) {
   auto InsertResult = Symbols.insert(
       std::make_pair(Name, SymbolMapping(ObjectAddress, LinkedAddress, Size)));
 
-  if (InsertResult.second)
-    AddressToMapping[ObjectAddress] = &*InsertResult.first;
+  if (ObjectAddress && InsertResult.second)
+    AddressToMapping[*ObjectAddress] = &*InsertResult.first;
   return InsertResult.second;
 }
 
@@ -47,8 +47,11 @@ void DebugMapObject::print(raw_ostream &
       Entries.begin(), Entries.end(),
       [](const Entry &LHS, const Entry &RHS) { return LHS.first < RHS.first; });
   for (const auto &Sym : Entries) {
-    OS << format("\t%016" PRIx64 " => %016" PRIx64 "+0x%x\t%s\n",
-                 uint64_t(Sym.second.ObjectAddress),
+    if (Sym.second.ObjectAddress)
+      OS << format("\t%016" PRIx64, uint64_t(*Sym.second.ObjectAddress));
+    else
+      OS << "\t????????????????";
+    OS << format(" => %016" PRIx64 "+0x%x\t%s\n",
                  uint64_t(Sym.second.BinaryAddress), uint32_t(Sym.second.Size),
                  Sym.first.data());
   }
@@ -136,7 +139,7 @@ struct MappingTraits<dsymutil::DebugMapO
 void MappingTraits<std::pair<std::string, DebugMapObject::SymbolMapping>>::
     mapping(IO &io, std::pair<std::string, DebugMapObject::SymbolMapping> &s) {
   io.mapRequired("sym", s.first);
-  io.mapRequired("objAddr", s.second.ObjectAddress);
+  io.mapOptional("objAddr", s.second.ObjectAddress);
   io.mapRequired("binAddr", s.second.BinaryAddress);
   io.mapOptional("size", s.second.Size);
 }
@@ -237,7 +240,9 @@ MappingTraits<dsymutil::DebugMapObject>:
   dsymutil::DebugMapObject Res(Path, TV);
   for (auto &Entry : Entries) {
     auto &Mapping = Entry.second;
-    uint64_t ObjAddress = Mapping.ObjectAddress;
+    Optional<uint64_t> ObjAddress;
+    if (Mapping.ObjectAddress)
+      ObjAddress = *Mapping.ObjectAddress;
     auto AddressIt = SymbolAddresses.find(Entry.first);
     if (AddressIt != SymbolAddresses.end())
       ObjAddress = AddressIt->getValue();

Modified: llvm/trunk/tools/dsymutil/DebugMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.h?rev=259317&r1=259316&r2=259317&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.h (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.h Sat Jan 30 22:29:22 2016
@@ -117,12 +117,15 @@ public:
 class DebugMapObject {
 public:
   struct SymbolMapping {
-    yaml::Hex64 ObjectAddress;
+    Optional<yaml::Hex64> ObjectAddress;
     yaml::Hex64 BinaryAddress;
     yaml::Hex32 Size;
-    SymbolMapping(uint64_t ObjectAddress, uint64_t BinaryAddress, uint32_t Size)
-        : ObjectAddress(ObjectAddress), BinaryAddress(BinaryAddress),
-          Size(Size) {}
+    SymbolMapping(Optional<uint64_t> ObjectAddr, uint64_t BinaryAddress,
+                  uint32_t Size)
+        : BinaryAddress(BinaryAddress), Size(Size) {
+      if (ObjectAddr)
+        ObjectAddress = *ObjectAddr;
+    }
     /// For YAML IO support
     SymbolMapping() = default;
   };
@@ -132,7 +135,7 @@ public:
   /// \brief Adds a symbol mapping to this DebugMapObject.
   /// \returns false if the symbol was already registered. The request
   /// is discarded in this case.
-  bool addSymbol(llvm::StringRef SymName, uint64_t ObjectAddress,
+  bool addSymbol(llvm::StringRef SymName, Optional<uint64_t> ObjectAddress,
                  uint64_t LinkedAddress, uint32_t Size);
 
   /// \brief Lookup a symbol mapping.

Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=259317&r1=259316&r2=259317&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Sat Jan 30 22:29:22 2016
@@ -1854,10 +1854,10 @@ void DwarfLinker::startDebugObject(DWARF
   // -gline-tables-only on Darwin.
   for (const auto &Entry : Obj.symbols()) {
     const auto &Mapping = Entry.getValue();
-    if (Mapping.Size)
-      Ranges[Mapping.ObjectAddress] = std::make_pair(
-          Mapping.ObjectAddress + Mapping.Size,
-          int64_t(Mapping.BinaryAddress) - Mapping.ObjectAddress);
+    if (Mapping.Size && Mapping.ObjectAddress)
+      Ranges[*Mapping.ObjectAddress] = std::make_pair(
+          *Mapping.ObjectAddress + Mapping.Size,
+          int64_t(Mapping.BinaryAddress) - *Mapping.ObjectAddress);
   }
 }
 
@@ -1988,14 +1988,16 @@ hasValidRelocation(uint32_t StartOffset,
 
   const auto &ValidReloc = ValidRelocs[NextValidReloc++];
   const auto &Mapping = ValidReloc.Mapping->getValue();
+  uint64_t ObjectAddress =
+      Mapping.ObjectAddress ? uint64_t(*Mapping.ObjectAddress) : UINT64_MAX;
   if (Linker.Options.Verbose)
     outs() << "Found valid debug map entry: " << ValidReloc.Mapping->getKey()
-           << " " << format("\t%016" PRIx64 " => %016" PRIx64,
-                            uint64_t(Mapping.ObjectAddress),
+           << " " << format("\t%016" PRIx64 " => %016" PRIx64, ObjectAddress,
                             uint64_t(Mapping.BinaryAddress));
 
-  Info.AddrAdjust = int64_t(Mapping.BinaryAddress) + ValidReloc.Addend -
-                    Mapping.ObjectAddress;
+  Info.AddrAdjust = int64_t(Mapping.BinaryAddress) + ValidReloc.Addend;
+  if (Mapping.ObjectAddress)
+    Info.AddrAdjust -= ObjectAddress;
   Info.InDebugMap = true;
   return true;
 }

Modified: llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp?rev=259317&r1=259316&r2=259317&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp Sat Jan 30 22:29:22 2016
@@ -391,7 +391,7 @@ void MachODebugMapParser::handleStabSymb
                    Twine(Name));
   if (!ObjectSymIt->getValue())
     return;
-  if (!CurrentDebugMapObject->addSymbol(Name, *ObjectSymIt->getValue(), Value,
+  if (!CurrentDebugMapObject->addSymbol(Name, ObjectSymIt->getValue(), Value,
                                         Size))
     return Warning(Twine("failed to insert symbol '") + Name +
                    "' in the debug map.");




More information about the llvm-commits mailing list