https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/70799
>From c791e527ee388659b35707816c0a67bee66dd0da Mon Sep 17 00:00:00 2001 From: Joseph Huber <jhub...@vols.utk.edu> Date: Tue, 31 Oct 2023 08:12:01 -0500 Subject: [PATCH] [StackProtector] Do not emit the stack protector on GPU architectures Summary: This patch changes the code generation to not emit the stack protector metadata on unsupported architectures. The issue was caused by system toolchains emitting stack protector option by default which would lead to errors when compiling for the GPU. I elected to change the code generation as we may want to update this in the future so we should keep the `clang` Driver code common. Although the user can use some combination of `-Xarch-device -fno-stack-protector` to override this, it is very irritating to do when we shouldn't emit this incompatible IR anyway. Fixes: https://github.com/llvm/llvm-project/issues/65911 --- clang/lib/CodeGen/CodeGenModule.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b1a6683a66bd052..db4e0d6552a4264 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -761,6 +761,14 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO, } } +static bool isStackProtectorOn(const LangOptions &LangOpts, + const llvm::Triple &Triple, + clang::LangOptions::StackProtectorMode Mode) { + if (Triple.isAMDGPU() || Triple.isNVPTX()) + return false; + return LangOpts.getStackProtector() == Mode; +} + void CodeGenModule::Release() { Module *Primary = getContext().getCurrentNamedModule(); if (CXX20ModuleInits && Primary && !Primary->isHeaderLikeModule()) @@ -2296,13 +2304,13 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (D && D->hasAttr<NoStackProtectorAttr>()) ; // Do nothing. else if (D && D->hasAttr<StrictGuardStackCheckAttr>() && - LangOpts.getStackProtector() == LangOptions::SSPOn) + isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn)) B.addAttribute(llvm::Attribute::StackProtectStrong); - else if (LangOpts.getStackProtector() == LangOptions::SSPOn) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn)) B.addAttribute(llvm::Attribute::StackProtect); - else if (LangOpts.getStackProtector() == LangOptions::SSPStrong) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPStrong)) B.addAttribute(llvm::Attribute::StackProtectStrong); - else if (LangOpts.getStackProtector() == LangOptions::SSPReq) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPReq)) B.addAttribute(llvm::Attribute::StackProtectReq); if (!D) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits