summaryrefslogtreecommitdiffstats
path: root/recipes-devtools/clang/clang/0009-clang-Enable-SSP-and-PIE-by-default.patch
blob: e9672c1073059632623e41b17a370117fce799b6 (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
From 549a201d29521e8c5dd2b21cc12df0ef1e33aa72 Mon Sep 17 00:00:00 2001
From: Evangelos Foutras <evangelos@foutrelis.com>
Date: Thu, 20 Sep 2018 06:20:28 +0300
Subject: [PATCH] clang: Enable SSP and PIE by default

This is a minimal set of changes needed to make clang use SSP and PIE by
default on Arch Linux. Tests that were easy to adjust have been changed
accordingly; only test/Driver/linux-ld.c has been marked as "expected
failure" due to the number of changes it would require (mostly replacing
crtbegin.o with crtbeginS.o).

Doing so is needed in order to align clang with the new default GCC
behavior in Arch which generates PIE executables by default and also
defaults to -fstack-protector-strong. It is not meant to be a long term
solution, but a simple temporary fix.

Hopefully these changes will be obsoleted by the introduction upstream
of a compile-time option (https://bugs.llvm.org/show_bug.cgi?id=13410)
---
 clang/lib/Driver/ToolChains/Linux.cpp | 14 ++++++++++++--
 clang/lib/Driver/ToolChains/Linux.h   |  1 +
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index d900508ad93..3e68d50dac2 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -972,8 +972,18 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
 }
 
 bool Linux::isPIEDefault() const {
-  return (getTriple().isAndroid() && !getTriple().isAndroidVersionLT(16)) ||
-          getTriple().isMusl() || getSanitizerArgs().requiresPIE();
+  const bool IsMips = getTriple().isMIPS();
+  const bool IsAndroid = getTriple().isAndroid();
+
+  if (IsMips || IsAndroid)
+    return (getTriple().isAndroid() && !getTriple().isAndroidVersionLT(16)) ||
+            getTriple().isMusl() || getSanitizerArgs().requiresPIE();
+
+  return true;
+}
+
+unsigned Linux::GetDefaultStackProtectorLevel(bool KernelOrKext) const {
+  return 2;
 }
 
 bool Linux::isNoExecStackDefault() const {
diff --git a/clang/lib/Driver/ToolChains/Linux.h b/clang/lib/Driver/ToolChains/Linux.h
index 4c61994691c..66134a3a327 100644
--- a/clang/lib/Driver/ToolChains/Linux.h
+++ b/clang/lib/Driver/ToolChains/Linux.h
@@ -39,6 +39,7 @@ public:
   CXXStdlibType GetDefaultCXXStdlibType() const override;
   bool isPIEDefault() const override;
   bool isNoExecStackDefault() const override;
+  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override;
   bool IsMathErrnoDefault() const override;
   SanitizerMask getSupportedSanitizers() const override;
   void addProfileRTLibs(const llvm::opt::ArgList &Args,