[PATCH] D90348: [Driver] specify -stack-protector 0 for -fno-stack-protector

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 28 15:37:34 PDT 2020


nickdesaulniers created this revision.
nickdesaulniers added reviewers: void, manojgupta.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nickdesaulniers requested review of this revision.

`-fno-stack-protector` now explicitly sets `-stack-protector 0` for the
invocation of cc1. In turn, -stack-protector 0 will set nossp IR fn attr
on all functions defined in the translation unit.

Fixes pr/47479.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90348

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/stack-protector.c


Index: clang/test/Driver/stack-protector.c
===================================================================
--- clang/test/Driver/stack-protector.c
+++ clang/test/Driver/stack-protector.c
@@ -1,6 +1,6 @@
 // RUN: %clang -fno-stack-protector -### %s 2>&1 | FileCheck %s -check-prefix=NOSSP
-// NOSSP-NOT: "-stack-protector"
-// NOSSP-NOT: "-stack-protector-buffer-size" 
+// NOSSP: "-stack-protector" "0"
+// NOSSP-NOT: "-stack-protector-buffer-size"
 
 // RUN: %clang -target i386-unknown-linux -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=SSP
 // SSP: "-stack-protector" "1"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3013,6 +3013,8 @@
       StackProtectorLevel = LangOptions::SSPStrong;
     else if (A->getOption().matches(options::OPT_fstack_protector_all))
       StackProtectorLevel = LangOptions::SSPReq;
+    else if (A->getOption().matches(options::OPT_fno_stack_protector))
+      StackProtectorLevel = LangOptions::SSPOff;
   } else {
     StackProtectorLevel = DefaultStackProtectorLevel;
   }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1594,7 +1594,8 @@
   if (!hasUnwindExceptions(LangOpts))
     B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (D && D->hasAttr<NoStackProtectorAttr>())
+  if (LangOpts.getStackProtector() == LangOptions::SSPOff ||
+      (D && D->hasAttr<NoStackProtectorAttr>()))
     B.addAttribute(llvm::Attribute::NoStackProtect);
   else if (LangOpts.getStackProtector() == LangOptions::SSPOn)
     B.addAttribute(llvm::Attribute::StackProtect);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90348.301459.patch
Type: text/x-patch
Size: 1815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201028/6ee578de/attachment.bin>


More information about the cfe-commits mailing list