mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-02 13:21:43 +00:00
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
This commit is contained in:
parent
9c524094cf
commit
323f7893f4
BIN
test/tools/llvm-objdump/X86/Inputs/stubbed.dylib.macho-x86_64
Executable file
BIN
test/tools/llvm-objdump/X86/Inputs/stubbed.dylib.macho-x86_64
Executable file
Binary file not shown.
BIN
test/tools/llvm-objdump/X86/Inputs/truncated-section.dylib.macho-x86_64
Executable file
BIN
test/tools/llvm-objdump/X86/Inputs/truncated-section.dylib.macho-x86_64
Executable file
Binary file not shown.
5
test/tools/llvm-objdump/X86/stubbed-dylib.test
Normal file
5
test/tools/llvm-objdump/X86/stubbed-dylib.test
Normal file
@ -0,0 +1,5 @@
|
||||
RUN: llvm-objdump -macho -d %p/Inputs/stubbed.dylib.macho-x86_64 | FileCheck %s
|
||||
|
||||
CHECK: (__TEXT,__text) section
|
||||
CHECK-NOT: func
|
||||
CHECK-NOT: func2
|
7
test/tools/llvm-objdump/X86/truncated-section.test
Normal file
7
test/tools/llvm-objdump/X86/truncated-section.test
Normal file
@ -0,0 +1,7 @@
|
||||
RUN: llvm-objdump -macho -d %p/Inputs/truncated-section.dylib.macho-x86_64 | FileCheck %s
|
||||
|
||||
CHECK: _func:
|
||||
CHECK: retq
|
||||
CHECK: retq
|
||||
|
||||
CHECK: section data ends, _func2 lies outside valid range
|
@ -6662,6 +6662,10 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
||||
|
||||
unsigned int Arch = MachOOF->getArch();
|
||||
|
||||
// Skip all symbols if this is a stubs file.
|
||||
if (Bytes.size() == 0)
|
||||
return;
|
||||
|
||||
// Disassemble symbol by symbol.
|
||||
for (unsigned SymIdx = 0; SymIdx != Symbols.size(); SymIdx++) {
|
||||
Expected<StringRef> SymNameOrErr = Symbols[SymIdx].getName();
|
||||
@ -6716,10 +6720,17 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
||||
continue;
|
||||
|
||||
// Start at the address of the symbol relative to the section's address.
|
||||
uint64_t SectSize = Sections[SectIdx].getSize();
|
||||
uint64_t Start = Symbols[SymIdx].getValue();
|
||||
uint64_t SectionAddress = Sections[SectIdx].getAddress();
|
||||
Start -= SectionAddress;
|
||||
|
||||
if (Start > SectSize) {
|
||||
outs() << "section data ends, " << SymName
|
||||
<< " lies outside valid range\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop disassembling either at the beginning of the next symbol or at
|
||||
// the end of the section.
|
||||
bool containsNextSym = false;
|
||||
@ -6745,8 +6756,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
||||
++NextSymIdx;
|
||||
}
|
||||
|
||||
uint64_t SectSize = Sections[SectIdx].getSize();
|
||||
uint64_t End = containsNextSym ? NextSym : SectSize;
|
||||
uint64_t End = containsNextSym ? std::min(NextSym, SectSize) : SectSize;
|
||||
uint64_t Size;
|
||||
|
||||
symbolTableWorked = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user