[llvm] r186029 - Don't crash in 'llvm -s' when an archive has no symtab.
Rafael Espindola
rafael.espindola at gmail.com
Wed Jul 10 13:14:23 PDT 2013
Author: rafael
Date: Wed Jul 10 15:14:22 2013
New Revision: 186029
URL: http://llvm.org/viewvc/llvm-project?rev=186029&view=rev
Log:
Don't crash in 'llvm -s' when an archive has no symtab.
Modified:
llvm/trunk/lib/Object/Archive.cpp
llvm/trunk/test/Object/nm-archive.test
llvm/trunk/tools/llvm-nm/llvm-nm.cpp
Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=186029&r1=186028&r2=186029&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Wed Jul 10 15:14:22 2013
@@ -210,7 +210,7 @@ error_code Archive::Child::getAsBinary(O
}
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 Archive::Symbol::getNext
}
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::begin_
}
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) {
Modified: llvm/trunk/test/Object/nm-archive.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/nm-archive.test?rev=186029&r1=186028&r2=186029&view=diff
==============================================================================
--- llvm/trunk/test/Object/nm-archive.test (original)
+++ llvm/trunk/test/Object/nm-archive.test Wed Jul 10 15:14:22 2013
@@ -1,25 +1,32 @@
RUN: llvm-nm %p/Inputs/archive-test.a-coff-i386 \
RUN: | FileCheck %s -check-prefix COFF
+COFF: trivial-object-test.coff-i386:
+COFF-NEXT: 00000000 d .data
+COFF-NEXT: 00000000 t .text
+COFF-NEXT: 00000000 d L_.str
+COFF-NEXT: U _SomeOtherFunction
+COFF-NEXT: 00000000 T _main
+COFF-NEXT: U _puts
+
+
RUN: llvm-as %p/Inputs/trivial.ll -o=%t1
RUN: rm -f %t2
RUN: llvm-ar rcs %t2 %t1
RUN: llvm-nm %t2 | FileCheck %s -check-prefix BITCODE
+BITCODE: U SomeOtherFunction
+BITCODE-NEXT: T main
+BITCODE-NEXT: U puts
+
+
Test we don't error with an archive with no symtab.
RUN: llvm-nm %p/Inputs/archive-test.a-gnu-no-symtab
+
Or in an archive with no symtab or string table.
RUN: llvm-nm %p/Inputs/archive-test.a-gnu-minimal
-COFF: trivial-object-test.coff-i386:
-COFF-NEXT: 00000000 d .data
-COFF-NEXT: 00000000 t .text
-COFF-NEXT: 00000000 d L_.str
-COFF-NEXT: U _SomeOtherFunction
-COFF-NEXT: 00000000 T _main
-COFF-NEXT: U _puts
-BITCODE: U SomeOtherFunction
-BITCODE-NEXT: T main
-BITCODE-NEXT: U puts
+And don't crash when asked to print a non existing symtab.
+RUN: llvm-nm -s %p/Inputs/archive-test.a-gnu-minimal
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=186029&r1=186028&r2=186029&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Wed Jul 10 15:14:22 2013
@@ -365,21 +365,24 @@ static void DumpSymbolNamesFromFile(std:
if (object::Archive *a = dyn_cast<object::Archive>(arch.get())) {
if (ArchiveMap) {
- outs() << "Archive map" << "\n";
- for (object::Archive::symbol_iterator i = a->begin_symbols(),
- e = a->end_symbols(); i != e; ++i) {
- object::Archive::child_iterator c;
- StringRef symname;
- StringRef filename;
- if (error(i->getMember(c)))
+ object::Archive::symbol_iterator I = a->begin_symbols();
+ object::Archive::symbol_iterator E = a->end_symbols();
+ if (I !=E) {
+ outs() << "Archive map" << "\n";
+ for (; I != E; ++I) {
+ object::Archive::child_iterator c;
+ StringRef symname;
+ StringRef filename;
+ if (error(I->getMember(c)))
return;
- if (error(i->getName(symname)))
+ if (error(I->getName(symname)))
return;
- if (error(c->getName(filename)))
+ if (error(c->getName(filename)))
return;
- outs() << symname << " in " << filename << "\n";
+ outs() << symname << " in " << filename << "\n";
+ }
+ outs() << "\n";
}
- outs() << "\n";
}
for (object::Archive::child_iterator i = a->begin_children(),
More information about the llvm-commits
mailing list