From 02ea3694a0a541f6328d120f02eb04977c1fc840 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 29 Nov 2022 10:31:20 -0500 Subject: Utils: Fix appending to global_ctors with program address spaces Also fix constructing sanitizer constructors in address space 0 so it's testable (this was also failing the verifier on the type of global_ctors). --- llvm/lib/Transforms/Utils/ModuleUtils.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms/Utils/ModuleUtils.cpp') diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index da588b3..b0f784b 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -30,7 +30,9 @@ static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F, // to the list. SmallVector CurrentCtors; StructType *EltTy = StructType::get( - IRB.getInt32Ty(), PointerType::getUnqual(FnTy), IRB.getInt8PtrTy()); + IRB.getInt32Ty(), PointerType::get(FnTy, F->getAddressSpace()), + IRB.getInt8PtrTy()); + if (GlobalVariable *GVCtor = M.getNamedGlobal(ArrayName)) { if (Constant *Init = GVCtor->getInitializer()) { unsigned n = Init->getNumOperands(); @@ -123,7 +125,8 @@ llvm::declareSanitizerInitFunction(Module &M, StringRef InitName, Function *llvm::createSanitizerCtor(Module &M, StringRef CtorName) { Function *Ctor = Function::createWithDefaultAttr( FunctionType::get(Type::getVoidTy(M.getContext()), false), - GlobalValue::InternalLinkage, 0, CtorName, &M); + GlobalValue::InternalLinkage, M.getDataLayout().getProgramAddressSpace(), + CtorName, &M); Ctor->addFnAttr(Attribute::NoUnwind); BasicBlock *CtorBB = BasicBlock::Create(M.getContext(), "", Ctor); ReturnInst::Create(M.getContext(), CtorBB); -- cgit v1.1