1 //===--- OSTargets.h - Declare OS target feature support --------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file declares OS specific TargetInfo types.
10 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
13 #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
20 template <typename TgtInfo
>
21 class LLVM_LIBRARY_VISIBILITY OSTargetInfo
: public TgtInfo
{
23 virtual void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
24 MacroBuilder
&Builder
) const = 0;
27 OSTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
28 : TgtInfo(Triple
, Opts
) {}
30 void getTargetDefines(const LangOptions
&Opts
,
31 MacroBuilder
&Builder
) const override
{
32 TgtInfo::getTargetDefines(Opts
, Builder
);
33 getOSDefines(Opts
, TgtInfo::getTriple(), Builder
);
38 template <typename Target
>
39 class LLVM_LIBRARY_VISIBILITY CloudABITargetInfo
: public OSTargetInfo
<Target
> {
41 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
42 MacroBuilder
&Builder
) const override
{
43 Builder
.defineMacro("__CloudABI__");
44 Builder
.defineMacro("__ELF__");
46 // CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
47 Builder
.defineMacro("__STDC_ISO_10646__", "201206L");
48 Builder
.defineMacro("__STDC_UTF_16__");
49 Builder
.defineMacro("__STDC_UTF_32__");
53 CloudABITargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
54 : OSTargetInfo
<Target
>(Triple
, Opts
) {}
58 template <typename Target
>
59 class LLVM_LIBRARY_VISIBILITY AnanasTargetInfo
: public OSTargetInfo
<Target
> {
61 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
62 MacroBuilder
&Builder
) const override
{
64 Builder
.defineMacro("__Ananas__");
65 Builder
.defineMacro("__ELF__");
69 AnanasTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
70 : OSTargetInfo
<Target
>(Triple
, Opts
) {}
73 void getDarwinDefines(MacroBuilder
&Builder
, const LangOptions
&Opts
,
74 const llvm::Triple
&Triple
, StringRef
&PlatformName
,
75 VersionTuple
&PlatformMinVersion
);
77 template <typename Target
>
78 class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo
: public OSTargetInfo
<Target
> {
80 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
81 MacroBuilder
&Builder
) const override
{
82 getDarwinDefines(Builder
, Opts
, Triple
, this->PlatformName
,
83 this->PlatformMinVersion
);
87 DarwinTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
88 : OSTargetInfo
<Target
>(Triple
, Opts
) {
89 // By default, no TLS, and we list permitted architecture/OS
91 this->TLSSupported
= false;
93 if (Triple
.isMacOSX())
94 this->TLSSupported
= !Triple
.isMacOSXVersionLT(10, 7);
95 else if (Triple
.isiOS()) {
96 // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
97 // 32-bit simulator from 10 onwards.
98 if (Triple
.isArch64Bit())
99 this->TLSSupported
= !Triple
.isOSVersionLT(8);
100 else if (Triple
.isArch32Bit()) {
101 if (!Triple
.isSimulatorEnvironment())
102 this->TLSSupported
= !Triple
.isOSVersionLT(9);
104 this->TLSSupported
= !Triple
.isOSVersionLT(10);
106 } else if (Triple
.isWatchOS()) {
107 if (!Triple
.isSimulatorEnvironment())
108 this->TLSSupported
= !Triple
.isOSVersionLT(2);
110 this->TLSSupported
= !Triple
.isOSVersionLT(3);
111 } else if (Triple
.isDriverKit()) {
112 // No TLS on DriverKit.
115 this->MCountName
= "\01mcount";
118 const char *getStaticInitSectionSpecifier() const override
{
119 // FIXME: We should return 0 when building kexts.
120 return "__TEXT,__StaticInit,regular,pure_instructions";
123 /// Darwin does not support protected visibility. Darwin's "default"
124 /// is very similar to ELF's "protected"; Darwin requires a "weak"
125 /// attribute on declarations that can be dynamically replaced.
126 bool hasProtectedVisibility() const override
{ return false; }
128 unsigned getExnObjectAlignment() const override
{
129 // Older versions of libc++abi guarantee an alignment of only 8-bytes for
130 // exception objects because of a bug in __cxa_exception that was
131 // eventually fixed in r319123.
132 llvm::VersionTuple MinVersion
;
133 const llvm::Triple
&T
= this->getTriple();
135 // Compute the earliest OS versions that have the fix to libc++abi.
137 case llvm::Triple::Darwin
:
138 case llvm::Triple::MacOSX
: // Earliest supporting version is 10.14.
139 MinVersion
= llvm::VersionTuple(10U, 14U);
141 case llvm::Triple::IOS
:
142 case llvm::Triple::TvOS
: // Earliest supporting version is 12.0.0.
143 MinVersion
= llvm::VersionTuple(12U);
145 case llvm::Triple::WatchOS
: // Earliest supporting version is 5.0.0.
146 MinVersion
= llvm::VersionTuple(5U);
149 // Conservatively return 8 bytes if OS is unknown.
153 if (T
.getOSVersion() < MinVersion
)
155 return OSTargetInfo
<Target
>::getExnObjectAlignment();
158 TargetInfo::IntType
getLeastIntTypeByWidth(unsigned BitWidth
,
159 bool IsSigned
) const final
{
160 // Darwin uses `long long` for `int_least64_t` and `int_fast64_t`.
161 return BitWidth
== 64
162 ? (IsSigned
? TargetInfo::SignedLongLong
163 : TargetInfo::UnsignedLongLong
)
164 : TargetInfo::getLeastIntTypeByWidth(BitWidth
, IsSigned
);
168 // DragonFlyBSD Target
169 template <typename Target
>
170 class LLVM_LIBRARY_VISIBILITY DragonFlyBSDTargetInfo
171 : public OSTargetInfo
<Target
> {
173 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
174 MacroBuilder
&Builder
) const override
{
175 // DragonFly defines; list based off of gcc output
176 Builder
.defineMacro("__DragonFly__");
177 Builder
.defineMacro("__DragonFly_cc_version", "100001");
178 Builder
.defineMacro("__ELF__");
179 Builder
.defineMacro("__KPRINTF_ATTRIBUTE__");
180 Builder
.defineMacro("__tune_i386__");
181 DefineStd(Builder
, "unix", Opts
);
182 if (this->HasFloat128
)
183 Builder
.defineMacro("__FLOAT128__");
187 DragonFlyBSDTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
188 : OSTargetInfo
<Target
>(Triple
, Opts
) {
189 switch (Triple
.getArch()) {
191 case llvm::Triple::x86
:
192 case llvm::Triple::x86_64
:
193 this->HasFloat128
= true;
194 this->MCountName
= ".mcount";
200 #ifndef FREEBSD_CC_VERSION
201 #define FREEBSD_CC_VERSION 0U
205 template <typename Target
>
206 class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo
: public OSTargetInfo
<Target
> {
208 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
209 MacroBuilder
&Builder
) const override
{
210 // FreeBSD defines; list based off of gcc output
212 unsigned Release
= Triple
.getOSMajorVersion();
215 unsigned CCVersion
= FREEBSD_CC_VERSION
;
217 CCVersion
= Release
* 100000U + 1U;
219 Builder
.defineMacro("__FreeBSD__", Twine(Release
));
220 Builder
.defineMacro("__FreeBSD_cc_version", Twine(CCVersion
));
221 Builder
.defineMacro("__KPRINTF_ATTRIBUTE__");
222 DefineStd(Builder
, "unix", Opts
);
223 Builder
.defineMacro("__ELF__");
225 // On FreeBSD, wchar_t contains the number of the code point as
226 // used by the character set of the locale. These character sets are
227 // not necessarily a superset of ASCII.
229 // FIXME: This is wrong; the macro refers to the numerical values
230 // of wchar_t *literals*, which are not locale-dependent. However,
231 // FreeBSD systems apparently depend on us getting this wrong, and
232 // setting this to 1 is conforming even if all the basic source
233 // character literals have the same encoding as char and wchar_t.
234 Builder
.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
238 FreeBSDTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
239 : OSTargetInfo
<Target
>(Triple
, Opts
) {
240 switch (Triple
.getArch()) {
242 case llvm::Triple::x86
:
243 case llvm::Triple::x86_64
:
244 this->MCountName
= ".mcount";
246 case llvm::Triple::mips
:
247 case llvm::Triple::mipsel
:
248 case llvm::Triple::ppc
:
249 case llvm::Triple::ppcle
:
250 case llvm::Triple::ppc64
:
251 case llvm::Triple::ppc64le
:
252 this->MCountName
= "_mcount";
254 case llvm::Triple::arm
:
255 this->MCountName
= "__mcount";
257 case llvm::Triple::riscv32
:
258 case llvm::Triple::riscv64
:
264 // GNU/kFreeBSD Target
265 template <typename Target
>
266 class LLVM_LIBRARY_VISIBILITY KFreeBSDTargetInfo
: public OSTargetInfo
<Target
> {
268 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
269 MacroBuilder
&Builder
) const override
{
270 // GNU/kFreeBSD defines; list based off of gcc output
272 DefineStd(Builder
, "unix", Opts
);
273 Builder
.defineMacro("__FreeBSD_kernel__");
274 Builder
.defineMacro("__GLIBC__");
275 Builder
.defineMacro("__ELF__");
276 if (Opts
.POSIXThreads
)
277 Builder
.defineMacro("_REENTRANT");
279 Builder
.defineMacro("_GNU_SOURCE");
283 KFreeBSDTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
284 : OSTargetInfo
<Target
>(Triple
, Opts
) {}
288 template <typename Target
>
289 class LLVM_LIBRARY_VISIBILITY HaikuTargetInfo
: public OSTargetInfo
<Target
> {
291 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
292 MacroBuilder
&Builder
) const override
{
293 // Haiku defines; list based off of gcc output
294 Builder
.defineMacro("__HAIKU__");
295 Builder
.defineMacro("__ELF__");
296 DefineStd(Builder
, "unix", Opts
);
297 if (this->HasFloat128
)
298 Builder
.defineMacro("__FLOAT128__");
302 HaikuTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
303 : OSTargetInfo
<Target
>(Triple
, Opts
) {
304 this->SizeType
= TargetInfo::UnsignedLong
;
305 this->IntPtrType
= TargetInfo::SignedLong
;
306 this->PtrDiffType
= TargetInfo::SignedLong
;
307 this->ProcessIDType
= TargetInfo::SignedLong
;
308 this->TLSSupported
= false;
309 switch (Triple
.getArch()) {
312 case llvm::Triple::x86
:
313 case llvm::Triple::x86_64
:
314 this->HasFloat128
= true;
321 template <typename Target
>
322 class LLVM_LIBRARY_VISIBILITY HurdTargetInfo
: public OSTargetInfo
<Target
> {
324 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
325 MacroBuilder
&Builder
) const override
{
326 // Hurd defines; list based off of gcc output.
327 DefineStd(Builder
, "unix", Opts
);
328 Builder
.defineMacro("__GNU__");
329 Builder
.defineMacro("__gnu_hurd__");
330 Builder
.defineMacro("__MACH__");
331 Builder
.defineMacro("__GLIBC__");
332 Builder
.defineMacro("__ELF__");
333 if (Opts
.POSIXThreads
)
334 Builder
.defineMacro("_REENTRANT");
336 Builder
.defineMacro("_GNU_SOURCE");
339 HurdTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
340 : OSTargetInfo
<Target
>(Triple
, Opts
) {}
344 template <typename Target
>
345 class LLVM_LIBRARY_VISIBILITY MinixTargetInfo
: public OSTargetInfo
<Target
> {
347 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
348 MacroBuilder
&Builder
) const override
{
351 Builder
.defineMacro("__minix", "3");
352 Builder
.defineMacro("_EM_WSIZE", "4");
353 Builder
.defineMacro("_EM_PSIZE", "4");
354 Builder
.defineMacro("_EM_SSIZE", "2");
355 Builder
.defineMacro("_EM_LSIZE", "4");
356 Builder
.defineMacro("_EM_FSIZE", "4");
357 Builder
.defineMacro("_EM_DSIZE", "8");
358 Builder
.defineMacro("__ELF__");
359 DefineStd(Builder
, "unix", Opts
);
363 MinixTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
364 : OSTargetInfo
<Target
>(Triple
, Opts
) {}
368 template <typename Target
>
369 class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo
: public OSTargetInfo
<Target
> {
371 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
372 MacroBuilder
&Builder
) const override
{
373 // Linux defines; list based off of gcc output
374 DefineStd(Builder
, "unix", Opts
);
375 DefineStd(Builder
, "linux", Opts
);
376 Builder
.defineMacro("__ELF__");
377 if (Triple
.isAndroid()) {
378 Builder
.defineMacro("__ANDROID__", "1");
379 this->PlatformName
= "android";
380 this->PlatformMinVersion
= Triple
.getEnvironmentVersion();
381 const unsigned Maj
= this->PlatformMinVersion
.getMajor();
383 Builder
.defineMacro("__ANDROID_MIN_SDK_VERSION__", Twine(Maj
));
384 // This historical but ambiguous name for the minSdkVersion macro. Keep
385 // defined for compatibility.
386 Builder
.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
389 Builder
.defineMacro("__gnu_linux__");
391 // Work around Issue #47994 until glibc PR build/27558 is fixed.
392 if (Triple
.isSPARC())
393 Builder
.defineMacro("__NO_INLINE__");
394 if (Opts
.POSIXThreads
)
395 Builder
.defineMacro("_REENTRANT");
397 Builder
.defineMacro("_GNU_SOURCE");
398 if (this->HasFloat128
)
399 Builder
.defineMacro("__FLOAT128__");
403 LinuxTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
404 : OSTargetInfo
<Target
>(Triple
, Opts
) {
405 this->WIntType
= TargetInfo::UnsignedInt
;
407 switch (Triple
.getArch()) {
410 case llvm::Triple::mips
:
411 case llvm::Triple::mipsel
:
412 case llvm::Triple::mips64
:
413 case llvm::Triple::mips64el
:
414 case llvm::Triple::ppc
:
415 case llvm::Triple::ppcle
:
416 case llvm::Triple::ppc64
:
417 case llvm::Triple::ppc64le
:
418 this->MCountName
= "_mcount";
420 case llvm::Triple::x86
:
421 case llvm::Triple::x86_64
:
422 this->HasFloat128
= true;
427 const char *getStaticInitSectionSpecifier() const override
{
428 return ".text.startup";
433 template <typename Target
>
434 class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo
: public OSTargetInfo
<Target
> {
436 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
437 MacroBuilder
&Builder
) const override
{
438 // NetBSD defines; list based off of gcc output
439 Builder
.defineMacro("__NetBSD__");
440 Builder
.defineMacro("__unix__");
441 Builder
.defineMacro("__ELF__");
442 if (Opts
.POSIXThreads
)
443 Builder
.defineMacro("_REENTRANT");
447 NetBSDTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
448 : OSTargetInfo
<Target
>(Triple
, Opts
) {
449 this->MCountName
= "__mcount";
454 template <typename Target
>
455 class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo
: public OSTargetInfo
<Target
> {
457 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
458 MacroBuilder
&Builder
) const override
{
459 // OpenBSD defines; list based off of gcc output
461 Builder
.defineMacro("__OpenBSD__");
462 DefineStd(Builder
, "unix", Opts
);
463 Builder
.defineMacro("__ELF__");
464 if (Opts
.POSIXThreads
)
465 Builder
.defineMacro("_REENTRANT");
466 if (this->HasFloat128
)
467 Builder
.defineMacro("__FLOAT128__");
470 Builder
.defineMacro("__STDC_NO_THREADS__");
474 OpenBSDTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
475 : OSTargetInfo
<Target
>(Triple
, Opts
) {
476 this->WCharType
= this->WIntType
= this->SignedInt
;
477 this->IntMaxType
= TargetInfo::SignedLongLong
;
478 this->Int64Type
= TargetInfo::SignedLongLong
;
479 switch (Triple
.getArch()) {
480 case llvm::Triple::x86
:
481 case llvm::Triple::x86_64
:
482 this->HasFloat128
= true;
485 this->MCountName
= "__mcount";
487 case llvm::Triple::mips64
:
488 case llvm::Triple::mips64el
:
489 case llvm::Triple::ppc
:
490 case llvm::Triple::ppc64
:
491 case llvm::Triple::ppc64le
:
492 case llvm::Triple::sparcv9
:
493 this->MCountName
= "_mcount";
495 case llvm::Triple::riscv32
:
496 case llvm::Triple::riscv64
:
503 template <typename Target
>
504 class LLVM_LIBRARY_VISIBILITY PSPTargetInfo
: public OSTargetInfo
<Target
> {
506 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
507 MacroBuilder
&Builder
) const override
{
508 // PSP defines; list based on the output of the pspdev gcc toolchain.
509 Builder
.defineMacro("PSP");
510 Builder
.defineMacro("_PSP");
511 Builder
.defineMacro("__psp__");
512 Builder
.defineMacro("__ELF__");
516 PSPTargetInfo(const llvm::Triple
&Triple
) : OSTargetInfo
<Target
>(Triple
) {}
520 template <typename Target
>
521 class LLVM_LIBRARY_VISIBILITY PS3PPUTargetInfo
: public OSTargetInfo
<Target
> {
523 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
524 MacroBuilder
&Builder
) const override
{
526 Builder
.defineMacro("__PPC__");
527 Builder
.defineMacro("__PPU__");
528 Builder
.defineMacro("__CELLOS_LV2__");
529 Builder
.defineMacro("__ELF__");
530 Builder
.defineMacro("__LP32__");
531 Builder
.defineMacro("_ARCH_PPC64");
532 Builder
.defineMacro("__powerpc64__");
536 PS3PPUTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
537 : OSTargetInfo
<Target
>(Triple
, Opts
) {
538 this->LongWidth
= this->LongAlign
= 32;
539 this->PointerWidth
= this->PointerAlign
= 32;
540 this->IntMaxType
= TargetInfo::SignedLongLong
;
541 this->Int64Type
= TargetInfo::SignedLongLong
;
542 this->SizeType
= TargetInfo::UnsignedInt
;
543 this->resetDataLayout("E-m:e-p:32:32-i64:64-n32:64");
547 // Common base class for PS4/PS5 targets.
548 template <typename Target
>
549 class LLVM_LIBRARY_VISIBILITY PSOSTargetInfo
: public OSTargetInfo
<Target
> {
551 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
552 MacroBuilder
&Builder
) const override
{
553 Builder
.defineMacro("__FreeBSD__", "9");
554 Builder
.defineMacro("__FreeBSD_cc_version", "900001");
555 Builder
.defineMacro("__KPRINTF_ATTRIBUTE__");
556 DefineStd(Builder
, "unix", Opts
);
557 Builder
.defineMacro("__ELF__");
558 Builder
.defineMacro("__SCE__");
562 PSOSTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
563 : OSTargetInfo
<Target
>(Triple
, Opts
) {
564 this->WCharType
= TargetInfo::UnsignedShort
;
566 // On PS4/PS5, TLS variable cannot be aligned to more than 32 bytes (256
568 this->MaxTLSAlign
= 256;
570 // On PS4/PS5, do not honor explicit bit field alignment,
571 // as in "__attribute__((aligned(2))) int b : 1;".
572 this->UseExplicitBitFieldAlignment
= false;
574 this->MCountName
= ".mcount";
575 this->NewAlign
= 256;
576 this->SuitableAlign
= 256;
579 TargetInfo::CallingConvCheckResult
580 checkCallingConvention(CallingConv CC
) const override
{
581 return (CC
== CC_C
) ? TargetInfo::CCCR_OK
: TargetInfo::CCCR_Error
;
586 template <typename Target
>
587 class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo
: public PSOSTargetInfo
<Target
> {
589 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
590 MacroBuilder
&Builder
) const override
{
591 // Start with base class defines.
592 PSOSTargetInfo
<Target
>::getOSDefines(Opts
, Triple
, Builder
);
594 Builder
.defineMacro("__ORBIS__");
598 PS4OSTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
599 : PSOSTargetInfo
<Target
>(Triple
, Opts
) {}
603 template <typename Target
>
604 class LLVM_LIBRARY_VISIBILITY PS5OSTargetInfo
: public PSOSTargetInfo
<Target
> {
606 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
607 MacroBuilder
&Builder
) const override
{
608 // Start with base class defines.
609 PSOSTargetInfo
<Target
>::getOSDefines(Opts
, Triple
, Builder
);
611 Builder
.defineMacro("__PROSPERO__");
615 PS5OSTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
616 : PSOSTargetInfo
<Target
>(Triple
, Opts
) {}
620 template <typename Target
>
621 class LLVM_LIBRARY_VISIBILITY RTEMSTargetInfo
: public OSTargetInfo
<Target
> {
623 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
624 MacroBuilder
&Builder
) const override
{
625 // RTEMS defines; list based off of gcc output
627 Builder
.defineMacro("__rtems__");
628 Builder
.defineMacro("__ELF__");
630 Builder
.defineMacro("_GNU_SOURCE");
634 RTEMSTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
635 : OSTargetInfo
<Target
>(Triple
, Opts
) {
636 switch (Triple
.getArch()) {
638 case llvm::Triple::x86
:
639 // this->MCountName = ".mcount";
641 case llvm::Triple::mips
:
642 case llvm::Triple::mipsel
:
643 case llvm::Triple::ppc
:
644 case llvm::Triple::ppc64
:
645 case llvm::Triple::ppc64le
:
646 // this->MCountName = "_mcount";
648 case llvm::Triple::arm
:
649 // this->MCountName = "__mcount";
656 template <typename Target
>
657 class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo
: public OSTargetInfo
<Target
> {
659 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
660 MacroBuilder
&Builder
) const override
{
661 DefineStd(Builder
, "sun", Opts
);
662 DefineStd(Builder
, "unix", Opts
);
663 Builder
.defineMacro("__ELF__");
664 Builder
.defineMacro("__svr4__");
665 Builder
.defineMacro("__SVR4");
666 // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
667 // newer, but to 500 for everything else. feature_test.h has a check to
668 // ensure that you are not using C99 with an old version of X/Open or C89
669 // with a new version.
671 Builder
.defineMacro("_XOPEN_SOURCE", "600");
673 Builder
.defineMacro("_XOPEN_SOURCE", "500");
674 if (Opts
.CPlusPlus
) {
675 Builder
.defineMacro("__C99FEATURES__");
676 Builder
.defineMacro("_FILE_OFFSET_BITS", "64");
678 // GCC restricts the next two to C++.
679 Builder
.defineMacro("_LARGEFILE_SOURCE");
680 Builder
.defineMacro("_LARGEFILE64_SOURCE");
681 Builder
.defineMacro("__EXTENSIONS__");
682 if (Opts
.POSIXThreads
)
683 Builder
.defineMacro("_REENTRANT");
684 if (this->HasFloat128
)
685 Builder
.defineMacro("__FLOAT128__");
689 SolarisTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
690 : OSTargetInfo
<Target
>(Triple
, Opts
) {
691 if (this->PointerWidth
== 64) {
692 this->WCharType
= this->WIntType
= this->SignedInt
;
694 this->WCharType
= this->WIntType
= this->SignedLong
;
696 switch (Triple
.getArch()) {
699 case llvm::Triple::x86
:
700 case llvm::Triple::x86_64
:
701 this->HasFloat128
= true;
708 template <typename Target
>
709 class AIXTargetInfo
: public OSTargetInfo
<Target
> {
711 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
712 MacroBuilder
&Builder
) const override
{
713 DefineStd(Builder
, "unix", Opts
);
714 Builder
.defineMacro("_IBMR2");
715 Builder
.defineMacro("_POWER");
716 Builder
.defineMacro("__THW_BIG_ENDIAN__");
718 Builder
.defineMacro("_AIX");
719 Builder
.defineMacro("__TOS_AIX__");
720 Builder
.defineMacro("__HOS_AIX__");
723 Builder
.defineMacro("__STDC_NO_ATOMICS__");
724 Builder
.defineMacro("__STDC_NO_THREADS__");
727 if (Opts
.EnableAIXExtendedAltivecABI
)
728 Builder
.defineMacro("__EXTABI__");
730 VersionTuple OsVersion
= Triple
.getOSVersion();
732 // Define AIX OS-Version Macros.
733 // Includes logic for legacy versions of AIX; no specific intent to support.
734 if (OsVersion
>= VersionTuple(3, 2))
735 Builder
.defineMacro("_AIX32");
736 if (OsVersion
>= VersionTuple(4, 1))
737 Builder
.defineMacro("_AIX41");
738 if (OsVersion
>= VersionTuple(4, 3))
739 Builder
.defineMacro("_AIX43");
740 if (OsVersion
>= VersionTuple(5, 0))
741 Builder
.defineMacro("_AIX50");
742 if (OsVersion
>= VersionTuple(5, 1))
743 Builder
.defineMacro("_AIX51");
744 if (OsVersion
>= VersionTuple(5, 2))
745 Builder
.defineMacro("_AIX52");
746 if (OsVersion
>= VersionTuple(5, 3))
747 Builder
.defineMacro("_AIX53");
748 if (OsVersion
>= VersionTuple(6, 1))
749 Builder
.defineMacro("_AIX61");
750 if (OsVersion
>= VersionTuple(7, 1))
751 Builder
.defineMacro("_AIX71");
752 if (OsVersion
>= VersionTuple(7, 2))
753 Builder
.defineMacro("_AIX72");
754 if (OsVersion
>= VersionTuple(7, 3))
755 Builder
.defineMacro("_AIX73");
757 // FIXME: Do not define _LONG_LONG when -fno-long-long is specified.
758 Builder
.defineMacro("_LONG_LONG");
760 if (Opts
.POSIXThreads
) {
761 Builder
.defineMacro("_THREAD_SAFE");
764 if (this->PointerWidth
== 64) {
765 Builder
.defineMacro("__64BIT__");
768 // Define _WCHAR_T when it is a fundamental type
769 // (i.e., for C++ without -fno-wchar).
770 if (Opts
.CPlusPlus
&& Opts
.WChar
) {
771 Builder
.defineMacro("_WCHAR_T");
776 AIXTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
777 : OSTargetInfo
<Target
>(Triple
, Opts
) {
778 this->TheCXXABI
.set(TargetCXXABI::XL
);
780 if (this->PointerWidth
== 64) {
781 this->WCharType
= this->UnsignedInt
;
783 this->WCharType
= this->UnsignedShort
;
785 this->UseZeroLengthBitfieldAlignment
= true;
788 // AIX sets FLT_EVAL_METHOD to be 1.
789 LangOptions::FPEvalMethodKind
getFPEvalMethod() const override
{
790 return LangOptions::FPEvalMethodKind::FEM_Double
;
793 bool defaultsToAIXPowerAlignment() const override
{ return true; }
797 template <typename Target
>
798 class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo
: public OSTargetInfo
<Target
> {
800 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
801 MacroBuilder
&Builder
) const override
{
802 // FIXME: _LONG_LONG should not be defined under -std=c89.
803 Builder
.defineMacro("_LONG_LONG");
804 Builder
.defineMacro("_OPEN_DEFAULT");
805 // _UNIX03_WITHDRAWN is required to build libcxx.
806 Builder
.defineMacro("_UNIX03_WITHDRAWN");
807 Builder
.defineMacro("__370__");
808 Builder
.defineMacro("__BFP__");
809 // FIXME: __BOOL__ should not be defined under -std=c89.
810 Builder
.defineMacro("__BOOL__");
811 Builder
.defineMacro("__LONGNAME__");
812 Builder
.defineMacro("__MVS__");
813 Builder
.defineMacro("__THW_370__");
814 Builder
.defineMacro("__THW_BIG_ENDIAN__");
815 Builder
.defineMacro("__TOS_390__");
816 Builder
.defineMacro("__TOS_MVS__");
817 Builder
.defineMacro("__XPLINK__");
819 if (this->PointerWidth
== 64)
820 Builder
.defineMacro("__64BIT__");
822 if (Opts
.CPlusPlus
) {
823 Builder
.defineMacro("__DLL__");
824 // _XOPEN_SOURCE=600 is required to build libcxx.
825 Builder
.defineMacro("_XOPEN_SOURCE", "600");
829 Builder
.defineMacro("_MI_BUILTIN");
830 Builder
.defineMacro("_EXT");
833 if (Opts
.CPlusPlus
&& Opts
.WChar
) {
834 // Macro __wchar_t is defined so that the wchar_t data
835 // type is not declared as a typedef in system headers.
836 Builder
.defineMacro("__wchar_t");
839 this->PlatformName
= llvm::Triple::getOSTypeName(Triple
.getOS());
843 ZOSTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
844 : OSTargetInfo
<Target
>(Triple
, Opts
) {
845 this->WCharType
= TargetInfo::UnsignedInt
;
846 this->MaxAlignedAttribute
= 128;
847 this->UseBitFieldTypeAlignment
= false;
848 this->UseZeroLengthBitfieldAlignment
= true;
849 this->UseLeadingZeroLengthBitfield
= false;
850 this->ZeroLengthBitfieldBoundary
= 32;
854 void addWindowsDefines(const llvm::Triple
&Triple
, const LangOptions
&Opts
,
855 MacroBuilder
&Builder
);
858 template <typename Target
>
859 class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo
: public OSTargetInfo
<Target
> {
861 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
862 MacroBuilder
&Builder
) const override
{
863 addWindowsDefines(Triple
, Opts
, Builder
);
867 WindowsTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
868 : OSTargetInfo
<Target
>(Triple
, Opts
) {
869 this->WCharType
= TargetInfo::UnsignedShort
;
870 this->WIntType
= TargetInfo::UnsignedShort
;
874 template <typename Target
>
875 class LLVM_LIBRARY_VISIBILITY NaClTargetInfo
: public OSTargetInfo
<Target
> {
877 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
878 MacroBuilder
&Builder
) const override
{
879 if (Opts
.POSIXThreads
)
880 Builder
.defineMacro("_REENTRANT");
882 Builder
.defineMacro("_GNU_SOURCE");
884 DefineStd(Builder
, "unix", Opts
);
885 Builder
.defineMacro("__ELF__");
886 Builder
.defineMacro("__native_client__");
890 NaClTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
891 : OSTargetInfo
<Target
>(Triple
, Opts
) {
892 this->LongAlign
= 32;
893 this->LongWidth
= 32;
894 this->PointerAlign
= 32;
895 this->PointerWidth
= 32;
896 this->IntMaxType
= TargetInfo::SignedLongLong
;
897 this->Int64Type
= TargetInfo::SignedLongLong
;
898 this->DoubleAlign
= 64;
899 this->LongDoubleWidth
= 64;
900 this->LongDoubleAlign
= 64;
901 this->LongLongWidth
= 64;
902 this->LongLongAlign
= 64;
903 this->SizeType
= TargetInfo::UnsignedInt
;
904 this->PtrDiffType
= TargetInfo::SignedInt
;
905 this->IntPtrType
= TargetInfo::SignedInt
;
906 // RegParmMax is inherited from the underlying architecture.
907 this->LongDoubleFormat
= &llvm::APFloat::IEEEdouble();
908 if (Triple
.getArch() == llvm::Triple::arm
) {
909 // Handled in ARM's setABI().
910 } else if (Triple
.getArch() == llvm::Triple::x86
) {
911 this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
912 "i64:64-n8:16:32-S128");
913 } else if (Triple
.getArch() == llvm::Triple::x86_64
) {
914 this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
915 "i64:64-n8:16:32:64-S128");
916 } else if (Triple
.getArch() == llvm::Triple::mipsel
) {
917 // Handled on mips' setDataLayout.
919 assert(Triple
.getArch() == llvm::Triple::le32
);
920 this->resetDataLayout("e-p:32:32-i64:64");
926 template <typename Target
>
927 class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo
: public OSTargetInfo
<Target
> {
929 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
930 MacroBuilder
&Builder
) const override
{
931 Builder
.defineMacro("__Fuchsia__");
932 Builder
.defineMacro("__ELF__");
933 if (Opts
.POSIXThreads
)
934 Builder
.defineMacro("_REENTRANT");
935 // Required by the libc++ locale support.
937 Builder
.defineMacro("_GNU_SOURCE");
938 Builder
.defineMacro("__Fuchsia_API_level__", Twine(Opts
.FuchsiaAPILevel
));
939 this->PlatformName
= "fuchsia";
940 this->PlatformMinVersion
= VersionTuple(Opts
.FuchsiaAPILevel
);
944 FuchsiaTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
945 : OSTargetInfo
<Target
>(Triple
, Opts
) {
946 this->MCountName
= "__mcount";
947 this->TheCXXABI
.set(TargetCXXABI::Fuchsia
);
951 // WebAssembly target
952 template <typename Target
>
953 class LLVM_LIBRARY_VISIBILITY WebAssemblyOSTargetInfo
954 : public OSTargetInfo
<Target
> {
956 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
957 MacroBuilder
&Builder
) const override
{
958 // A common platform macro.
959 if (Opts
.POSIXThreads
)
960 Builder
.defineMacro("_REENTRANT");
961 // Follow g++ convention and predefine _GNU_SOURCE for C++.
963 Builder
.defineMacro("_GNU_SOURCE");
964 // Indicate that we have __float128.
965 Builder
.defineMacro("__FLOAT128__");
969 explicit WebAssemblyOSTargetInfo(const llvm::Triple
&Triple
,
970 const TargetOptions
&Opts
)
971 : OSTargetInfo
<Target
>(Triple
, Opts
) {
972 this->MCountName
= "__mcount";
973 this->TheCXXABI
.set(TargetCXXABI::WebAssembly
);
974 this->HasFloat128
= true;
979 template <typename Target
>
980 class LLVM_LIBRARY_VISIBILITY WASITargetInfo
981 : public WebAssemblyOSTargetInfo
<Target
> {
982 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
983 MacroBuilder
&Builder
) const final
{
984 WebAssemblyOSTargetInfo
<Target
>::getOSDefines(Opts
, Triple
, Builder
);
985 Builder
.defineMacro("__wasi__");
989 explicit WASITargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
990 : WebAssemblyOSTargetInfo
<Target
>(Triple
, Opts
) {}
994 template <typename Target
>
995 class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
996 : public WebAssemblyOSTargetInfo
<Target
> {
997 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
998 MacroBuilder
&Builder
) const final
{
999 WebAssemblyOSTargetInfo
<Target
>::getOSDefines(Opts
, Triple
, Builder
);
1000 DefineStd(Builder
, "unix", Opts
);
1001 Builder
.defineMacro("__EMSCRIPTEN__");
1002 if (Opts
.POSIXThreads
)
1003 Builder
.defineMacro("__EMSCRIPTEN_PTHREADS__");
1007 explicit EmscriptenTargetInfo(const llvm::Triple
&Triple
,
1008 const TargetOptions
&Opts
)
1009 : WebAssemblyOSTargetInfo
<Target
>(Triple
, Opts
) {
1010 // Keeping the alignment of long double to 8 bytes even though its size is
1011 // 16 bytes allows emscripten to have an 8-byte-aligned max_align_t which
1012 // in turn gives is a 8-byte aligned malloc.
1013 // Emscripten's ABI is unstable and we may change this back to 128 to match
1014 // the WebAssembly default in the future.
1015 this->LongDoubleAlign
= 64;
1019 } // namespace targets
1020 } // namespace clang
1021 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H