diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.h b/llvm/lib/Target/PowerPC/PPCISelLowering.h --- a/llvm/lib/Target/PowerPC/PPCISelLowering.h +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.h @@ -1073,6 +1073,7 @@ /// Override to support customized stack guard loading. bool useLoadStackGuardNode() const override; void insertSSPDeclarations(Module &M) const override; + Value *getSDagStackGuard(const Module &M) const override; bool isFPImmLegal(const APFloat &Imm, EVT VT, bool ForCodeSize) const override; diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -130,6 +130,8 @@ static SDValue widenVec(SelectionDAG &DAG, SDValue Vec, const SDLoc &dl); +static const char AIXSSPCanaryWordName[] = "__ssp_canary_word"; + // FIXME: Remove this once the bug has been fixed! extern cl::opt ANDIGlueBug; @@ -16406,12 +16408,24 @@ return true; } -// Override to disable global variable loading on Linux. +// Override to disable global variable loading on Linux and insert AIX canary +// word declaration. void PPCTargetLowering::insertSSPDeclarations(Module &M) const { + if (Subtarget.isAIXABI()) { + M.getOrInsertGlobal(AIXSSPCanaryWordName, + Type::getInt8PtrTy(M.getContext())); + return; + } if (!Subtarget.isTargetLinux()) return TargetLowering::insertSSPDeclarations(M); } +Value *PPCTargetLowering::getSDagStackGuard(const Module &M) const { + if (Subtarget.isAIXABI()) + return M.getGlobalVariable(AIXSSPCanaryWordName); + return TargetLowering::getSDagStackGuard(M); +} + bool PPCTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT, bool ForCodeSize) const { if (!VT.isSimple() || !Subtarget.hasVSX()) diff --git a/llvm/test/CodeGen/PowerPC/stack-guard-oob.ll b/llvm/test/CodeGen/PowerPC/stack-guard-oob.ll --- a/llvm/test/CodeGen/PowerPC/stack-guard-oob.ll +++ b/llvm/test/CodeGen/PowerPC/stack-guard-oob.ll @@ -1,7 +1,9 @@ ; RUN: llc -mtriple=powerpc64le -O0 < %s | FileCheck %s +; RUN: llc -mtriple=powerpc64-ibm-aix-xcoff -O0 < %s | FileCheck %s --check-prefix=AIX ; CHECK-LABEL: in_bounds: ; CHECK-NOT: __stack_chk_guard +; AIX-NOT: __ssp_canary_word define i32 @in_bounds() #0 { %var = alloca i32, align 4 store i32 0, i32* %var, align 4 @@ -12,6 +14,7 @@ ; CHECK-LABEL: constant_out_of_bounds: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @constant_out_of_bounds() #0 { %var = alloca i32, align 4 store i32 0, i32* %var, align 4 @@ -22,6 +25,7 @@ ; CHECK-LABEL: nonconstant_out_of_bounds: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @nonconstant_out_of_bounds(i32 %n) #0 { %var = alloca i32, align 4 store i32 0, i32* %var, align 4 @@ -32,6 +36,7 @@ ; CHECK-LABEL: phi_before_gep_in_bounds: ; CHECK-NOT: __stack_chk_guard +; AIX-NOT: __ssp_canary_word define i32 @phi_before_gep_in_bounds(i32 %k) #0 { entry: %var1 = alloca i32, align 4 @@ -53,6 +58,7 @@ ; CHECK-LABEL: phi_before_gep_constant_out_of_bounds: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @phi_before_gep_constant_out_of_bounds(i32 %k) #0 { entry: %var1 = alloca i32, align 4 @@ -74,6 +80,7 @@ ; CHECK-LABEL: phi_before_gep_nonconstant_out_of_bounds: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @phi_before_gep_nonconstant_out_of_bounds(i32 %k, i32 %n) #0 { entry: %var1 = alloca i32, align 4 @@ -95,6 +102,7 @@ ; CHECK-LABEL: phi_after_gep_in_bounds: ; CHECK-NOT: __stack_chk_guard +; AIX-NOT: __ssp_canary_word define i32 @phi_after_gep_in_bounds(i32 %k) #0 { entry: %var1 = alloca i32, align 4 @@ -120,6 +128,7 @@ ; CHECK-LABEL: phi_after_gep_constant_out_of_bounds_a: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @phi_after_gep_constant_out_of_bounds_a(i32 %k) #0 { entry: %var1 = alloca i32, align 4 @@ -145,6 +154,7 @@ ; CHECK-LABEL: phi_after_gep_constant_out_of_bounds_b: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @phi_after_gep_constant_out_of_bounds_b(i32 %k) #0 { entry: %var1 = alloca i32, align 4 @@ -170,6 +180,7 @@ ; CHECK-LABEL: phi_different_types_a: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i64 @phi_different_types_a(i32 %k) #0 { entry: %var1 = alloca i64, align 4 @@ -191,6 +202,7 @@ ; CHECK-LABEL: phi_different_types_b: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i64 @phi_different_types_b(i32 %k) #0 { entry: %var1 = alloca i32, align 4 @@ -212,6 +224,7 @@ ; CHECK-LABEL: phi_after_gep_nonconstant_out_of_bounds_a: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @phi_after_gep_nonconstant_out_of_bounds_a(i32 %k, i32 %n) #0 { entry: %var1 = alloca i32, align 4 @@ -237,6 +250,7 @@ ; CHECK-LABEL: phi_after_gep_nonconstant_out_of_bounds_b: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @phi_after_gep_nonconstant_out_of_bounds_b(i32 %k, i32 %n) #0 { entry: %var1 = alloca i32, align 4 @@ -265,6 +279,7 @@ ; CHECK-LABEL: struct_in_bounds: ; CHECK-NOT: __stack_chk_guard +; AIX-NOT: __ssp_canary_word define void @struct_in_bounds() #0 { %var = alloca %struct.outer, align 4 %outergep = getelementptr inbounds %struct.outer, %struct.outer* %var, i32 0, i32 1 @@ -275,6 +290,7 @@ ; CHECK-LABEL: struct_constant_out_of_bounds_a: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define void @struct_constant_out_of_bounds_a() #0 { %var = alloca %struct.outer, align 4 %outergep = getelementptr inbounds %struct.outer, %struct.outer* %var, i32 1, i32 0 @@ -287,6 +303,7 @@ ; Here the offset is out-of-bounds of the addressed struct.inner member, but ; still within bounds of the outer struct so no stack guard is needed. ; CHECK-NOT: __stack_chk_guard +; AIX-NOT: __ssp_canary_word define void @struct_constant_out_of_bounds_b() #0 { %var = alloca %struct.outer, align 4 %outergep = getelementptr inbounds %struct.outer, %struct.outer* %var, i32 0, i32 0 @@ -298,6 +315,7 @@ ; CHECK-LABEL: struct_constant_out_of_bounds_c: ; Here we are out-of-bounds of both the inner and outer struct. ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define void @struct_constant_out_of_bounds_c() #0 { %var = alloca %struct.outer, align 4 %outergep = getelementptr inbounds %struct.outer, %struct.outer* %var, i32 0, i32 1 @@ -308,6 +326,7 @@ ; CHECK-LABEL: struct_nonconstant_out_of_bounds_a: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define void @struct_nonconstant_out_of_bounds_a(i32 %n) #0 { %var = alloca %struct.outer, align 4 %outergep = getelementptr inbounds %struct.outer, %struct.outer* %var, i32 %n, i32 0 @@ -318,6 +337,7 @@ ; CHECK-LABEL: struct_nonconstant_out_of_bounds_b: ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define void @struct_nonconstant_out_of_bounds_b(i32 %n) #0 { %var = alloca %struct.outer, align 4 %outergep = getelementptr inbounds %struct.outer, %struct.outer* %var, i32 0, i32 0 @@ -328,6 +348,7 @@ ; CHECK-LABEL: bitcast_smaller_load ; CHECK-NOT: __stack_chk_guard +; AIX-NOT: __ssp_canary_word define i32 @bitcast_smaller_load() #0 { %var = alloca i64, align 4 store i64 0, i64* %var, align 4 @@ -338,6 +359,7 @@ ; CHECK-LABEL: bitcast_same_size_load ; CHECK-NOT: __stack_chk_guard +; AIX-NOT: __ssp_canary_word define i32 @bitcast_same_size_load() #0 { %var = alloca i64, align 4 store i64 0, i64* %var, align 4 @@ -349,6 +371,7 @@ ; CHECK-LABEL: bitcast_larger_load ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i64 @bitcast_larger_load() #0 { %var = alloca i32, align 4 store i32 0, i32* %var, align 4 @@ -359,6 +382,7 @@ ; CHECK-LABEL: bitcast_larger_store ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @bitcast_larger_store() #0 { %var = alloca i32, align 4 %bitcast = bitcast i32* %var to i64* @@ -369,6 +393,7 @@ ; CHECK-LABEL: bitcast_larger_cmpxchg ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i64 @bitcast_larger_cmpxchg(i64 %desired, i64 %new) #0 { %var = alloca i32, align 4 %bitcast = bitcast i32* %var to i64* @@ -379,6 +404,7 @@ ; CHECK-LABEL: bitcast_larger_atomic_rmw ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i64 @bitcast_larger_atomic_rmw() #0 { %var = alloca i32, align 4 %bitcast = bitcast i32* %var to i64* @@ -390,6 +416,7 @@ ; CHECK-LABEL: bitcast_overlap ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @bitcast_overlap() #0 { %var = alloca i32, align 4 %bitcast = bitcast i32* %var to %struct.packed* @@ -402,6 +429,7 @@ ; CHECK-LABEL: multi_dimensional_array ; CHECK: __stack_chk_guard +; AIX: __ssp_canary_word define i32 @multi_dimensional_array() #0 { %var = alloca %struct.multi_dimensional, align 4 %gep1 = getelementptr inbounds %struct.multi_dimensional, %struct.multi_dimensional* %var, i32 0, i32 0