Blame patches/clang_host/clang-0007-Enable-stack-protector-by-default-for-alpine-linux.patch

Lucio Andrés Illanes Albornoz (arab, vxp) 585426
From da8ea517105fff702f936695dcfae844ac85260d Mon Sep 17 00:00:00 2001
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
From: Natanael Copa <ncopa@alpinelinux.org>
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Date: Tue, 23 Feb 2016 10:16:54 +0000
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Subject: [PATCH 7/7] Enable stack protector by default for alpine linux
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
---
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 lib/Driver/ToolChains.cpp     |  7 +++++++
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 lib/Driver/ToolChains.h       |  1 +
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 test/Driver/stack-protector.c | 14 ++++++++++++++
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 3 files changed, 22 insertions(+)
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index 1a8ebf5..59b7601 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- a/lib/Driver/ToolChains.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/lib/Driver/ToolChains.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -4193,6 +4193,13 @@ void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   ToolChain::addProfileRTLibs(Args, CmdArgs);
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 }
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+unsigned Linux::GetDefaultStackProtectorLevel(bool KernelOrKext) const {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  StringRef VendorName = Linux::getTriple().getVendorName();
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  if (VendorName.compare("alpine") == 0)
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+    return 2;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+}
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index f940e58..977ea66 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- a/lib/Driver/ToolChains.h
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/lib/Driver/ToolChains.h
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -796,6 +796,7 @@ public:
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
                           llvm::opt::ArgStringList &CC1Args) const override;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   bool isPIEDefault() const override;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   SanitizerMask getSupportedSanitizers() const override;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   void addProfileRTLibs(const llvm::opt::ArgList &Args,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
                         llvm::opt::ArgStringList &CmdArgs) const override;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/test/Driver/stack-protector.c b/test/Driver/stack-protector.c
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index 487af56..2fbd39a 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- a/test/Driver/stack-protector.c
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/test/Driver/stack-protector.c
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -24,6 +24,20 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // SSP-ALL: "-stack-protector" "3"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // SSP-ALL-NOT: "-stack-protector-buffer-size" 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN: %clang -target x86_64-alpine-linux-musl -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// ALPINE: "-stack-protector" "2"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_SPS
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// ALPINE_SPS: "-stack-protector" "2"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_ALL
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// ALPINE_ALL: "-stack-protector" "3"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// ALPINE_ALL-NOT: "-stack-protector-buffer-size"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN: %clang -target x86_64-alpine-linux-musl -fno-stack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_NOSSP
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// ALPINE_NOSSP-NOT: "-stack-protector"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// ALPINE_NOSSP-NOT: "-stack-protector-buffer-size"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // RUN: %clang -target x86_64-scei-ps4 -### %s 2>&1 | FileCheck %s -check-prefix=SSP-PS4
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // RUN: %clang -target x86_64-scei-ps4 -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=SSP-PS4
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // SSP-PS4: "-stack-protector" "2"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
-- 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
2.7.3
Lucio Andrés Illanes Albornoz (arab, vxp) 585426