llvm.org GIT mirror llvm / 323f789
llvm-objdump: handle stubbed and malformed dylibs better We were quite happy to read past the end of the valid section data when disassembling. Instead we entirely skip stub dylibs, and tell the user what's happened if their section only has partial data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275487 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Northover 4 years ago
5 changed file(s) with 24 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 RUN: llvm-objdump -macho -d %p/Inputs/stubbed.dylib.macho-x86_64 | FileCheck %s
1
2 CHECK: (__TEXT,__text) section
3 CHECK-NOT: func
4 CHECK-NOT: func2
0 RUN: llvm-objdump -macho -d %p/Inputs/truncated-section.dylib.macho-x86_64 | FileCheck %s
1
2 CHECK: _func:
3 CHECK: retq
4 CHECK: retq
5
6 CHECK: section data ends, _func2 lies outside valid range
66616661
66626662 unsigned int Arch = MachOOF->getArch();
66636663
6664 // Skip all symbols if this is a stubs file.
6665 if (Bytes.size() == 0)
6666 return;
6667
66646668 // Disassemble symbol by symbol.
66656669 for (unsigned SymIdx = 0; SymIdx != Symbols.size(); SymIdx++) {
66666670 Expected SymNameOrErr = Symbols[SymIdx].getName();
67156719 continue;
67166720
67176721 // Start at the address of the symbol relative to the section's address.
6722 uint64_t SectSize = Sections[SectIdx].getSize();
67186723 uint64_t Start = Symbols[SymIdx].getValue();
67196724 uint64_t SectionAddress = Sections[SectIdx].getAddress();
67206725 Start -= SectionAddress;
6726
6727 if (Start > SectSize) {
6728 outs() << "section data ends, " << SymName
6729 << " lies outside valid range\n";
6730 return;
6731 }
67216732
67226733 // Stop disassembling either at the beginning of the next symbol or at
67236734 // the end of the section.
67446755 ++NextSymIdx;
67456756 }
67466757
6747 uint64_t SectSize = Sections[SectIdx].getSize();
6748 uint64_t End = containsNextSym ? NextSym : SectSize;
6758 uint64_t End = containsNextSym ? std::min(NextSym, SectSize) : SectSize;
67496759 uint64_t Size;
67506760
67516761 symbolTableWorked = true;