summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Driver/Distro.h5
-rw-r--r--clang/lib/Driver/Distro.cpp3
-rw-r--r--clang/lib/Driver/ToolChains/Linux.cpp11
-rw-r--r--clang/test/Driver/pic.c16
4 files changed, 32 insertions, 3 deletions
diff --git a/clang/include/clang/Driver/Distro.h b/clang/include/clang/Driver/Distro.h
index eeb4f25f348..4ab4e2ae993 100644
--- a/clang/include/clang/Driver/Distro.h
+++ b/clang/include/clang/Driver/Distro.h
@@ -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;
+ }
+
/// @}
};
diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
index 9a0b854e32f..f15c919b9aa 100644
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -129,6 +129,9 @@ static Distro::DistroType DetectDistro(vfs::FileSystem &VFS) {
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;
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 9b722166c5f..ca042f38db8 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -210,7 +210,12 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
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::Triple &Triple, const ArgList &Args)
// 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 ArgList &DriverArgs,
bool Linux::isPIEDefault() const {
return (getTriple().isAndroid() && !getTriple().isAndroidVersionLT(16)) ||
- getSanitizerArgs().requiresPIE();
+ getTriple().isMusl() || getSanitizerArgs().requiresPIE();
}
SanitizerMask Linux::getSupportedSanitizers() const {
diff --git a/clang/test/Driver/pic.c b/clang/test/Driver/pic.c
index f2618eede3c..9b3aa0e7713 100644
--- a/clang/test/Driver/pic.c
+++ b/clang/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
OpenPOWER on IntegriCloud