[llvm] r186868 - [stackprotector] Refactored ssp prologue creation code into its own helper function.
Michael Gottesman
mgottesman at apple.com
Mon Jul 22 13:44:11 PDT 2013
Author: mgottesman
Date: Mon Jul 22 15:44:11 2013
New Revision: 186868
URL: http://llvm.org/viewvc/llvm-project?rev=186868&view=rev
Log:
[stackprotector] Refactored ssp prologue creation code into its own helper function.
No functionality change.
rdar://13935163
Modified:
llvm/trunk/lib/CodeGen/StackProtector.cpp
Modified: llvm/trunk/lib/CodeGen/StackProtector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StackProtector.cpp?rev=186868&r1=186867&r2=186868&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/StackProtector.cpp (original)
+++ llvm/trunk/lib/CodeGen/StackProtector.cpp Mon Jul 22 15:44:11 2013
@@ -265,6 +265,46 @@ bool StackProtector::RequiresStackProtec
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::InsertStackProtecto
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();
}
More information about the llvm-commits
mailing list