From dc45212ef12fe0b1e8f95a01cd8a056e8060c825 Mon Sep 17 00:00:00 2001 From: no92 Date: Sun, 17 Nov 2024 23:03:27 +0100 Subject: [PATCH] llvm: enable managarm target for RISC-V --- bootstrap.d/managarm-build.y4.yml | 2 +- bootstrap.d/sys-devel.y4.yml | 2 +- .../0001-llvm-Add-managarm-OS-target.patch | 21 +++++++--- .../0002-clang-Add-managarm-OS-target.patch | 40 +++++++++++++++---- .../llvm/0003-clang-Add-managarm-tests.patch | 4 +- .../llvm/0004-WIP-kernel-environment.patch | 6 +-- 6 files changed, 55 insertions(+), 20 deletions(-) diff --git a/bootstrap.d/managarm-build.y4.yml b/bootstrap.d/managarm-build.y4.yml index f8fb8fe41..32d8a6645 100644 --- a/bootstrap.d/managarm-build.y4.yml +++ b/bootstrap.d/managarm-build.y4.yml @@ -197,7 +197,7 @@ tools: - binutils tools_required: - host-cmake - revision: 2 + revision: 3 configure: - args: - 'cmake' diff --git a/bootstrap.d/sys-devel.y4.yml b/bootstrap.d/sys-devel.y4.yml index 790485ea5..9e547c7d9 100644 --- a/bootstrap.d/sys-devel.y4.yml +++ b/bootstrap.d/sys-devel.y4.yml @@ -365,7 +365,7 @@ packages: pkgs_required: - mlibc - zlib - revision: 2 + revision: 3 configure: - args: - 'cmake' diff --git a/patches/llvm/0001-llvm-Add-managarm-OS-target.patch b/patches/llvm/0001-llvm-Add-managarm-OS-target.patch index fbb61cb10..49ac72681 100644 --- a/patches/llvm/0001-llvm-Add-managarm-OS-target.patch +++ b/patches/llvm/0001-llvm-Add-managarm-OS-target.patch @@ -1,15 +1,15 @@ -From 4abf6abfcd5711de7fc24af4f08f259798996440 Mon Sep 17 00:00:00 2001 +From 9d681fdec1f5f86244dd0ba429f35805e1ddde61 Mon Sep 17 00:00:00 2001 From: no92 Date: Fri, 6 Sep 2024 21:17:53 +0200 -Subject: [PATCH 1/5] [llvm] Add managarm OS target +Subject: [PATCH 1/4] [llvm] Add managarm OS target --- llvm/include/llvm/ADT/bit.h | 2 +- - llvm/include/llvm/TargetParser/Triple.h | 2 ++ + llvm/include/llvm/TargetParser/Triple.h | 6 ++++++ llvm/lib/Support/Unix/Path.inc | 13 ++++++++----- llvm/lib/TargetParser/Triple.cpp | 4 ++++ llvm/unittests/TargetParser/TripleTest.cpp | 18 ++++++++++++++++++ - 5 files changed, 33 insertions(+), 6 deletions(-) + 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h index c42b5e686b..7a36ef2eb5 100644 @@ -25,7 +25,7 @@ index c42b5e686b..7a36ef2eb5 100644 #elif defined(_AIX) #include diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h -index 779bd9017d..818c3a9b5b 100644 +index 779bd9017d..3ff75723b3 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -207,6 +207,7 @@ public: @@ -44,6 +44,17 @@ index 779bd9017d..818c3a9b5b 100644 PAuthTest, +@@ -821,6 +823,10 @@ public: + + bool isVulkanOS() const { return getOS() == Triple::Vulkan; } + ++ bool isOSManagarm() const { ++ return getOS() == Triple::Managarm; ++ } ++ + bool isShaderStageEnvironment() const { + EnvironmentType Env = getEnvironment(); + return Env == Triple::Pixel || Env == Triple::Vertex || diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index 44097bad7b..f7e5d8748b 100644 --- a/llvm/lib/Support/Unix/Path.inc diff --git a/patches/llvm/0002-clang-Add-managarm-OS-target.patch b/patches/llvm/0002-clang-Add-managarm-OS-target.patch index bcdd63870..594f80a74 100644 --- a/patches/llvm/0002-clang-Add-managarm-OS-target.patch +++ b/patches/llvm/0002-clang-Add-managarm-OS-target.patch @@ -1,21 +1,22 @@ -From d501a9af0261875c1f702aaf2e1f04356076f2a3 Mon Sep 17 00:00:00 2001 +From 80bd6cc08d6ff8806e293d97f6c723081ec481fc Mon Sep 17 00:00:00 2001 From: no92 Date: Fri, 6 Sep 2024 21:18:39 +0200 -Subject: [PATCH 2/5] [clang] Add managarm OS target +Subject: [PATCH 2/4] [clang] Add managarm OS target --- - clang/lib/Basic/Targets.cpp | 6 + + clang/lib/Basic/Targets.cpp | 9 + clang/lib/Basic/Targets/OSTargets.h | 30 +++ clang/lib/Driver/CMakeLists.txt | 1 + clang/lib/Driver/Driver.cpp | 4 + + clang/lib/Driver/ToolChains/Gnu.cpp | 2 + clang/lib/Driver/ToolChains/Managarm.cpp | 227 +++++++++++++++++++++++ clang/lib/Driver/ToolChains/Managarm.h | 55 ++++++ - 6 files changed, 323 insertions(+) + 7 files changed, 328 insertions(+) create mode 100644 clang/lib/Driver/ToolChains/Managarm.cpp create mode 100644 clang/lib/Driver/ToolChains/Managarm.h diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp -index 0021d33c45..18b06085dd 100644 +index 0021d33c45..b2be3803b2 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -159,6 +159,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, @@ -28,7 +29,17 @@ index 0021d33c45..18b06085dd 100644 case llvm::Triple::NetBSD: return std::make_unique>(Triple, Opts); -@@ -637,6 +640,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, +@@ -451,6 +454,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, + return std::make_unique>(Triple, + Opts); + } ++ case llvm::Triple::Managarm: ++ return std::make_unique>(Triple, ++ Opts); + default: + return std::make_unique(Triple, Opts); + } +@@ -637,6 +643,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, return std::make_unique>(Triple, Opts); case llvm::Triple::Hurd: return std::make_unique>(Triple, Opts); @@ -92,7 +103,7 @@ index 4fd10bf671..67e9d90ae6 100644 ToolChains/MinGW.cpp ToolChains/MSP430.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp -index df802450ad..d41f2d8491 100644 +index 93e85f7dff..f9261b412e 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -32,6 +32,7 @@ @@ -103,7 +114,7 @@ index df802450ad..d41f2d8491 100644 #include "ToolChains/MinGW.h" #include "ToolChains/MipsLinux.h" #include "ToolChains/NaCl.h" -@@ -6438,6 +6439,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, +@@ -6437,6 +6438,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::Fuchsia: TC = std::make_unique(*this, Target, Args); break; @@ -113,6 +124,19 @@ index df802450ad..d41f2d8491 100644 case llvm::Triple::Solaris: TC = std::make_unique(*this, Target, Args); break; +diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp +index 8397f1121e..53b326f6e7 100644 +--- a/clang/lib/Driver/ToolChains/Gnu.cpp ++++ b/clang/lib/Driver/ToolChains/Gnu.cpp +@@ -228,6 +228,8 @@ static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) { + return "elf_iamcu"; + return "elf_i386"; + case llvm::Triple::aarch64: ++ if (T.isOSManagarm()) ++ return "aarch64managarm"; + return "aarch64linux"; + case llvm::Triple::aarch64_be: + return "aarch64linuxb"; diff --git a/clang/lib/Driver/ToolChains/Managarm.cpp b/clang/lib/Driver/ToolChains/Managarm.cpp new file mode 100644 index 0000000000..51abd8459f diff --git a/patches/llvm/0003-clang-Add-managarm-tests.patch b/patches/llvm/0003-clang-Add-managarm-tests.patch index 99b82522b..c8b4171e6 100644 --- a/patches/llvm/0003-clang-Add-managarm-tests.patch +++ b/patches/llvm/0003-clang-Add-managarm-tests.patch @@ -1,7 +1,7 @@ -From 58495a0e8e4d9fa54a1650578b1293eeae54c1b7 Mon Sep 17 00:00:00 2001 +From 3faf84c1dfb842b6005bb276ede5e2cc6a96883b Mon Sep 17 00:00:00 2001 From: no92 Date: Tue, 5 Nov 2024 01:43:57 +0100 -Subject: [PATCH 3/5] [clang] Add managarm tests +Subject: [PATCH 3/4] [clang] Add managarm tests --- .../lib/aarch64-managarm-mlibc/.keep | 0 diff --git a/patches/llvm/0004-WIP-kernel-environment.patch b/patches/llvm/0004-WIP-kernel-environment.patch index 322c99558..ca78532d3 100644 --- a/patches/llvm/0004-WIP-kernel-environment.patch +++ b/patches/llvm/0004-WIP-kernel-environment.patch @@ -1,7 +1,7 @@ -From 5f2b6a823fc5cc8c9e6323ec234925adc1abd749 Mon Sep 17 00:00:00 2001 +From 5045e500406b216f3a77d4b410c0d31117f63e0c Mon Sep 17 00:00:00 2001 From: no92 Date: Tue, 5 Nov 2024 01:44:16 +0100 -Subject: [PATCH 4/5] WIP: kernel environment +Subject: [PATCH 4/4] WIP: kernel environment --- llvm/include/llvm/TargetParser/Triple.h | 1 + @@ -9,7 +9,7 @@ Subject: [PATCH 4/5] WIP: kernel environment 2 files changed, 3 insertions(+) diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h -index 818c3a9b5b..aba538520a 100644 +index 3ff75723b3..82824b9eee 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -299,6 +299,7 @@ public: