r318608 - [Driver] add initial support for alpine linux

Martell Malone via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 18 16:08:12 PST 2017


Author: martell
Date: Sat Nov 18 16:08:12 2017
New Revision: 318608

URL: http://llvm.org/viewvc/llvm-project?rev=318608&view=rev
Log:
[Driver] add initial support for alpine linux

set -pie as default for musl linux targets
add detection of alpine linux
append appropriate compile flags for alpine

Reviewers: rnk

Differential Revision: https://reviews.llvm.org/D39588

Modified:
    cfe/trunk/include/clang/Driver/Distro.h
    cfe/trunk/lib/Driver/Distro.cpp
    cfe/trunk/lib/Driver/ToolChains/Linux.cpp
    cfe/trunk/test/Driver/pic.c

Modified: cfe/trunk/include/clang/Driver/Distro.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Distro.h?rev=318608&r1=318607&r2=318608&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Distro.h (original)
+++ cfe/trunk/include/clang/Driver/Distro.h Sat Nov 18 16:08:12 2017
@@ -26,6 +26,7 @@ public:
     // 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 @@ public:
     return DistroVal >= UbuntuHardy && DistroVal <= UbuntuBionic;
   }
 
+  bool IsAlpineLinux() const {
+    return DistroVal == AlpineLinux;
+  }
+
   /// @}
 };
 

Modified: cfe/trunk/lib/Driver/Distro.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Distro.cpp?rev=318608&r1=318607&r2=318608&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Distro.cpp (original)
+++ cfe/trunk/lib/Driver/Distro.cpp Sat Nov 18 16:08:12 2017
@@ -129,6 +129,9 @@ static Distro::DistroType DetectDistro(v
   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;
 

Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.cpp?rev=318608&r1=318607&r2=318608&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Linux.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp Sat Nov 18 16:08:12 2017
@@ -210,7 +210,12 @@ Linux::Linux(const Driver &D, const llvm
 
   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 @@ Linux::Linux(const Driver &D, const llvm
   // 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 @@ void Linux::AddIAMCUIncludeArgs(const Ar
 
 bool Linux::isPIEDefault() const {
   return (getTriple().isAndroid() && !getTriple().isAndroidVersionLT(16)) ||
-         getSanitizerArgs().requiresPIE();
+          getTriple().isMusl() || getSanitizerArgs().requiresPIE();
 }
 
 SanitizerMask Linux::getSupportedSanitizers() const {

Modified: cfe/trunk/test/Driver/pic.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/pic.c?rev=318608&r1=318607&r2=318608&view=diff
==============================================================================
--- cfe/trunk/test/Driver/pic.c (original)
+++ cfe/trunk/test/Driver/pic.c Sat Nov 18 16:08:12 2017
@@ -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




More information about the cfe-commits mailing list