aboutsummaryrefslogtreecommitdiff
path: root/llvm_mode
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-08-02 22:28:16 +0200
committervan Hauser <vh@thc.org>2020-08-02 22:28:16 +0200
commit1cddd51662865ee407dcc93d6f1ef8ce443585a1 (patch)
tree3effe2c8c76ce44765bee2b4da33c61002fd8122 /llvm_mode
parent6041b1c4866d11b443545f5b9d6f17ef5483304c (diff)
downloadafl++-1cddd51662865ee407dcc93d6f1ef8ce443585a1.tar.gz
refactoring debug/be_quiet, fatal on dont_optimize and instrument_file
Diffstat (limited to 'llvm_mode')
-rw-r--r--llvm_mode/LLVMInsTrim.so.cc2
-rw-r--r--llvm_mode/afl-clang-fast.c4
-rw-r--r--llvm_mode/afl-llvm-common.cc20
-rw-r--r--llvm_mode/afl-llvm-common.h9
-rw-r--r--llvm_mode/afl-llvm-lto-instrim.so.cc4
-rw-r--r--llvm_mode/afl-llvm-lto-instrumentation.so.cc7
-rw-r--r--llvm_mode/afl-llvm-lto-instrumentlist.so.cc8
-rw-r--r--llvm_mode/afl-llvm-pass.so.cc2
-rw-r--r--llvm_mode/cmplog-instructions-pass.cc3
-rw-r--r--llvm_mode/cmplog-routines-pass.cc3
-rw-r--r--llvm_mode/compare-transform-pass.so.cc3
-rw-r--r--llvm_mode/split-compares-pass.so.cc3
-rw-r--r--llvm_mode/split-switches-pass.so.cc3
13 files changed, 39 insertions, 32 deletions
diff --git a/llvm_mode/LLVMInsTrim.so.cc b/llvm_mode/LLVMInsTrim.so.cc
index 75548266..4d8c4719 100644
--- a/llvm_mode/LLVMInsTrim.so.cc
+++ b/llvm_mode/LLVMInsTrim.so.cc
@@ -56,7 +56,6 @@ struct InsTrim : public ModulePass {
protected:
uint32_t function_minimum_size = 1;
- uint32_t debug = 0;
char * skip_nozero = NULL;
private:
@@ -102,7 +101,6 @@ struct InsTrim : public ModulePass {
bool runOnModule(Module &M) override {
- char be_quiet = 0;
setvbuf(stdout, NULL, _IONBF, 0);
if ((isatty(2) && !getenv("AFL_QUIET")) || getenv("AFL_DEBUG") != NULL) {
diff --git a/llvm_mode/afl-clang-fast.c b/llvm_mode/afl-clang-fast.c
index 57330395..738433ac 100644
--- a/llvm_mode/afl-clang-fast.c
+++ b/llvm_mode/afl-clang-fast.c
@@ -639,6 +639,10 @@ int main(int argc, char **argv, char **envp) {
}
+ if ((getenv("AFL_LLVM_INSTRUMENT_FILE") || getenv("AFL_LLVM_WHITELIST")) &&
+ getenv("AFL_DONT_OPTIMIZE"))
+ FATAL("AFL_LLVM_INSTRUMENT_FILE and AFL_DONT_OPTIMIZE cannot be combined");
+
if (getenv("AFL_LLVM_INSTRIM") || getenv("INSTRIM") ||
getenv("INSTRIM_LIB")) {
diff --git a/llvm_mode/afl-llvm-common.cc b/llvm_mode/afl-llvm-common.cc
index 47b49358..9a884ded 100644
--- a/llvm_mode/afl-llvm-common.cc
+++ b/llvm_mode/afl-llvm-common.cc
@@ -14,6 +14,8 @@
#include <fstream>
#include <llvm/Support/raw_ostream.h>
+
+#define IS_EXTERN extern
#include "afl-llvm-common.h"
using namespace llvm;
@@ -88,6 +90,7 @@ void initInstrumentList() {
char *instrumentListFilename = getenv("AFL_LLVM_INSTRUMENT_FILE");
if (!instrumentListFilename)
instrumentListFilename = getenv("AFL_LLVM_WHITELIST");
+
if (instrumentListFilename) {
std::string line;
@@ -105,6 +108,10 @@ void initInstrumentList() {
}
+ if (debug)
+ SAYF(cMGN "[D] " cRST "loaded instrument list with %zu entries\n",
+ myInstrumentList.size());
+
}
bool isInInstrumentList(llvm::Function *F) {
@@ -145,8 +152,6 @@ bool isInInstrumentList(llvm::Function *F) {
}
- (void)instLine;
-
/* Continue only if we know where we actually are */
if (!instFilename.str().empty()) {
@@ -164,6 +169,10 @@ bool isInInstrumentList(llvm::Function *F) {
if (fnmatch(("*" + *it).c_str(), instFilename.str().c_str(), 0) ==
0) {
+ if (debug)
+ SAYF(cMGN "[D] " cRST
+ "Function %s is in the list (%s), instrumenting ... \n",
+ F->getName().str().c_str(), instFilename.str().c_str());
return true;
}
@@ -219,12 +228,15 @@ bool isInInstrumentList(llvm::Function *F) {
// we could not find out the location. in this case we say it is not
// in the the instrument file list
-
+ if (!be_quiet)
+ WARNF(
+ "No debug information found for function %s, will not be "
+ "instrumented (recompile with -g -O[1-3]).",
+ F->getName().str().c_str());
return false;
}
- //
return false;
}
diff --git a/llvm_mode/afl-llvm-common.h b/llvm_mode/afl-llvm-common.h
index 38e0c830..5b96be43 100644
--- a/llvm_mode/afl-llvm-common.h
+++ b/llvm_mode/afl-llvm-common.h
@@ -38,5 +38,14 @@ void initInstrumentList();
bool isInInstrumentList(llvm::Function *F);
unsigned long long int calculateCollisions(uint32_t edges);
+#ifndef IS_EXTERN
+ #define IS_EXTERN
+#endif
+
+IS_EXTERN int debug;
+IS_EXTERN int be_quiet;
+
+#undef IS_EXTERN
+
#endif
diff --git a/llvm_mode/afl-llvm-lto-instrim.so.cc b/llvm_mode/afl-llvm-lto-instrim.so.cc
index dba98777..98e9ff9a 100644
--- a/llvm_mode/afl-llvm-lto-instrim.so.cc
+++ b/llvm_mode/afl-llvm-lto-instrim.so.cc
@@ -73,8 +73,8 @@ struct InsTrimLTO : public ModulePass {
protected:
uint32_t function_minimum_size = 1;
char * skip_nozero = NULL;
- int afl_global_id = 1, debug = 0, autodictionary = 1;
- uint32_t be_quiet = 0, inst_blocks = 0, inst_funcs = 0;
+ int afl_global_id = 1, autodictionary = 1;
+ uint32_t inst_blocks = 0, inst_funcs = 0;
uint64_t map_addr = 0x10000;
public:
diff --git a/llvm_mode/afl-llvm-lto-instrumentation.so.cc b/llvm_mode/afl-llvm-lto-instrumentation.so.cc
index d81b35f4..5686eb56 100644
--- a/llvm_mode/afl-llvm-lto-instrumentation.so.cc
+++ b/llvm_mode/afl-llvm-lto-instrumentation.so.cc
@@ -86,9 +86,9 @@ class AFLLTOPass : public ModulePass {
bool runOnModule(Module &M) override;
protected:
- int afl_global_id = 1, debug = 0, autodictionary = 1;
+ int afl_global_id = 1, autodictionary = 1;
uint32_t function_minimum_size = 1;
- uint32_t be_quiet = 0, inst_blocks = 0, inst_funcs = 0, total_instr = 0;
+ uint32_t inst_blocks = 0, inst_funcs = 0, total_instr = 0;
uint64_t map_addr = 0x10000;
char * skip_nozero = NULL;
@@ -207,7 +207,8 @@ bool AFLLTOPass::runOnModule(Module &M) {
if (debug)
fprintf(stderr,
"DEBUG: Function %s is not in a source file that was specified "
- "in the instrument file list\n", F.getName().str().c_str());
+ "in the instrument file list\n",
+ F.getName().str().c_str());
continue;
}
diff --git a/llvm_mode/afl-llvm-lto-instrumentlist.so.cc b/llvm_mode/afl-llvm-lto-instrumentlist.so.cc
index dc1a9a61..ab7c0c58 100644
--- a/llvm_mode/afl-llvm-lto-instrumentlist.so.cc
+++ b/llvm_mode/afl-llvm-lto-instrumentlist.so.cc
@@ -104,7 +104,6 @@ class AFLcheckIfInstrument : public ModulePass {
protected:
std::list<std::string> myInstrumentList;
- int debug = 0;
};
@@ -116,7 +115,6 @@ bool AFLcheckIfInstrument::runOnModule(Module &M) {
/* Show a banner */
- char be_quiet = 0;
setvbuf(stdout, NULL, _IONBF, 0);
if ((isatty(2) && !getenv("AFL_QUIET")) || getenv("AFL_DEBUG") != NULL) {
@@ -209,8 +207,10 @@ bool AFLcheckIfInstrument::runOnModule(Module &M) {
} else {
if (!be_quiet)
- WARNF("No debug information found for function %s, recompile with -g",
- F.getName().str().c_str());
+ WARNF(
+ "No debug information found for function %s, recompile with -g "
+ "-O[1-3]",
+ F.getName().str().c_str());
continue;
}
diff --git a/llvm_mode/afl-llvm-pass.so.cc b/llvm_mode/afl-llvm-pass.so.cc
index 90cf3eb4..618abe48 100644
--- a/llvm_mode/afl-llvm-pass.so.cc
+++ b/llvm_mode/afl-llvm-pass.so.cc
@@ -82,7 +82,6 @@ class AFLCoverage : public ModulePass {
protected:
uint32_t ngram_size = 0;
- uint32_t debug = 0;
uint32_t map_size = MAP_SIZE;
uint32_t function_minimum_size = 1;
char * ctx_str = NULL, *skip_nozero = NULL;
@@ -139,7 +138,6 @@ bool AFLCoverage::runOnModule(Module &M) {
/* Show a banner */
- char be_quiet = 0;
setvbuf(stdout, NULL, _IONBF, 0);
if (getenv("AFL_DEBUG")) debug = 1;
diff --git a/llvm_mode/cmplog-instructions-pass.cc b/llvm_mode/cmplog-instructions-pass.cc
index f929361a..7c48d906 100644
--- a/llvm_mode/cmplog-instructions-pass.cc
+++ b/llvm_mode/cmplog-instructions-pass.cc
@@ -76,9 +76,6 @@ class CmpLogInstructions : public ModulePass {
}
- protected:
- int be_quiet = 0;
-
private:
bool hookInstrs(Module &M);
diff --git a/llvm_mode/cmplog-routines-pass.cc b/llvm_mode/cmplog-routines-pass.cc
index 318193a4..a0f8f64f 100644
--- a/llvm_mode/cmplog-routines-pass.cc
+++ b/llvm_mode/cmplog-routines-pass.cc
@@ -76,9 +76,6 @@ class CmpLogRoutines : public ModulePass {
}
- protected:
- int be_quiet = 0;
-
private:
bool hookRtns(Module &M);
diff --git a/llvm_mode/compare-transform-pass.so.cc b/llvm_mode/compare-transform-pass.so.cc
index d389651c..bed3597a 100644
--- a/llvm_mode/compare-transform-pass.so.cc
+++ b/llvm_mode/compare-transform-pass.so.cc
@@ -75,9 +75,6 @@ class CompareTransform : public ModulePass {
}
- protected:
- int be_quiet = 0;
-
private:
bool transformCmps(Module &M, const bool processStrcmp,
const bool processMemcmp, const bool processStrncmp,
diff --git a/llvm_mode/split-compares-pass.so.cc b/llvm_mode/split-compares-pass.so.cc
index f65adde8..3630bd8c 100644
--- a/llvm_mode/split-compares-pass.so.cc
+++ b/llvm_mode/split-compares-pass.so.cc
@@ -71,9 +71,6 @@ class SplitComparesTransform : public ModulePass {
}
- protected:
- int be_quiet = 0;
-
private:
int enableFPSplit;
diff --git a/llvm_mode/split-switches-pass.so.cc b/llvm_mode/split-switches-pass.so.cc
index 44075c94..f025df77 100644
--- a/llvm_mode/split-switches-pass.so.cc
+++ b/llvm_mode/split-switches-pass.so.cc
@@ -91,9 +91,6 @@ class SplitSwitchesTransform : public ModulePass {
typedef std::vector<CaseExpr> CaseVector;
- protected:
- int be_quiet = 0;
-
private:
bool splitSwitches(Module &M);
bool transformCmps(Module &M, const bool processStrcmp,