aboutsummaryrefslogtreecommitdiffstats
path: root/main/clang/clang-0007-Enable-stack-protector-by-default-for-alpine-linux.patch
blob: a4cb92618116ebb322a4751e7c68fe06fc75fe61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From da8ea517105fff702f936695dcfae844ac85260d Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Tue, 23 Feb 2016 10:16:54 +0000
Subject: [PATCH 7/7] Enable stack protector by default for alpine linux

---
 lib/Driver/ToolChains.cpp     |  7 +++++++
 lib/Driver/ToolChains.h       |  1 +
 test/Driver/stack-protector.c | 14 ++++++++++++++
 3 files changed, 22 insertions(+)

diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 1a8ebf5..59b7601 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -4193,6 +4193,13 @@ void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args,
   ToolChain::addProfileRTLibs(Args, CmdArgs);
 }
 
+unsigned Linux::GetDefaultStackProtectorLevel(bool KernelOrKext) const {
+  StringRef VendorName = Linux::getTriple().getVendorName();
+  if (VendorName.compare("alpine") == 0)
+    return 2;
+  return 1;
+}
+
 /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
 
 DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple,
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index f940e58..977ea66 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -796,6 +796,7 @@ public:
   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
                           llvm::opt::ArgStringList &CC1Args) const override;
   bool isPIEDefault() const override;
+  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override;
   SanitizerMask getSupportedSanitizers() const override;
   void addProfileRTLibs(const llvm::opt::ArgList &Args,
                         llvm::opt::ArgStringList &CmdArgs) const override;
diff --git a/test/Driver/stack-protector.c b/test/Driver/stack-protector.c
index 487af56..2fbd39a 100644
--- a/test/Driver/stack-protector.c
+++ b/test/Driver/stack-protector.c
@@ -24,6 +24,20 @@
 // SSP-ALL: "-stack-protector" "3"
 // SSP-ALL-NOT: "-stack-protector-buffer-size" 
 
+// RUN: %clang -target x86_64-alpine-linux-musl -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE
+// ALPINE: "-stack-protector" "2"
+
+// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_SPS
+// ALPINE_SPS: "-stack-protector" "2"
+
+// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_ALL
+// ALPINE_ALL: "-stack-protector" "3"
+// ALPINE_ALL-NOT: "-stack-protector-buffer-size"
+
+// RUN: %clang -target x86_64-alpine-linux-musl -fno-stack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_NOSSP
+// ALPINE_NOSSP-NOT: "-stack-protector"
+// ALPINE_NOSSP-NOT: "-stack-protector-buffer-size"
+
 // RUN: %clang -target x86_64-scei-ps4 -### %s 2>&1 | FileCheck %s -check-prefix=SSP-PS4
 // RUN: %clang -target x86_64-scei-ps4 -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=SSP-PS4
 // SSP-PS4: "-stack-protector" "2"
-- 
2.7.3