Don't crash in 'llvm -s' when an archive has no symtab.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186029 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp
index 292d50a..91cc4ef 100644
--- a/lib/Object/Archive.cpp
+++ b/lib/Object/Archive.cpp
@@ -210,7 +210,7 @@
}
Archive::Archive(MemoryBuffer *source, error_code &ec)
- : Binary(Binary::ID_Archive, source) {
+ : Binary(Binary::ID_Archive, source), SymbolTable(end_children()) {
// Check for sufficient magic.
if (!source || source->getBufferSize()
< (8 + sizeof(ArchiveMemberHeader)) // Smallest archive.
@@ -375,6 +375,9 @@
}
Archive::symbol_iterator Archive::begin_symbols() const {
+ if (SymbolTable == end_children())
+ return symbol_iterator(Symbol(this, 0, 0));
+
const char *buf = SymbolTable->getBuffer().begin();
if (kind() == K_GNU) {
uint32_t symbol_count = 0;
@@ -395,6 +398,9 @@
}
Archive::symbol_iterator Archive::end_symbols() const {
+ if (SymbolTable == end_children())
+ return symbol_iterator(Symbol(this, 0, 0));
+
const char *buf = SymbolTable->getBuffer().begin();
uint32_t symbol_count = 0;
if (kind() == K_GNU) {