Skip to content

Commit 256aeb1

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

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

llvm/lib/Transforms/IPO/CrossDSOCFI.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,30 @@ 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())
96108
F->addFnAttr("target-features", "+thumb-mode");
97-
if (T.isAArch64()) {
98-
if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
99-
M.getModuleFlag("branch-target-enforcement"))) {
100-
if (BTE->getZExtValue() != 0) {
101-
F->addFnAttr("branch-target-enforcement");
102-
}
103-
}
104-
}
105109

106110
auto args = F->arg_begin();
107111
Value &CallSiteTypeId = *(args++);

0 commit comments

Comments
 (0)