diff --git a/src/passes/strings-encoding/StringEncoding.cpp b/src/passes/strings-encoding/StringEncoding.cpp index 49a25b92..4410c35a 100644 --- a/src/passes/strings-encoding/StringEncoding.cpp +++ b/src/passes/strings-encoding/StringEncoding.cpp @@ -361,8 +361,10 @@ bool StringEncoding::injectOnStackLoop(BasicBlock& BB, Instruction& I, Use& Op, CastEncPtr = IRB.CreateBitCast(&G, IRB.getInt8PtrTy()); } - auto NewF = Function::Create(FDecode->getFunctionType(), llvm::GlobalValue::PrivateLinkage, - "__omvll_decode", BB.getModule()); + auto *M = BB.getModule(); + FunctionCallee DecodeCallee = + M->getOrInsertFunction("__omvll_decode", FDecode->getFunctionType()); + auto *NewF = cast(DecodeCallee.getCallee()); ValueToValueMapTy VMap; auto NewFArgsIt = NewF->arg_begin(); @@ -372,6 +374,7 @@ bool StringEncoding::injectOnStackLoop(BasicBlock& BB, Instruction& I, Use& Op, } SmallVector Returns; CloneFunctionInto(NewF, FDecode, VMap, CloneFunctionChangeType::DifferentModule, Returns); + NewF->setDSOLocal(true); std::vector Args = { CastClearBuffer, CastEncPtr ? CastEncPtr : EncPtr, KeyVal, VStrSize}; @@ -508,8 +511,9 @@ bool StringEncoding::processGlobal(BasicBlock& BB, Instruction&, Use& Op, Global fatalError("Can't find the 'decode' routine"); } - auto NewF = Function::Create(FDecode->getFunctionType(), llvm::GlobalValue::PrivateLinkage, - "__omvll_decode", M); + FunctionCallee DecodeCallee = + M->getOrInsertFunction("__omvll_decode", FDecode->getFunctionType()); + auto *NewF = cast(DecodeCallee.getCallee()); ValueToValueMapTy VMap; auto NewFArgsIt = NewF->arg_begin(); @@ -519,6 +523,7 @@ bool StringEncoding::processGlobal(BasicBlock& BB, Instruction&, Use& Op, Global } SmallVector Returns; CloneFunctionInto(NewF, FDecode, VMap, CloneFunctionChangeType::DifferentModule, Returns); + NewF->setDSOLocal(true); std::vector Args = { DataPtr, DataPtr, KeyVal, VStrSize