diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h index 70d8879bf05..25494c55392 100644 --- a/include/llvm/ADT/Triple.h +++ b/include/llvm/ADT/Triple.h @@ -219,6 +219,7 @@ public: ELF, MachO, Wasm, + XCOFF, }; private: @@ -598,6 +599,11 @@ public: !isAndroid(); } + /// Tests whether the OS is AIX. + bool isOSAIX() const { + return getOS() == Triple::AIX; + } + /// Tests whether the OS uses the ELF binary format. bool isOSBinFormatELF() const { return getObjectFormat() == Triple::ELF; @@ -618,6 +624,11 @@ public: return getObjectFormat() == Triple::Wasm; } + /// Tests whether the OS uses the XCOFF binary format. + bool isOSBinFormatXCOFF() const { + return getObjectFormat() == Triple::XCOFF; + } + /// Tests whether the target is the PS4 CPU bool isPS4CPU() const { return getArch() == Triple::x86_64 && diff --git a/include/llvm/MC/MCObjectFileInfo.h b/include/llvm/MC/MCObjectFileInfo.h index 0c1ade48fec..5d45d21a3a2 100644 --- a/include/llvm/MC/MCObjectFileInfo.h +++ b/include/llvm/MC/MCObjectFileInfo.h @@ -380,7 +380,7 @@ public: return EHFrameSection; } - enum Environment { IsMachO, IsELF, IsCOFF, IsWasm }; + enum Environment { IsMachO, IsELF, IsCOFF, IsWasm, IsXCOFF }; Environment getObjectFileType() const { return Env; } bool isPositionIndependent() const { return PositionIndependent; } diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 69e18ed8998..49fad131a2c 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -161,6 +161,9 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry *Name, return new (Name, *this) MCSymbolMachO(Name, IsTemporary); case MCObjectFileInfo::IsWasm: return new (Name, *this) MCSymbolWasm(Name, IsTemporary); + case MCObjectFileInfo::IsXCOFF: + // TODO: Need to implement class MCSymbolXCOFF. + break; } } return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name, diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp index d9f1b2cb059..1c845f64050 100644 --- a/lib/MC/MCObjectFileInfo.cpp +++ b/lib/MC/MCObjectFileInfo.cpp @@ -801,6 +801,11 @@ void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC, Env = IsWasm; initWasmMCObjectFileInfo(TT); break; + case Triple::XCOFF: + Env = IsXCOFF; + // TODO: Initialize MCObjectFileInfo for XCOFF format when + // MCSectionXCOFF is ready. + break; case Triple::UnknownObjectFormat: report_fatal_error("Cannot initialize MC for unknown object file format."); break; @@ -816,6 +821,7 @@ MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, case Triple::MachO: case Triple::COFF: case Triple::Wasm: + case Triple::XCOFF: case Triple::UnknownObjectFormat: report_fatal_error("Cannot get DWARF comdat section for this object file " "format: not implemented."); diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 4b487825935..a153ee184e3 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -710,6 +710,9 @@ AsmParser::AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out, case MCObjectFileInfo::IsWasm: PlatformParser.reset(createWasmAsmParser()); break; + case MCObjectFileInfo::IsXCOFF: + // TODO: Need to implement createXCOFFAsmParser for XCOFF format. + break; } PlatformParser->Initialize(*this); diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index ab9fcccd5c4..83ce4f0f122 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -534,6 +534,9 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) { static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) { return StringSwitch(EnvironmentName) + // "xcoff" must come before "coff" because of the order-dependendent + // pattern matching. + .EndsWith("xcoff", Triple::XCOFF) .EndsWith("coff", Triple::COFF) .EndsWith("elf", Triple::ELF) .EndsWith("macho", Triple::MachO) @@ -622,6 +625,7 @@ static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) { case Triple::ELF: return "elf"; case Triple::MachO: return "macho"; case Triple::Wasm: return "wasm"; + case Triple::XCOFF: return "xcoff"; } llvm_unreachable("unknown object format type"); } @@ -686,6 +690,8 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { case Triple::ppc64: if (T.isOSDarwin()) return Triple::MachO; + else if (T.isOSAIX()) + return Triple::XCOFF; return Triple::ELF; case Triple::wasm32: diff --git a/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index 76a0665239d..c3779233870 100644 --- a/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -5594,6 +5594,9 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) { case MCObjectFileInfo::IsWasm: CurrentFormat = WASM; break; + case MCObjectFileInfo::IsXCOFF: + llvm_unreachable("unexpected object format"); + break; } if (~Prefix->SupportedFormats & CurrentFormat) { diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp index 6ad6b62e90c..a83ef44211c 100644 --- a/unittests/ADT/TripleTest.cpp +++ b/unittests/ADT/TripleTest.cpp @@ -1258,6 +1258,11 @@ TEST(TripleTest, FileFormat) { EXPECT_EQ(Triple::Wasm, Triple("wasm64-unknown-wasi-musl-wasm").getObjectFormat()); + EXPECT_EQ(Triple::XCOFF, Triple("powerpc-ibm-aix").getObjectFormat()); + EXPECT_EQ(Triple::XCOFF, Triple("powerpc64-ibm-aix").getObjectFormat()); + EXPECT_EQ(Triple::XCOFF, Triple("powerpc---xcoff").getObjectFormat()); + EXPECT_EQ(Triple::XCOFF, Triple("powerpc64---xcoff").getObjectFormat()); + Triple MSVCNormalized(Triple::normalize("i686-pc-windows-msvc-elf")); EXPECT_EQ(Triple::ELF, MSVCNormalized.getObjectFormat()); @@ -1276,6 +1281,9 @@ TEST(TripleTest, FileFormat) { T.setObjectFormat(Triple::MachO); EXPECT_EQ(Triple::MachO, T.getObjectFormat()); + + T.setObjectFormat(Triple::XCOFF); + EXPECT_EQ(Triple::XCOFF, T.getObjectFormat()); } TEST(TripleTest, NormalizeWindows) {