MC CFG: When disassembly is impossible, fallback to data bytes.
This is the behavior of sequential disassemblers (llvm-objdump, ...), when there is no instruction size hint (fixed-length, ...) While there, also do some minor cleanup. llvm-svn: 188883
This commit is contained in:
parent
a376353346
commit
57bc9677cd
|
|
@ -102,19 +102,29 @@ void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
|
||||||
StringRef SecName; SI->getName(SecName);
|
StringRef SecName; SI->getName(SecName);
|
||||||
|
|
||||||
if (isText) {
|
if (isText) {
|
||||||
MCTextAtom *Text = Module->createTextAtom(StartAddr, EndAddr);
|
MCTextAtom *Text = 0;
|
||||||
Text->setName(SecName);
|
MCDataAtom *InvalidData = 0;
|
||||||
|
|
||||||
uint64_t InstSize;
|
uint64_t InstSize;
|
||||||
for (uint64_t Index = 0; Index < SecSize; Index += InstSize) {
|
for (uint64_t Index = 0; Index < SecSize; Index += InstSize) {
|
||||||
|
const uint64_t CurAddr = StartAddr + Index;
|
||||||
MCInst Inst;
|
MCInst Inst;
|
||||||
if (Dis.getInstruction(Inst, InstSize, memoryObject, Index,
|
if (Dis.getInstruction(Inst, InstSize, memoryObject, CurAddr, nulls(),
|
||||||
nulls(), nulls()))
|
nulls())) {
|
||||||
|
if (!Text) {
|
||||||
|
Text = Module->createTextAtom(CurAddr, CurAddr);
|
||||||
|
Text->setName(SecName);
|
||||||
|
}
|
||||||
Text->addInst(Inst, InstSize);
|
Text->addInst(Inst, InstSize);
|
||||||
else
|
InvalidData = 0;
|
||||||
// We don't care about splitting mixed atoms either.
|
} else {
|
||||||
llvm_unreachable("Couldn't disassemble instruction in atom.");
|
if (!InvalidData) {
|
||||||
|
Text = 0;
|
||||||
|
InvalidData = Module->createDataAtom(CurAddr, EndAddr);
|
||||||
|
}
|
||||||
|
InvalidData->addData(Contents[Index]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
MCDataAtom *Data = Module->createDataAtom(StartAddr, EndAddr);
|
MCDataAtom *Data = Module->createDataAtom(StartAddr, EndAddr);
|
||||||
Data->setName(SecName);
|
Data->setName(SecName);
|
||||||
|
|
@ -134,6 +144,8 @@ namespace {
|
||||||
BBInfoSetTy Succs;
|
BBInfoSetTy Succs;
|
||||||
BBInfoSetTy Preds;
|
BBInfoSetTy Preds;
|
||||||
|
|
||||||
|
BBInfo() : Atom(0), BB(0) {}
|
||||||
|
|
||||||
void addSucc(BBInfo &Succ) {
|
void addSucc(BBInfo &Succ) {
|
||||||
Succs.insert(&Succ);
|
Succs.insert(&Succ);
|
||||||
Succ.Preds.insert(this);
|
Succ.Preds.insert(this);
|
||||||
|
|
@ -232,8 +244,8 @@ void MCObjectDisassembler::buildCFG(MCModule *Module) {
|
||||||
// Create MCBBs.
|
// Create MCBBs.
|
||||||
SmallSetVector<BBInfo*, 16> Worklist;
|
SmallSetVector<BBInfo*, 16> Worklist;
|
||||||
Worklist.insert(&BBI);
|
Worklist.insert(&BBI);
|
||||||
for (size_t WI = 0; WI < Worklist.size(); ++WI) {
|
for (size_t wi = 0; wi < Worklist.size(); ++wi) {
|
||||||
BBInfo *BBI = Worklist[WI];
|
BBInfo *BBI = Worklist[wi];
|
||||||
if (!BBI->Atom)
|
if (!BBI->Atom)
|
||||||
continue;
|
continue;
|
||||||
BBI->BB = &MCFN.createBlock(*BBI->Atom);
|
BBI->BB = &MCFN.createBlock(*BBI->Atom);
|
||||||
|
|
@ -247,17 +259,19 @@ void MCObjectDisassembler::buildCFG(MCModule *Module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set preds/succs.
|
// Set preds/succs.
|
||||||
for (size_t WI = 0; WI < Worklist.size(); ++WI) {
|
for (size_t wi = 0; wi < Worklist.size(); ++wi) {
|
||||||
BBInfo *BBI = Worklist[WI];
|
BBInfo *BBI = Worklist[wi];
|
||||||
MCBasicBlock *MCBB = BBI->BB;
|
MCBasicBlock *MCBB = BBI->BB;
|
||||||
if (!MCBB)
|
if (!MCBB)
|
||||||
continue;
|
continue;
|
||||||
for (BBInfoSetTy::iterator SI = BBI->Succs.begin(), SE = BBI->Succs.end();
|
for (BBInfoSetTy::iterator SI = BBI->Succs.begin(), SE = BBI->Succs.end();
|
||||||
SI != SE; ++SI)
|
SI != SE; ++SI)
|
||||||
MCBB->addSuccessor((*SI)->BB);
|
if ((*SI)->BB)
|
||||||
|
MCBB->addSuccessor((*SI)->BB);
|
||||||
for (BBInfoSetTy::iterator PI = BBI->Preds.begin(), PE = BBI->Preds.end();
|
for (BBInfoSetTy::iterator PI = BBI->Preds.begin(), PE = BBI->Preds.end();
|
||||||
PI != PE; ++PI)
|
PI != PE; ++PI)
|
||||||
MCBB->addPredecessor((*PI)->BB);
|
if ((*PI)->BB)
|
||||||
|
MCBB->addPredecessor((*PI)->BB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue