Skip to content

Commit 027975d

Browse files
committed
add inst_ratio
1 parent 59f3a01 commit 027975d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

docs/environment_variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `ANGORA_OUTPUT_COND_LOC=1` : (Debug option) Output the location of each predicate during compiling.
99
- `ANGORA_TAINT_CUSTOM_RULE=/path/to/object` : object contains those proxy function (how to propagate taints), e.g. `ANGORA_TAINT_CUSTOM_RULE=~/angora/bin/lib/zlib-func.o` . You should add it as custom type in the file passed by `ANGORA_TAINT_RULE_LIST` first.
1010
- `ANGORA_TAINT_RULE_LIST=/path/to/list` : DataFlowSanitizer’s [ABI list](https://clang.llvm.org/docs/DataFlowSanitizer.html), e.g. `ANGORA_TAINT_RULE_LIST=~/angora/bin/rules/zlib_abilist.txt`.
11+
- `ANGORA_INST_RATIO`:
1112

1213
# Environment variables for running
1314

llvm_mode/pass/AngoraPass.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class AngoraLLVMPass : public ModulePass {
6363
u32 CidCounter;
6464
unsigned long int RandSeed = 1;
6565
bool is_bc;
66+
unsigned int inst_ratio = 100;
6667

6768
// Const Variables
6869
DenseSet<u32> UniqCidSet;
@@ -117,6 +118,7 @@ class AngoraLLVMPass : public ModulePass {
117118
bool runOnModule(Module &M) override;
118119
u32 getInstructionId(Instruction *Inst);
119120
u32 getRandomBasicBlockId();
121+
bool skipBasicBlock();
120122
u32 getRandomNum();
121123
void setRandomNumSeed(u32 seed);
122124
u32 getRandomContextId();
@@ -145,6 +147,8 @@ char AngoraLLVMPass::ID = 0;
145147

146148
u32 AngoraLLVMPass::getRandomBasicBlockId() { return random() % MAP_SIZE; }
147149

150+
bool AngoraLLVMPass::skipBasicBlock() { return (random() % 100) >= inst_ratio; }
151+
148152
// http://pubs.opengroup.org/onlinepubs/009695399/functions/rand.html
149153
u32 AngoraLLVMPass::getRandomNum() {
150154
RandSeed = RandSeed * 1103515245 + 12345;
@@ -222,6 +226,14 @@ void AngoraLLVMPass::initVariables(Module &M) {
222226
errs() << "Input is LLVM bitcode\n";
223227
}
224228

229+
char* inst_ratio_str = getenv("ANGORA_INST_RATIO");
230+
if (inst_ratio_str) {
231+
if (sscanf(inst_ratio_str, "%u", &inst_ratio) != 1 || !inst_ratio ||
232+
inst_ratio > 100)
233+
FATAL("Bad value of ANGORA_INST_RATIO (must be between 1 and 100)");
234+
}
235+
errs() << "inst_ratio: " << inst_ratio << "\n";
236+
225237
// set seed
226238
srandom(ModId);
227239
setRandomNumSeed(ModId);
@@ -365,9 +377,9 @@ void AngoraLLVMPass::initVariables(Module &M) {
365377
// Coverage statistics: AFL's Branch count
366378
// Angora enable function-call context.
367379
void AngoraLLVMPass::countEdge(Module &M, BasicBlock &BB) {
368-
if (!FastMode)
380+
if (!FastMode || skipBasicBlock())
369381
return;
370-
382+
371383
// LLVMContext &C = M.getContext();
372384
unsigned int cur_loc = getRandomBasicBlockId();
373385
ConstantInt *CurLoc = ConstantInt::get(Int32Ty, cur_loc);

0 commit comments

Comments
 (0)