[llvm] r248253 - [llvm-mc-fuzzer] Support untested instruction discovery for variable length instruction sets like microMIPS.

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 02:22:54 PDT 2015


Author: dsanders
Date: Tue Sep 22 04:22:53 2015
New Revision: 248253

URL: http://llvm.org/viewvc/llvm-project?rev=248253&view=rev
Log:
[llvm-mc-fuzzer] Support untested instruction discovery for variable length instruction sets like microMIPS.

Summary:
For fixed length instructions, we can use -max_len to limit the fuzzer to a
single instruction. This doesn't work for variable length instruction sets
since a 4-byte input could consist of one 4-byte instruction or two 2-byte
instructions.

This patch adds a --insn-limit to llvm-mc-fuzzer to limit the input in
terms of instructions processed.

Reviewers: kcc

Subscribers: kcc, llvm-commits

Differential Revision: http://reviews.llvm.org/D12960

Modified:
    llvm/trunk/tools/llvm-mc-fuzzer/llvm-mc-fuzzer.cpp

Modified: llvm/trunk/tools/llvm-mc-fuzzer/llvm-mc-fuzzer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc-fuzzer/llvm-mc-fuzzer.cpp?rev=248253&r1=248252&r2=248253&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc-fuzzer/llvm-mc-fuzzer.cpp (original)
+++ llvm/trunk/tools/llvm-mc-fuzzer/llvm-mc-fuzzer.cpp Tue Sep 22 04:22:53 2015
@@ -44,6 +44,12 @@ static cl::opt<std::string>
          cl::desc("Target a specific cpu type (-mcpu=help for details)"),
          cl::value_desc("cpu-name"), cl::init(""));
 
+// This is useful for variable-length instruction sets.
+static cl::opt<unsigned> InsnLimit(
+    "insn-limit",
+    cl::desc("Limit the number of instructions to process (0 for no limit)"),
+    cl::value_desc("count"), cl::init(0));
+
 static cl::list<std::string>
     MAttrs("mattr", cl::CommaSeparated,
            cl::desc("Target specific attributes (-mattr=help for details)"),
@@ -67,11 +73,16 @@ void DisassembleOneInput(const uint8_t *
   assert(Ctx);
   uint8_t *p = DataCopy.data();
   unsigned Consumed;
+  unsigned InstructionsProcessed = 0;
   do {
     Consumed = LLVMDisasmInstruction(Ctx, p, Size, 0, AssemblyText,
                                      AssemblyTextBufSize);
     Size -= Consumed;
     p += Consumed;
+
+    InstructionsProcessed ++;
+    if (InsnLimit != 0 && InstructionsProcessed < InsnLimit)
+      break;
   } while (Consumed != 0);
   LLVMDisasmDispose(Ctx);
 }




More information about the llvm-commits mailing list