Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit ff8ecfc

Browse files
petrhosekpftbest
authored andcommitted
Add triple for Fuchsia
Fuchsia is a new operating system. Change-Id: Id2cd63b5a98c71be555d64e4c4228b0d273610af
1 parent a5d61b2 commit ff8ecfc

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed

cmake/platforms/Fuchsia.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Toolchain config for Fuchsia.
2+
3+
SET(CMAKE_SYSTEM_NAME Fuchsia)
4+
5+
if(NOT CMAKE_C_COMPILER)
6+
SET(CMAKE_C_COMPILER clang)
7+
endif()
8+
9+
if(NOT CMAKE_CXX_COMPILER)
10+
set(CMAKE_CXX_COMPILER clang++)
11+
endif()
12+
13+
if(NOT CMAKE_AR)
14+
set(CMAKE_CXX_COMPILER llvm-ar)
15+
endif()
16+
17+
if(NOT CMAKE_RANLIB)
18+
set(CMAKE_CXX_COMPILER llvm-ranlib)
19+
endif()
20+
21+
set(FUCHSIA 1 CACHE STRING "" FORCE)
22+
23+
# let's pretend that Fuchsia is Unix for a while
24+
set(UNIX 1 CACHE STRING "" FORCE)
25+
26+
# search for programs in the build host directories
27+
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
28+
# for libraries and headers in the target directories
29+
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
30+
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

include/llvm/ADT/Triple.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class Triple {
145145
Darwin,
146146
DragonFly,
147147
FreeBSD,
148+
Fuchsia,
148149
IOS,
149150
KFreeBSD,
150151
Linux,
@@ -463,6 +464,10 @@ class Triple {
463464
return getOS() == Triple::FreeBSD;
464465
}
465466

467+
bool isOSFuchsia() const {
468+
return getOS() == Triple::Fuchsia;
469+
}
470+
466471
bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
467472

468473
bool isOSSolaris() const {

lib/Support/Triple.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ const char *Triple::getOSTypeName(OSType Kind) {
171171
case Darwin: return "darwin";
172172
case DragonFly: return "dragonfly";
173173
case FreeBSD: return "freebsd";
174+
case Fuchsia: return "fuchsia";
174175
case IOS: return "ios";
175176
case KFreeBSD: return "kfreebsd";
176177
case Linux: return "linux";
@@ -443,6 +444,7 @@ static Triple::OSType parseOS(StringRef OSName) {
443444
.StartsWith("darwin", Triple::Darwin)
444445
.StartsWith("dragonfly", Triple::DragonFly)
445446
.StartsWith("freebsd", Triple::FreeBSD)
447+
.StartsWith("fuchsia", Triple::Fuchsia)
446448
.StartsWith("ios", Triple::IOS)
447449
.StartsWith("kfreebsd", Triple::KFreeBSD)
448450
.StartsWith("linux", Triple::Linux)

lib/Target/X86/X86TargetMachine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
5252

5353
if (TT.isOSLinux() || TT.isOSNaCl())
5454
return make_unique<X86LinuxNaClTargetObjectFile>();
55+
if (TT.isOSFuchsia())
56+
return make_unique<X86FuchsiaTargetObjectFile>();
5557
if (TT.isOSBinFormatELF())
5658
return make_unique<X86ELFTargetObjectFile>();
5759
if (TT.isKnownWindowsMSVCEnvironment() || TT.isWindowsCoreCLREnvironment())

lib/Target/X86/X86TargetObjectFile.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx,
7373
InitializeELF(TM.Options.UseInitArray);
7474
}
7575

76+
void
77+
X86FuchsiaTargetObjectFile::Initialize(MCContext &Ctx,
78+
const TargetMachine &TM) {
79+
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
80+
InitializeELF(TM.Options.UseInitArray);
81+
}
82+
7683
const MCExpr *X86WindowsTargetObjectFile::lowerRelativeReference(
7784
const GlobalValue *LHS, const GlobalValue *RHS, Mangler &Mang,
7885
const TargetMachine &TM) const {

lib/Target/X86/X86TargetObjectFile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ namespace llvm {
5555
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
5656
};
5757

58+
/// \brief This implementation is used for Fuchsia on x86-64.
59+
class X86FuchsiaTargetObjectFile : public X86ELFTargetObjectFile {
60+
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
61+
};
62+
5863
/// \brief This implementation is used for Windows targets on x86 and x86-64.
5964
class X86WindowsTargetObjectFile : public TargetLoweringObjectFileCOFF {
6065
const MCExpr *

unittests/ADT/TripleTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ TEST(TripleTest, ParsedIDs) {
200200
EXPECT_EQ(Triple::CloudABI, T.getOS());
201201
EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
202202

203+
T = Triple("x86_64-unknown-fuchsia");
204+
EXPECT_EQ(Triple::x86_64, T.getArch());
205+
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
206+
EXPECT_EQ(Triple::Fuchsia, T.getOS());
207+
EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
208+
203209
T = Triple("wasm32-unknown-unknown");
204210
EXPECT_EQ(Triple::wasm32, T.getArch());
205211
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());

0 commit comments

Comments
 (0)