From b0aab57571fc6ea9d3778fbfb2683733b5668445 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Fri, 19 Jun 2020 13:43:35 +0200 Subject: [PATCH] [SystemZ/ZOS] Add binary format goff and operating system zos to the triple Adds the binary format goff and the operating system zos to the triple class. goff is selected as default binary format if zos is choosen as operating system. No further functionality is added. Reviewers: efriedma, tahonermann, hubert.reinterpertcast, MaskRay Reviewed By: efriedma, tahonermann, hubert.reinterpertcast Differential Revision: https://reviews.llvm.org/D82081 --- include/llvm/ADT/Triple.h | 7 ++++++ include/llvm/Support/TargetRegistry.h | 2 ++ lib/Bitcode/Writer/BitcodeWriter.cpp | 6 +++++ lib/MC/MCObjectFileInfo.cpp | 4 ++++ lib/Support/Triple.cpp | 10 +++++++- .../Instrumentation/AddressSanitizer.cpp | 3 ++- unittests/ADT/TripleTest.cpp | 24 +++++++++++++++++++ 7 files changed, 54 insertions(+), 2 deletions(-) diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h index c578c097c6f..7c3a4b2b699 100644 --- a/include/llvm/ADT/Triple.h +++ b/include/llvm/ADT/Triple.h @@ -173,6 +173,7 @@ public: OpenBSD, Solaris, Win32, + ZOS, Haiku, Minix, RTEMS, @@ -224,6 +225,7 @@ public: COFF, ELF, + GOFF, MachO, Wasm, XCOFF, @@ -468,6 +470,8 @@ public: return getSubArch() == Triple::ARMSubArch_v7k; } + bool isOSzOS() const { return getOS() == Triple::ZOS; } + /// isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS). bool isOSDarwin() const { return isMacOSX() || isiOS() || isWatchOS(); @@ -620,6 +624,9 @@ public: return getObjectFormat() == Triple::COFF; } + /// Tests whether the OS uses the GOFF binary format. + bool isOSBinFormatGOFF() const { return getObjectFormat() == Triple::GOFF; } + /// Tests whether the environment is MachO. bool isOSBinFormatMachO() const { return getObjectFormat() == Triple::MachO; diff --git a/include/llvm/Support/TargetRegistry.h b/include/llvm/Support/TargetRegistry.h index d91eabae823..2c65eb60f91 100644 --- a/include/llvm/Support/TargetRegistry.h +++ b/include/llvm/Support/TargetRegistry.h @@ -510,6 +510,8 @@ public: S = createWasmStreamer(Ctx, std::move(TAB), std::move(OW), std::move(Emitter), RelaxAll); break; + case Triple::GOFF: + report_fatal_error("GOFF MCObjectStreamer not implemented yet"); case Triple::XCOFF: S = createXCOFFStreamer(Ctx, std::move(TAB), std::move(OW), std::move(Emitter), RelaxAll); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 7afef397e05..b6b2eb3b0db 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4740,6 +4740,9 @@ static const char *getSectionNameForBitcode(const Triple &T) { case Triple::Wasm: case Triple::UnknownObjectFormat: return ".llvmbc"; + case Triple::GOFF: + llvm_unreachable("GOFF is not yet implemented"); + break; case Triple::XCOFF: llvm_unreachable("XCOFF is not yet implemented"); break; @@ -4756,6 +4759,9 @@ static const char *getSectionNameForCommandline(const Triple &T) { case Triple::Wasm: case Triple::UnknownObjectFormat: return ".llvmcmd"; + case Triple::GOFF: + llvm_unreachable("GOFF is not yet implemented"); + break; case Triple::XCOFF: llvm_unreachable("XCOFF is not yet implemented"); break; diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp index b77a9635f64..a400cc9de75 100644 --- a/lib/MC/MCObjectFileInfo.cpp +++ b/lib/MC/MCObjectFileInfo.cpp @@ -904,6 +904,9 @@ void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC, Env = IsWasm; initWasmMCObjectFileInfo(TT); break; + case Triple::GOFF: + report_fatal_error("Cannot initialize MC for GOFF object file format"); + break; case Triple::XCOFF: Env = IsXCOFF; initXCOFFMCObjectFileInfo(TT); @@ -923,6 +926,7 @@ MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, case Triple::MachO: case Triple::COFF: case Triple::Wasm: + case Triple::GOFF: case Triple::XCOFF: case Triple::UnknownObjectFormat: report_fatal_error("Cannot get DWARF comdat section for this object file " diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index 72648273b4c..7c2c44a5380 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -215,6 +215,7 @@ StringRef Triple::getOSTypeName(OSType Kind) { case WASI: return "wasi"; case WatchOS: return "watchos"; case Win32: return "windows"; + case ZOS: return "zos"; } llvm_unreachable("Invalid OSType"); @@ -499,6 +500,7 @@ static Triple::OSType parseOS(StringRef OSName) { .StartsWith("solaris", Triple::Solaris) .StartsWith("win32", Triple::Win32) .StartsWith("windows", Triple::Win32) + .StartsWith("zos", Triple::ZOS) .StartsWith("haiku", Triple::Haiku) .StartsWith("minix", Triple::Minix) .StartsWith("rtems", Triple::RTEMS) @@ -552,6 +554,7 @@ static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) { .EndsWith("xcoff", Triple::XCOFF) .EndsWith("coff", Triple::COFF) .EndsWith("elf", Triple::ELF) + .EndsWith("goff", Triple::GOFF) .EndsWith("macho", Triple::MachO) .EndsWith("wasm", Triple::Wasm) .Default(Triple::UnknownObjectFormat); @@ -643,6 +646,7 @@ static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) { case Triple::UnknownObjectFormat: return ""; case Triple::COFF: return "coff"; case Triple::ELF: return "elf"; + case Triple::GOFF: return "goff"; case Triple::MachO: return "macho"; case Triple::Wasm: return "wasm"; case Triple::XCOFF: return "xcoff"; @@ -700,7 +704,6 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { case Triple::sparcv9: case Triple::spir64: case Triple::spir: - case Triple::systemz: case Triple::tce: case Triple::tcele: case Triple::thumbeb: @@ -714,6 +717,11 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { return Triple::XCOFF; return Triple::ELF; + case Triple::systemz: + if (T.isOSzOS()) + return Triple::GOFF; + return Triple::ELF; + case Triple::wasm32: case Triple::wasm64: return Triple::Wasm; diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 85ab19c20e8..5d52a4b0fc1 100644 --- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1950,9 +1950,10 @@ StringRef ModuleAddressSanitizer::getGlobalMetadataSection() const { case Triple::ELF: return "asan_globals"; case Triple::MachO: return "__DATA,__asan_globals,regular"; case Triple::Wasm: + case Triple::GOFF: case Triple::XCOFF: report_fatal_error( - "ModuleAddressSanitizer not implemented for object file format."); + "ModuleAddressSanitizer not implemented for object file format"); case Triple::UnknownObjectFormat: break; } diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp index 1852d7b6a1b..1a6b0557bf5 100644 --- a/unittests/ADT/TripleTest.cpp +++ b/unittests/ADT/TripleTest.cpp @@ -136,6 +136,18 @@ TEST(TripleTest, ParsedIDs) { EXPECT_EQ(Triple::FreeBSD, T.getOS()); EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("s390x-ibm-zos"); + EXPECT_EQ(Triple::systemz, T.getArch()); + EXPECT_EQ(Triple::IBM, T.getVendor()); + EXPECT_EQ(Triple::ZOS, T.getOS()); + EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + + T = Triple("systemz-ibm-zos"); + EXPECT_EQ(Triple::systemz, T.getArch()); + EXPECT_EQ(Triple::IBM, T.getVendor()); + EXPECT_EQ(Triple::ZOS, T.getOS()); + EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("arm-none-none-eabi"); EXPECT_EQ(Triple::arm, T.getArch()); EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); @@ -1314,6 +1326,15 @@ TEST(TripleTest, FileFormat) { EXPECT_EQ(Triple::ELF, Triple("i686-pc-windows-msvc-elf").getObjectFormat()); EXPECT_EQ(Triple::ELF, Triple("i686-pc-cygwin-elf").getObjectFormat()); + EXPECT_EQ(Triple::ELF, Triple("systemz-ibm-linux").getObjectFormat()); + EXPECT_EQ(Triple::ELF, Triple("systemz-ibm-unknown").getObjectFormat()); + + EXPECT_EQ(Triple::GOFF, Triple("s390x-ibm-zos").getObjectFormat()); + EXPECT_EQ(Triple::GOFF, Triple("systemz-ibm-zos").getObjectFormat()); + EXPECT_EQ(Triple::GOFF, Triple("s390x-ibm-zos-goff").getObjectFormat()); + EXPECT_EQ(Triple::GOFF, Triple("s390x-unknown-zos-goff").getObjectFormat()); + EXPECT_EQ(Triple::GOFF, Triple("s390x---goff").getObjectFormat()); + EXPECT_EQ(Triple::Wasm, Triple("wasm32-unknown-unknown").getObjectFormat()); EXPECT_EQ(Triple::Wasm, Triple("wasm64-unknown-unknown").getObjectFormat()); EXPECT_EQ(Triple::Wasm, Triple("wasm32-wasi").getObjectFormat()); @@ -1360,6 +1381,9 @@ TEST(TripleTest, FileFormat) { T.setObjectFormat(Triple::XCOFF); EXPECT_EQ(Triple::XCOFF, T.getObjectFormat()); + + T.setObjectFormat(Triple::GOFF); + EXPECT_EQ(Triple::GOFF, T.getObjectFormat()); } TEST(TripleTest, NormalizeWindows) {