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 using OSTargetInfo
<Target
>::OSTargetInfo
;
57 template <typename Target
>
58 class LLVM_LIBRARY_VISIBILITY AnanasTargetInfo
: public OSTargetInfo
<Target
> {
60 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
61 MacroBuilder
&Builder
) const override
{
63 Builder
.defineMacro("__Ananas__");
64 Builder
.defineMacro("__ELF__");
68 using OSTargetInfo
<Target
>::OSTargetInfo
;
71 void getDarwinDefines(MacroBuilder
&Builder
, const LangOptions
&Opts
,
72 const llvm::Triple
&Triple
, StringRef
&PlatformName
,
73 VersionTuple
&PlatformMinVersion
);
75 template <typename Target
>
76 class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo
: public OSTargetInfo
<Target
> {
78 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
79 MacroBuilder
&Builder
) const override
{
80 getDarwinDefines(Builder
, Opts
, Triple
, this->PlatformName
,
81 this->PlatformMinVersion
);
85 DarwinTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
86 : OSTargetInfo
<Target
>(Triple
, Opts
) {
87 // By default, no TLS, and we list permitted architecture/OS
89 this->TLSSupported
= false;
91 if (Triple
.isMacOSX())
92 this->TLSSupported
= !Triple
.isMacOSXVersionLT(10, 7);
93 else if (Triple
.isiOS()) {
94 // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
95 // 32-bit simulator from 10 onwards.
96 if (Triple
.isArch64Bit())
97 this->TLSSupported
= !Triple
.isOSVersionLT(8);
98 else if (Triple
.isArch32Bit()) {
99 if (!Triple
.isSimulatorEnvironment())
100 this->TLSSupported
= !Triple
.isOSVersionLT(9);
102 this->TLSSupported
= !Triple
.isOSVersionLT(10);
104 } else if (Triple
.isWatchOS()) {
105 if (!Triple
.isSimulatorEnvironment())
106 this->TLSSupported
= !Triple
.isOSVersionLT(2);
108 this->TLSSupported
= !Triple
.isOSVersionLT(3);
109 } else if (Triple
.isDriverKit()) {
110 // No TLS on DriverKit.
113 this->MCountName
= "\01mcount";
116 const char *getStaticInitSectionSpecifier() const override
{
117 // FIXME: We should return 0 when building kexts.
118 return "__TEXT,__StaticInit,regular,pure_instructions";
121 /// Darwin does not support protected visibility. Darwin's "default"
122 /// is very similar to ELF's "protected"; Darwin requires a "weak"
123 /// attribute on declarations that can be dynamically replaced.
124 bool hasProtectedVisibility() const override
{ return false; }
126 unsigned getExnObjectAlignment() const override
{
127 // Older versions of libc++abi guarantee an alignment of only 8-bytes for
128 // exception objects because of a bug in __cxa_exception that was
129 // eventually fixed in r319123.
130 llvm::VersionTuple MinVersion
;
131 const llvm::Triple
&T
= this->getTriple();
133 // Compute the earliest OS versions that have the fix to libc++abi.
135 case llvm::Triple::Darwin
:
136 case llvm::Triple::MacOSX
: // Earliest supporting version is 10.14.
137 MinVersion
= llvm::VersionTuple(10U, 14U);
139 case llvm::Triple::IOS
:
140 case llvm::Triple::TvOS
: // Earliest supporting version is 12.0.0.
141 MinVersion
= llvm::VersionTuple(12U);
143 case llvm::Triple::WatchOS
: // Earliest supporting version is 5.0.0.
144 MinVersion
= llvm::VersionTuple(5U);
147 // Conservatively return 8 bytes if OS is unknown.
151 if (T
.getOSVersion() < MinVersion
)
153 return OSTargetInfo
<Target
>::getExnObjectAlignment();
156 TargetInfo::IntType
getLeastIntTypeByWidth(unsigned BitWidth
,
157 bool IsSigned
) const final
{
158 // Darwin uses `long long` for `int_least64_t` and `int_fast64_t`.
159 return BitWidth
== 64
160 ? (IsSigned
? TargetInfo::SignedLongLong
161 : TargetInfo::UnsignedLongLong
)
162 : TargetInfo::getLeastIntTypeByWidth(BitWidth
, IsSigned
);
165 bool areDefaultedSMFStillPOD(const LangOptions
&) const override
{
170 // DragonFlyBSD Target
171 template <typename Target
>
172 class LLVM_LIBRARY_VISIBILITY DragonFlyBSDTargetInfo
173 : public OSTargetInfo
<Target
> {
175 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
176 MacroBuilder
&Builder
) const override
{
177 // DragonFly defines; list based off of gcc output
178 Builder
.defineMacro("__DragonFly__");
179 Builder
.defineMacro("__DragonFly_cc_version", "100001");
180 Builder
.defineMacro("__ELF__");
181 Builder
.defineMacro("__KPRINTF_ATTRIBUTE__");
182 Builder
.defineMacro("__tune_i386__");
183 DefineStd(Builder
, "unix", Opts
);
184 if (this->HasFloat128
)
185 Builder
.defineMacro("__FLOAT128__");
189 DragonFlyBSDTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
190 : OSTargetInfo
<Target
>(Triple
, Opts
) {
191 switch (Triple
.getArch()) {
193 case llvm::Triple::x86
:
194 case llvm::Triple::x86_64
:
195 this->HasFloat128
= true;
196 this->MCountName
= ".mcount";
202 #ifndef FREEBSD_CC_VERSION
203 #define FREEBSD_CC_VERSION 0U
207 template <typename Target
>
208 class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo
: public OSTargetInfo
<Target
> {
210 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
211 MacroBuilder
&Builder
) const override
{
212 // FreeBSD defines; list based off of gcc output
214 unsigned Release
= Triple
.getOSMajorVersion();
217 unsigned CCVersion
= FREEBSD_CC_VERSION
;
219 CCVersion
= Release
* 100000U + 1U;
221 Builder
.defineMacro("__FreeBSD__", Twine(Release
));
222 Builder
.defineMacro("__FreeBSD_cc_version", Twine(CCVersion
));
223 Builder
.defineMacro("__KPRINTF_ATTRIBUTE__");
224 DefineStd(Builder
, "unix", Opts
);
225 Builder
.defineMacro("__ELF__");
227 // On FreeBSD, wchar_t contains the number of the code point as
228 // used by the character set of the locale. These character sets are
229 // not necessarily a superset of ASCII.
231 // FIXME: This is wrong; the macro refers to the numerical values
232 // of wchar_t *literals*, which are not locale-dependent. However,
233 // FreeBSD systems apparently depend on us getting this wrong, and
234 // setting this to 1 is conforming even if all the basic source
235 // character literals have the same encoding as char and wchar_t.
236 Builder
.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
240 FreeBSDTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
241 : OSTargetInfo
<Target
>(Triple
, Opts
) {
242 switch (Triple
.getArch()) {
244 case llvm::Triple::x86
:
245 case llvm::Triple::x86_64
:
246 this->MCountName
= ".mcount";
248 case llvm::Triple::mips
:
249 case llvm::Triple::mipsel
:
250 case llvm::Triple::ppc
:
251 case llvm::Triple::ppcle
:
252 case llvm::Triple::ppc64
:
253 case llvm::Triple::ppc64le
:
254 this->MCountName
= "_mcount";
256 case llvm::Triple::arm
:
257 this->MCountName
= "__mcount";
259 case llvm::Triple::riscv32
:
260 case llvm::Triple::riscv64
:
266 // GNU/kFreeBSD Target
267 template <typename Target
>
268 class LLVM_LIBRARY_VISIBILITY KFreeBSDTargetInfo
: public OSTargetInfo
<Target
> {
270 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
271 MacroBuilder
&Builder
) const override
{
272 // GNU/kFreeBSD defines; list based off of gcc output
274 DefineStd(Builder
, "unix", Opts
);
275 Builder
.defineMacro("__FreeBSD_kernel__");
276 Builder
.defineMacro("__GLIBC__");
277 Builder
.defineMacro("__ELF__");
278 if (Opts
.POSIXThreads
)
279 Builder
.defineMacro("_REENTRANT");
281 Builder
.defineMacro("_GNU_SOURCE");
285 using OSTargetInfo
<Target
>::OSTargetInfo
;
289 template <typename Target
>
290 class LLVM_LIBRARY_VISIBILITY HaikuTargetInfo
: public OSTargetInfo
<Target
> {
292 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
293 MacroBuilder
&Builder
) const override
{
294 // Haiku defines; list based off of gcc output
295 Builder
.defineMacro("__HAIKU__");
296 Builder
.defineMacro("__ELF__");
297 DefineStd(Builder
, "unix", Opts
);
298 if (this->HasFloat128
)
299 Builder
.defineMacro("__FLOAT128__");
303 HaikuTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
304 : OSTargetInfo
<Target
>(Triple
, Opts
) {
305 this->SizeType
= TargetInfo::UnsignedLong
;
306 this->IntPtrType
= TargetInfo::SignedLong
;
307 this->PtrDiffType
= TargetInfo::SignedLong
;
308 this->ProcessIDType
= TargetInfo::SignedLong
;
309 this->TLSSupported
= false;
310 switch (Triple
.getArch()) {
313 case llvm::Triple::x86
:
314 case llvm::Triple::x86_64
:
315 this->HasFloat128
= true;
322 template <typename Target
>
323 class LLVM_LIBRARY_VISIBILITY HurdTargetInfo
: public OSTargetInfo
<Target
> {
325 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
326 MacroBuilder
&Builder
) const override
{
327 // Hurd defines; list based off of gcc output.
328 DefineStd(Builder
, "unix", Opts
);
329 Builder
.defineMacro("__GNU__");
330 Builder
.defineMacro("__gnu_hurd__");
331 Builder
.defineMacro("__MACH__");
332 Builder
.defineMacro("__GLIBC__");
333 Builder
.defineMacro("__ELF__");
334 if (Opts
.POSIXThreads
)
335 Builder
.defineMacro("_REENTRANT");
337 Builder
.defineMacro("_GNU_SOURCE");
340 using OSTargetInfo
<Target
>::OSTargetInfo
;
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 using OSTargetInfo
<Target
>::OSTargetInfo
;
367 template <typename Target
>
368 class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo
: public OSTargetInfo
<Target
> {
370 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
371 MacroBuilder
&Builder
) const override
{
372 // Linux defines; list based off of gcc output
373 DefineStd(Builder
, "unix", Opts
);
374 DefineStd(Builder
, "linux", Opts
);
375 Builder
.defineMacro("__ELF__");
376 if (Triple
.isAndroid()) {
377 Builder
.defineMacro("__ANDROID__", "1");
378 this->PlatformName
= "android";
379 this->PlatformMinVersion
= Triple
.getEnvironmentVersion();
380 const unsigned Maj
= this->PlatformMinVersion
.getMajor();
382 Builder
.defineMacro("__ANDROID_MIN_SDK_VERSION__", Twine(Maj
));
383 // This historical but ambiguous name for the minSdkVersion macro. Keep
384 // defined for compatibility.
385 Builder
.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
388 Builder
.defineMacro("__gnu_linux__");
390 if (Opts
.POSIXThreads
)
391 Builder
.defineMacro("_REENTRANT");
393 Builder
.defineMacro("_GNU_SOURCE");
394 if (this->HasFloat128
)
395 Builder
.defineMacro("__FLOAT128__");
399 LinuxTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
400 : OSTargetInfo
<Target
>(Triple
, Opts
) {
401 this->WIntType
= TargetInfo::UnsignedInt
;
403 switch (Triple
.getArch()) {
406 case llvm::Triple::mips
:
407 case llvm::Triple::mipsel
:
408 case llvm::Triple::mips64
:
409 case llvm::Triple::mips64el
:
410 case llvm::Triple::ppc
:
411 case llvm::Triple::ppcle
:
412 case llvm::Triple::ppc64
:
413 case llvm::Triple::ppc64le
:
414 this->MCountName
= "_mcount";
416 case llvm::Triple::x86
:
417 case llvm::Triple::x86_64
:
418 this->HasFloat128
= true;
423 const char *getStaticInitSectionSpecifier() const override
{
424 return ".text.startup";
429 template <typename Target
>
430 class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo
: public OSTargetInfo
<Target
> {
432 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
433 MacroBuilder
&Builder
) const override
{
434 // NetBSD defines; list based off of gcc output
435 Builder
.defineMacro("__NetBSD__");
436 Builder
.defineMacro("__unix__");
437 Builder
.defineMacro("__ELF__");
438 if (Opts
.POSIXThreads
)
439 Builder
.defineMacro("_REENTRANT");
443 NetBSDTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
444 : OSTargetInfo
<Target
>(Triple
, Opts
) {
445 this->MCountName
= "__mcount";
450 template <typename Target
>
451 class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo
: public OSTargetInfo
<Target
> {
453 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
454 MacroBuilder
&Builder
) const override
{
455 // OpenBSD defines; list based off of gcc output
457 Builder
.defineMacro("__OpenBSD__");
458 DefineStd(Builder
, "unix", Opts
);
459 Builder
.defineMacro("__ELF__");
460 if (Opts
.POSIXThreads
)
461 Builder
.defineMacro("_REENTRANT");
462 if (this->HasFloat128
)
463 Builder
.defineMacro("__FLOAT128__");
466 Builder
.defineMacro("__STDC_NO_THREADS__");
470 OpenBSDTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
471 : OSTargetInfo
<Target
>(Triple
, Opts
) {
472 this->WCharType
= this->WIntType
= this->SignedInt
;
473 this->IntMaxType
= TargetInfo::SignedLongLong
;
474 this->Int64Type
= TargetInfo::SignedLongLong
;
475 switch (Triple
.getArch()) {
476 case llvm::Triple::x86
:
477 case llvm::Triple::x86_64
:
478 this->HasFloat128
= true;
481 this->MCountName
= "__mcount";
483 case llvm::Triple::mips64
:
484 case llvm::Triple::mips64el
:
485 case llvm::Triple::ppc
:
486 case llvm::Triple::ppc64
:
487 case llvm::Triple::ppc64le
:
488 case llvm::Triple::sparcv9
:
489 this->MCountName
= "_mcount";
491 case llvm::Triple::riscv32
:
492 case llvm::Triple::riscv64
:
499 template <typename Target
>
500 class LLVM_LIBRARY_VISIBILITY PS3PPUTargetInfo
: public OSTargetInfo
<Target
> {
502 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
503 MacroBuilder
&Builder
) const override
{
505 Builder
.defineMacro("__PPC__");
506 Builder
.defineMacro("__PPU__");
507 Builder
.defineMacro("__CELLOS_LV2__");
508 Builder
.defineMacro("__ELF__");
509 Builder
.defineMacro("__LP32__");
510 Builder
.defineMacro("_ARCH_PPC64");
511 Builder
.defineMacro("__powerpc64__");
515 PS3PPUTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
516 : OSTargetInfo
<Target
>(Triple
, Opts
) {
517 this->LongWidth
= this->LongAlign
= 32;
518 this->PointerWidth
= this->PointerAlign
= 32;
519 this->IntMaxType
= TargetInfo::SignedLongLong
;
520 this->Int64Type
= TargetInfo::SignedLongLong
;
521 this->SizeType
= TargetInfo::UnsignedInt
;
522 this->resetDataLayout("E-m:e-p:32:32-i64:64-n32:64");
526 // Common base class for PS4/PS5 targets.
527 template <typename Target
>
528 class LLVM_LIBRARY_VISIBILITY PSOSTargetInfo
: public OSTargetInfo
<Target
> {
530 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
531 MacroBuilder
&Builder
) const override
{
532 Builder
.defineMacro("__FreeBSD__", "9");
533 Builder
.defineMacro("__FreeBSD_cc_version", "900001");
534 Builder
.defineMacro("__KPRINTF_ATTRIBUTE__");
535 DefineStd(Builder
, "unix", Opts
);
536 Builder
.defineMacro("__ELF__");
537 Builder
.defineMacro("__SCE__");
541 PSOSTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
542 : OSTargetInfo
<Target
>(Triple
, Opts
) {
543 this->WCharType
= TargetInfo::UnsignedShort
;
545 // On PS4/PS5, TLS variable cannot be aligned to more than 32 bytes (256
547 this->MaxTLSAlign
= 256;
549 // On PS4/PS5, do not honor explicit bit field alignment,
550 // as in "__attribute__((aligned(2))) int b : 1;".
551 this->UseExplicitBitFieldAlignment
= false;
553 this->MCountName
= ".mcount";
554 this->NewAlign
= 256;
555 this->SuitableAlign
= 256;
558 TargetInfo::CallingConvCheckResult
559 checkCallingConvention(CallingConv CC
) const override
{
560 return (CC
== CC_C
) ? TargetInfo::CCCR_OK
: TargetInfo::CCCR_Error
;
563 bool areDefaultedSMFStillPOD(const LangOptions
&) const override
{
569 template <typename Target
>
570 class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo
: public PSOSTargetInfo
<Target
> {
572 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
573 MacroBuilder
&Builder
) const override
{
574 // Start with base class defines.
575 PSOSTargetInfo
<Target
>::getOSDefines(Opts
, Triple
, Builder
);
577 Builder
.defineMacro("__ORBIS__");
581 using PSOSTargetInfo
<Target
>::PSOSTargetInfo
;
585 template <typename Target
>
586 class LLVM_LIBRARY_VISIBILITY PS5OSTargetInfo
: public PSOSTargetInfo
<Target
> {
588 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
589 MacroBuilder
&Builder
) const override
{
590 // Start with base class defines.
591 PSOSTargetInfo
<Target
>::getOSDefines(Opts
, Triple
, Builder
);
593 Builder
.defineMacro("__PROSPERO__");
597 using PSOSTargetInfo
<Target
>::PSOSTargetInfo
;
601 template <typename Target
>
602 class LLVM_LIBRARY_VISIBILITY RTEMSTargetInfo
: public OSTargetInfo
<Target
> {
604 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
605 MacroBuilder
&Builder
) const override
{
606 // RTEMS defines; list based off of gcc output
608 Builder
.defineMacro("__rtems__");
609 Builder
.defineMacro("__ELF__");
611 Builder
.defineMacro("_GNU_SOURCE");
615 RTEMSTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
616 : OSTargetInfo
<Target
>(Triple
, Opts
) {
617 switch (Triple
.getArch()) {
619 case llvm::Triple::x86
:
620 // this->MCountName = ".mcount";
622 case llvm::Triple::mips
:
623 case llvm::Triple::mipsel
:
624 case llvm::Triple::ppc
:
625 case llvm::Triple::ppc64
:
626 case llvm::Triple::ppc64le
:
627 // this->MCountName = "_mcount";
629 case llvm::Triple::arm
:
630 // this->MCountName = "__mcount";
637 template <typename Target
>
638 class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo
: public OSTargetInfo
<Target
> {
640 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
641 MacroBuilder
&Builder
) const override
{
642 DefineStd(Builder
, "sun", Opts
);
643 DefineStd(Builder
, "unix", Opts
);
644 Builder
.defineMacro("__ELF__");
645 Builder
.defineMacro("__svr4__");
646 Builder
.defineMacro("__SVR4");
647 // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
648 // newer, but to 500 for everything else. feature_test.h has a check to
649 // ensure that you are not using C99 with an old version of X/Open or C89
650 // with a new version.
652 Builder
.defineMacro("_XOPEN_SOURCE", "600");
654 Builder
.defineMacro("_XOPEN_SOURCE", "500");
655 if (Opts
.CPlusPlus
) {
656 Builder
.defineMacro("__C99FEATURES__");
657 Builder
.defineMacro("_FILE_OFFSET_BITS", "64");
659 // GCC restricts the next two to C++.
660 Builder
.defineMacro("_LARGEFILE_SOURCE");
661 Builder
.defineMacro("_LARGEFILE64_SOURCE");
662 Builder
.defineMacro("__EXTENSIONS__");
663 if (Opts
.POSIXThreads
)
664 Builder
.defineMacro("_REENTRANT");
665 if (this->HasFloat128
)
666 Builder
.defineMacro("__FLOAT128__");
670 SolarisTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
671 : OSTargetInfo
<Target
>(Triple
, Opts
) {
672 if (this->PointerWidth
== 64) {
673 this->WCharType
= this->WIntType
= this->SignedInt
;
675 this->WCharType
= this->WIntType
= this->SignedLong
;
677 switch (Triple
.getArch()) {
680 case llvm::Triple::x86
:
681 case llvm::Triple::x86_64
:
682 this->HasFloat128
= true;
689 template <typename Target
>
690 class AIXTargetInfo
: public OSTargetInfo
<Target
> {
692 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
693 MacroBuilder
&Builder
) const override
{
694 DefineStd(Builder
, "unix", Opts
);
695 Builder
.defineMacro("_IBMR2");
696 Builder
.defineMacro("_POWER");
697 Builder
.defineMacro("__THW_BIG_ENDIAN__");
699 Builder
.defineMacro("_AIX");
700 Builder
.defineMacro("__TOS_AIX__");
701 Builder
.defineMacro("__HOS_AIX__");
704 Builder
.defineMacro("__STDC_NO_ATOMICS__");
705 Builder
.defineMacro("__STDC_NO_THREADS__");
708 if (Opts
.EnableAIXExtendedAltivecABI
)
709 Builder
.defineMacro("__EXTABI__");
711 VersionTuple OsVersion
= Triple
.getOSVersion();
713 // Define AIX OS-Version Macros.
714 // Includes logic for legacy versions of AIX; no specific intent to support.
715 if (OsVersion
>= VersionTuple(3, 2))
716 Builder
.defineMacro("_AIX32");
717 if (OsVersion
>= VersionTuple(4, 1))
718 Builder
.defineMacro("_AIX41");
719 if (OsVersion
>= VersionTuple(4, 3))
720 Builder
.defineMacro("_AIX43");
721 if (OsVersion
>= VersionTuple(5, 0))
722 Builder
.defineMacro("_AIX50");
723 if (OsVersion
>= VersionTuple(5, 1))
724 Builder
.defineMacro("_AIX51");
725 if (OsVersion
>= VersionTuple(5, 2))
726 Builder
.defineMacro("_AIX52");
727 if (OsVersion
>= VersionTuple(5, 3))
728 Builder
.defineMacro("_AIX53");
729 if (OsVersion
>= VersionTuple(6, 1))
730 Builder
.defineMacro("_AIX61");
731 if (OsVersion
>= VersionTuple(7, 1))
732 Builder
.defineMacro("_AIX71");
733 if (OsVersion
>= VersionTuple(7, 2))
734 Builder
.defineMacro("_AIX72");
735 if (OsVersion
>= VersionTuple(7, 3))
736 Builder
.defineMacro("_AIX73");
738 // FIXME: Do not define _LONG_LONG when -fno-long-long is specified.
739 Builder
.defineMacro("_LONG_LONG");
741 if (Opts
.POSIXThreads
) {
742 Builder
.defineMacro("_THREAD_SAFE");
745 if (this->PointerWidth
== 64) {
746 Builder
.defineMacro("__64BIT__");
749 // Define _WCHAR_T when it is a fundamental type
750 // (i.e., for C++ without -fno-wchar).
751 if (Opts
.CPlusPlus
&& Opts
.WChar
) {
752 Builder
.defineMacro("_WCHAR_T");
757 AIXTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
758 : OSTargetInfo
<Target
>(Triple
, Opts
) {
759 this->MCountName
= "__mcount";
760 this->TheCXXABI
.set(TargetCXXABI::XL
);
762 if (this->PointerWidth
== 64) {
763 this->WCharType
= this->UnsignedInt
;
765 this->WCharType
= this->UnsignedShort
;
767 this->UseZeroLengthBitfieldAlignment
= true;
770 // AIX sets FLT_EVAL_METHOD to be 1.
771 LangOptions::FPEvalMethodKind
getFPEvalMethod() const override
{
772 return LangOptions::FPEvalMethodKind::FEM_Double
;
775 bool defaultsToAIXPowerAlignment() const override
{ return true; }
777 bool areDefaultedSMFStillPOD(const LangOptions
&) const override
{
783 template <typename Target
>
784 class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo
: public OSTargetInfo
<Target
> {
786 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
787 MacroBuilder
&Builder
) const override
{
788 // FIXME: _LONG_LONG should not be defined under -std=c89.
789 Builder
.defineMacro("_LONG_LONG");
790 Builder
.defineMacro("_OPEN_DEFAULT");
791 // _UNIX03_WITHDRAWN is required to build libcxx.
792 Builder
.defineMacro("_UNIX03_WITHDRAWN");
793 Builder
.defineMacro("__370__");
794 Builder
.defineMacro("__BFP__");
795 // FIXME: __BOOL__ should not be defined under -std=c89.
796 Builder
.defineMacro("__BOOL__");
797 Builder
.defineMacro("__LONGNAME__");
798 Builder
.defineMacro("__MVS__");
799 Builder
.defineMacro("__THW_370__");
800 Builder
.defineMacro("__THW_BIG_ENDIAN__");
801 Builder
.defineMacro("__TOS_390__");
802 Builder
.defineMacro("__TOS_MVS__");
803 Builder
.defineMacro("__XPLINK__");
805 if (this->PointerWidth
== 64)
806 Builder
.defineMacro("__64BIT__");
808 if (Opts
.CPlusPlus
) {
809 Builder
.defineMacro("__DLL__");
810 // _XOPEN_SOURCE=600 is required to build libcxx.
811 Builder
.defineMacro("_XOPEN_SOURCE", "600");
815 Builder
.defineMacro("_MI_BUILTIN");
816 Builder
.defineMacro("_EXT");
819 if (Opts
.CPlusPlus
&& Opts
.WChar
) {
820 // Macro __wchar_t is defined so that the wchar_t data
821 // type is not declared as a typedef in system headers.
822 Builder
.defineMacro("__wchar_t");
825 this->PlatformName
= llvm::Triple::getOSTypeName(Triple
.getOS());
829 ZOSTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
830 : OSTargetInfo
<Target
>(Triple
, Opts
) {
831 this->WCharType
= TargetInfo::UnsignedInt
;
832 this->MaxAlignedAttribute
= 128;
833 this->UseBitFieldTypeAlignment
= false;
834 this->UseZeroLengthBitfieldAlignment
= true;
835 this->UseLeadingZeroLengthBitfield
= false;
836 this->ZeroLengthBitfieldBoundary
= 32;
839 bool areDefaultedSMFStillPOD(const LangOptions
&) const override
{
844 void addWindowsDefines(const llvm::Triple
&Triple
, const LangOptions
&Opts
,
845 MacroBuilder
&Builder
);
848 template <typename Target
>
849 class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo
: public OSTargetInfo
<Target
> {
851 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
852 MacroBuilder
&Builder
) const override
{
853 addWindowsDefines(Triple
, Opts
, Builder
);
857 WindowsTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
858 : OSTargetInfo
<Target
>(Triple
, Opts
) {
859 this->WCharType
= TargetInfo::UnsignedShort
;
860 this->WIntType
= TargetInfo::UnsignedShort
;
864 template <typename Target
>
865 class LLVM_LIBRARY_VISIBILITY NaClTargetInfo
: public OSTargetInfo
<Target
> {
867 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
868 MacroBuilder
&Builder
) const override
{
869 if (Opts
.POSIXThreads
)
870 Builder
.defineMacro("_REENTRANT");
872 Builder
.defineMacro("_GNU_SOURCE");
874 DefineStd(Builder
, "unix", Opts
);
875 Builder
.defineMacro("__ELF__");
876 Builder
.defineMacro("__native_client__");
880 NaClTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
881 : OSTargetInfo
<Target
>(Triple
, Opts
) {
882 this->LongAlign
= 32;
883 this->LongWidth
= 32;
884 this->PointerAlign
= 32;
885 this->PointerWidth
= 32;
886 this->IntMaxType
= TargetInfo::SignedLongLong
;
887 this->Int64Type
= TargetInfo::SignedLongLong
;
888 this->DoubleAlign
= 64;
889 this->LongDoubleWidth
= 64;
890 this->LongDoubleAlign
= 64;
891 this->LongLongWidth
= 64;
892 this->LongLongAlign
= 64;
893 this->SizeType
= TargetInfo::UnsignedInt
;
894 this->PtrDiffType
= TargetInfo::SignedInt
;
895 this->IntPtrType
= TargetInfo::SignedInt
;
896 // RegParmMax is inherited from the underlying architecture.
897 this->LongDoubleFormat
= &llvm::APFloat::IEEEdouble();
898 if (Triple
.getArch() == llvm::Triple::arm
) {
899 // Handled in ARM's setABI().
900 } else if (Triple
.getArch() == llvm::Triple::x86
) {
901 this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
902 "i64:64-n8:16:32-S128");
903 } else if (Triple
.getArch() == llvm::Triple::x86_64
) {
904 this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
905 "i64:64-n8:16:32:64-S128");
906 } else if (Triple
.getArch() == llvm::Triple::mipsel
) {
907 // Handled on mips' setDataLayout.
909 assert(Triple
.getArch() == llvm::Triple::le32
);
910 this->resetDataLayout("e-p:32:32-i64:64");
916 template <typename Target
>
917 class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo
: public OSTargetInfo
<Target
> {
919 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
920 MacroBuilder
&Builder
) const override
{
921 Builder
.defineMacro("__Fuchsia__");
922 Builder
.defineMacro("__ELF__");
923 if (Opts
.POSIXThreads
)
924 Builder
.defineMacro("_REENTRANT");
925 // Required by the libc++ locale support.
927 Builder
.defineMacro("_GNU_SOURCE");
928 Builder
.defineMacro("__Fuchsia_API_level__", Twine(Opts
.FuchsiaAPILevel
));
929 this->PlatformName
= "fuchsia";
930 this->PlatformMinVersion
= VersionTuple(Opts
.FuchsiaAPILevel
);
934 FuchsiaTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
935 : OSTargetInfo
<Target
>(Triple
, Opts
) {
936 this->MCountName
= "__mcount";
937 this->TheCXXABI
.set(TargetCXXABI::Fuchsia
);
941 // WebAssembly target
942 template <typename Target
>
943 class LLVM_LIBRARY_VISIBILITY WebAssemblyOSTargetInfo
944 : public OSTargetInfo
<Target
> {
946 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
947 MacroBuilder
&Builder
) const override
{
948 // A common platform macro.
949 if (Opts
.POSIXThreads
)
950 Builder
.defineMacro("_REENTRANT");
951 // Follow g++ convention and predefine _GNU_SOURCE for C++.
953 Builder
.defineMacro("_GNU_SOURCE");
954 // Indicate that we have __float128.
955 Builder
.defineMacro("__FLOAT128__");
959 explicit WebAssemblyOSTargetInfo(const llvm::Triple
&Triple
,
960 const TargetOptions
&Opts
)
961 : OSTargetInfo
<Target
>(Triple
, Opts
) {
962 this->MCountName
= "__mcount";
963 this->TheCXXABI
.set(TargetCXXABI::WebAssembly
);
964 this->HasFloat128
= true;
969 template <typename Target
>
970 class LLVM_LIBRARY_VISIBILITY WASITargetInfo
971 : public WebAssemblyOSTargetInfo
<Target
> {
972 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
973 MacroBuilder
&Builder
) const final
{
974 WebAssemblyOSTargetInfo
<Target
>::getOSDefines(Opts
, Triple
, Builder
);
975 Builder
.defineMacro("__wasi__");
979 using WebAssemblyOSTargetInfo
<Target
>::WebAssemblyOSTargetInfo
;
983 template <typename Target
>
984 class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
985 : public WebAssemblyOSTargetInfo
<Target
> {
986 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
987 MacroBuilder
&Builder
) const final
{
988 WebAssemblyOSTargetInfo
<Target
>::getOSDefines(Opts
, Triple
, Builder
);
989 DefineStd(Builder
, "unix", Opts
);
990 Builder
.defineMacro("__EMSCRIPTEN__");
991 if (Opts
.POSIXThreads
)
992 Builder
.defineMacro("__EMSCRIPTEN_PTHREADS__");
996 explicit EmscriptenTargetInfo(const llvm::Triple
&Triple
,
997 const TargetOptions
&Opts
)
998 : WebAssemblyOSTargetInfo
<Target
>(Triple
, Opts
) {
999 // Keeping the alignment of long double to 8 bytes even though its size is
1000 // 16 bytes allows emscripten to have an 8-byte-aligned max_align_t which
1001 // in turn gives is a 8-byte aligned malloc.
1002 // Emscripten's ABI is unstable and we may change this back to 128 to match
1003 // the WebAssembly default in the future.
1004 this->LongDoubleAlign
= 64;
1008 } // namespace targets
1009 } // namespace clang
1010 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H