Blame patches/clang_host/clang-0005-Enable-PIE-by-default-for-alpine-linux.patch

Lucio Andrés Illanes Albornoz (arab, vxp) 585426
From efbdf70c883a356106fc1bcb1c2917ec6c0a6157 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 09:35:26 +0100
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Subject: [PATCH 5/7] Enable PIE by default for alpine linux
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Alpine Linux uses PIE by default.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
---
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 lib/Driver/ToolChains.cpp |  5 ++++-
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 lib/Driver/Tools.cpp      |  4 +++-
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 test/Driver/pic.c         | 12 ++++++++++++
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 3 files changed, 19 insertions(+), 2 deletions(-)
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 0db9644..82449bf 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
@@ -4143,7 +4143,10 @@ void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   }
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 }
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
-bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); }
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+bool Linux::isPIEDefault() const {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  return getSanitizerArgs().requiresPIE() ||
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+         Linux::getTriple().getVendorName().compare("alpine") == 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+}
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 SanitizerMask Linux::getSupportedSanitizers() const {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index ea1ce6f..8fd3649 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- a/lib/Driver/Tools.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/lib/Driver/Tools.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -7919,7 +7919,9 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   if (!D.SysRoot.empty())
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
     CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
-  if (IsPIE)
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  if (Args.hasArg(options::OPT_nopie))
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+    CmdArgs.push_back("-nopie");
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  else if (IsPIE)
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
     CmdArgs.push_back("-pie");
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   if (Args.hasArg(options::OPT_static)) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/test/Driver/pic.c b/test/Driver/pic.c
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index aeb2ee3..9b8e0f6 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- a/test/Driver/pic.c
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/test/Driver/pic.c
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -243,6 +243,18 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // RUN: %clang %s -target i386-pc-openbsd -nopie -### 2>&1 \
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // RUN:   | FileCheck %s --check-prefix=CHECK-NOPIE-LD
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 //
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// On Alpine Linux, we want similar PIE-by-default behavior
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN: %clang -c %s -target x86_64-alpine-linux-musl -### 2>&1 \
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN: %clang -c %s -target i686-alpine-linux-musl -### 2>&1 \
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN: %clang -c %s -target armv6-alpine-linux-musleabihf -### 2>&1 \
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN: %clang -c %s -target armv7-alpine-linux-musleabihf -### 2>&1 \
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN: %clang %s -target x86_64-alpine-linux-musl -nopie -### 2>&1 \
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+// RUN:   | FileCheck %s --check-prefix=CHECK-NOPIE-LD
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+//
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // On Android PIC is enabled by default
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // RUN: %clang -c %s -target i686-linux-android -### 2>&1 \
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
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