Author: Nick Desaulniers Date: 2021-04-27T10:12:58-07:00 New Revision: ea8416bf4df4e2823d85d50d8ddd69dd8ed54720
URL: https://github.com/llvm/llvm-project/commit/ea8416bf4df4e2823d85d50d8ddd69dd8ed54720 DIFF: https://github.com/llvm/llvm-project/commit/ea8416bf4df4e2823d85d50d8ddd69dd8ed54720.diff LOG: [CodeGenOptions] make StackProtectorGuardOffset signed GCC supports negative values for -mstack-protector-guard-offset=, this should be a signed value. Pre-req to D100919. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D101325 Added: Modified: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Clang.cpp llvm/include/llvm/CodeGen/CommandFlags.h llvm/include/llvm/Target/TargetOptions.h llvm/lib/CodeGen/CommandFlags.cpp llvm/lib/Target/X86/X86ISelLowering.cpp llvm/test/CodeGen/X86/stack-protector-3.ll Removed: ################################################################################ diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index d3ea7d2a94df5..68ebcc62ab2c8 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -371,7 +371,7 @@ ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel) VALUE_CODEGENOPT(TLSSize, 8, 0) /// The default stack protector guard offset to use. -VALUE_CODEGENOPT(StackProtectorGuardOffset, 32, (unsigned)-1) +VALUE_CODEGENOPT(StackProtectorGuardOffset, 32, INT_MAX) /// Number of path components to strip when emitting checks. (0 == full /// filename) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 8de28538192c5..4c171b94193e0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3345,7 +3345,7 @@ def mstack_protector_guard_EQ : Joined<["-"], "mstack-protector-guard=">, Group< MarshallingInfoString<CodeGenOpts<"StackProtectorGuard">>; def mstack_protector_guard_offset_EQ : Joined<["-"], "mstack-protector-guard-offset=">, Group<m_Group>, Flags<[CC1Option]>, HelpText<"Use the given offset for addressing the stack-protector guard">, - MarshallingInfoInt<CodeGenOpts<"StackProtectorGuardOffset">, "(unsigned)-1">; + MarshallingInfoInt<CodeGenOpts<"StackProtectorGuardOffset">, "INT_MAX">; def mstack_protector_guard_reg_EQ : Joined<["-"], "mstack-protector-guard-reg=">, Group<m_Group>, Flags<[CC1Option]>, HelpText<"Use the given reg for addressing the stack-protector guard">, MarshallingInfoString<CodeGenOpts<"StackProtectorGuardReg">, [{"none"}]>; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 42d215103ee3c..e90d4744d7851 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3124,7 +3124,7 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, if (!EffectiveTriple.isX86()) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; - unsigned Offset; + int Offset; if (Value.getAsInteger(10, Offset)) { D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value; return; diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h index 69ce85e6d7ec8..a12733801213e 100644 --- a/llvm/include/llvm/CodeGen/CommandFlags.h +++ b/llvm/include/llvm/CodeGen/CommandFlags.h @@ -107,7 +107,7 @@ bool getXCOFFTracebackTable(); std::string getBBSections(); std::string getStackProtectorGuard(); -unsigned getStackProtectorGuardOffset(); +int getStackProtectorGuardOffset(); std::string getStackProtectorGuardReg(); unsigned getTLSSize(); diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index 651dbe163a811..5dab7de949066 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -332,7 +332,7 @@ namespace llvm { unsigned XRayOmitFunctionIndex : 1; /// Stack protector guard offset to use. - unsigned StackProtectorGuardOffset = -1U; + int StackProtectorGuardOffset = INT_MAX; /// Stack protector guard mode to use, e.g. tls, global. StackProtectorGuards StackProtectorGuard = diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp index 76d871978532f..4c6c5950117fe 100644 --- a/llvm/lib/CodeGen/CommandFlags.cpp +++ b/llvm/lib/CodeGen/CommandFlags.cpp @@ -80,7 +80,7 @@ CGOPT(bool, IgnoreXCOFFVisibility) CGOPT(bool, XCOFFTracebackTable) CGOPT(std::string, BBSections) CGOPT(std::string, StackProtectorGuard) -CGOPT(unsigned, StackProtectorGuardOffset) +CGOPT(int, StackProtectorGuardOffset) CGOPT(std::string, StackProtectorGuardReg) CGOPT(unsigned, TLSSize) CGOPT(bool, EmulatedTLS) @@ -375,9 +375,9 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() { cl::init("none")); CGBINDOPT(StackProtectorGuardReg); - static cl::opt<unsigned> StackProtectorGuardOffset( + static cl::opt<int> StackProtectorGuardOffset( "stack-protector-guard-offset", cl::desc("Stack protector guard offset"), - cl::init((unsigned)-1)); + cl::init(INT_MAX)); CGBINDOPT(StackProtectorGuardOffset); static cl::opt<unsigned> TLSSize( diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index a5fe2cd986db6..1a0c4b5fe1be6 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -2484,7 +2484,7 @@ static bool hasStackGuardSlotTLS(const Triple &TargetTriple) { } static Constant* SegmentOffset(IRBuilder<> &IRB, - unsigned Offset, unsigned AddressSpace) { + int Offset, unsigned AddressSpace) { return ConstantExpr::getIntToPtr( ConstantInt::get(Type::getInt32Ty(IRB.getContext()), Offset), Type::getInt8PtrTy(IRB.getContext())->getPointerTo(AddressSpace)); @@ -2501,11 +2501,11 @@ Value *X86TargetLowering::getIRStackGuard(IRBuilder<> &IRB) const { } else { unsigned AddressSpace = getAddressSpace(); // Specially, some users may customize the base reg and offset. - unsigned Offset = getTargetMachine().Options.StackProtectorGuardOffset; + int Offset = getTargetMachine().Options.StackProtectorGuardOffset; // If we don't set -stack-protector-guard-offset value: // %fs:0x28, unless we're using a Kernel code model, in which case // it's %gs:0x28. gs:0x14 on i386. - if (Offset == (unsigned)-1) + if (Offset == INT_MAX) Offset = (Subtarget.is64Bit()) ? 0x28 : 0x14; const auto &GuardReg = getTargetMachine().Options.StackProtectorGuardReg; @@ -2576,7 +2576,7 @@ Value *X86TargetLowering::getSafeStackPointerLocation(IRBuilder<> &IRB) const { if (Subtarget.isTargetAndroid()) { // %fs:0x48, unless we're using a Kernel code model, in which case it's %gs: // %gs:0x24 on i386 - unsigned Offset = (Subtarget.is64Bit()) ? 0x48 : 0x24; + int Offset = (Subtarget.is64Bit()) ? 0x48 : 0x24; return SegmentOffset(IRB, Offset, getAddressSpace()); } diff --git a/llvm/test/CodeGen/X86/stack-protector-3.ll b/llvm/test/CodeGen/X86/stack-protector-3.ll index 96b1a0860e6b1..5cae90e24e6b0 100644 --- a/llvm/test/CodeGen/X86/stack-protector-3.ll +++ b/llvm/test/CodeGen/X86/stack-protector-3.ll @@ -4,6 +4,7 @@ ; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-reg=fs -o - < %s | FileCheck --check-prefix=CHECK-TLS-FS-40 %s ; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-reg=gs -o - < %s | FileCheck --check-prefix=CHECK-GS %s ; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-offset=20 -o - < %s | FileCheck --check-prefix=CHECK-OFFSET %s +; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-offset=-20 -o - < %s | FileCheck --check-prefix=CHECK-NEGATIVE-OFFSET %s ; CHECK-TLS-FS-40: movq %fs:40, %rax ; CHECK-TLS-FS-40: movq %fs:40, %rax @@ -29,6 +30,15 @@ ; CHECK-OFFSET-NEXT: .cfi_def_cfa_offset 32 ; CHECK-OFFSET-NEXT: callq __stack_chk_fail +; CHECK-NEGATIVE-OFFSET: movl $4294967276, %eax # imm = 0xFFFFFFEC +; CHECK-NEGATIVE-OFFSET: movq %fs:(%rax), %rcx +; CHECK-NEGATIVE-OFFSET: movq %fs:(%rax), %rax +; CHECK-NEGATIVE-OFFSET-NEXT: cmpq 16(%rsp), %rax +; CHECK-NEGATIVE-OFFSET-NEXT: jne .LBB0_2 +; CHECK-NEGATIVE-OFFSET: .LBB0_2: +; CHECK-NEGATIVE-OFFSET-NEXT: .cfi_def_cfa_offset 32 +; CHECK-NEGATIVE-OFFSET-NEXT: callq __stack_chk_fail + ; CHECK-GLOBAL: movq __stack_chk_guard(%rip), %rax ; CHECK-GLOBAL: movq __stack_chk_guard(%rip), %rax ; CHECK-GLOBAL-NEXT: cmpq 16(%rsp), %rax _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits