diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/Targets.cpp | 9 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Driver/ArgList.cpp | 29 | ||||
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Frontend/InitPreprocessor.cpp | 7 |
5 files changed, 58 insertions, 4 deletions
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 9910e28fcda..d1158a6c6fc 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -235,11 +235,14 @@ static void GetDarwinLanguageOptions(LangOptions &Opts, if (!getDarwinNumber(Triple, Maj, Min, Rev)) return; - // Blocks default to on for 10.6 (darwin10) and beyond. - // As does nonfragile-abi for 64bit mode - if (Maj > 9) + // Blocks and stack protectors default to on for 10.6 (darwin10) and beyond. + if (Maj > 9) { Opts.Blocks = 1; + Opts.StackProtector = 1; + } + // Non-fragile ABI (in 64-bit mode) default to on for 10.5 (darwin9) and + // beyond. if (Maj >= 9 && Opts.ObjC1 && !strncmp(Triple, "x86_64", 6)) Opts.ObjCNonFragileABI = 1; } diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 30c5d28c227..61b6737be11 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -392,6 +392,11 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, if (CompileOpts.NoImplicitFloat) FuncAttrs |= llvm::Attribute::NoImplicitFloat; + if (Features.StackProtector == 1) + FuncAttrs |= llvm::Attribute::StackProtect; + else if (Features.StackProtector == 2) + FuncAttrs |= llvm::Attribute::StackProtectReq; + QualType RetTy = FI.getReturnType(); unsigned Index = 1; const ABIArgInfo &RetAI = FI.getReturnInfo(); diff --git a/clang/lib/Driver/ArgList.cpp b/clang/lib/Driver/ArgList.cpp index 593694cfbbf..54dd4bb7753 100644 --- a/clang/lib/Driver/ArgList.cpp +++ b/clang/lib/Driver/ArgList.cpp @@ -49,6 +49,35 @@ Arg *ArgList::getLastArg(options::ID Id0, options::ID Id1, bool Claim) const { return Res; } +Arg *ArgList::getLastArg(options::ID Id0, options::ID Id1, options::ID Id2, + bool Claim) const { + Arg *Res = 0; + Arg *A0 = getLastArg(Id0, false); + Arg *A1 = getLastArg(Id1, false); + Arg *A2 = getLastArg(Id2, false); + + int A0Idx = A0 ? A0->getIndex() : -1; + int A1Idx = A1 ? A1->getIndex() : -1; + int A2Idx = A2 ? A2->getIndex() : -1; + + if (A0Idx > A1Idx) { + if (A0Idx > A2Idx) + Res = A0; + else if (A2Idx != -1) + Res = A2; + } else { + if (A1Idx > A2Idx) + Res = A1; + else if (A2Idx != -1) + Res = A2; + } + + if (Claim && Res) + Res->claim(); + + return Res; +} + bool ArgList::hasFlag(options::ID Pos, options::ID Neg, bool Default) const { if (Arg *A = getLastArg(Pos, Neg)) return A->getOption().matches(Pos); diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index bfc247a015f..ac07906c8fd 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -498,6 +498,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_fvisibility_EQ); Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); + // Forward stack protector flags. + if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, + options::OPT_fstack_protector_all, + options::OPT_fstack_protector)) { + if (A->getOption().matches(options::OPT_fno_stack_protector)) + CmdArgs.push_back("--stack-protector=0"); + else if (A->getOption().matches(options::OPT_fstack_protector)) + CmdArgs.push_back("--stack-protector=1"); + else + CmdArgs.push_back("--stack-protector=2"); + } + // Forward -f options with positive and negative forms; we translate // these by hand. diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 730414e4482..554868fd273 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -423,7 +423,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI, sprintf(MacroBuf, "__DECIMAL_DIG__=%d", PickFP(&TI.getLongDoubleFormat(), -1/*FIXME*/, 17, 21, 33, 36)); DefineBuiltinMacro(Buf, MacroBuf); - + + if (LangOpts.StackProtector == 1) + DefineBuiltinMacro(Buf, "__SSP__=1"); + else if (LangOpts.StackProtector == 2) + DefineBuiltinMacro(Buf, "__SSP_ALL__=2"); + // Get other target #defines. TI.getTargetDefines(LangOpts, Buf); } |