fix llvm compatibility problems. Should compile now with llvm 3.8.0

up to llvm 8.0
This commit is contained in:
Hexcoder
2019-06-03 23:20:47 +02:00
parent b3a504248f
commit b4678b77f1
7 changed files with 13 additions and 45 deletions

View File

@ -23,11 +23,11 @@ BIN_PATH = $(PREFIX)/bin
VERSION = $(shell grep '^\#define VERSION ' ../config.h | cut -d '"' -f2)
LLVM_CONFIG ?= llvm-config
LLVM_OK = $(shell $(LLVM_CONFIG) --version | egrep -q '^[5-6]' && echo 0 || echo 1 )
LLVM_UNSUPPORTED = $(shell $(LLVM_CONFIG) --version | egrep -q '^[7-9]' && echo 1 || echo 0 )
#LLVM_OK = $(shell $(LLVM_CONFIG) --version | egrep -q '^[5-6]' && echo 0 || echo 1 )
LLVM_UNSUPPORTED = $(shell $(LLVM_CONFIG) --version | egrep -q '^[3].0' && echo 1 || echo 0 )
ifeq "$(LLVM_UNSUPPORTED)" "1"
$(error llvm_mode only supports versions 3.9 up to 6.0.1 )
$(error llvm_mode only supports llvm versions 3.8.0 and higher )
endif
CFLAGS ?= -O3 -funroll-loops
@ -42,7 +42,7 @@ CXXFLAGS ?= -O3 -funroll-loops
CXXFLAGS += -Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign \
-DVERSION=\"$(VERSION)\" -Wno-variadic-macros
CLANG_CFL = `$(LLVM_CONFIG) --cxxflags` -fno-rtti -fpic $(CXXFLAGS)
CLANG_CFL = `$(LLVM_CONFIG) --cxxflags` -Wl,-znodelete -fno-rtti -fpic $(CXXFLAGS)
CLANG_LFL = `$(LLVM_CONFIG) --ldflags` $(LDFLAGS)
# User teor2345 reports that this is required to make things work on MacOS X.
@ -57,11 +57,7 @@ endif
ifeq "$(origin CC)" "default"
CC = clang
ifeq "$(LLVM_OK)" "1"
CXX = clang++
else
CXX = g++
endif
CXX = clang++
endif
ifndef AFL_TRACE_PC

View File

@ -7,8 +7,7 @@ Fast LLVM-based instrumentation for afl-fuzz
1) Introduction
---------------
! llvm_mode works with verison 3.0 up to 6.0.1 !
! llvm version 7, 8 and 9 do not work !
!!! This works with LLVM from version 3.8.1 up to version 8 !!!
The code in this directory allows you to instrument programs for AFL using
true compiler-level instrumentation, instead of the more crude

View File

@ -296,8 +296,6 @@ static void edit_params(u32 argc, char** argv) {
if (maybe_linking) {
cc_params[cc_par_cnt++] = "-Wl,-znodelete";
if (x_set) {
cc_params[cc_par_cnt++] = "-x";
cc_params[cc_par_cnt++] = "none";

View File

@ -32,21 +32,12 @@
#include <unistd.h>
#include "llvm/IR/BasicBlock.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/CFG.h"
#include <algorithm>
using namespace llvm;

View File

@ -45,12 +45,8 @@ namespace {
bool runOnModule(Module &M) override;
#if (__clang_major__ < 4)
#ifndef __GNUG__
#if LLVM_VERSION_MAJOR < 4
const char * getPassName() const override {
#else
StringRef getPassName() const override {
#endif
#else
StringRef getPassName() const override {
#endif
@ -76,7 +72,7 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp, const
Constant* c = M.getOrInsertFunction("tolower",
Int32Ty,
Int32Ty
#if __clang_major__ < 7
#if LLVM_VERSION_MAJOR < 5
, nullptr
#endif
);
@ -222,7 +218,7 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp, const
BranchInst::Create(end_bb, next_bb);
PHINode *PN = PHINode::Create(Int32Ty, constLen + 1, "cmp_phi");
#if __clang_major__ < 8
#if LLVM_VERSION_MAJOR < 8
TerminatorInst *term = bb->getTerminator();
#else
Instruction *term = bb->getTerminator();
@ -263,7 +259,7 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp, const
next_bb = BasicBlock::Create(C, "cmp_added", end_bb->getParent(), end_bb);
BranchInst::Create(end_bb, next_bb);
#if __clang_major__ < 8
#if LLVM_VERSION_MAJOR < 8
TerminatorInst *term = cur_bb->getTerminator();
#else
Instruction *term = cur_bb->getTerminator();

View File

@ -33,14 +33,10 @@ namespace {
SplitComparesTransform() : ModulePass(ID) {}
bool runOnModule(Module &M) override;
#if __clang_major__ >= 4
#if LLVM_VERSION_MAJOR >= 4
StringRef getPassName() const override {
#else
#ifndef __GNUG__
const char * getPassName() const override {
#else
StringRef getPassName() const override {
#endif
#endif
return "simplifies and splits ICMP instructions";
}

View File

@ -45,14 +45,10 @@ namespace {
bool runOnModule(Module &M) override;
#if __clang_major__ >= 4
#if LLVM_VERSION_MAJOR >= 4
StringRef getPassName() const override {
#else
#ifndef __GNUG__
const char * getPassName() const override {
#else
StringRef getPassName() const override {
#endif
#endif
return "splits switch constructs";
}
@ -258,12 +254,8 @@ bool SplitSwitchesTransform::splitSwitches(Module &M) {
/* Prepare cases vector. */
CaseVector Cases;
for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end(); i != e; ++i)
#if __clang_major__ < 5
#ifndef __GNUG__
#if LLVM_VERSION_MAJOR < 5
Cases.push_back(CaseExpr(i.getCaseValue(), i.getCaseSuccessor()));
#else
Cases.push_back(CaseExpr(i->getCaseValue(), i->getCaseSuccessor()));
#endif
#else
Cases.push_back(CaseExpr(i->getCaseValue(), i->getCaseSuccessor()));
#endif