Skip to content

Commit b36fbf1

Browse files
committed
[libafl_cc] Fix for LLVM opaque pointers in passes
LLVM began introducing opaque pointers (pointer types with purposefully undefined pointee types) around LLVM 13[1] like in commit: `2155dc51d700 ([IR] Introduce the opaque pointer type, 2021-05-01)` introducing the function: `PointerType::get(LLVMContext &C, unsigned AddressSpace)` and had wholesale switched to only opaque pointers by LLVM 17[2]. Part of that effort deprecates many functions, including: `PointerType::get(Type *ElementType, unsigned AddressSpace)` though this function was depreacted much later in LLVM 21 in commit: `146ad71bc71a ([IR] Deprecate PointerType::get/getUnqual pointee type overload (#134517), 2025-04-07)` Switch libafl_cc's passes to the new function to avoid deprecation warnings [1]: https://releases.llvm.org/13.0.1/docs/ReleaseNotes.html#changes-to-the-llvm-ir [2]: https://releases.llvm.org/22.1.0/docs/OpaquePointers.html#version-support
1 parent b87ef2e commit b36fbf1

4 files changed

Lines changed: 11 additions & 17 deletions

File tree

crates/libafl_cc/src/autotokens-pass.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,11 @@ PreservedAnalyses AutoTokensPass::run(Module &M, ModuleAnalysisManager &MAM) {
299299
isStrcmp &=
300300
FT->getNumParams() == 2 && FT->getReturnType()->isIntegerTy(32) &&
301301
FT->getParamType(0) == FT->getParamType(1) &&
302-
FT->getParamType(0) ==
303-
IntegerType::getInt8Ty(M.getContext())->getPointerTo(0);
302+
FT->getParamType(0) == PointerType::get(M.getContext(), 0);
304303
isStrcasecmp &=
305304
FT->getNumParams() == 2 && FT->getReturnType()->isIntegerTy(32) &&
306305
FT->getParamType(0) == FT->getParamType(1) &&
307-
FT->getParamType(0) ==
308-
IntegerType::getInt8Ty(M.getContext())->getPointerTo(0);
306+
FT->getParamType(0) == PointerType::get(M.getContext(), 0);
309307
isMemcmp &= FT->getNumParams() == 3 &&
310308
FT->getReturnType()->isIntegerTy(32) &&
311309
FT->getParamType(0)->isPointerTy() &&
@@ -314,14 +312,12 @@ PreservedAnalyses AutoTokensPass::run(Module &M, ModuleAnalysisManager &MAM) {
314312
isStrncmp &=
315313
FT->getNumParams() == 3 && FT->getReturnType()->isIntegerTy(32) &&
316314
FT->getParamType(0) == FT->getParamType(1) &&
317-
FT->getParamType(0) ==
318-
IntegerType::getInt8Ty(M.getContext())->getPointerTo(0) &&
315+
FT->getParamType(0) == PointerType::get(M.getContext(), 0) &&
319316
FT->getParamType(2)->isIntegerTy();
320317
isStrncasecmp &=
321318
FT->getNumParams() == 3 && FT->getReturnType()->isIntegerTy(32) &&
322319
FT->getParamType(0) == FT->getParamType(1) &&
323-
FT->getParamType(0) ==
324-
IntegerType::getInt8Ty(M.getContext())->getPointerTo(0) &&
320+
FT->getParamType(0) == PointerType::get(M.getContext(), 0) &&
325321
FT->getParamType(2)->isIntegerTy();
326322
isStdString &= FT->getNumParams() >= 2 &&
327323
FT->getParamType(0)->isPointerTy() &&

crates/libafl_cc/src/cmplog-instructions-pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
158158
}
159159
#endif
160160

161-
Constant *Null = Constant::getNullValue(PointerType::get(Int8Ty, 0));
161+
Constant *Null = Constant::getNullValue(PointerType::get(M.getContext(), 0));
162162

163163
/* iterate over all functions, bbs and instruction and add suitable calls */
164164
for (auto &F : M) {

crates/libafl_cc/src/cmplog-routines-pass.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool CmpLogRoutines::hookRtns(Module &M) {
7575
IntegerType *Int8Ty = IntegerType::getInt8Ty(C);
7676
IntegerType *Int64Ty = IntegerType::getInt64Ty(C);
7777
IntegerType *Int32Ty = IntegerType::getInt32Ty(C);
78-
PointerType *i8PtrTy = PointerType::get(Int8Ty, 0);
78+
PointerType *i8PtrTy = PointerType::get(M.getContext(), 0);
7979

8080
FunctionCallee cmplogHookFn;
8181
FunctionCallee cmplogLlvmStdStd;
@@ -229,8 +229,7 @@ bool CmpLogRoutines::hookRtns(Module &M) {
229229
isStrcmp &=
230230
FT->getNumParams() == 2 && FT->getReturnType()->isIntegerTy(32) &&
231231
FT->getParamType(0) == FT->getParamType(1) &&
232-
FT->getParamType(0) ==
233-
IntegerType::getInt8Ty(M.getContext())->getPointerTo(0);
232+
FT->getParamType(0) == PointerType::get(M.getContext(), 0);
234233

235234
bool isStrncmp = (!FuncName.compare("strncmp") ||
236235
!FuncName.compare("xmlStrncmp") ||
@@ -246,8 +245,7 @@ bool CmpLogRoutines::hookRtns(Module &M) {
246245
isStrncmp &=
247246
FT->getNumParams() == 3 && FT->getReturnType()->isIntegerTy(32) &&
248247
FT->getParamType(0) == FT->getParamType(1) &&
249-
FT->getParamType(0) ==
250-
IntegerType::getInt8Ty(M.getContext())->getPointerTo(0) &&
248+
FT->getParamType(0) == PointerType::get(M.getContext(), 0) &&
251249
FT->getParamType(2)->isIntegerTy();
252250

253251
bool isGccStdStringStdString =

crates/libafl_cc/src/coverage-accounting-pass.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ PreservedAnalyses AFLCoverage::run(Module &M, ModuleAnalysisManager &MAM) {
232232
__afl_acc_prev_loc is thread-local. */
233233

234234
GlobalVariable *AFLMemOpPtr = new GlobalVariable(
235-
M, PointerType::get(Int32Ty, 0), false, GlobalValue::ExternalLinkage, 0,
236-
"__afl_acc_memop_ptr");
235+
M, PointerType::get(M.getContext(), 0), false,
236+
GlobalValue::ExternalLinkage, 0, "__afl_acc_memop_ptr");
237237

238238
GlobalVariable *AFLPrevLoc;
239239

@@ -301,7 +301,7 @@ PreservedAnalyses AFLCoverage::run(Module &M, ModuleAnalysisManager &MAM) {
301301
/* Load SHM pointer */
302302

303303
LoadInst *MemReadPtr =
304-
IRB.CreateLoad(PointerType::get(Int32Ty, 0), AFLMemOpPtr);
304+
IRB.CreateLoad(PointerType::get(M.getContext(), 0), AFLMemOpPtr);
305305
MemReadPtr->setMetadata(M.getMDKindID("nosanitize"),
306306
MDNode::get(C, None));
307307
Value *MemReadPtrIdx =

0 commit comments

Comments
 (0)