Object, COFF: getRelocationSymbol shouldn't assert
authorDavid Majnemer <david.majnemer@gmail.com>
Thu, 13 Nov 2014 07:42:11 +0000 (07:42 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Thu, 13 Nov 2014 07:42:11 +0000 (07:42 +0000)
lib/Object is supposed to be robust to malformed object files.  Don't
assert if we don't have a symbol table.  I'll try to come up with a test
case later.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221870 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/COFFObjectFile.cpp
tools/llvm-readobj/COFFDumper.cpp

index 8d8711c7837b57d683ac7410dd0888f75668be16..8312fed734c485310c586bf762dda71e784ef20d 100644 (file)
@@ -996,7 +996,7 @@ symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const {
   else if (SymbolTable32)
     Ref.p = reinterpret_cast<uintptr_t>(SymbolTable32 + R->SymbolTableIndex);
   else
-    llvm_unreachable("no symbol table pointer!");
+    return symbol_end();
   return symbol_iterator(SymbolRef(Ref, this));
 }
 
index 7c12f068a82d96b9e83e55977d39af005cb9b75f..bb4315835c20e715d541743e7bcf356c3128956b 100644 (file)
@@ -800,7 +800,7 @@ void COFFDumper::printRelocation(const SectionRef &Section,
   if (error(Reloc.getTypeName(RelocName)))
     return;
   symbol_iterator Symbol = Reloc.getSymbol();
-  if (error(Symbol->getName(SymbolName)))
+  if (Symbol != Obj->symbol_end() && error(Symbol->getName(SymbolName)))
     return;
   if (error(Section.getContents(Contents)))
     return;
@@ -809,12 +809,12 @@ void COFFDumper::printRelocation(const SectionRef &Section,
     DictScope Group(W, "Relocation");
     W.printHex("Offset", Offset);
     W.printNumber("Type", RelocName, RelocType);
-    W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
+    W.printString("Symbol", SymbolName.empty() ? "-" : SymbolName);
   } else {
     raw_ostream& OS = W.startLine();
     OS << W.hex(Offset)
        << " " << RelocName
-       << " " << (SymbolName.size() > 0 ? SymbolName : "-")
+       << " " << (SymbolName.empty() ? "-" : SymbolName)
        << "\n";
   }
 }