Skip to content

Commit 201600f

Browse files
committed
Use createWithDefaultAttr instead of explicitly modifying attributes.
Per review comment.
1 parent cbdee73 commit 201600f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

llvm/lib/Transforms/IPO/CrossDSOCFI.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,26 @@ void CrossDSOCFI::buildCFICheck(Module &M) {
8282
}
8383

8484
LLVMContext &Ctx = M.getContext();
85-
FunctionCallee C = M.getOrInsertFunction(
86-
"__cfi_check", Type::getVoidTy(Ctx), Type::getInt64Ty(Ctx),
87-
PointerType::getUnqual(Ctx), PointerType::getUnqual(Ctx));
85+
FunctionType *CFICheckTy =
86+
FunctionType::get(Type::getVoidTy(Ctx),
87+
{Type::getInt64Ty(Ctx), PointerType::getUnqual(Ctx),
88+
PointerType::getUnqual(Ctx)},
89+
false);
90+
FunctionCallee C = Function::createWithDefaultAttr(
91+
CFICheckTy, GlobalValue::ExternalLinkage, 0, "__cfi_check", &M);
8892
Function *F = cast<Function>(C.getCallee());
89-
// Take over the existing function. The frontend emits a weak stub so that the
90-
// linker knows about the symbol; this pass replaces the function body.
91-
F->deleteBody();
9293
F->setAlignment(Align(4096));
94+
if (F->getName() != "__cfi_check") {
95+
// The frontend might have already created a function named __cfi_check;
96+
// delete it.
97+
GlobalValue *G = M.getNamedValue("__cfi_check");
98+
assert(G && "cfi_check must exist after we constructed it");
99+
if (G->getAddressSpace() != F->getAddressSpace())
100+
report_fatal_error("__cfi_check with unexpected address space");
101+
G->replaceAllUsesWith(F);
102+
F->takeName(G);
103+
G->eraseFromParent();
104+
}
93105

94106
Triple T(M.getTargetTriple());
95107
if (T.isARM() || T.isThumb())

0 commit comments

Comments
 (0)