aboutsummaryrefslogtreecommitdiffstats
path: root/main/clang/clang-0004-Add-musl-targets-and-dynamic-linker.patch
blob: 6384b088f675be0c5a1c1c5418632dbf67ed807e (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
From 4777c16fc6e717a852366fa2a447c852cca3b62d Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Fri, 19 Feb 2016 13:35:08 +0100
Subject: [PATCH 4/7] Add musl targets and dynamic linker

---
 lib/Basic/Targets.cpp      |  2 ++
 lib/CodeGen/TargetInfo.cpp |  6 +++++-
 lib/Driver/ToolChains.cpp  | 15 ++++++++++-----
 lib/Driver/Tools.cpp       | 44 +++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index af8aea0..1e27c7a 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -4513,6 +4513,8 @@ public:
       case llvm::Triple::Android:
       case llvm::Triple::GNUEABI:
       case llvm::Triple::GNUEABIHF:
+      case llvm::Triple::MuslEABI:
+      case llvm::Triple::MuslEABIHF:
         setABI("aapcs-linux");
         break;
       case llvm::Triple::EABIHF:
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
index 3d1ddef..f6b3474 100644
--- a/lib/CodeGen/TargetInfo.cpp
+++ b/lib/CodeGen/TargetInfo.cpp
@@ -4757,6 +4757,8 @@ public:
     case llvm::Triple::EABIHF:
     case llvm::Triple::GNUEABI:
     case llvm::Triple::GNUEABIHF:
+    case llvm::Triple::MuslEABI:
+    case llvm::Triple::MuslEABIHF:
       return true;
     default:
       return false;
@@ -4767,6 +4769,7 @@ public:
     switch (getTarget().getTriple().getEnvironment()) {
     case llvm::Triple::EABIHF:
     case llvm::Triple::GNUEABIHF:
+    case llvm::Triple::MuslEABIHF:
       return true;
     default:
       return false;
@@ -7492,7 +7495,8 @@ const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
         Kind = ARMABIInfo::AAPCS16_VFP;
       else if (CodeGenOpts.FloatABI == "hard" ||
                (CodeGenOpts.FloatABI != "soft" &&
-                Triple.getEnvironment() == llvm::Triple::GNUEABIHF))
+                (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+                 Triple.getEnvironment() == llvm::Triple::MuslEABIHF)))
         Kind = ARMABIInfo::AAPCS_VFP;
 
       return *(TheTargetCodeGenInfo = new ARMTargetCodeGenInfo(Types, Kind));
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 6b0b31d..0db9644 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -1523,7 +1523,8 @@ bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const {
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
     LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
-    if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) {
+    if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+        TargetTriple.getEnvironment() == llvm::Triple::MuslEABIHF) {
       TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples));
     } else {
       TripleAliases.append(begin(ARMTriples), end(ARMTriples));
@@ -1532,7 +1533,8 @@ bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const {
   case llvm::Triple::armeb:
   case llvm::Triple::thumbeb:
     LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs));
-    if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) {
+    if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+        TargetTriple.getEnvironment() == llvm::Triple::MuslEABIHF) {
       TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples));
     } else {
       TripleAliases.append(begin(ARMebTriples), end(ARMebTriples));
@@ -3528,7 +3530,8 @@ static std::string getMultiarchTriple(const Driver &D,
   // regardless of what the actual target triple is.
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
-    if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
+    if (TargetEnvironment == llvm::Triple::GNUEABIHF ||
+        TargetEnvironment == llvm::Triple::MuslEABIHF) {
       if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf"))
         return "arm-linux-gnueabihf";
     } else {
@@ -3538,7 +3541,8 @@ static std::string getMultiarchTriple(const Driver &D,
     break;
   case llvm::Triple::armeb:
   case llvm::Triple::thumbeb:
-    if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
+    if (TargetEnvironment == llvm::Triple::GNUEABIHF ||
+        TargetEnvironment == llvm::Triple::MuslEABIHF) {
       if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf"))
         return "armeb-linux-gnueabihf";
     } else {
@@ -3969,7 +3973,8 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
     break;
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
-    if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
+    if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF ||
+        getTriple().getEnvironment() == llvm::Triple::MuslEABIHF)
       MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs;
     else
       MultiarchIncludeDirs = ARMMultiarchIncludeDirs;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index b7ac24f..ea1ce6f 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -712,6 +712,7 @@ arm::FloatABI arm::getARMFloatABI(const ToolChain &TC, const ArgList &Args) {
     case llvm::Triple::FreeBSD:
       switch (Triple.getEnvironment()) {
       case llvm::Triple::GNUEABIHF:
+      case llvm::Triple::MuslEABIHF:
         ABI = FloatABI::Hard;
         break;
       default:
@@ -725,6 +726,7 @@ arm::FloatABI arm::getARMFloatABI(const ToolChain &TC, const ArgList &Args) {
       switch (Triple.getEnvironment()) {
       case llvm::Triple::GNUEABIHF:
       case llvm::Triple::EABIHF:
+      case llvm::Triple::MuslEABIHF:
         ABI = FloatABI::Hard;
         break;
       case llvm::Triple::GNUEABI:
@@ -968,6 +970,8 @@ void Clang::AddARMTargetArgs(const llvm::Triple &Triple, const ArgList &Args,
     case llvm::Triple::Android:
     case llvm::Triple::GNUEABI:
     case llvm::Triple::GNUEABIHF:
+    case llvm::Triple::MuslEABI:
+    case llvm::Triple::MuslEABIHF:
       ABIName = "aapcs-linux";
       break;
     case llvm::Triple::EABIHF:
@@ -7857,6 +7861,8 @@ void freebsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
     switch (getToolChain().getTriple().getEnvironment()) {
     case llvm::Triple::GNUEABIHF:
     case llvm::Triple::GNUEABI:
+    case llvm::Triple::MuslEABIHF:
+    case llvm::Triple::MuslEABI:
     case llvm::Triple::EABI:
       CmdArgs.push_back("-meabi=5");
       break;
@@ -8199,10 +8205,12 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     switch (getToolChain().getTriple().getEnvironment()) {
     case llvm::Triple::EABI:
     case llvm::Triple::GNUEABI:
+    case llvm::Triple::MuslEABI:
       CmdArgs.push_back("armelf_nbsd_eabi");
       break;
     case llvm::Triple::EABIHF:
     case llvm::Triple::GNUEABIHF:
+    case llvm::Triple::MuslEABIHF:
       CmdArgs.push_back("armelf_nbsd_eabihf");
       break;
     default:
@@ -8219,10 +8227,12 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     switch (getToolChain().getTriple().getEnvironment()) {
     case llvm::Triple::EABI:
     case llvm::Triple::GNUEABI:
+    case llvm::Triple::MuslEABI:
       CmdArgs.push_back("armelfb_nbsd_eabi");
       break;
     case llvm::Triple::EABIHF:
     case llvm::Triple::GNUEABIHF:
+    case llvm::Triple::MuslEABIHF:
       CmdArgs.push_back("armelfb_nbsd_eabihf");
       break;
     default:
@@ -8623,11 +8633,43 @@ static void AddLibgcc(const llvm::Triple &Triple, const Driver &D,
     CmdArgs.push_back("-ldl");
 }
 
+static std::string getMuslDynamicLinker(const llvm::Triple::ArchType Arch,
+                                        const llvm::Triple::EnvironmentType Env) {
+  switch (Arch) {
+  case llvm::Triple::arm:
+  case llvm::Triple::thumb:
+    return Env == llvm::Triple::MuslEABIHF ?
+           "/lib/ld-musl-armhf.so.1" : "/lib/ld-musl-arm.so.1";
+  case llvm::Triple::armeb:
+  case llvm::Triple::thumbeb:
+    return Env == llvm::Triple::MuslEABIHF ?
+           "/lib/ld-musl-armebhf.so.1" : "/lib/ld-musl-armeb.so.1";
+  case llvm::Triple::aarch64:
+    return "/lib/ld-musl-aarch64.so.1";
+  case llvm::Triple::aarch64_be:
+    return "/lib/ld-musl-aarch64_be.so.1";
+  case llvm::Triple::mips:
+    return "/lib/ld-musl-mips.so.1";
+  case llvm::Triple::mipsel:
+    return "/lib/ld-musl-mipsel.so.1";
+  case llvm::Triple::ppc:
+    return "/lib/ld-musl-powerpc.so.1";
+  case llvm::Triple::x86:
+    return "/lib/ld-musl-i386.so.1";
+//case llvm::Triple::x86_64:
+  default:
+    return "/lib/ld-musl-x86_64.so.1";
+  }
+  return NULL;
+}
+
 static std::string getLinuxDynamicLinker(const ArgList &Args,
                                          const toolchains::Linux &ToolChain) {
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
 
-  if (ToolChain.getTriple().isAndroid()) {
+  if (ToolChain.getTriple().isMusl()) {
+    return getMuslDynamicLinker(Arch, ToolChain.getTriple().getEnvironment());
+  } else if (ToolChain.getTriple().isAndroid()) {
     if (ToolChain.getTriple().isArch64Bit())
       return "/system/bin/linker64";
     else
-- 
2.7.3