Skip to content

Commit c163d7f

Browse files
jefferytotiranerlend-aasland
authored
gh-95855: Refactor platform triplet detection code, add detection for MIPS soft float and musl libc (#107221)
- Move platform triplet detection code into Misc/platform_triplet.c - Refactor MIPS detection, use defined(__mips64) to detect MIPS64 - Compute libc values in separate section - Add detection for MIPS soft float - Add detection for musl musl supports SPE with its soft-float ABI: https://git.musl-libc.org/cgit/musl/commit/?id=7be59733d71ada3a32a98622507399253f1d5e48 Original patch by Christian Heimes. Co-authored-by: Christian Heimes <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 809ea7c commit c163d7f

File tree

4 files changed

+265
-376
lines changed

4 files changed

+265
-376
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Refactor platform triplet detection code and add detection for MIPS soft
2+
float and musl libc.

Misc/platform_triplet.c

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
/* Detect platform triplet from builtin defines
2+
* cc -E Misc/platform_triplet.c | grep '^PLATFORM_TRIPLET=' | tr -d ' '
3+
*/
4+
#undef bfin
5+
#undef cris
6+
#undef fr30
7+
#undef linux
8+
#undef hppa
9+
#undef hpux
10+
#undef i386
11+
#undef mips
12+
#undef powerpc
13+
#undef sparc
14+
#undef unix
15+
#if defined(__ANDROID__)
16+
# Android is not a multiarch system.
17+
#elif defined(__linux__)
18+
/*
19+
* BEGIN of Linux block
20+
*/
21+
// Detect libc (based on config.guess)
22+
# include <features.h>
23+
# if defined(__UCLIBC__)
24+
# error uclibc not supported
25+
# elif defined(__dietlibc__)
26+
# error dietlibc not supported
27+
# elif defined(__GLIBC__)
28+
# define LIBC gnu
29+
# define LIBC_X32 gnux32
30+
# if defined(__ARM_PCS_VFP)
31+
# define LIBC_ARM gnueabihf
32+
# else
33+
# define LIBC_ARM gnueabi
34+
# endif
35+
# if defined(__loongarch__)
36+
# if defined(__loongarch_soft_float)
37+
# define LIBC_LA gnusf
38+
# elif defined(__loongarch_single_float)
39+
# define LIBC_LA gnuf32
40+
# elif defined(__loongarch_double_float)
41+
# define LIBC_LA gnu
42+
# else
43+
# error unknown loongarch floating-point base abi
44+
# endif
45+
# endif
46+
# if defined(_MIPS_SIM)
47+
# if defined(__mips_hard_float)
48+
# if _MIPS_SIM == _ABIO32
49+
# define LIBC_MIPS gnu
50+
# elif _MIPS_SIM == _ABIN32
51+
# define LIBC_MIPS gnuabin32
52+
# elif _MIPS_SIM == _ABI64
53+
# define LIBC_MIPS gnuabi64
54+
# else
55+
# error unknown mips sim value
56+
# endif
57+
# else
58+
# if _MIPS_SIM == _ABIO32
59+
# define LIBC_MIPS gnusf
60+
# elif _MIPS_SIM == _ABIN32
61+
# define LIBC_MIPS gnuabin32sf
62+
# elif _MIPS_SIM == _ABI64
63+
# define LIBC_MIPS gnuabi64sf
64+
# else
65+
# error unknown mips sim value
66+
# endif
67+
# endif
68+
# endif
69+
# if defined(__SPE__)
70+
# define LIBC_PPC gnuspe
71+
# else
72+
# define LIBC_PPC gnu
73+
# endif
74+
# else
75+
// Heuristic to detect musl libc
76+
# include <stdarg.h>
77+
# ifdef __DEFINED_va_list
78+
# define LIBC musl
79+
# define LIBC_X32 muslx32
80+
# if defined(__ARM_PCS_VFP)
81+
# define LIBC_ARM musleabihf
82+
# else
83+
# define LIBC_ARM musleabi
84+
# endif
85+
# if defined(__loongarch__)
86+
# if defined(__loongarch_soft_float)
87+
# define LIBC_LA muslsf
88+
# elif defined(__loongarch_single_float)
89+
# define LIBC_LA muslf32
90+
# elif defined(__loongarch_double_float)
91+
# define LIBC_LA musl
92+
# else
93+
# error unknown loongarch floating-point base abi
94+
# endif
95+
# endif
96+
# if defined(_MIPS_SIM)
97+
# if defined(__mips_hard_float)
98+
# if _MIPS_SIM == _ABIO32
99+
# define LIBC_MIPS musl
100+
# elif _MIPS_SIM == _ABIN32
101+
# define LIBC_MIPS musln32
102+
# elif _MIPS_SIM == _ABI64
103+
# define LIBC_MIPS musl
104+
# else
105+
# error unknown mips sim value
106+
# endif
107+
# else
108+
# if _MIPS_SIM == _ABIO32
109+
# define LIBC_MIPS muslsf
110+
# elif _MIPS_SIM == _ABIN32
111+
# define LIBC_MIPS musln32sf
112+
# elif _MIPS_SIM == _ABI64
113+
# define LIBC_MIPS muslsf
114+
# else
115+
# error unknown mips sim value
116+
# endif
117+
# endif
118+
# endif
119+
# if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
120+
# define LIBC_PPC muslsf
121+
# else
122+
# define LIBC_PPC musl
123+
# endif
124+
# else
125+
# error unknown libc
126+
# endif
127+
# endif
128+
129+
# if defined(__x86_64__) && defined(__LP64__)
130+
PLATFORM_TRIPLET=x86_64-linux-LIBC
131+
# elif defined(__x86_64__) && defined(__ILP32__)
132+
PLATFORM_TRIPLET=x86_64-linux-LIBC_X32
133+
# elif defined(__i386__)
134+
PLATFORM_TRIPLET=i386-linux-LIBC
135+
# elif defined(__aarch64__) && defined(__AARCH64EL__)
136+
# if defined(__ILP32__)
137+
PLATFORM_TRIPLET=aarch64_ilp32-linux-LIBC
138+
# else
139+
PLATFORM_TRIPLET=aarch64-linux-LIBC
140+
# endif
141+
# elif defined(__aarch64__) && defined(__AARCH64EB__)
142+
# if defined(__ILP32__)
143+
PLATFORM_TRIPLET=aarch64_be_ilp32-linux-LIBC
144+
# else
145+
PLATFORM_TRIPLET=aarch64_be-linux-LIBC
146+
# endif
147+
# elif defined(__alpha__)
148+
PLATFORM_TRIPLET=alpha-linux-LIBC
149+
# elif defined(__ARM_EABI__)
150+
# if defined(__ARMEL__)
151+
PLATFORM_TRIPLET=arm-linux-LIBC_ARM
152+
# else
153+
PLATFORM_TRIPLET=armeb-linux-LIBC_ARM
154+
# endif
155+
# elif defined(__hppa__)
156+
PLATFORM_TRIPLET=hppa-linux-LIBC
157+
# elif defined(__ia64__)
158+
PLATFORM_TRIPLET=ia64-linux-LIBC
159+
# elif defined(__loongarch__) && defined(__loongarch_lp64)
160+
PLATFORM_TRIPLET=loongarch64-linux-LIBC_LA
161+
# elif defined(__m68k__) && !defined(__mcoldfire__)
162+
PLATFORM_TRIPLET=m68k-linux-LIBC
163+
# elif defined(__mips__)
164+
# if defined(__mips_isa_rev) && (__mips_isa_rev >=6)
165+
# if defined(_MIPSEL) && defined(__mips64)
166+
PLATFORM_TRIPLET=mipsisa64r6el-linux-LIBC_MIPS
167+
# elif defined(_MIPSEL)
168+
PLATFORM_TRIPLET=mipsisa32r6el-linux-LIBC_MIPS
169+
# elif defined(__mips64)
170+
PLATFORM_TRIPLET=mipsisa64r6-linux-LIBC_MIPS
171+
# else
172+
PLATFORM_TRIPLET=mipsisa32r6-linux-LIBC_MIPS
173+
# endif
174+
# else
175+
# if defined(_MIPSEL) && defined(__mips64)
176+
PLATFORM_TRIPLET=mips64el-linux-LIBC_MIPS
177+
# elif defined(_MIPSEL)
178+
PLATFORM_TRIPLET=mipsel-linux-LIBC_MIPS
179+
# elif defined(__mips64)
180+
PLATFORM_TRIPLET=mips64-linux-LIBC_MIPS
181+
# else
182+
PLATFORM_TRIPLET=mips-linux-LIBC_MIPS
183+
# endif
184+
# endif
185+
# elif defined(__or1k__)
186+
PLATFORM_TRIPLET=or1k-linux-LIBC
187+
# elif defined(__powerpc64__)
188+
# if defined(__LITTLE_ENDIAN__)
189+
PLATFORM_TRIPLET=powerpc64le-linux-LIBC
190+
# else
191+
PLATFORM_TRIPLET=powerpc64-linux-LIBC
192+
# endif
193+
# elif defined(__powerpc__)
194+
PLATFORM_TRIPLET=powerpc-linux-LIBC_PPC
195+
# elif defined(__s390x__)
196+
PLATFORM_TRIPLET=s390x-linux-LIBC
197+
# elif defined(__s390__)
198+
PLATFORM_TRIPLET=s390-linux-LIBC
199+
# elif defined(__sh__) && defined(__LITTLE_ENDIAN__)
200+
PLATFORM_TRIPLET=sh4-linux-LIBC
201+
# elif defined(__sparc__) && defined(__arch64__)
202+
PLATFORM_TRIPLET=sparc64-linux-LIBC
203+
# elif defined(__sparc__)
204+
PLATFORM_TRIPLET=sparc-linux-LIBC
205+
# elif defined(__riscv)
206+
# if __riscv_xlen == 32
207+
PLATFORM_TRIPLET=riscv32-linux-LIBC
208+
# elif __riscv_xlen == 64
209+
PLATFORM_TRIPLET=riscv64-linux-LIBC
210+
# else
211+
# error unknown platform triplet
212+
# endif
213+
# else
214+
# error unknown platform triplet
215+
# endif
216+
/*
217+
* END of Linux block
218+
*/
219+
#elif defined(__FreeBSD_kernel__)
220+
# if defined(__LP64__)
221+
PLATFORM_TRIPLET=x86_64-kfreebsd-gnu
222+
# elif defined(__i386__)
223+
PLATFORM_TRIPLET=i386-kfreebsd-gnu
224+
# else
225+
# error unknown platform triplet
226+
# endif
227+
#elif defined(__gnu_hurd__)
228+
PLATFORM_TRIPLET=i386-gnu
229+
#elif defined(__APPLE__)
230+
PLATFORM_TRIPLET=darwin
231+
#elif defined(__VXWORKS__)
232+
PLATFORM_TRIPLET=vxworks
233+
#elif defined(__wasm32__)
234+
# if defined(__EMSCRIPTEN__)
235+
PLATFORM_TRIPLET=wasm32-emscripten
236+
# elif defined(__wasi__)
237+
# if defined(_REENTRANT)
238+
PLATFORM_TRIPLET=wasm32-wasi-threads
239+
# else
240+
PLATFORM_TRIPLET=wasm32-wasi
241+
# endif
242+
# else
243+
# error unknown wasm32 platform
244+
# endif
245+
#elif defined(__wasm64__)
246+
# if defined(__EMSCRIPTEN__)
247+
PLATFORM_TRIPLET=wasm64-emscripten
248+
# elif defined(__wasi__)
249+
PLATFORM_TRIPLET=wasm64-wasi
250+
# else
251+
# error unknown wasm64 platform
252+
# endif
253+
#else
254+
# error unknown platform triplet
255+
#endif

0 commit comments

Comments
 (0)