llvm.org GIT mirror llvm / 5159718
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 Rafael Espindola 6 years ago
3 changed file(s) with 39 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
209209 }
210210
211211 Archive::Archive(MemoryBuffer *source, error_code &ec)
212 : Binary(Binary::ID_Archive, source) {
212 : Binary(Binary::ID_Archive, source), SymbolTable(end_children()) {
213213 // Check for sufficient magic.
214214 if (!source || source->getBufferSize()
215215 < (8 + sizeof(ArchiveMemberHeader)) // Smallest archive.
374374 }
375375
376376 Archive::symbol_iterator Archive::begin_symbols() const {
377 if (SymbolTable == end_children())
378 return symbol_iterator(Symbol(this, 0, 0));
379
377380 const char *buf = SymbolTable->getBuffer().begin();
378381 if (kind() == K_GNU) {
379382 uint32_t symbol_count = 0;
394397 }
395398
396399 Archive::symbol_iterator Archive::end_symbols() const {
400 if (SymbolTable == end_children())
401 return symbol_iterator(Symbol(this, 0, 0));
402
397403 const char *buf = SymbolTable->getBuffer().begin();
398404 uint32_t symbol_count = 0;
399405 if (kind() == K_GNU) {
0 RUN: llvm-nm %p/Inputs/archive-test.a-coff-i386 \
11 RUN: | FileCheck %s -check-prefix COFF
2
3 RUN: llvm-as %p/Inputs/trivial.ll -o=%t1
4 RUN: rm -f %t2
5 RUN: llvm-ar rcs %t2 %t1
6 RUN: llvm-nm %t2 | FileCheck %s -check-prefix BITCODE
7
8 Test we don't error with an archive with no symtab.
9 RUN: llvm-nm %p/Inputs/archive-test.a-gnu-no-symtab
10
11 Or in an archive with no symtab or string table.
12 RUN: llvm-nm %p/Inputs/archive-test.a-gnu-minimal
132
143 COFF: trivial-object-test.coff-i386:
154 COFF-NEXT: 00000000 d .data
198 COFF-NEXT: 00000000 T _main
209 COFF-NEXT: U _puts
2110
11
12 RUN: llvm-as %p/Inputs/trivial.ll -o=%t1
13 RUN: rm -f %t2
14 RUN: llvm-ar rcs %t2 %t1
15 RUN: llvm-nm %t2 | FileCheck %s -check-prefix BITCODE
16
2217 BITCODE: U SomeOtherFunction
2318 BITCODE-NEXT: T main
2419 BITCODE-NEXT: U puts
20
21
22 Test we don't error with an archive with no symtab.
23 RUN: llvm-nm %p/Inputs/archive-test.a-gnu-no-symtab
24
25
26 Or in an archive with no symtab or string table.
27 RUN: llvm-nm %p/Inputs/archive-test.a-gnu-minimal
28
29
30 And don't crash when asked to print a non existing symtab.
31 RUN: llvm-nm -s %p/Inputs/archive-test.a-gnu-minimal
364364
365365 if (object::Archive *a = dyn_cast(arch.get())) {
366366 if (ArchiveMap) {
367 outs() << "Archive map" << "\n";
368 for (object::Archive::symbol_iterator i = a->begin_symbols(),
369 e = a->end_symbols(); i != e; ++i) {
370 object::Archive::child_iterator c;
371 StringRef symname;
372 StringRef filename;
373 if (error(i->getMember(c)))
367 object::Archive::symbol_iterator I = a->begin_symbols();
368 object::Archive::symbol_iterator E = a->end_symbols();
369 if (I !=E) {
370 outs() << "Archive map" << "\n";
371 for (; I != E; ++I) {
372 object::Archive::child_iterator c;
373 StringRef symname;
374 StringRef filename;
375 if (error(I->getMember(c)))
374376 return;
375 if (error(i->getName(symname)))
377 if (error(I->getName(symname)))
376378 return;
377 if (error(c->getName(filename)))
379 if (error(c->getName(filename)))
378380 return;
379 outs() << symname << " in " << filename << "\n";
381 outs() << symname << " in " << filename << "\n";
382 }
383 outs() << "\n";
380384 }
381 outs() << "\n";
382385 }
383386
384387 for (object::Archive::child_iterator i = a->begin_children(),