clang  9.0.0svn
OSTargets.h
Go to the documentation of this file.
1 //===--- OSTargets.h - Declare OS target feature support --------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares OS specific TargetInfo types.
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
13 #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
14 
15 #include "Targets.h"
16 #include "llvm/MC/MCSectionMachO.h"
17 
18 namespace clang {
19 namespace targets {
20 
21 template <typename TgtInfo>
22 class LLVM_LIBRARY_VISIBILITY OSTargetInfo : public TgtInfo {
23 protected:
24  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
25  MacroBuilder &Builder) const = 0;
26 
27 public:
28  OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
29  : TgtInfo(Triple, Opts) {}
30 
31  void getTargetDefines(const LangOptions &Opts,
32  MacroBuilder &Builder) const override {
33  TgtInfo::getTargetDefines(Opts, Builder);
34  getOSDefines(Opts, TgtInfo::getTriple(), Builder);
35  }
36 };
37 
38 // CloudABI Target
39 template <typename Target>
40 class LLVM_LIBRARY_VISIBILITY CloudABITargetInfo : public OSTargetInfo<Target> {
41 protected:
42  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
43  MacroBuilder &Builder) const override {
44  Builder.defineMacro("__CloudABI__");
45  Builder.defineMacro("__ELF__");
46 
47  // CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
48  Builder.defineMacro("__STDC_ISO_10646__", "201206L");
49  Builder.defineMacro("__STDC_UTF_16__");
50  Builder.defineMacro("__STDC_UTF_32__");
51  }
52 
53 public:
54  CloudABITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
55  : OSTargetInfo<Target>(Triple, Opts) {}
56 };
57 
58 // Ananas target
59 template <typename Target>
60 class LLVM_LIBRARY_VISIBILITY AnanasTargetInfo : public OSTargetInfo<Target> {
61 protected:
62  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
63  MacroBuilder &Builder) const override {
64  // Ananas defines
65  Builder.defineMacro("__Ananas__");
66  Builder.defineMacro("__ELF__");
67  }
68 
69 public:
70  AnanasTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
71  : OSTargetInfo<Target>(Triple, Opts) {}
72 };
73 
74 void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
75  const llvm::Triple &Triple, StringRef &PlatformName,
76  VersionTuple &PlatformMinVersion);
77 
78 template <typename Target>
79 class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public OSTargetInfo<Target> {
80 protected:
81  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
82  MacroBuilder &Builder) const override {
83  getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
84  this->PlatformMinVersion);
85  }
86 
87 public:
88  DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
89  : OSTargetInfo<Target>(Triple, Opts) {
90  // By default, no TLS, and we whitelist permitted architecture/OS
91  // combinations.
92  this->TLSSupported = false;
93 
94  if (Triple.isMacOSX())
95  this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7);
96  else if (Triple.isiOS()) {
97  // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
98  // 32-bit simulator from 10 onwards.
99  if (Triple.isArch64Bit())
100  this->TLSSupported = !Triple.isOSVersionLT(8);
101  else if (Triple.isArch32Bit()) {
102  if (!Triple.isSimulatorEnvironment())
103  this->TLSSupported = !Triple.isOSVersionLT(9);
104  else
105  this->TLSSupported = !Triple.isOSVersionLT(10);
106  }
107  } else if (Triple.isWatchOS()) {
108  if (!Triple.isSimulatorEnvironment())
109  this->TLSSupported = !Triple.isOSVersionLT(2);
110  else
111  this->TLSSupported = !Triple.isOSVersionLT(3);
112  }
113 
114  this->MCountName = "\01mcount";
115  }
116 
117  std::string isValidSectionSpecifier(StringRef SR) const override {
118  // Let MCSectionMachO validate this.
119  StringRef Segment, Section;
120  unsigned TAA, StubSize;
121  bool HasTAA;
122  return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
123  TAA, HasTAA, StubSize);
124  }
125 
126  const char *getStaticInitSectionSpecifier() const override {
127  // FIXME: We should return 0 when building kexts.
128  return "__TEXT,__StaticInit,regular,pure_instructions";
129  }
130 
131  /// Darwin does not support protected visibility. Darwin's "default"
132  /// is very similar to ELF's "protected"; Darwin requires a "weak"
133  /// attribute on declarations that can be dynamically replaced.
134  bool hasProtectedVisibility() const override { return false; }
135 
136  unsigned getExnObjectAlignment() const override {
137  // Older versions of libc++abi guarantee an alignment of only 8-bytes for
138  // exception objects because of a bug in __cxa_exception that was
139  // eventually fixed in r319123.
140  llvm::VersionTuple MinVersion;
141  const llvm::Triple &T = this->getTriple();
142 
143  // Compute the earliest OS versions that have the fix to libc++abi.
144  switch (T.getOS()) {
145  case llvm::Triple::Darwin:
146  case llvm::Triple::MacOSX: // Earliest supporting version is 10.14.
147  MinVersion = llvm::VersionTuple(10U, 14U);
148  break;
149  case llvm::Triple::IOS:
150  case llvm::Triple::TvOS: // Earliest supporting version is 12.0.0.
151  MinVersion = llvm::VersionTuple(12U);
152  break;
153  case llvm::Triple::WatchOS: // Earliest supporting version is 5.0.0.
154  MinVersion = llvm::VersionTuple(5U);
155  break;
156  default:
157  llvm_unreachable("Unexpected OS");
158  }
159 
160  unsigned Major, Minor, Micro;
161  T.getOSVersion(Major, Minor, Micro);
162  if (llvm::VersionTuple(Major, Minor, Micro) < MinVersion)
163  return 64;
165  }
166 
168  bool IsSigned) const final {
169  // Darwin uses `long long` for `int_least64_t` and `int_fast64_t`.
170  return BitWidth == 64
171  ? (IsSigned ? TargetInfo::SignedLongLong
173  : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
174  }
175 };
176 
177 // DragonFlyBSD Target
178 template <typename Target>
179 class LLVM_LIBRARY_VISIBILITY DragonFlyBSDTargetInfo
180  : public OSTargetInfo<Target> {
181 protected:
182  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
183  MacroBuilder &Builder) const override {
184  // DragonFly defines; list based off of gcc output
185  Builder.defineMacro("__DragonFly__");
186  Builder.defineMacro("__DragonFly_cc_version", "100001");
187  Builder.defineMacro("__ELF__");
188  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
189  Builder.defineMacro("__tune_i386__");
190  DefineStd(Builder, "unix", Opts);
191  }
192 
193 public:
194  DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
195  : OSTargetInfo<Target>(Triple, Opts) {
196  switch (Triple.getArch()) {
197  default:
198  case llvm::Triple::x86:
199  case llvm::Triple::x86_64:
200  this->MCountName = ".mcount";
201  break;
202  }
203  }
204 };
205 
206 #ifndef FREEBSD_CC_VERSION
207 #define FREEBSD_CC_VERSION 0U
208 #endif
209 
210 // FreeBSD Target
211 template <typename Target>
212 class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo<Target> {
213 protected:
214  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
215  MacroBuilder &Builder) const override {
216  // FreeBSD defines; list based off of gcc output
217 
218  unsigned Release = Triple.getOSMajorVersion();
219  if (Release == 0U)
220  Release = 8U;
221  unsigned CCVersion = FREEBSD_CC_VERSION;
222  if (CCVersion == 0U)
223  CCVersion = Release * 100000U + 1U;
224 
225  Builder.defineMacro("__FreeBSD__", Twine(Release));
226  Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
227  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
228  DefineStd(Builder, "unix", Opts);
229  Builder.defineMacro("__ELF__");
230 
231  // On FreeBSD, wchar_t contains the number of the code point as
232  // used by the character set of the locale. These character sets are
233  // not necessarily a superset of ASCII.
234  //
235  // FIXME: This is wrong; the macro refers to the numerical values
236  // of wchar_t *literals*, which are not locale-dependent. However,
237  // FreeBSD systems apparently depend on us getting this wrong, and
238  // setting this to 1 is conforming even if all the basic source
239  // character literals have the same encoding as char and wchar_t.
240  Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
241  }
242 
243 public:
244  FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
245  : OSTargetInfo<Target>(Triple, Opts) {
246  switch (Triple.getArch()) {
247  default:
248  case llvm::Triple::x86:
249  case llvm::Triple::x86_64:
250  this->MCountName = ".mcount";
251  break;
252  case llvm::Triple::mips:
253  case llvm::Triple::mipsel:
254  case llvm::Triple::ppc:
255  case llvm::Triple::ppc64:
256  case llvm::Triple::ppc64le:
257  this->MCountName = "_mcount";
258  break;
259  case llvm::Triple::arm:
260  this->MCountName = "__mcount";
261  break;
262  }
263  }
264 };
265 
266 // GNU/kFreeBSD Target
267 template <typename Target>
268 class LLVM_LIBRARY_VISIBILITY KFreeBSDTargetInfo : public OSTargetInfo<Target> {
269 protected:
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
273 
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");
280  if (Opts.CPlusPlus)
281  Builder.defineMacro("_GNU_SOURCE");
282  }
283 
284 public:
285  KFreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
286  : OSTargetInfo<Target>(Triple, Opts) {}
287 };
288 
289 // Haiku Target
290 template <typename Target>
291 class LLVM_LIBRARY_VISIBILITY HaikuTargetInfo : public OSTargetInfo<Target> {
292 protected:
293  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
294  MacroBuilder &Builder) const override {
295  // Haiku defines; list based off of gcc output
296  Builder.defineMacro("__HAIKU__");
297  Builder.defineMacro("__ELF__");
298  DefineStd(Builder, "unix", Opts);
299  if (this->HasFloat128)
300  Builder.defineMacro("__FLOAT128__");
301  }
302 
303 public:
304  HaikuTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
305  : OSTargetInfo<Target>(Triple, Opts) {
306  this->SizeType = TargetInfo::UnsignedLong;
307  this->IntPtrType = TargetInfo::SignedLong;
308  this->PtrDiffType = TargetInfo::SignedLong;
309  this->ProcessIDType = TargetInfo::SignedLong;
310  this->TLSSupported = false;
311  switch (Triple.getArch()) {
312  default:
313  break;
314  case llvm::Triple::x86:
315  case llvm::Triple::x86_64:
316  this->HasFloat128 = true;
317  break;
318  }
319  }
320 };
321 
322 // Hurd target
323 template <typename Target>
324 class LLVM_LIBRARY_VISIBILITY HurdTargetInfo : public OSTargetInfo<Target> {
325 protected:
326  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
327  MacroBuilder &Builder) const override {
328  // Hurd defines; list based off of gcc output.
329  DefineStd(Builder, "unix", Opts);
330  Builder.defineMacro("__GNU__");
331  Builder.defineMacro("__gnu_hurd__");
332  Builder.defineMacro("__MACH__");
333  Builder.defineMacro("__GLIBC__");
334  Builder.defineMacro("__ELF__");
335  if (Opts.POSIXThreads)
336  Builder.defineMacro("_REENTRANT");
337  if (Opts.CPlusPlus)
338  Builder.defineMacro("_GNU_SOURCE");
339  }
340 public:
341  HurdTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
342  : OSTargetInfo<Target>(Triple, Opts) {}
343 };
344 
345 // Minix Target
346 template <typename Target>
347 class LLVM_LIBRARY_VISIBILITY MinixTargetInfo : public OSTargetInfo<Target> {
348 protected:
349  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
350  MacroBuilder &Builder) const override {
351  // Minix defines
352 
353  Builder.defineMacro("__minix", "3");
354  Builder.defineMacro("_EM_WSIZE", "4");
355  Builder.defineMacro("_EM_PSIZE", "4");
356  Builder.defineMacro("_EM_SSIZE", "2");
357  Builder.defineMacro("_EM_LSIZE", "4");
358  Builder.defineMacro("_EM_FSIZE", "4");
359  Builder.defineMacro("_EM_DSIZE", "8");
360  Builder.defineMacro("__ELF__");
361  DefineStd(Builder, "unix", Opts);
362  }
363 
364 public:
365  MinixTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
366  : OSTargetInfo<Target>(Triple, Opts) {}
367 };
368 
369 // Linux target
370 template <typename Target>
371 class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public OSTargetInfo<Target> {
372 protected:
373  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
374  MacroBuilder &Builder) const override {
375  // Linux defines; list based off of gcc output
376  DefineStd(Builder, "unix", Opts);
377  DefineStd(Builder, "linux", Opts);
378  Builder.defineMacro("__ELF__");
379  if (Triple.isAndroid()) {
380  Builder.defineMacro("__ANDROID__", "1");
381  unsigned Maj, Min, Rev;
382  Triple.getEnvironmentVersion(Maj, Min, Rev);
383  this->PlatformName = "android";
384  this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
385  if (Maj)
386  Builder.defineMacro("__ANDROID_API__", Twine(Maj));
387  } else {
388  Builder.defineMacro("__gnu_linux__");
389  }
390  if (Opts.POSIXThreads)
391  Builder.defineMacro("_REENTRANT");
392  if (Opts.CPlusPlus)
393  Builder.defineMacro("_GNU_SOURCE");
394  if (this->HasFloat128)
395  Builder.defineMacro("__FLOAT128__");
396  }
397 
398 public:
399  LinuxTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
400  : OSTargetInfo<Target>(Triple, Opts) {
401  this->WIntType = TargetInfo::UnsignedInt;
402 
403  switch (Triple.getArch()) {
404  default:
405  break;
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::ppc64:
412  case llvm::Triple::ppc64le:
413  this->MCountName = "_mcount";
414  break;
415  case llvm::Triple::x86:
416  case llvm::Triple::x86_64:
417  this->HasFloat128 = true;
418  break;
419  }
420  }
421 
422  const char *getStaticInitSectionSpecifier() const override {
423  return ".text.startup";
424  }
425 };
426 
427 // NetBSD Target
428 template <typename Target>
429 class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public OSTargetInfo<Target> {
430 protected:
431  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
432  MacroBuilder &Builder) const override {
433  // NetBSD defines; list based off of gcc output
434  Builder.defineMacro("__NetBSD__");
435  Builder.defineMacro("__unix__");
436  Builder.defineMacro("__ELF__");
437  if (Opts.POSIXThreads)
438  Builder.defineMacro("_REENTRANT");
439  }
440 
441 public:
442  NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
443  : OSTargetInfo<Target>(Triple, Opts) {
444  this->MCountName = "__mcount";
445  }
446 };
447 
448 // OpenBSD Target
449 template <typename Target>
450 class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
451 protected:
452  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
453  MacroBuilder &Builder) const override {
454  // OpenBSD defines; list based off of gcc output
455 
456  Builder.defineMacro("__OpenBSD__");
457  DefineStd(Builder, "unix", Opts);
458  Builder.defineMacro("__ELF__");
459  if (Opts.POSIXThreads)
460  Builder.defineMacro("_REENTRANT");
461  if (this->HasFloat128)
462  Builder.defineMacro("__FLOAT128__");
463  }
464 
465 public:
466  OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
467  : OSTargetInfo<Target>(Triple, Opts) {
468  switch (Triple.getArch()) {
469  case llvm::Triple::x86:
470  case llvm::Triple::x86_64:
471  this->HasFloat128 = true;
472  LLVM_FALLTHROUGH;
473  default:
474  this->MCountName = "__mcount";
475  break;
476  case llvm::Triple::mips64:
477  case llvm::Triple::mips64el:
478  case llvm::Triple::ppc:
479  case llvm::Triple::sparcv9:
480  this->MCountName = "_mcount";
481  break;
482  }
483  }
484 };
485 
486 // PSP Target
487 template <typename Target>
488 class LLVM_LIBRARY_VISIBILITY PSPTargetInfo : public OSTargetInfo<Target> {
489 protected:
490  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
491  MacroBuilder &Builder) const override {
492  // PSP defines; list based on the output of the pspdev gcc toolchain.
493  Builder.defineMacro("PSP");
494  Builder.defineMacro("_PSP");
495  Builder.defineMacro("__psp__");
496  Builder.defineMacro("__ELF__");
497  }
498 
499 public:
500  PSPTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {}
501 };
502 
503 // PS3 PPU Target
504 template <typename Target>
505 class LLVM_LIBRARY_VISIBILITY PS3PPUTargetInfo : public OSTargetInfo<Target> {
506 protected:
507  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
508  MacroBuilder &Builder) const override {
509  // PS3 PPU defines.
510  Builder.defineMacro("__PPC__");
511  Builder.defineMacro("__PPU__");
512  Builder.defineMacro("__CELLOS_LV2__");
513  Builder.defineMacro("__ELF__");
514  Builder.defineMacro("__LP32__");
515  Builder.defineMacro("_ARCH_PPC64");
516  Builder.defineMacro("__powerpc64__");
517  }
518 
519 public:
520  PS3PPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
521  : OSTargetInfo<Target>(Triple, Opts) {
522  this->LongWidth = this->LongAlign = 32;
523  this->PointerWidth = this->PointerAlign = 32;
524  this->IntMaxType = TargetInfo::SignedLongLong;
525  this->Int64Type = TargetInfo::SignedLongLong;
526  this->SizeType = TargetInfo::UnsignedInt;
527  this->resetDataLayout("E-m:e-p:32:32-i64:64-n32:64");
528  }
529 };
530 
531 template <typename Target>
532 class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public OSTargetInfo<Target> {
533 protected:
534  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
535  MacroBuilder &Builder) const override {
536  Builder.defineMacro("__FreeBSD__", "9");
537  Builder.defineMacro("__FreeBSD_cc_version", "900001");
538  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
539  DefineStd(Builder, "unix", Opts);
540  Builder.defineMacro("__ELF__");
541  Builder.defineMacro("__ORBIS__");
542  }
543 
544 public:
545  PS4OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
546  : OSTargetInfo<Target>(Triple, Opts) {
547  this->WCharType = TargetInfo::UnsignedShort;
548 
549  // On PS4, TLS variable cannot be aligned to more than 32 bytes (256 bits).
550  this->MaxTLSAlign = 256;
551 
552  // On PS4, do not honor explicit bit field alignment,
553  // as in "__attribute__((aligned(2))) int b : 1;".
554  this->UseExplicitBitFieldAlignment = false;
555 
556  switch (Triple.getArch()) {
557  default:
558  case llvm::Triple::x86_64:
559  this->MCountName = ".mcount";
560  this->NewAlign = 256;
561  break;
562  }
563  }
564 };
565 
566 // RTEMS Target
567 template <typename Target>
568 class LLVM_LIBRARY_VISIBILITY RTEMSTargetInfo : public OSTargetInfo<Target> {
569 protected:
570  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
571  MacroBuilder &Builder) const override {
572  // RTEMS defines; list based off of gcc output
573 
574  Builder.defineMacro("__rtems__");
575  Builder.defineMacro("__ELF__");
576  if (Opts.CPlusPlus)
577  Builder.defineMacro("_GNU_SOURCE");
578  }
579 
580 public:
581  RTEMSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
582  : OSTargetInfo<Target>(Triple, Opts) {
583  switch (Triple.getArch()) {
584  default:
585  case llvm::Triple::x86:
586  // this->MCountName = ".mcount";
587  break;
588  case llvm::Triple::mips:
589  case llvm::Triple::mipsel:
590  case llvm::Triple::ppc:
591  case llvm::Triple::ppc64:
592  case llvm::Triple::ppc64le:
593  // this->MCountName = "_mcount";
594  break;
595  case llvm::Triple::arm:
596  // this->MCountName = "__mcount";
597  break;
598  }
599  }
600 };
601 
602 // Solaris target
603 template <typename Target>
604 class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo : public OSTargetInfo<Target> {
605 protected:
606  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
607  MacroBuilder &Builder) const override {
608  DefineStd(Builder, "sun", Opts);
609  DefineStd(Builder, "unix", Opts);
610  Builder.defineMacro("__ELF__");
611  Builder.defineMacro("__svr4__");
612  Builder.defineMacro("__SVR4");
613  // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
614  // newer, but to 500 for everything else. feature_test.h has a check to
615  // ensure that you are not using C99 with an old version of X/Open or C89
616  // with a new version.
617  if (Opts.C99)
618  Builder.defineMacro("_XOPEN_SOURCE", "600");
619  else
620  Builder.defineMacro("_XOPEN_SOURCE", "500");
621  if (Opts.CPlusPlus)
622  Builder.defineMacro("__C99FEATURES__");
623  Builder.defineMacro("_LARGEFILE_SOURCE");
624  Builder.defineMacro("_LARGEFILE64_SOURCE");
625  Builder.defineMacro("__EXTENSIONS__");
626  if (Opts.POSIXThreads)
627  Builder.defineMacro("_REENTRANT");
628  if (this->HasFloat128)
629  Builder.defineMacro("__FLOAT128__");
630  }
631 
632 public:
633  SolarisTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
634  : OSTargetInfo<Target>(Triple, Opts) {
635  // FIXME: WIntType should be SignedLong
636  switch (Triple.getArch()) {
637  default:
638  break;
639  case llvm::Triple::x86:
640  case llvm::Triple::x86_64:
641  this->HasFloat128 = true;
642  break;
643  }
644  }
645 };
646 
647 // AIX Target
648 template <typename Target>
649 class AIXTargetInfo : public OSTargetInfo<Target> {
650 protected:
651  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
652  MacroBuilder &Builder) const override {
653  DefineStd(Builder, "unix", Opts);
654  Builder.defineMacro("_IBMR2");
655  Builder.defineMacro("_POWER");
656 
657  Builder.defineMacro("_AIX");
658 
659  unsigned Major, Minor, Micro;
660  Triple.getOSVersion(Major, Minor, Micro);
661 
662  // Define AIX OS-Version Macros.
663  // Includes logic for legacy versions of AIX; no specific intent to support.
664  std::pair<int, int> OsVersion = {Major, Minor};
665  if (OsVersion >= std::make_pair(3, 2)) Builder.defineMacro("_AIX32");
666  if (OsVersion >= std::make_pair(4, 1)) Builder.defineMacro("_AIX41");
667  if (OsVersion >= std::make_pair(4, 3)) Builder.defineMacro("_AIX43");
668  if (OsVersion >= std::make_pair(5, 0)) Builder.defineMacro("_AIX50");
669  if (OsVersion >= std::make_pair(5, 1)) Builder.defineMacro("_AIX51");
670  if (OsVersion >= std::make_pair(5, 2)) Builder.defineMacro("_AIX52");
671  if (OsVersion >= std::make_pair(5, 3)) Builder.defineMacro("_AIX53");
672  if (OsVersion >= std::make_pair(6, 1)) Builder.defineMacro("_AIX61");
673  if (OsVersion >= std::make_pair(7, 1)) Builder.defineMacro("_AIX71");
674  if (OsVersion >= std::make_pair(7, 2)) Builder.defineMacro("_AIX72");
675 
676  // FIXME: Do not define _LONG_LONG when -fno-long-long is specified.
677  Builder.defineMacro("_LONG_LONG");
678 
679  if (Opts.POSIXThreads) {
680  Builder.defineMacro("_THREAD_SAFE");
681  }
682 
683  if (this->PointerWidth == 64) {
684  Builder.defineMacro("__64BIT__");
685  }
686 
687  // Define _WCHAR_T when it is a fundamental type
688  // (i.e., for C++ without -fno-wchar).
689  if (Opts.CPlusPlus && Opts.WChar) {
690  Builder.defineMacro("_WCHAR_T");
691  }
692  }
693 
694 public:
695  AIXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
696  : OSTargetInfo<Target>(Triple, Opts) {
697  if (this->PointerWidth == 64) {
698  this->WCharType = this->UnsignedInt;
699  } else {
700  this->WCharType = this->UnsignedShort;
701  }
702  this->UseZeroLengthBitfieldAlignment = true;
703  }
704 
705  // AIX sets FLT_EVAL_METHOD to be 1.
706  unsigned getFloatEvalMethod() const override { return 1; }
707  bool hasInt128Type() const override { return false; }
708 };
709 
710 // Windows target
711 template <typename Target>
712 class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
713 protected:
714  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
715  MacroBuilder &Builder) const override {
716  Builder.defineMacro("_WIN32");
717  if (Triple.isArch64Bit())
718  Builder.defineMacro("_WIN64");
719  if (Triple.isWindowsGNUEnvironment())
720  addMinGWDefines(Triple, Opts, Builder);
721 
722  }
724  MacroBuilder &Builder) const {
725  if (Opts.CPlusPlus) {
726  if (Opts.RTTIData)
727  Builder.defineMacro("_CPPRTTI");
728 
729  if (Opts.CXXExceptions)
730  Builder.defineMacro("_CPPUNWIND");
731  }
732 
733  if (Opts.Bool)
734  Builder.defineMacro("__BOOL_DEFINED");
735 
736  if (!Opts.CharIsSigned)
737  Builder.defineMacro("_CHAR_UNSIGNED");
738 
739  // FIXME: POSIXThreads isn't exactly the option this should be defined for,
740  // but it works for now.
741  if (Opts.POSIXThreads)
742  Builder.defineMacro("_MT");
743 
744  if (Opts.MSCompatibilityVersion) {
745  Builder.defineMacro("_MSC_VER",
746  Twine(Opts.MSCompatibilityVersion / 100000));
747  Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
748  // FIXME We cannot encode the revision information into 32-bits
749  Builder.defineMacro("_MSC_BUILD", Twine(1));
750 
751  if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
752  Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
753 
755  if (Opts.CPlusPlus2a)
756  Builder.defineMacro("_MSVC_LANG", "201704L");
757  else if (Opts.CPlusPlus17)
758  Builder.defineMacro("_MSVC_LANG", "201703L");
759  else if (Opts.CPlusPlus14)
760  Builder.defineMacro("_MSVC_LANG", "201402L");
761  }
762  }
763 
764  if (Opts.MicrosoftExt) {
765  Builder.defineMacro("_MSC_EXTENSIONS");
766 
767  if (Opts.CPlusPlus11) {
768  Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
769  Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
770  Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
771  }
772  }
773 
774  Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
775  }
776 
777 public:
778  WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
779  : OSTargetInfo<Target>(Triple, Opts) {
780  this->WCharType = TargetInfo::UnsignedShort;
781  this->WIntType = TargetInfo::UnsignedShort;
782  }
783 };
784 
785 template <typename Target>
786 class LLVM_LIBRARY_VISIBILITY NaClTargetInfo : public OSTargetInfo<Target> {
787 protected:
788  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
789  MacroBuilder &Builder) const override {
790  if (Opts.POSIXThreads)
791  Builder.defineMacro("_REENTRANT");
792  if (Opts.CPlusPlus)
793  Builder.defineMacro("_GNU_SOURCE");
794 
795  DefineStd(Builder, "unix", Opts);
796  Builder.defineMacro("__ELF__");
797  Builder.defineMacro("__native_client__");
798  }
799 
800 public:
801  NaClTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
802  : OSTargetInfo<Target>(Triple, Opts) {
803  this->LongAlign = 32;
804  this->LongWidth = 32;
805  this->PointerAlign = 32;
806  this->PointerWidth = 32;
807  this->IntMaxType = TargetInfo::SignedLongLong;
808  this->Int64Type = TargetInfo::SignedLongLong;
809  this->DoubleAlign = 64;
810  this->LongDoubleWidth = 64;
811  this->LongDoubleAlign = 64;
812  this->LongLongWidth = 64;
813  this->LongLongAlign = 64;
814  this->SizeType = TargetInfo::UnsignedInt;
815  this->PtrDiffType = TargetInfo::SignedInt;
816  this->IntPtrType = TargetInfo::SignedInt;
817  // RegParmMax is inherited from the underlying architecture.
818  this->LongDoubleFormat = &llvm::APFloat::IEEEdouble();
819  if (Triple.getArch() == llvm::Triple::arm) {
820  // Handled in ARM's setABI().
821  } else if (Triple.getArch() == llvm::Triple::x86) {
822  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32-S128");
823  } else if (Triple.getArch() == llvm::Triple::x86_64) {
824  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32:64-S128");
825  } else if (Triple.getArch() == llvm::Triple::mipsel) {
826  // Handled on mips' setDataLayout.
827  } else {
828  assert(Triple.getArch() == llvm::Triple::le32);
829  this->resetDataLayout("e-p:32:32-i64:64");
830  }
831  }
832 };
833 
834 // Fuchsia Target
835 template <typename Target>
836 class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo : public OSTargetInfo<Target> {
837 protected:
838  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
839  MacroBuilder &Builder) const override {
840  Builder.defineMacro("__Fuchsia__");
841  Builder.defineMacro("__ELF__");
842  if (Opts.POSIXThreads)
843  Builder.defineMacro("_REENTRANT");
844  // Required by the libc++ locale support.
845  if (Opts.CPlusPlus)
846  Builder.defineMacro("_GNU_SOURCE");
847  }
848 
849 public:
850  FuchsiaTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
851  : OSTargetInfo<Target>(Triple, Opts) {
852  this->MCountName = "__mcount";
853  }
854 };
855 
856 // WebAssembly target
857 template <typename Target>
858 class LLVM_LIBRARY_VISIBILITY WebAssemblyOSTargetInfo
859  : public OSTargetInfo<Target> {
860 protected:
861  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
862  MacroBuilder &Builder) const {
863  // A common platform macro.
864  if (Opts.POSIXThreads)
865  Builder.defineMacro("_REENTRANT");
866  // Follow g++ convention and predefine _GNU_SOURCE for C++.
867  if (Opts.CPlusPlus)
868  Builder.defineMacro("_GNU_SOURCE");
869  // Indicate that we have __float128.
870  Builder.defineMacro("__FLOAT128__");
871  }
872 
873 public:
874  explicit WebAssemblyOSTargetInfo(const llvm::Triple &Triple,
875  const TargetOptions &Opts)
876  : OSTargetInfo<Target>(Triple, Opts) {
877  this->MCountName = "__mcount";
878  this->TheCXXABI.set(TargetCXXABI::WebAssembly);
879  this->HasFloat128 = true;
880  }
881 };
882 
883 // WASI target
884 template <typename Target>
885 class LLVM_LIBRARY_VISIBILITY WASITargetInfo
886  : public WebAssemblyOSTargetInfo<Target> {
887  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
888  MacroBuilder &Builder) const final {
889  WebAssemblyOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
890  Builder.defineMacro("__wasi__");
891  }
892 
893 public:
894  explicit WASITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
895  : WebAssemblyOSTargetInfo<Target>(Triple, Opts) {}
896 };
897 
898 // Emscripten target
899 template <typename Target>
900 class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
901  : public WebAssemblyOSTargetInfo<Target> {
902  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
903  MacroBuilder &Builder) const final {
904  WebAssemblyOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
905  Builder.defineMacro("__EMSCRIPTEN__");
906  }
907 
908 public:
909  explicit EmscriptenTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
910  : WebAssemblyOSTargetInfo<Target>(Triple, Opts) {}
911 };
912 
913 } // namespace targets
914 } // namespace clang
915 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
PSPTargetInfo(const llvm::Triple &Triple)
Definition: OSTargets.h:500
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:42
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:54
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:293
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:280
unsigned getFloatEvalMethod() const override
Definition: OSTargets.h:706
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:838
WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:778
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
Definition: TargetInfo.cpp:244
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:81
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:326
const char * getStaticInitSectionSpecifier() const override
Definition: OSTargets.h:126
Options for controlling the target.
Definition: TargetOptions.h:26
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:507
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:714
WebAssemblyOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:874
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:214
LinuxTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:399
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const
Definition: OSTargets.h:861
bool hasProtectedVisibility() const override
Darwin does not support protected visibility.
Definition: OSTargets.h:134
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
RTEMSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:581
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:62
AnanasTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:70
NaClTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:801
const char * getStaticInitSectionSpecifier() const override
Definition: OSTargets.h:422
bool hasInt128Type() const override
Definition: OSTargets.h:707
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:373
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:270
AIXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:695
void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:101
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:182
std::string isValidSectionSpecifier(StringRef SR) const override
Definition: OSTargets.h:117
KFreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:285
EmscriptenTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:909
SolarisTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:633
void getVisualStudioDefines(const LangOptions &Opts, MacroBuilder &Builder) const
Definition: OSTargets.h:723
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
Definition: OSTargets.h:31
DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:88
HaikuTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:304
DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:194
FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:244
void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple, StringRef &PlatformName, VersionTuple &PlatformMinVersion)
Definition: OSTargets.cpp:22
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:534
#define FREEBSD_CC_VERSION
Definition: OSTargets.h:207
FuchsiaTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:850
CloudABITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:54
The WebAssembly ABI is a modified version of the Itanium ABI.
Definition: TargetCXXABI.h:104
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition: TargetInfo.h:104
Dataflow Directional Tag Classes.
PS4OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:545
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:570
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:349
HurdTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:341
NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:442
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:431
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:788
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:490
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:606
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:452
MinixTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:365
unsigned getExnObjectAlignment() const override
Definition: OSTargets.h:136
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:651
OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:28
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
Definition: MacroBuilder.h:29
OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:466
WASITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:894
PS3PPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:520
TargetInfo::IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final
Definition: OSTargets.h:167