diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h index 2e02045f1573..18f8fcc12a5a 100644 --- a/include/llvm/ADT/Triple.h +++ b/include/llvm/ADT/Triple.h @@ -144,6 +144,7 @@ class Triple { Darwin, DragonFly, FreeBSD, + Fuchsia, IOS, KFreeBSD, Linux, @@ -462,6 +463,10 @@ class Triple { return getOS() == Triple::FreeBSD; } + bool isOSFuchsia() const { + return getOS() == Triple::Fuchsia; + } + bool isOSDragonFly() const { return getOS() == Triple::DragonFly; } bool isOSSolaris() const { diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index bc12203d8176..1470563a6e9c 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -168,6 +168,7 @@ StringRef Triple::getOSTypeName(OSType Kind) { case Darwin: return "darwin"; case DragonFly: return "dragonfly"; case FreeBSD: return "freebsd"; + case Fuchsia: return "fuchsia"; case IOS: return "ios"; case KFreeBSD: return "kfreebsd"; case Linux: return "linux"; @@ -438,6 +439,7 @@ static Triple::OSType parseOS(StringRef OSName) { .StartsWith("darwin", Triple::Darwin) .StartsWith("dragonfly", Triple::DragonFly) .StartsWith("freebsd", Triple::FreeBSD) + .StartsWith("fuchsia", Triple::Fuchsia) .StartsWith("ios", Triple::IOS) .StartsWith("kfreebsd", Triple::KFreeBSD) .StartsWith("linux", Triple::Linux) diff --git a/lib/Target/X86/X86TargetMachine.cpp b/lib/Target/X86/X86TargetMachine.cpp index d231581e9de8..53480eb0ba91 100644 --- a/lib/Target/X86/X86TargetMachine.cpp +++ b/lib/Target/X86/X86TargetMachine.cpp @@ -54,6 +54,8 @@ static std::unique_ptr createTLOF(const Triple &TT) { return make_unique(); if (TT.isOSLinux() || TT.isOSNaCl()) return make_unique(); + if (TT.isOSFuchsia()) + return make_unique(); if (TT.isOSBinFormatELF()) return make_unique(); if (TT.isKnownWindowsMSVCEnvironment() || TT.isWindowsCoreCLREnvironment()) diff --git a/lib/Target/X86/X86TargetObjectFile.cpp b/lib/Target/X86/X86TargetObjectFile.cpp index aa837c3f30c0..d050ec0287ff 100644 --- a/lib/Target/X86/X86TargetObjectFile.cpp +++ b/lib/Target/X86/X86TargetObjectFile.cpp @@ -72,6 +72,13 @@ X86FreeBSDTargetObjectFile::Initialize(MCContext &Ctx, InitializeELF(TM.Options.UseInitArray); } +void +X86FuchsiaTargetObjectFile::Initialize(MCContext &Ctx, + const TargetMachine &TM) { + TargetLoweringObjectFileELF::Initialize(Ctx, TM); + InitializeELF(TM.Options.UseInitArray); +} + void X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { diff --git a/lib/Target/X86/X86TargetObjectFile.h b/lib/Target/X86/X86TargetObjectFile.h index b57f0bb50164..39d2e84e5ed7 100644 --- a/lib/Target/X86/X86TargetObjectFile.h +++ b/lib/Target/X86/X86TargetObjectFile.h @@ -55,6 +55,11 @@ namespace llvm { void Initialize(MCContext &Ctx, const TargetMachine &TM) override; }; + /// \brief This implementation is used for Fuchsia on x86-64. + class X86FuchsiaTargetObjectFile : public X86ELFTargetObjectFile { + void Initialize(MCContext &Ctx, const TargetMachine &TM) override; + }; + /// X86LinuxNaClTargetObjectFile - This implementation is used for linux and /// Native Client on x86 and x86-64. class X86LinuxNaClTargetObjectFile : public X86ELFTargetObjectFile { diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp index 8d0539a118c2..3555e38e45c1 100644 --- a/unittests/ADT/TripleTest.cpp +++ b/unittests/ADT/TripleTest.cpp @@ -200,6 +200,12 @@ TEST(TripleTest, ParsedIDs) { EXPECT_EQ(Triple::CloudABI, T.getOS()); EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("x86_64-unknown-fuchsia"); + EXPECT_EQ(Triple::x86_64, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::Fuchsia, T.getOS()); + EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("wasm32-unknown-unknown"); EXPECT_EQ(Triple::wasm32, T.getArch()); EXPECT_EQ(Triple::UnknownVendor, T.getVendor());