[PATCH] D39588: Distro: initial support for alpine

Martell Malone via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 3 05:04:58 PDT 2017


martell updated this revision to Diff 121462.
martell edited the summary of this revision.

Repository:
  rL LLVM

https://reviews.llvm.org/D39588

Files:
  include/clang/Driver/Distro.h
  lib/Driver/Distro.cpp
  lib/Driver/ToolChains/Linux.cpp
  test/Driver/pic.c


Index: test/Driver/pic.c
===================================================================
--- test/Driver/pic.c
+++ test/Driver/pic.c
@@ -152,6 +152,22 @@
 // RUN: %clang %s -target i386-unknown-linux -shared -pie -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIE
 //
+// On Musl Linux, PIE is enabled by default, but can be disabled.
+// RUN: %clang -c %s -target x86_64-linux-musl -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
+// RUN: %clang -c %s -target i686-linux-musl -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
+// RUN: %clang -c %s -target armv6-linux-musleabihf -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
+// RUN: %clang -c %s -target armv7-linux-musleabihf -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
+// RUN: %clang %s -target x86_64-linux-musl -nopie -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIE
+// RUN: %clang %s -target x86_64-linux-musl -pie -nopie -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIE
+// RUN: %clang %s -target x86_64-linux-musl -nopie -pie -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
+//
 // Darwin is a beautiful and unique snowflake when it comes to these flags.
 // When targeting a 32-bit darwin system, only level 2 is supported. On 64-bit
 // targets, there is simply nothing you can do, there is no PIE, there is only
Index: lib/Driver/ToolChains/Linux.cpp
===================================================================
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -210,7 +210,12 @@
 
   Distro Distro(D.getVFS());
 
-  if (Distro.IsOpenSUSE() || Distro.IsUbuntu()) {
+  if (Distro.IsAlpineLinux()) {
+    ExtraOpts.push_back("-z");
+    ExtraOpts.push_back("now");
+  }
+
+  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux()) {
     ExtraOpts.push_back("-z");
     ExtraOpts.push_back("relro");
   }
@@ -232,7 +237,7 @@
   // Android loader does not support .gnu.hash.
   // Hexagon linker/loader does not support .gnu.hash
   if (!IsMips && !IsAndroid && !IsHexagon) {
-    if (Distro.IsRedhat() || Distro.IsOpenSUSE() ||
+    if (Distro.IsRedhat() || Distro.IsOpenSUSE() || Distro.IsAlpineLinux() ||
         (Distro.IsUbuntu() && Distro >= Distro::UbuntuMaverick))
       ExtraOpts.push_back("--hash-style=gnu");
 
@@ -812,7 +817,7 @@
 
 bool Linux::isPIEDefault() const {
   return (getTriple().isAndroid() && !getTriple().isAndroidVersionLT(16)) ||
-         getSanitizerArgs().requiresPIE();
+          getTriple().isMusl() || getSanitizerArgs().requiresPIE();
 }
 
 SanitizerMask Linux::getSupportedSanitizers() const {
Index: lib/Driver/Distro.cpp
===================================================================
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -129,6 +129,9 @@
   if (VFS.exists("/etc/exherbo-release"))
     return Distro::Exherbo;
 
+  if (VFS.exists("/etc/alpine-release"))
+    return Distro::AlpineLinux;
+
   if (VFS.exists("/etc/arch-release"))
     return Distro::ArchLinux;
 
Index: include/clang/Driver/Distro.h
===================================================================
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -26,6 +26,7 @@
     // NB: Releases of a particular Linux distro should be kept together
     // in this enum, because some tests are done by integer comparison against
     // the first and last known member in the family, e.g. IsRedHat().
+    AlpineLinux,
     ArchLinux,
     DebianLenny,
     DebianSqueeze,
@@ -116,6 +117,10 @@
     return DistroVal >= UbuntuHardy && DistroVal <= UbuntuBionic;
   }
 
+  bool IsAlpineLinux() const {
+    return DistroVal == AlpineLinux;
+  }
+
   /// @}
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39588.121462.patch
Type: text/x-patch
Size: 3749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171103/3f1a7efd/attachment-0001.bin>


More information about the cfe-commits mailing list