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();
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;
++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;