mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-22 02:26:11 +00:00
![Dan Klishch](/assets/img/avatar_default.png)
Apart from bumping the toolchain Clang's and port's version, this commit completely overhauls the way LLVM toolchain is built. First, it gets rid of a complicated two-stage process of first compiling clang and compiler-rt builtins and then building libunwind, libc++abi, and libc++ -- it is possible to create a complete cross-compilation toolchain in a single CMake invocation with a modern LLVM. Moreover, the old method was inherently unsupported and subtly broken. Next, it utilizes full potential of the Stubs "framework". Now we are even able to compile Clang with -Wl,-z,defs which makes one of the patches obsolete and the whole installation less error-prone. Note that it comes at a cost of complicating the bootstrap process on a completely novel architecture but this hopefully won't happen often. Lastly, it fixes handling of the -no*lib* family of flags in the Serenity LLVM driver and correctly uses -nostartfiles in conjunction with stubs to make necessary CMake configure-time checks succeed.
135 lines
5.6 KiB
Diff
135 lines
5.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Daniel Bertalan <dani@danielbertalan.dev>
|
|
Date: Thu, 14 Apr 2022 09:54:22 +0200
|
|
Subject: [PATCH] [llvm] Add support for building LLVM on SerenityOS
|
|
|
|
Adds SerenityOS `#ifdef`s for platform-specific code.
|
|
|
|
We stub out wait4, as SerenityOS doesn't support querying a child
|
|
process's resource usage information.
|
|
|
|
POSIX shm is not supported by SerenityOS yet, so disable it in Orc.
|
|
|
|
Serenity gives each thread a default of 1MiB of stack. Increase the
|
|
default stack size for llvm applications when running on SerenityOS.
|
|
|
|
Co-Authored-By: sin-ack <sin-ack@users.noreply.github.com>
|
|
Co-Authored-By: Tim Schumacher <timschumi@gmx.de>
|
|
---
|
|
llvm/cmake/modules/HandleLLVMOptions.cmake | 3 +++
|
|
llvm/include/llvm/ADT/bit.h | 2 +-
|
|
llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp | 3 ++-
|
|
.../TargetProcess/ExecutorSharedMemoryMapperService.cpp | 3 ++-
|
|
llvm/lib/Support/Unix/Path.inc | 5 ++++-
|
|
llvm/lib/Support/Unix/Program.inc | 9 ++++++++-
|
|
6 files changed, 20 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
|
|
index 0699a8586fcc..29d0d46fdcb4 100644
|
|
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
|
|
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
|
|
@@ -503,6 +503,9 @@ elseif(MINGW OR CYGWIN)
|
|
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
append("-Wa,-mbig-obj" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
endif()
|
|
+elseif(SERENITYOS)
|
|
+ # SerenityOS sets a very low default stack size value, so increase it to 4MB manually.
|
|
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,stack-size=4194304")
|
|
endif()
|
|
|
|
option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
|
|
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
|
|
index c42b5e686bdc..ad4ad534f40c 100644
|
|
--- a/llvm/include/llvm/ADT/bit.h
|
|
+++ b/llvm/include/llvm/ADT/bit.h
|
|
@@ -29,7 +29,7 @@
|
|
|
|
#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \
|
|
defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || \
|
|
- defined(__OpenBSD__) || defined(__DragonFly__)
|
|
+ defined(__OpenBSD__) || defined(__DragonFly__) || defined(__serenity__)
|
|
#include <endian.h>
|
|
#elif defined(_AIX)
|
|
#include <sys/machine.h>
|
|
diff --git a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
|
|
index 9cfe547c84c3..f43a317064f5 100644
|
|
--- a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
|
|
+++ b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
|
|
@@ -215,7 +215,8 @@ SharedMemoryMapper::Create(ExecutorProcessControl &EPC, SymbolAddrs SAs) {
|
|
|
|
void SharedMemoryMapper::reserve(size_t NumBytes,
|
|
OnReservedFunction OnReserved) {
|
|
-#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
|
|
+#if (defined(LLVM_ON_UNIX) && !(defined(__ANDROID__) || defined(__serenity__))) \
|
|
+ || defined(_WIN32)
|
|
|
|
EPC.callSPSWrapperAsync<
|
|
rt::SPSExecutorSharedMemoryMapperServiceReserveSignature>(
|
|
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
|
|
index e8b0e240ac1f..fcc7bfe1c1cc 100644
|
|
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
|
|
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
|
|
@@ -47,7 +47,8 @@ static DWORD getWindowsProtectionFlags(MemProt MP) {
|
|
|
|
Expected<std::pair<ExecutorAddr, std::string>>
|
|
ExecutorSharedMemoryMapperService::reserve(uint64_t Size) {
|
|
-#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
|
|
+#if (defined(LLVM_ON_UNIX) && !(defined(__ANDROID__) || defined(__serenity__))) \
|
|
+ || defined(_WIN32)
|
|
|
|
#if defined(LLVM_ON_UNIX)
|
|
|
|
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
|
|
index 9f89d63bb0fd..5035b1b05f4d 100644
|
|
--- a/llvm/lib/Support/Unix/Path.inc
|
|
+++ b/llvm/lib/Support/Unix/Path.inc
|
|
@@ -112,7 +112,7 @@ typedef uint_t uint;
|
|
#endif
|
|
|
|
#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \
|
|
- defined(__MVS__)
|
|
+ defined(__MVS__) || defined(__serenity__)
|
|
#define STATVFS_F_FLAG(vfs) (vfs).f_flag
|
|
#else
|
|
#define STATVFS_F_FLAG(vfs) (vfs).f_flags
|
|
@@ -511,6 +511,9 @@ static bool is_local_impl(struct STATVFS &Vfs) {
|
|
#elif defined(__HAIKU__)
|
|
// Haiku doesn't expose this information.
|
|
return false;
|
|
+#elif defined(__serenity__)
|
|
+ // Serenity doesn't yet support remote filesystem mounts.
|
|
+ return false;
|
|
#elif defined(__sun)
|
|
// statvfs::f_basetype contains a null-terminated FSType name of the mounted
|
|
// target
|
|
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
|
|
index 5d9757bcc51b..18295dc2229c 100644
|
|
--- a/llvm/lib/Support/Unix/Program.inc
|
|
+++ b/llvm/lib/Support/Unix/Program.inc
|
|
@@ -342,7 +342,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program,
|
|
namespace llvm {
|
|
namespace sys {
|
|
|
|
-#if defined(_AIX)
|
|
+#if defined(_AIX) || defined(__serenity__)
|
|
static pid_t(wait4)(pid_t pid, int *status, int options, struct rusage *usage);
|
|
#elif !defined(__Fuchsia__)
|
|
using ::wait4;
|
|
@@ -385,6 +385,13 @@ pid_t(llvm::sys::wait4)(pid_t pid, int *status, int options,
|
|
}
|
|
#endif
|
|
|
|
+#ifdef __serenity__
|
|
+pid_t (llvm::sys::wait4)(pid_t pid, int *status, int options,
|
|
+ struct rusage*) {
|
|
+ return ::waitpid(pid, status, options);
|
|
+}
|
|
+#endif
|
|
+
|
|
ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
|
|
std::optional<unsigned> SecondsToWait,
|
|
std::string *ErrMsg,
|
|
--
|
|
2.44.0
|
|
|