From 4d59c8fdb955ea0d668b854f467e12bce05a8857 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 30 Nov 2020 18:29:55 +0100 Subject: [PATCH] -fstack-clash-protection: Return an actual error when used on unsupported OS $ clang-12: error: -fstack-clash-protection is not supported on Windows or Mac OS X Differential Revision: https://reviews.llvm.org/D92245 --- clang/include/clang/Basic/DiagnosticDriverKinds.td | 2 ++ clang/lib/Driver/ToolChains/Clang.cpp | 11 +++++++---- llvm/test/CodeGen/X86/stack-clash-large.ll | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index e92a4bf..736950b 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -273,6 +273,8 @@ def err_drv_unsupported_embed_bitcode : Error<"%0 is not supported with -fembed-bitcode">; def err_drv_bitcode_unsupported_on_toolchain : Error< "-fembed-bitcode is not supported on versions of iOS prior to 6.0">; +def err_drv_stack_clash_protection_unsupported_on_toolchain : Error< + "-fstack-clash-protection is not supported on %0">; def err_drv_invalid_malign_branch_EQ : Error< "invalid argument '%0' to -malign-branch=; each element must be one of: %1">; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 300ab6e..c04b350 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3067,12 +3067,15 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, } } -static void RenderSCPOptions(const ToolChain &TC, const ArgList &Args, - ArgStringList &CmdArgs) { +static void RenderSCPOptions(const Driver &D, const ToolChain &TC, + const ArgList &Args, ArgStringList &CmdArgs) { const llvm::Triple &EffectiveTriple = TC.getEffectiveTriple(); - if (!EffectiveTriple.isOSLinux()) + if (EffectiveTriple.isOSWindows()) { + D.Diag(diag::err_drv_stack_clash_protection_unsupported_on_toolchain) + << EffectiveTriple.getOSName(); return; + } if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() && !EffectiveTriple.isPPC64()) @@ -5550,7 +5553,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString("-mspeculative-load-hardening")); RenderSSPOptions(D, TC, Args, CmdArgs, KernelOrKext); - RenderSCPOptions(TC, Args, CmdArgs); + RenderSCPOptions(D, TC, Args, CmdArgs); RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs); // Translate -mstackrealign diff --git a/llvm/test/CodeGen/X86/stack-clash-large.ll b/llvm/test/CodeGen/X86/stack-clash-large.ll index dd53cd8..7deae31 100644 --- a/llvm/test/CodeGen/X86/stack-clash-large.ll +++ b/llvm/test/CodeGen/X86/stack-clash-large.ll @@ -1,5 +1,7 @@ ; RUN: llc -mtriple=x86_64-linux-android < %s | FileCheck -check-prefix=CHECK-X86-64 %s ; RUN: llc -mtriple=i686-linux-android < %s | FileCheck -check-prefix=CHECK-X86-32 %s +; RUN: llc -mtriple=x86_64-unknown-freebsd < %s | FileCheck -check-prefix=CHECK-X86-64 %s +; RUN: llc -mtriple=x86_64-pc-linux-gnu < %s | FileCheck -check-prefix=CHECK-X86-64 %s define i32 @foo() local_unnamed_addr #0 { -- 2.7.4