aboutsummaryrefslogtreecommitdiffstats
path: root/main/llvm/llvm-alpine-linux.patch
blob: 8bef4b177769cd204d1057acff8ee273698e05fc (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
--- a/include/llvm/ADT/Triple.h
+++ b/include/llvm/ADT/Triple.h
@@ -117,7 +117,10 @@
     EABI,
     MachO,
     Android,
-    ELF
+    ELF,
+    Musl,
+    MuslEABI,
+    MuslEABIHF
   };
 
 private:
--- a/lib/Support/Triple.cpp.orig
+++ b/lib/Support/Triple.cpp
@@ -153,6 +153,9 @@ const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
   case MachO: return "macho";
   case Android: return "android";
   case ELF: return "elf";
+  case Musl: return "musl";
+  case MuslEABI: return "muslgnueabi";
+  case MuslEABIHF: return "muslgnueabihf";
   }
 
   llvm_unreachable("Invalid EnvironmentType!");
@@ -305,6 +308,9 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
     .StartsWith("macho", Triple::MachO)
     .StartsWith("android", Triple::Android)
     .StartsWith("elf", Triple::ELF)
+    .StartsWith("muslgnueabihf", Triple::MuslEABIHF)
+    .StartsWith("muslgnueabi", Triple::MuslEABI)
+    .StartsWith("musl", Triple::Musl)
     .Default(Triple::UnknownEnvironment);
 }
 
--- a/tools/clang/lib/Driver/ToolChains.cpp
+++ b/tools/clang/lib/Driver/ToolChains.cpp
@@ -1118,20 +1118,23 @@ void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const {
   static const char *const ARMTriples[] = { "arm-linux-gnueabi",
                                             "arm-linux-androideabi" };
   static const char *const ARMHFTriples[] = { "arm-linux-gnueabihf",
-                                              "armv7hl-redhat-linux-gnueabi" };
+                                              "armv7hl-redhat-linux-gnueabi",
+                                              "armv6-alpine-linux-muslgnueabihf",
+                                              "armv7-alpine-linux-muslgnueabihf" };
 
   static const char *const X86_64LibDirs[] = { "/lib64", "/lib" };
   static const char *const X86_64Triples[] = {
     "x86_64-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-pc-linux-gnu",
     "x86_64-redhat-linux6E", "x86_64-redhat-linux", "x86_64-suse-linux",
-    "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", "x86_64-slackware-linux"
+    "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", "x86_64-slackware-linux",
+    "x86_64-alpine-linux-musl"
   };
   static const char *const X86LibDirs[] = { "/lib32", "/lib" };
   static const char *const X86Triples[] = {
     "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu", "i386-linux-gnu",
     "i386-redhat-linux6E", "i686-redhat-linux", "i586-redhat-linux",
     "i386-redhat-linux", "i586-suse-linux", "i486-slackware-linux",
-    "i686-montavista-linux"
+    "i686-montavista-linux", "i486-alpine-linux-musl"
   };
 
   static const char *const MIPSLibDirs[] = { "/lib" };
@@ -2166,6 +2169,7 @@ Tool *Solaris::buildLinker() const {
 /// Distribution (very bare-bones at the moment).
 
 enum Distro {
+  AlpineLinux,
   ArchLinux,
   DebianLenny,
   DebianSqueeze,
@@ -2276,6 +2280,9 @@ static Distro DetectDistro(llvm::Triple::ArchType Arch) {
   if (llvm::sys::fs::exists("/etc/arch-release"))
     return ArchLinux;
 
+  if (llvm::sys::fs::exists("/etc/alpine-release"))
+    return AlpineLinux;
+
   return UnknownDistro;
 }
 
--- a/tools/clang/lib/Driver/Tools.cpp
+++ b/tools/clang/lib/Driver/Tools.cpp
@@ -6355,16 +6355,28 @@ static StringRef getLinuxDynamicLinker(const ArgList &Args,
                                        const toolchains::Linux &ToolChain) {
   if (ToolChain.getTriple().getEnvironment() == llvm::Triple::Android)
     return "/system/bin/linker";
-  else if (ToolChain.getArch() == llvm::Triple::x86)
-    return "/lib/ld-linux.so.2";
-  else if (ToolChain.getArch() == llvm::Triple::aarch64)
+  else if (ToolChain.getArch() == llvm::Triple::x86) {
+    switch (ToolChain.getTriple().getEnvironment()) {
+    case llvm::Triple::Musl:
+      return "/lib/ld-musl-i386.so.1";
+    default:
+      return "/lib/ld-linux.so.2";
+    }
+  } else if (ToolChain.getArch() == llvm::Triple::aarch64)
     return "/lib/ld-linux-aarch64.so.1";
   else if (ToolChain.getArch() == llvm::Triple::arm ||
            ToolChain.getArch() == llvm::Triple::thumb) {
-    if (ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
+    switch (ToolChain.getTriple().getEnvironment()) {
+    case llvm::Triple::Musl:
+    case llvm::Triple::MuslEABI:
+      return "/lib/ld-musl-arm.so.3";
+    case llvm::Triple::MuslEABIHF:
+      return "/lib/ld-musl-armhf.so.3";
+    case llvm::Triple::GNUEABIHF:
       return "/lib/ld-linux-armhf.so.3";
-    else
+    default:
       return "/lib/ld-linux.so.3";
+    }
   } else if (ToolChain.getArch() == llvm::Triple::mips ||
              ToolChain.getArch() == llvm::Triple::mipsel)
     return "/lib/ld.so.1";
@@ -6380,8 +6392,14 @@ static StringRef getLinuxDynamicLinker(const ArgList &Args,
            ToolChain.getArch() == llvm::Triple::ppc64le ||
            ToolChain.getArch() == llvm::Triple::systemz)
     return "/lib64/ld64.so.1";
-  else
-    return "/lib64/ld-linux-x86-64.so.2";
+  else {
+    switch (ToolChain.getTriple().getEnvironment()) {
+    case llvm::Triple::Musl:
+      return "/lib/ld-musl-x86_64.so.1";
+    default:
+      return "/lib64/ld-linux-x86-64.so.2";
+    }
+  }
 }
 
 void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA,