Skip to content

Commit

Permalink
make llvm 14-dev working. again.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhauser-thc committed Dec 9, 2021
1 parent 4c6d94e commit db36033
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 45 deletions.
4 changes: 2 additions & 2 deletions GNUmakefile.llvm
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ instrumentation/afl-llvm-common.o: instrumentation/afl-llvm-common.cc instrument
ifeq "$(LLVM_MIN_4_0_1)" "0"
$(info [!] N-gram branch coverage instrumentation is not available for llvm version $(LLVMVER))
endif
$(CXX) $(CLANG_CPPFL) -DLLVMInsTrim_EXPORTS -fno-rtti -fPIC -std=$(LLVM_STDCXX) -shared $< -o $@ $(CLANG_LFL) instrumentation/afl-llvm-common.o
$(CXX) $(CLANG_CPPFL) -Wdeprecated -fno-rtti -fPIC -std=$(LLVM_STDCXX) -shared $< -o $@ $(CLANG_LFL) instrumentation/afl-llvm-common.o

./SanitizerCoveragePCGUARD.so: instrumentation/SanitizerCoveragePCGUARD.so.cc instrumentation/afl-llvm-common.o | test_deps
ifeq "$(LLVM_10_OK)" "1"
-$(CXX) $(CLANG_CPPFL) -fno-rtti -fPIC -std=$(LLVM_STDCXX) -shared $< -o $@ $(CLANG_LFL) instrumentation/afl-llvm-common.o
-$(CXX) $(CLANG_CPPFL) -Wdeprecated -fno-rtti -fPIC -std=$(LLVM_STDCXX) -shared $< -o $@ $(CLANG_LFL) instrumentation/afl-llvm-common.o
endif

./afl-llvm-lto-instrumentlist.so: instrumentation/afl-llvm-lto-instrumentlist.so.cc instrumentation/afl-llvm-common.o
Expand Down
2 changes: 1 addition & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ sending a mail to <[email protected]>.
- fix for shared linking on MacOS
- fixed a potential crash in targets for LAF string handling
- added AFL_USE_TSAN thread sanitizer support
- llvm and LTO mode modified to work with new llvm 14-dev (again)
- llvm and LTO mode modified to work with new llvm 14-dev (again. again.)
- fix for AFL_REAL_LD
- added the very good grammar mutator "GramaTron" to the
custom_mutators
Expand Down
19 changes: 10 additions & 9 deletions instrumentation/SanitizerCoverageLTO.so.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ bool ModuleSanitizerCoverage::instrumentModule(
M, PointerType::get(Int8Tyi, 0), false,
GlobalValue::ExternalLinkage, 0, "__afl_dictionary");

Value *AFLDictOff = IRB.CreateGEP(AFLInternalDictionary, Zero);
Value *AFLDictOff = IRB.CreateGEP(Int8Ty, AFLInternalDictionary, Zero);
Value *AFLDictPtr =
IRB.CreatePointerCast(AFLDictOff, PointerType::get(Int8Tyi, 0));
StoreInst *StoreDict = IRB.CreateStore(AFLDictPtr, AFLDictionary);
Expand Down Expand Up @@ -1388,7 +1388,8 @@ void ModuleSanitizerCoverage::instrumentFunction(
local_selects++;
uint32_t vector_cur = 0;
/* Load SHM pointer */
LoadInst *MapPtr = IRB.CreateLoad(AFLMapPtr);
LoadInst *MapPtr =
IRB.CreateLoad(PointerType::get(Int8Ty, 0), AFLMapPtr);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(MapPtr);

while (1) {
Expand All @@ -1399,12 +1400,12 @@ void ModuleSanitizerCoverage::instrumentFunction(
/* Load counter for CurLoc */
if (!vector_cnt) {

MapPtrIdx = IRB.CreateGEP(MapPtr, result);
MapPtrIdx = IRB.CreateGEP(Int8Ty, MapPtr, result);

} else {

auto element = IRB.CreateExtractElement(result, vector_cur++);
MapPtrIdx = IRB.CreateGEP(MapPtr, element);
MapPtrIdx = IRB.CreateGEP(Int8Ty, MapPtr, element);

}

Expand All @@ -1418,7 +1419,7 @@ void ModuleSanitizerCoverage::instrumentFunction(

} else {

LoadInst *Counter = IRB.CreateLoad(MapPtrIdx);
LoadInst *Counter = IRB.CreateLoad(IRB.getInt8Ty(), MapPtrIdx);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(Counter);

/* Update bitmap */
Expand Down Expand Up @@ -1672,13 +1673,13 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,

if (map_addr) {

MapPtrIdx = IRB.CreateGEP(MapPtrFixed, CurLoc);
MapPtrIdx = IRB.CreateGEP(Int8Ty, MapPtrFixed, CurLoc);

} else {

LoadInst *MapPtr = IRB.CreateLoad(AFLMapPtr);
LoadInst *MapPtr = IRB.CreateLoad(PointerType::get(Int8Ty, 0), AFLMapPtr);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(MapPtr);
MapPtrIdx = IRB.CreateGEP(MapPtr, CurLoc);
MapPtrIdx = IRB.CreateGEP(Int8Ty, MapPtr, CurLoc);

}

Expand All @@ -1693,7 +1694,7 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,

} else {

LoadInst *Counter = IRB.CreateLoad(MapPtrIdx);
LoadInst *Counter = IRB.CreateLoad(IRB.getInt8Ty(), MapPtrIdx);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(Counter);

Value *Incr = IRB.CreateAdd(Counter, One);
Expand Down
23 changes: 12 additions & 11 deletions instrumentation/SanitizerCoveragePCGUARD.so.cc
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ bool ModuleSanitizerCoverage::InjectCoverage(Function & F,
ConstantInt::get(IntptrTy, (++special + AllBlocks.size()) * 4)),
Int32PtrTy);

LoadInst *Idx = IRB.CreateLoad(GuardPtr);
LoadInst *Idx = IRB.CreateLoad(IRB.getInt32Ty(), GuardPtr);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(Idx);

callInst->setOperand(1, Idx);
Expand Down Expand Up @@ -1059,7 +1059,8 @@ bool ModuleSanitizerCoverage::InjectCoverage(Function & F,

/* Load SHM pointer */

LoadInst *MapPtr = IRB.CreateLoad(AFLMapPtr);
LoadInst *MapPtr =
IRB.CreateLoad(PointerType::get(Int8Ty, 0), AFLMapPtr);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(MapPtr);

/*
Expand All @@ -1078,17 +1079,17 @@ bool ModuleSanitizerCoverage::InjectCoverage(Function & F,
/* Load counter for CurLoc */
if (!vector_cnt) {

CurLoc = IRB.CreateLoad(result);
CurLoc = IRB.CreateLoad(IRB.getInt32Ty(), result);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(CurLoc);
MapPtrIdx = IRB.CreateGEP(MapPtr, CurLoc);
MapPtrIdx = IRB.CreateGEP(Int8Ty, MapPtr, CurLoc);

} else {

auto element = IRB.CreateExtractElement(result, vector_cur++);
auto elementptr = IRB.CreateIntToPtr(element, Int32PtrTy);
auto elementld = IRB.CreateLoad(elementptr);
auto elementld = IRB.CreateLoad(IRB.getInt32Ty(), elementptr);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(elementld);
MapPtrIdx = IRB.CreateGEP(MapPtr, elementld);
MapPtrIdx = IRB.CreateGEP(Int8Ty, MapPtr, elementld);

}

Expand All @@ -1102,7 +1103,7 @@ bool ModuleSanitizerCoverage::InjectCoverage(Function & F,

} else {

LoadInst *Counter = IRB.CreateLoad(MapPtrIdx);
LoadInst *Counter = IRB.CreateLoad(IRB.getInt8Ty(), MapPtrIdx);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(Counter);

/* Update bitmap */
Expand Down Expand Up @@ -1347,17 +1348,17 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
ConstantInt::get(IntptrTy, Idx * 4)),
Int32PtrTy);

LoadInst *CurLoc = IRB.CreateLoad(GuardPtr);
LoadInst *CurLoc = IRB.CreateLoad(IRB.getInt32Ty(), GuardPtr);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(CurLoc);

/* Load SHM pointer */

LoadInst *MapPtr = IRB.CreateLoad(AFLMapPtr);
LoadInst *MapPtr = IRB.CreateLoad(PointerType::get(Int8Ty, 0), AFLMapPtr);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(MapPtr);

/* Load counter for CurLoc */

Value *MapPtrIdx = IRB.CreateGEP(MapPtr, CurLoc);
Value *MapPtrIdx = IRB.CreateGEP(Int8Ty, MapPtr, CurLoc);

if (use_threadsafe_counters) {

Expand All @@ -1369,7 +1370,7 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,

} else {

LoadInst *Counter = IRB.CreateLoad(MapPtrIdx);
LoadInst *Counter = IRB.CreateLoad(IRB.getInt8Ty(), MapPtrIdx);
ModuleSanitizerCoverage::SetNoSanitizeMetadata(Counter);

/* Update bitmap */
Expand Down
44 changes: 36 additions & 8 deletions instrumentation/afl-llvm-pass.so.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ bool AFLCoverage::runOnModule(Module &M) {
#ifdef AFL_HAVE_VECTOR_INTRINSICS
if (ctx_k) {

PrevCaller = IRB.CreateLoad(AFLPrevCaller);
PrevCaller = IRB.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
IRB.getInt32Ty(),
#endif
AFLPrevCaller);
PrevCaller->setMetadata(M.getMDKindID("nosanitize"),
MDNode::get(C, None));
PrevCtx =
Expand All @@ -467,7 +471,11 @@ bool AFLCoverage::runOnModule(Module &M) {

// load the context ID of the previous function and write to to a
// local variable on the stack
LoadInst *PrevCtxLoad = IRB.CreateLoad(AFLContext);
LoadInst *PrevCtxLoad = IRB.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
IRB.getInt32Ty(),
#endif
AFLContext);
PrevCtxLoad->setMetadata(M.getMDKindID("nosanitize"),
MDNode::get(C, None));
PrevCtx = PrevCtxLoad;
Expand Down Expand Up @@ -620,7 +628,11 @@ bool AFLCoverage::runOnModule(Module &M) {

/* Load prev_loc */

LoadInst *PrevLoc = IRB.CreateLoad(AFLPrevLoc);
LoadInst *PrevLoc = IRB.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
IRB.getInt32Ty(),
#endif
AFLPrevLoc);
PrevLoc->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
Value *PrevLocTrans;

Expand All @@ -644,20 +656,28 @@ bool AFLCoverage::runOnModule(Module &M) {

/* Load SHM pointer */

LoadInst *MapPtr = IRB.CreateLoad(AFLMapPtr);
LoadInst *MapPtr = IRB.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLMapPtr);
MapPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));

Value *MapPtrIdx;
#ifdef AFL_HAVE_VECTOR_INTRINSICS
if (ngram_size)
MapPtrIdx = IRB.CreateGEP(
MapPtr,
Int8Ty, MapPtr,
IRB.CreateZExt(
IRB.CreateXor(PrevLocTrans, IRB.CreateZExt(CurLoc, Int32Ty)),
Int32Ty));
else
#endif
MapPtrIdx = IRB.CreateGEP(MapPtr, IRB.CreateXor(PrevLocTrans, CurLoc));
MapPtrIdx = IRB.CreateGEP(
#if LLVM_VERSION_MAJOR >= 14
Int8Ty,
#endif
MapPtr, IRB.CreateXor(PrevLocTrans, CurLoc));

/* Update bitmap */

Expand All @@ -676,7 +696,11 @@ bool AFLCoverage::runOnModule(Module &M) {

} else {

LoadInst *Counter = IRB.CreateLoad(MapPtrIdx);
LoadInst *Counter = IRB.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
IRB.getInt8Ty(),
#endif
MapPtrIdx);
Counter->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));

Value *Incr = IRB.CreateAdd(Counter, One);
Expand Down Expand Up @@ -813,7 +837,11 @@ bool AFLCoverage::runOnModule(Module &M) {
IRBuilder<> IRB(&(*it0));

// load the old counter value atomically
LoadInst *Counter = IRB.CreateLoad(MapPtrIdx);
LoadInst *Counter = IRB.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
IRB.getInt8Ty(),
#endif
MapPtrIdx);
Counter->setAlignment(llvm::Align());
Counter->setAtomic(llvm::AtomicOrdering::Monotonic);
Counter->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
Expand Down
6 changes: 5 additions & 1 deletion instrumentation/cmplog-instructions-pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ bool CmpLogInstructions::hookInstrs(Module &M) {

IRBuilder<> IRB2(selectcmpInst->getParent());
IRB2.SetInsertPoint(selectcmpInst);
LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm =
Expand Down
48 changes: 40 additions & 8 deletions instrumentation/cmplog-routines-pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ bool CmpLogRoutines::hookRtns(Module &M) {
IRBuilder<> IRB2(callInst->getParent());
IRB2.SetInsertPoint(callInst);

LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm = SplitBlockAndInsertIfThen(is_not_null, callInst, false);
Expand All @@ -475,7 +479,11 @@ bool CmpLogRoutines::hookRtns(Module &M) {
IRBuilder<> IRB2(callInst->getParent());
IRB2.SetInsertPoint(callInst);

LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm = SplitBlockAndInsertIfThen(is_not_null, callInst, false);
Expand Down Expand Up @@ -506,7 +514,11 @@ bool CmpLogRoutines::hookRtns(Module &M) {
IRBuilder<> IRB2(callInst->getParent());
IRB2.SetInsertPoint(callInst);

LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm = SplitBlockAndInsertIfThen(is_not_null, callInst, false);
Expand All @@ -533,7 +545,11 @@ bool CmpLogRoutines::hookRtns(Module &M) {
IRBuilder<> IRB2(callInst->getParent());
IRB2.SetInsertPoint(callInst);

LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm = SplitBlockAndInsertIfThen(is_not_null, callInst, false);
Expand Down Expand Up @@ -564,7 +580,11 @@ bool CmpLogRoutines::hookRtns(Module &M) {
IRBuilder<> IRB2(callInst->getParent());
IRB2.SetInsertPoint(callInst);

LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm = SplitBlockAndInsertIfThen(is_not_null, callInst, false);
Expand All @@ -590,7 +610,11 @@ bool CmpLogRoutines::hookRtns(Module &M) {
IRBuilder<> IRB2(callInst->getParent());
IRB2.SetInsertPoint(callInst);

LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm = SplitBlockAndInsertIfThen(is_not_null, callInst, false);
Expand All @@ -616,7 +640,11 @@ bool CmpLogRoutines::hookRtns(Module &M) {
IRBuilder<> IRB2(callInst->getParent());
IRB2.SetInsertPoint(callInst);

LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm = SplitBlockAndInsertIfThen(is_not_null, callInst, false);
Expand All @@ -642,7 +670,11 @@ bool CmpLogRoutines::hookRtns(Module &M) {
IRBuilder<> IRB2(callInst->getParent());
IRB2.SetInsertPoint(callInst);

LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm = SplitBlockAndInsertIfThen(is_not_null, callInst, false);
Expand Down
6 changes: 5 additions & 1 deletion instrumentation/cmplog-switches-pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
IRBuilder<> IRB2(SI->getParent());
IRB2.SetInsertPoint(SI);

LoadInst *CmpPtr = IRB2.CreateLoad(AFLCmplogPtr);
LoadInst *CmpPtr = IRB2.CreateLoad(
#if LLVM_VERSION_MAJOR >= 14
PointerType::get(Int8Ty, 0),
#endif
AFLCmplogPtr);
CmpPtr->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
auto is_not_null = IRB2.CreateICmpNE(CmpPtr, Null);
auto ThenTerm = SplitBlockAndInsertIfThen(is_not_null, SI, false);
Expand Down
Loading

0 comments on commit db36033

Please sign in to comment.