[llvm] r188883 - MC CFG: When disassembly is impossible, fallback to data bytes.
Ahmed Bougacha
ahmed.bougacha at gmail.com
Wed Aug 21 12:46:47 PDT 2013
On Wed, Aug 21, 2013 at 10:29 AM, David Blaikie <dblaikie at gmail.com> wrote:
> On Wed, Aug 21, 2013 at 12:28 AM, Ahmed Bougacha
> <ahmed.bougacha at gmail.com> wrote:
>> Author: ab
>> Date: Wed Aug 21 02:28:32 2013
>> New Revision: 188883
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=188883&view=rev
>> Log:
>> MC CFG: When disassembly is impossible, fallback to data bytes.
>
> Missing test case.
Yep, was working on the testcase, r188925.
-- Ahmed
>> 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.
>
> More text about what the cleanup was, and/or doing it in a separate
> patch would be good.
>
>>
>> Modified:
>> llvm/trunk/lib/MC/MCObjectDisassembler.cpp
>>
>> Modified: llvm/trunk/lib/MC/MCObjectDisassembler.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectDisassembler.cpp?rev=188883&r1=188882&r2=188883&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/MC/MCObjectDisassembler.cpp (original)
>> +++ llvm/trunk/lib/MC/MCObjectDisassembler.cpp Wed Aug 21 02:28:32 2013
>> @@ -102,19 +102,29 @@ void MCObjectDisassembler::buildSectionA
>> StringRef SecName; SI->getName(SecName);
>>
>> if (isText) {
>> - MCTextAtom *Text = Module->createTextAtom(StartAddr, EndAddr);
>> - Text->setName(SecName);
>> + MCTextAtom *Text = 0;
>> + MCDataAtom *InvalidData = 0;
>> +
>> uint64_t InstSize;
>> for (uint64_t Index = 0; Index < SecSize; Index += InstSize) {
>> + const uint64_t CurAddr = StartAddr + Index;
>> MCInst Inst;
>> - if (Dis.getInstruction(Inst, InstSize, memoryObject, Index,
>> - nulls(), nulls()))
>> + if (Dis.getInstruction(Inst, InstSize, memoryObject, CurAddr, nulls(),
>> + nulls())) {
>> + if (!Text) {
>> + Text = Module->createTextAtom(CurAddr, CurAddr);
>> + Text->setName(SecName);
>> + }
>> Text->addInst(Inst, InstSize);
>> - else
>> - // We don't care about splitting mixed atoms either.
>> - llvm_unreachable("Couldn't disassemble instruction in atom.");
>> + InvalidData = 0;
>> + } else {
>> + if (!InvalidData) {
>> + Text = 0;
>> + InvalidData = Module->createDataAtom(CurAddr, EndAddr);
>> + }
>> + InvalidData->addData(Contents[Index]);
>> + }
>> }
>> -
>> } else {
>> MCDataAtom *Data = Module->createDataAtom(StartAddr, EndAddr);
>> Data->setName(SecName);
>> @@ -134,6 +144,8 @@ namespace {
>> BBInfoSetTy Succs;
>> BBInfoSetTy Preds;
>>
>> + BBInfo() : Atom(0), BB(0) {}
>> +
>> void addSucc(BBInfo &Succ) {
>> Succs.insert(&Succ);
>> Succ.Preds.insert(this);
>> @@ -232,8 +244,8 @@ void MCObjectDisassembler::buildCFG(MCMo
>> // Create MCBBs.
>> SmallSetVector<BBInfo*, 16> Worklist;
>> Worklist.insert(&BBI);
>> - for (size_t WI = 0; WI < Worklist.size(); ++WI) {
>> - BBInfo *BBI = Worklist[WI];
>> + for (size_t wi = 0; wi < Worklist.size(); ++wi) {
>> + BBInfo *BBI = Worklist[wi];
>> if (!BBI->Atom)
>> continue;
>> BBI->BB = &MCFN.createBlock(*BBI->Atom);
>> @@ -247,17 +259,19 @@ void MCObjectDisassembler::buildCFG(MCMo
>> }
>>
>> // Set preds/succs.
>> - for (size_t WI = 0; WI < Worklist.size(); ++WI) {
>> - BBInfo *BBI = Worklist[WI];
>> + for (size_t wi = 0; wi < Worklist.size(); ++wi) {
>> + BBInfo *BBI = Worklist[wi];
>> MCBasicBlock *MCBB = BBI->BB;
>> if (!MCBB)
>> continue;
>> for (BBInfoSetTy::iterator SI = BBI->Succs.begin(), SE = BBI->Succs.end();
>> - SI != SE; ++SI)
>> - MCBB->addSuccessor((*SI)->BB);
>> + SI != SE; ++SI)
>> + if ((*SI)->BB)
>> + MCBB->addSuccessor((*SI)->BB);
>> for (BBInfoSetTy::iterator PI = BBI->Preds.begin(), PE = BBI->Preds.end();
>> - PI != PE; ++PI)
>> - MCBB->addPredecessor((*PI)->BB);
>> + PI != PE; ++PI)
>> + if ((*PI)->BB)
>> + MCBB->addPredecessor((*PI)->BB);
>> }
>> }
>> }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list