diff options
author | Eli Friedman <efriedma@codeaurora.org> | 2018-04-21 00:07:46 +0000 |
---|---|---|
committer | Eli Friedman <efriedma@codeaurora.org> | 2018-04-21 00:07:46 +0000 |
commit | 78ffb44f1745918509562efac9bec44afe7e02e3 (patch) | |
tree | 6c33f1026776d0c18f5a70aab1b156577e1dca34 | |
parent | 5dd3768d28fb935290950593cdecef51e4abee14 (diff) |
[AArch64] Don't crash trying to resolve __stack_chk_guard.
In certain cases, the compiler might try to merge __stack_chk_guard with
another global variable. (Or someone could theoretically define
__stack_chk_guard as an alias.) In that case, make sure we don't crash.
Differential Revision: https://reviews.llvm.org/D45746
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330495 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/TargetLoweringBase.cpp | 7 | ||||
-rw-r--r-- | test/CodeGen/AArch64/stackguard-internal.ll | 21 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/CodeGen/TargetLoweringBase.cpp b/lib/CodeGen/TargetLoweringBase.cpp index 53a3918ab83..beeff7d59cc 100644 --- a/lib/CodeGen/TargetLoweringBase.cpp +++ b/lib/CodeGen/TargetLoweringBase.cpp @@ -1624,13 +1624,16 @@ Value *TargetLoweringBase::getIRStackGuard(IRBuilder<> &IRB) const { // Currently only support "standard" __stack_chk_guard. // TODO: add LOAD_STACK_GUARD support. void TargetLoweringBase::insertSSPDeclarations(Module &M) const { - M.getOrInsertGlobal("__stack_chk_guard", Type::getInt8PtrTy(M.getContext())); + if (!M.getNamedValue("__stack_chk_guard")) + new GlobalVariable(M, Type::getInt8PtrTy(M.getContext()), false, + GlobalVariable::ExternalLinkage, + nullptr, "__stack_chk_guard"); } // Currently only support "standard" __stack_chk_guard. // TODO: add LOAD_STACK_GUARD support. Value *TargetLoweringBase::getSDagStackGuard(const Module &M) const { - return M.getGlobalVariable("__stack_chk_guard", true); + return M.getNamedValue("__stack_chk_guard"); } Value *TargetLoweringBase::getSSPStackGuardCheck(const Module &M) const { diff --git a/test/CodeGen/AArch64/stackguard-internal.ll b/test/CodeGen/AArch64/stackguard-internal.ll new file mode 100644 index 00000000000..6dcdf161985 --- /dev/null +++ b/test/CodeGen/AArch64/stackguard-internal.ll @@ -0,0 +1,21 @@ +; RUN: llc -O3 %s -o - | FileCheck %s +target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" +target triple = "aarch64-linux-gnu" + +; Make sure we correctly lower stack guards even if __stack_chk_guard +; is an alias. (The alias is created by GlobalMerge.) +; CHECK: adrp {{.*}}, __stack_chk_guard +; CHECK: ldr {{.*}}, [{{.*}}, :lo12:__stack_chk_guard] +; CHECK: .set __stack_chk_guard, .L_MergedGlobals+4 + +@__stack_chk_guard = internal global [8 x i32] zeroinitializer, align 4 +@x = internal global i32 0, align 4 + +define i32 @b() nounwind sspstrong { +entry: + %z = alloca [10 x i32], align 4 + %arraydecay = getelementptr inbounds [10 x i32], [10 x i32]* %z, i64 0, i64 0 + %call = call i32 @a(i32* getelementptr inbounds ([8 x i32], [8 x i32]* @__stack_chk_guard, i64 0, i64 0), i32* nonnull @x, i32* nonnull %arraydecay) #3 + ret i32 %call +} +declare i32 @a(i32*, i32*, i32*) |