[llvm-commits] [llvm] r167728 - in /llvm/trunk: include/llvm/DebugInfo/DIContext.h lib/DebugInfo/DIContext.cpp lib/DebugInfo/DWARFContext.h lib/DebugInfo/DWARFFormValue.cpp tools/llvm-dwarfdump/llvm-dwarfdump.cpp

Alexey Samsonov samsonov at google.com
Mon Nov 12 06:25:36 PST 2012


Author: samsonov
Date: Mon Nov 12 08:25:36 2012
New Revision: 167728

URL: http://llvm.org/viewvc/llvm-project?rev=167728&view=rev
Log:
Fixup for r167558: Store raw pointer (instead of reference) to RelocMap in DIContext. This is needed to prevent crashes because of dangling reference if the clients don't provide RelocMap to DIContext constructor.

Modified:
    llvm/trunk/include/llvm/DebugInfo/DIContext.h
    llvm/trunk/lib/DebugInfo/DIContext.cpp
    llvm/trunk/lib/DebugInfo/DWARFContext.h
    llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp
    llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DIContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=167728&r1=167727&r2=167728&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DIContext.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DIContext.h Mon Nov 12 08:25:36 2012
@@ -109,7 +109,7 @@
                                     StringRef lineSection = StringRef(),
                                     StringRef stringSection = StringRef(),
                                     StringRef rangeSection = StringRef(),
-                                    const RelocAddrMap &Map = RelocAddrMap());
+                                    const RelocAddrMap *Map = 0);
 
   virtual void dump(raw_ostream &OS) = 0;
 

Modified: llvm/trunk/lib/DebugInfo/DIContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DIContext.cpp?rev=167728&r1=167727&r2=167728&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DIContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DIContext.cpp Mon Nov 12 08:25:36 2012
@@ -20,7 +20,7 @@
                                       StringRef lineSection,
                                       StringRef stringSection,
                                       StringRef rangeSection,
-                                      const RelocAddrMap &Map) {
+                                      const RelocAddrMap *Map) {
   return new DWARFContextInMemory(isLittleEndian, infoSection, abbrevSection,
                                   aRangeSection, lineSection, stringSection,
                                   rangeSection, Map);

Modified: llvm/trunk/lib/DebugInfo/DWARFContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.h?rev=167728&r1=167727&r2=167728&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFContext.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFContext.h Mon Nov 12 08:25:36 2012
@@ -26,7 +26,7 @@
 /// methods that a concrete implementation provides.
 class DWARFContext : public DIContext {
   bool IsLittleEndian;
-  const RelocAddrMap &RelocMap;
+  const RelocAddrMap *RelocMap;
 
   SmallVector<DWARFCompileUnit, 1> CUs;
   OwningPtr<DWARFDebugAbbrev> Abbrev;
@@ -39,7 +39,7 @@
   /// Read compile units from the debug_info section and store them in CUs.
   void parseCompileUnits();
 protected:
-  DWARFContext(bool isLittleEndian, const RelocAddrMap &Map) :
+  DWARFContext(bool isLittleEndian, const RelocAddrMap *Map) :
     IsLittleEndian(isLittleEndian), RelocMap(Map) {}
 public:
   virtual void dump(raw_ostream &OS);
@@ -73,7 +73,7 @@
       DILineInfoSpecifier Specifier = DILineInfoSpecifier());
 
   bool isLittleEndian() const { return IsLittleEndian; }
-  const RelocAddrMap &relocMap() const { return RelocMap; }
+  const RelocAddrMap *relocMap() const { return RelocMap; }
 
   virtual StringRef getInfoSection() = 0;
   virtual StringRef getAbbrevSection() = 0;
@@ -113,7 +113,7 @@
                        StringRef lineSection,
                        StringRef stringSection,
                        StringRef rangeSection,
-                       const RelocAddrMap &Map = RelocAddrMap())
+                       const RelocAddrMap *Map = 0)
     : DWARFContext(isLittleEndian, Map),
       InfoSection(infoSection),
       AbbrevSection(abbrevSection),

Modified: llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp?rev=167728&r1=167727&r2=167728&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp Mon Nov 12 08:25:36 2012
@@ -100,16 +100,20 @@
     switch (Form) {
     case DW_FORM_addr:
     case DW_FORM_ref_addr: {
-      RelocAddrMap::const_iterator AI
-        = cu->getContext().relocMap().find(*offset_ptr);
-      if (AI != cu->getContext().relocMap().end()) {
-        const std::pair<uint8_t, int64_t> &R = AI->second;
-        Value.uval = R.second;
-        *offset_ptr += R.first;
-      } else
+      bool InRelocMap = false;
+      if (const RelocAddrMap *RelocMap = cu->getContext().relocMap()) {
+        RelocAddrMap::const_iterator AI = RelocMap->find(*offset_ptr);
+        if (AI != RelocMap->end()) {
+          const std::pair<uint8_t, int64_t> &R = AI->second;
+          Value.uval = R.second;
+          *offset_ptr += R.first;
+          InRelocMap = true;
+        }
+      }
+      if (!InRelocMap)
         Value.uval = data.getUnsigned(offset_ptr, cu->getAddressByteSize());
-    }
       break;
+    }
     case DW_FORM_exprloc:
     case DW_FORM_block:
       Value.uval = data.getULEB128(offset_ptr);
@@ -148,13 +152,17 @@
       Value.sval = data.getSLEB128(offset_ptr);
       break;
     case DW_FORM_strp: {
-      RelocAddrMap::const_iterator AI
-        = cu->getContext().relocMap().find(*offset_ptr);
-      if (AI != cu->getContext().relocMap().end()) {
-        const std::pair<uint8_t, int64_t> &R = AI->second;
-        Value.uval = R.second;
-        *offset_ptr += R.first;
-      } else
+      bool InRelocMap = false;
+      if (const RelocAddrMap *RelocMap = cu->getContext().relocMap()) {
+        RelocAddrMap::const_iterator AI = RelocMap->find(*offset_ptr);
+        if (AI != RelocMap->end()) {
+          const std::pair<uint8_t, int64_t> &R = AI->second;
+          Value.uval = R.second;
+          *offset_ptr += R.first;
+          InRelocMap = true;
+        }
+      }
+      if (!InRelocMap)
         Value.uval = data.getU32(offset_ptr);
       break;
     }

Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=167728&r1=167727&r2=167728&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Mon Nov 12 08:25:36 2012
@@ -162,7 +162,7 @@
                                                         DebugLineSection,
                                                         DebugStringSection,
                                                         DebugRangesSection,
-                                                        RelocMap));
+                                                        &RelocMap));
   if (Address == -1ULL) {
     outs() << Filename
            << ":\tfile format " << Obj->getFileFormatName() << "\n\n";





More information about the llvm-commits mailing list