From e5712054fa8ff047455cdb03d45762d3eaf153c9 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Mon, 30 Jul 2018 10:59:14 +0200 Subject: [PATCH 1/2] Add support for writing HermitCore (https://hermitcore.org) ELF binaries. HermitCore is a POSIX-compatible kernel for running a single application in an isolated environment to get maximum performance and predictable runtime behavior. It can either be used bare-metal on hardware or a VM (Unikernel) or side by side to an existing Linux system (Multikernel). Due to the latter feature, HermitCore binaries are marked with a different OS ABI to let the Linux ELF loader distinguish them from regular Unix/Linux binaries and load them using the HermitCore "proxy" tool. --- include/llvm/ADT/Triple.h | 3 ++- include/llvm/BinaryFormat/ELF.h | 1 + include/llvm/MC/MCELFObjectWriter.h | 2 ++ lib/Support/Triple.cpp | 2 ++ tools/llvm-readobj/ELFDumper.cpp | 1 + unittests/ADT/TripleTest.cpp | 6 ++++++ 6 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h index c95b16dd4e8c..76fe6d38f2d0 100644 --- a/include/llvm/ADT/Triple.h +++ b/include/llvm/ADT/Triple.h @@ -182,7 +182,8 @@ class Triple { Mesa3D, Contiki, AMDPAL, // AMD PAL Runtime - LastOSType = AMDPAL + HermitCore, // HermitCore Unikernel/Multikernel + LastOSType = HermitCore }; enum EnvironmentType { UnknownEnvironment, diff --git a/include/llvm/BinaryFormat/ELF.h b/include/llvm/BinaryFormat/ELF.h index 37940a42af9d..c815c1587c1c 100644 --- a/include/llvm/BinaryFormat/ELF.h +++ b/include/llvm/BinaryFormat/ELF.h @@ -357,6 +357,7 @@ enum { ELFOSABI_AMDGPU_HSA = 64, // AMD HSA runtime ELFOSABI_AMDGPU_PAL = 65, // AMD PAL runtime ELFOSABI_AMDGPU_MESA3D = 66, // AMD GCN GPUs (GFX6+) for MESA runtime + ELFOSABI_HERMITCORE = 66, // HermitCore Unikernel/Multikernel ELFOSABI_ARM = 97, // ARM ELFOSABI_C6000_ELFABI = 64, // Bare-metal TMS320C6000 ELFOSABI_C6000_LINUX = 65, // Linux TMS320C6000 diff --git a/include/llvm/MC/MCELFObjectWriter.h b/include/llvm/MC/MCELFObjectWriter.h index bff58fef6af9..d8c606b50070 100644 --- a/include/llvm/MC/MCELFObjectWriter.h +++ b/include/llvm/MC/MCELFObjectWriter.h @@ -73,6 +73,8 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter { switch (OSType) { case Triple::CloudABI: return ELF::ELFOSABI_CLOUDABI; + case Triple::HermitCore: + return ELF::ELFOSABI_HERMITCORE; case Triple::PS4: case Triple::FreeBSD: return ELF::ELFOSABI_FREEBSD; diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index b14d6492b1ed..10b4fce37975 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -209,6 +209,7 @@ StringRef Triple::getOSTypeName(OSType Kind) { case Mesa3D: return "mesa3d"; case Contiki: return "contiki"; case AMDPAL: return "amdpal"; + case HermitCore: return "hermit"; } llvm_unreachable("Invalid OSType"); @@ -502,6 +503,7 @@ static Triple::OSType parseOS(StringRef OSName) { .StartsWith("mesa3d", Triple::Mesa3D) .StartsWith("contiki", Triple::Contiki) .StartsWith("amdpal", Triple::AMDPAL) + .StartsWith("hermit", Triple::HermitCore) .Default(Triple::UnknownOS); } diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 9a2be3100ac6..c4e405c2c17f 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -868,6 +868,7 @@ static const EnumEntry ElfOSABI[] = { {"AROS", "AROS", ELF::ELFOSABI_AROS}, {"FenixOS", "FenixOS", ELF::ELFOSABI_FENIXOS}, {"CloudABI", "CloudABI", ELF::ELFOSABI_CLOUDABI}, + {"HermitCore", "HermitCore", ELF::ELFOSABI_HERMITCORE}, {"Standalone", "Standalone App", ELF::ELFOSABI_STANDALONE} }; diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp index 3963a966ef62..a3d4920eebec 100644 --- a/unittests/ADT/TripleTest.cpp +++ b/unittests/ADT/TripleTest.cpp @@ -235,6 +235,12 @@ TEST(TripleTest, ParsedIDs) { EXPECT_EQ(Triple::Fuchsia, T.getOS()); EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("x86_64-unknown-hermit"); + EXPECT_EQ(Triple::x86_64, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::HermitCore, 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()); From 04277e8c32e4552dcd16154e74acdbd48ce19b97 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Wed, 15 Aug 2018 13:38:33 +0200 Subject: [PATCH 2/2] Update patch to latest version from https://reviews.llvm.org/D48964 --- include/llvm/BinaryFormat/ELF.h | 1 - include/llvm/MC/MCELFObjectWriter.h | 2 +- tools/llvm-readobj/ELFDumper.cpp | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/llvm/BinaryFormat/ELF.h b/include/llvm/BinaryFormat/ELF.h index c815c1587c1c..37940a42af9d 100644 --- a/include/llvm/BinaryFormat/ELF.h +++ b/include/llvm/BinaryFormat/ELF.h @@ -357,7 +357,6 @@ enum { ELFOSABI_AMDGPU_HSA = 64, // AMD HSA runtime ELFOSABI_AMDGPU_PAL = 65, // AMD PAL runtime ELFOSABI_AMDGPU_MESA3D = 66, // AMD GCN GPUs (GFX6+) for MESA runtime - ELFOSABI_HERMITCORE = 66, // HermitCore Unikernel/Multikernel ELFOSABI_ARM = 97, // ARM ELFOSABI_C6000_ELFABI = 64, // Bare-metal TMS320C6000 ELFOSABI_C6000_LINUX = 65, // Linux TMS320C6000 diff --git a/include/llvm/MC/MCELFObjectWriter.h b/include/llvm/MC/MCELFObjectWriter.h index d8c606b50070..58cb3aeda8d9 100644 --- a/include/llvm/MC/MCELFObjectWriter.h +++ b/include/llvm/MC/MCELFObjectWriter.h @@ -74,7 +74,7 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter { case Triple::CloudABI: return ELF::ELFOSABI_CLOUDABI; case Triple::HermitCore: - return ELF::ELFOSABI_HERMITCORE; + return ELF::ELFOSABI_STANDALONE; case Triple::PS4: case Triple::FreeBSD: return ELF::ELFOSABI_FREEBSD; diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index c4e405c2c17f..9a2be3100ac6 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -868,7 +868,6 @@ static const EnumEntry ElfOSABI[] = { {"AROS", "AROS", ELF::ELFOSABI_AROS}, {"FenixOS", "FenixOS", ELF::ELFOSABI_FENIXOS}, {"CloudABI", "CloudABI", ELF::ELFOSABI_CLOUDABI}, - {"HermitCore", "HermitCore", ELF::ELFOSABI_HERMITCORE}, {"Standalone", "Standalone App", ELF::ELFOSABI_STANDALONE} };