mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-28 19:31:58 +00:00
[stackprotector] Refactored ssp prologue creation code into its own helper function.
No functionality change. rdar://13935163 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186868 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fdd16bb918
commit
c03d5ec320
@ -265,6 +265,46 @@ bool StackProtector::RequiresStackProtector() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Insert code into the entry block that stores the __stack_chk_guard
|
||||
/// variable onto the stack:
|
||||
///
|
||||
/// entry:
|
||||
/// StackGuardSlot = alloca i8*
|
||||
/// StackGuard = load __stack_chk_guard
|
||||
/// call void @llvm.stackprotect.create(StackGuard, StackGuardSlot)
|
||||
///
|
||||
static void CreatePrologue(Function *F, Module *M, ReturnInst *RI,
|
||||
const TargetLoweringBase *TLI, const Triple &Trip,
|
||||
AllocaInst *&AI, Value *&StackGuardVar) {
|
||||
PointerType *PtrTy = Type::getInt8PtrTy(RI->getContext());
|
||||
unsigned AddressSpace, Offset;
|
||||
if (TLI->getStackCookieLocation(AddressSpace, Offset)) {
|
||||
Constant *OffsetVal =
|
||||
ConstantInt::get(Type::getInt32Ty(RI->getContext()), Offset);
|
||||
|
||||
StackGuardVar = ConstantExpr::getIntToPtr(OffsetVal,
|
||||
PointerType::get(PtrTy,
|
||||
AddressSpace));
|
||||
} else if (Trip.getOS() == llvm::Triple::OpenBSD) {
|
||||
StackGuardVar = M->getOrInsertGlobal("__guard_local", PtrTy);
|
||||
cast<GlobalValue>(StackGuardVar)
|
||||
->setVisibility(GlobalValue::HiddenVisibility);
|
||||
} else {
|
||||
StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy);
|
||||
}
|
||||
|
||||
BasicBlock &Entry = F->getEntryBlock();
|
||||
Instruction *InsPt = &Entry.front();
|
||||
|
||||
AI = new AllocaInst(PtrTy, "StackGuardSlot", InsPt);
|
||||
LoadInst *LI = new LoadInst(StackGuardVar, "StackGuard", false, InsPt);
|
||||
|
||||
Value *Args[] = { LI, AI };
|
||||
CallInst::
|
||||
Create(Intrinsic::getDeclaration(M, Intrinsic::stackprotector),
|
||||
Args, "", InsPt);
|
||||
}
|
||||
|
||||
/// InsertStackProtectors - Insert code into the prologue and epilogue of the
|
||||
/// function.
|
||||
///
|
||||
@ -283,41 +323,7 @@ bool StackProtector::InsertStackProtectors() {
|
||||
if (!RI) continue;
|
||||
|
||||
if (!FailBB) {
|
||||
// Insert code into the entry block that stores the __stack_chk_guard
|
||||
// variable onto the stack:
|
||||
//
|
||||
// entry:
|
||||
// StackGuardSlot = alloca i8*
|
||||
// StackGuard = load __stack_chk_guard
|
||||
// call void @llvm.stackprotect.create(StackGuard, StackGuardSlot)
|
||||
//
|
||||
PointerType *PtrTy = Type::getInt8PtrTy(RI->getContext());
|
||||
unsigned AddressSpace, Offset;
|
||||
if (TLI->getStackCookieLocation(AddressSpace, Offset)) {
|
||||
Constant *OffsetVal =
|
||||
ConstantInt::get(Type::getInt32Ty(RI->getContext()), Offset);
|
||||
|
||||
StackGuardVar = ConstantExpr::getIntToPtr(OffsetVal,
|
||||
PointerType::get(PtrTy, AddressSpace));
|
||||
} else if (Trip.getOS() == llvm::Triple::OpenBSD) {
|
||||
StackGuardVar = M->getOrInsertGlobal("__guard_local", PtrTy);
|
||||
cast<GlobalValue>(StackGuardVar)
|
||||
->setVisibility(GlobalValue::HiddenVisibility);
|
||||
} else {
|
||||
StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy);
|
||||
}
|
||||
|
||||
BasicBlock &Entry = F->getEntryBlock();
|
||||
Instruction *InsPt = &Entry.front();
|
||||
|
||||
AI = new AllocaInst(PtrTy, "StackGuardSlot", InsPt);
|
||||
LoadInst *LI = new LoadInst(StackGuardVar, "StackGuard", false, InsPt);
|
||||
|
||||
Value *Args[] = { LI, AI };
|
||||
CallInst::
|
||||
Create(Intrinsic::getDeclaration(M, Intrinsic::stackprotector),
|
||||
Args, "", InsPt);
|
||||
|
||||
CreatePrologue(F, M, RI, TLI, Trip, AI, StackGuardVar);
|
||||
// Create the basic block to jump to when the guard check fails.
|
||||
FailBB = CreateFailBB();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user