llvm_mode: lower llvm version reqs to 3.4 (LLInsTrim will not be
available)
MODIFY
llvm_mode/GNUmakefile
llvm_mode/GNUmakefile
@@ -39,7 +39,7 @@ else
endif
LLVMVER = $(shell $(LLVM_CONFIG) --version 2>/dev/null | sed 's/git//' )
-LLVM_UNSUPPORTED = $(shell $(LLVM_CONFIG) --version 2>/dev/null | egrep -q '^3\.[0-7]|^1[2-9]' && echo 1 || echo 0 )
+LLVM_UNSUPPORTED = $(shell $(LLVM_CONFIG) --version 2>/dev/null | egrep -q '^3\.[0-3]|^1[2-9]' && echo 1 || echo 0 )
LLVM_NEW_API = $(shell $(LLVM_CONFIG) --version 2>/dev/null | egrep -q '^1[0-9]' && echo 1 || echo 0 )
LLVM_MAJOR = $(shell $(LLVM_CONFIG) --version 2>/dev/null | sed 's/\..*//')
LLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir 2>/dev/null)

MODIFY
llvm_mode/LLVMInsTrim.so.cc
llvm_mode/LLVMInsTrim.so.cc
@@ -160,9 +160,21 @@ struct InsTrim : public ModulePass {
else
#else
if (ngram_size_str)
+#ifdef LLVM_VERSION_STRING
FATAL(
"Sorry, NGRAM branch coverage is not supported with llvm version %s!",
LLVM_VERSION_STRING);
+#else
+#ifndef LLVM_VERSION_PATCH
+ FATAL(
+ "Sorry, NGRAM branch coverage is not supported with llvm version %d.%d.%d!",
+ LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, 0);
+#else
+ FATAL(
+ "Sorry, NGRAM branch coverage is not supported with llvm version %d.%d.%d!",
+ LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, LLVM_VERISON_PATCH);
+#endif
+#endif
#endif
PrevLocSize = 1;

MODIFY
llvm_mode/afl-llvm-common.cc
llvm_mode/afl-llvm-common.cc
@@ -33,7 +33,10 @@ char *getBBName(const llvm::BasicBlock *BB) {
std::string Str;
raw_string_ostream OS(Str);
+#if LLVM_VERSION_MAJOR >= 4 || \
+ (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7)
BB->printAsOperand(OS, false);
+#endif
name = strdup(OS.str().c_str());
return name;
@@ -171,7 +174,7 @@ bool isInWhitelist(llvm::Function *F) {
#else
if (!Loc.isUnknown()) {
- DILocation cDILoc(Loc.getAsMDNode(C));
+ DILocation cDILoc(Loc.getAsMDNode(F->getContext()));
unsigned int instLine = cDILoc.getLineNumber();
StringRef instFilename = cDILoc.getFilename();

MODIFY
llvm_mode/afl-llvm-pass.so.cc
llvm_mode/afl-llvm-pass.so.cc
@@ -211,8 +211,15 @@ bool AFLCoverage::runOnModule(Module &M) {
else
#else
if (ngram_size_str)
- FATAL("Sorry, NGRAM branch coverage is not supported with llvm version %s!",
- LLVM_VERSION_STRING);
+#ifndef LLVM_VERSION_PATCH
+ FATAL("Sorry, NGRAM branch coverage is not supported with llvm version %d.%d.%d!",
+ LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR,
+ 0);
+#else
+ FATAL("Sorry, NGRAM branch coverage is not supported with llvm version %d.%d.%d!",
+ LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR,
+ LLVM_VERSION_PATCH);
+#endif
#endif
PrevLocSize = 1;

MODIFY
llvm_mode/compare-transform-pass.so.cc
llvm_mode/compare-transform-pass.so.cc
#include "llvm/Config/llvm-config.h"
#include "llvm/ADT/Statistic.h"
-#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"

MODIFY
llvm_mode/split-compares-pass.so.cc
llvm_mode/split-compares-pass.so.cc
#include "llvm/Config/llvm-config.h"
#include "llvm/Pass.h"
-#include "llvm/IR/DebugInfo.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"

MODIFY
llvm_mode/split-switches-pass.so.cc
llvm_mode/split-switches-pass.so.cc
#include "llvm/Config/llvm-config.h"
#include "llvm/ADT/Statistic.h"
-#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"

MODIFY
test/test.sh
test/test.sh
@@ -338,6 +338,7 @@ test -e ../afl-clang-fast -a -e ../split-switches-pass.so && {
rm -f test-instr.plain
# now for the special llvm_mode things
+ test -e ../libLLVMInsTrim.so && {
AFL_LLVM_INSTRIM=1 AFL_LLVM_INSTRIM_LOOPHEAD=1 ../afl-clang-fast -o test-instr.instrim ../test-instr.c > /dev/null 2>test.out
test -e test-instr.instrim && {
TUPLES=`echo 0|../afl-showmap -m ${MEM_LIMIT} -o /dev/null -- ./test-instr.instrim 2>&1 | grep Captur | awk '{print$3}'`
@@ -352,6 +353,10 @@ test -e ../afl-clang-fast -a -e ../split-switches-pass.so && {
$ECHO "$RED[!] llvm_mode InsTrim compilation failed"
CODE=1
}
+ } || {
+ $ECHO "$YELLOW[-] llvm_mode InsTrim not compiled, cannot test"
+ INCOMPLETE=1
+ }
AFL_DEBUG=1 AFL_LLVM_LAF_SPLIT_SWITCHES=1 AFL_LLVM_LAF_TRANSFORM_COMPARES=1 AFL_LLVM_LAF_SPLIT_COMPARES=1 ../afl-clang-fast -o test-compcov.compcov test-compcov.c > test.out 2>&1
test -e test-compcov.compcov && {
grep --binary-files=text -Eq " [ 12][0-9][0-9] location| [3-9][0-9] location" test.out && {

llvm_mode: lower llvm version reqs to 3.4 (LLInsTrim will not be
available)