diff options
author | Logan Chien <loganchien@google.com> | 2013-11-06 22:22:01 +0800 |
---|---|---|
committer | Andrew Hsieh <andrewhsieh@google.com> | 2015-03-24 11:53:46 -0700 |
commit | 5230452a6bf78fbe77f70132a1e8b67c65df4a74 (patch) | |
tree | d17dd50d6fefa3893374b5c1917cf147862304a8 | |
parent | 3722003fb74fdd7e2f8bddeec33af3b6ae1e6e91 (diff) | |
download | llvm-5230452a6bf78fbe77f70132a1e8b67c65df4a74.tar.gz |
[ndk][x86] Add option to store sp cookie in var.
Add an option to store the stack protector cookie
in the global variable.
-rw-r--r-- | lib/Target/X86/X86ISelLowering.cpp | 9 | ||||
-rw-r--r-- | test/CodeGen/X86/stack-protector-force-gv.ll | 22 |
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index b75842738ee..28475bded65 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -84,6 +84,12 @@ static cl::opt<int> ReciprocalEstimateRefinementSteps( "result of the hardware reciprocal estimate instruction."), cl::NotHidden); +// Force to store the stack protector cookie in the global variable +static cl::opt<bool> ForceGlobalVarStackProtectorCookie( + "x86-force-gv-stack-cookie", + cl::init(false), + cl::desc("Store the stack protector cookie in the global variable")); + // Forward declarations. static SDValue getMOVL(SelectionDAG &DAG, SDLoc dl, EVT VT, SDValue V1, SDValue V2); @@ -1962,6 +1968,9 @@ bool X86TargetLowering::getStackCookieLocation(unsigned &AddressSpace, if (!Subtarget->isTargetLinux()) return false; + if (ForceGlobalVarStackProtectorCookie) + return false; + if (Subtarget->is64Bit()) { // %fs:0x28, unless we're using a Kernel code model, in which case it's %gs: Offset = 0x28; diff --git a/test/CodeGen/X86/stack-protector-force-gv.ll b/test/CodeGen/X86/stack-protector-force-gv.ll new file mode 100644 index 00000000000..bc647d17a3c --- /dev/null +++ b/test/CodeGen/X86/stack-protector-force-gv.ll @@ -0,0 +1,22 @@ +; RUN: llc < %s -mtriple=i386-pc-linux-gnu -x86-force-gv-stack-cookie -o - \ +; RUN: | FileCheck %s + +@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1 +declare i8* @strcpy(i8*, i8*) +declare i32 @printf(i8*, ...) + +define void @test(i8* %a) nounwind uwtable ssp { +entry: +; CHECK: test: +; CHECK: movl __stack_chk_guard +; CHECK: calll __stack_chk_fail + %a.addr = alloca i8*, align 8 + %buf = alloca [16 x i8], align 16 + store i8* %a, i8** %a.addr, align 8 + %arraydecay = getelementptr inbounds [16 x i8]* %buf, i32 0, i32 0 + %0 = load i8** %a.addr, align 8 + %call = call i8* @strcpy(i8* %arraydecay, i8* %0) + %arraydecay1 = getelementptr inbounds [16 x i8]* %buf, i32 0, i32 0 + %call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i32 0, i32 0), i8* %arraydecay1) + ret void +} |