summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-11-21 08:25:51 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-11-28 09:38:57 -0800
commite88ca09609017f5a8c5d3185376aa21172fab2e5 (patch)
treec52871fdedc1c62ca12e85964b39fcdd1767bd04
parentf29f9762a2d243ad2366b130bd1f15c240df0f7a (diff)
downloadserenity-e88ca09609017f5a8c5d3185376aa21172fab2e5.zip
Ports: Upgrade LLVM to version 13.0.0
With this update, we now use our custom `serenity` Clang target, which means that all system-specific compilation options (e.g. default PIE, header search paths) will be handled automatically. This port has been tested to build `Source/little` on all 4 toolchain-architecture pairs. Furthermore, `lib(std)c++` headers are picked up correctly and our AK headers can be included without any issues. Due to recent kernel fixes related to memory-mapped files, the LLD linker can now be used by default, so there's no need to also build the GCC port alongside this. Although our patches cover building libLLVM as a shared library, this is currently not enabled by default, as DynamicLoader is very slow in dealing with such a large number of relocations.
-rw-r--r--Ports/AvailablePorts.md2
-rw-r--r--Ports/llvm/ReadMe.md5
-rwxr-xr-xPorts/llvm/package.sh38
-rw-r--r--Ports/llvm/patches/ReadMe.md49
-rw-r--r--Ports/llvm/patches/build-crt.patch13
-rw-r--r--Ports/llvm/patches/insert-ifdef-serenity.patch74
-rw-r--r--Ports/llvm/patches/remove-version-script.patch35
l---------Ports/llvm/patches/toolchain.patch1
8 files changed, 158 insertions, 59 deletions
diff --git a/Ports/AvailablePorts.md b/Ports/AvailablePorts.md
index c093fe47c6..66ff6a3235 100644
--- a/Ports/AvailablePorts.md
+++ b/Ports/AvailablePorts.md
@@ -95,7 +95,7 @@ Please make sure to keep this list up to date when adding and updating ports. :^
| [`libxml2`](libxml2/) | libxml2 | 2.9.12 | http://www.xmlsoft.org/ |
| [`libzip`](libzip/) | libzip | 1.7.3 | https://libzip.org/ |
| [`links`](links/) | Links web browser | 2.22 | http://links.twibright.com/ |
-| [`llvm`](llvm/) | LLVM | 12.0.0 | https://llvm.org/ |
+| [`llvm`](llvm/) | LLVM | 13.0.0 | https://llvm.org/ |
| [`lua`](lua/) | Lua | 5.3.5 | https://www.lua.org/ |
| [`lure`](lure/) | Lure of the Temptress | 1.1 | https://www.scummvm.org/games/#games-lure |
| [`m4`](m4/) | GNU M4 | 1.4.9 | https://www.gnu.org/software/m4/ |
diff --git a/Ports/llvm/ReadMe.md b/Ports/llvm/ReadMe.md
deleted file mode 100644
index 286d6218f1..0000000000
--- a/Ports/llvm/ReadMe.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# LLVM port for SerenityOS
-
-This folder contains the SerenityOS port of LLVM/Clang. Right now it builds LLVM, Clang, lld and compiler-rt.
-To compile programs it is recommended to install the GCC port because Clang is not able to use lld yet,
-that's why GNU ld should be used.
diff --git a/Ports/llvm/package.sh b/Ports/llvm/package.sh
index a537f060aa..298a828c42 100755
--- a/Ports/llvm/package.sh
+++ b/Ports/llvm/package.sh
@@ -1,11 +1,12 @@
#!/usr/bin/env -S bash ../.port_include.sh
port=llvm
useconfigure=true
-version=12.0.0
+version=13.0.0
workdir=llvm-project-llvmorg-${version}
configopts=("-DCMAKE_TOOLCHAIN_FILE=${SERENITY_BUILD_DIR}/CMakeToolchain.txt")
-files="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${version}.zip llvm.zip f77723b70a5d4ab14899feda87d6cf601612165899abb2f6c7b670e517f45e2d"
+files="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${version}.zip llvm.zip 333a4e053fb543d9efb8dc68126d9e7a948ecb246985f2804a0ecbc5ccdb9d08"
auth_type=sha256
+depends=("ncurses" "zlib")
pre_patch() {
host_env
@@ -18,25 +19,42 @@ pre_patch() {
}
configure() {
+ if [ "$SERENITY_TOOLCHAIN" = "Clang" ]; then
+ stdlib=""
+ unwindlib=""
+ else
+ stdlib="libstdc++"
+ unwindlib="libgcc"
+ fi
mkdir -p llvm-build
cmake ${workdir}/llvm \
+ -G Ninja \
-B llvm-build "${configopts[@]}" \
-DCMAKE_BUILD_TYPE=MinSizeRel \
- -DLLVM_TARGETS_TO_BUILD=X86 \
+ -DCMAKE_FIND_ROOT_PATH="$SERENITY_BUILD_DIR"/Root \
+ -DCLANG_DEFAULT_CXX_STDLIB=$stdlib \
+ -DCLANG_DEFAULT_UNWINDLIB=$unwindlib \
+ -DCLANG_TABLEGEN=$(pwd)/llvm-host/bin/clang-tblgen \
+ -DCOMPILER_RT_BUILD_CRT=ON \
+ -DCOMPILER_RT_BUILD_ORC=OFF \
+ -DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=OFF \
+ -DCOMPILER_RT_OS_DIR=serenity \
+ -DHAVE_LIBRT=OFF \
+ -DLLVM_DEFAULT_TARGET_TRIPLE=$SERENITY_ARCH-pc-serenity \
-DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" \
- -DLLVM_TABLEGEN=$(pwd)/llvm-host/bin/llvm-tblgen \
- -DCMAKE_CROSSCOMPILING=True \
- -DLLVM_DEFAULT_TARGET_TRIPLE=i386-none-gnueabi \
- -DLLVM_TARGET_ARCH=X86 \
+ -DLLVM_HAVE_LIBXAR=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
- -DCLANG_TABLEGEN=$(pwd)/llvm-host/bin/clang-tblgen
+ -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON \
+ -DLLVM_PTHREAD_LIB=pthread \
+ -DLLVM_TABLEGEN=$(pwd)/llvm-host/bin/llvm-tblgen \
+ -DLLVM_TARGETS_TO_BUILD=X86
}
build() {
- make -C llvm-build -j $(nproc) --no-print-directory
+ ninja -C llvm-build
}
install() {
- make -C llvm-build -j $(nproc) --no-print-directory install
+ ninja -C llvm-build install
}
diff --git a/Ports/llvm/patches/ReadMe.md b/Ports/llvm/patches/ReadMe.md
index 154a20d834..8d964da28a 100644
--- a/Ports/llvm/patches/ReadMe.md
+++ b/Ports/llvm/patches/ReadMe.md
@@ -1,9 +1,54 @@
# Patches for LLVM on SerenityOS
-## `remove-wstring.patch`
+## `build-crt.patch`
+
+This patch lets us use LLVM's `crtbegin.o`/`crtend.o` implementation.
-Removes `wstring`s from the source code, as SerenityOS doesn't support them yet.
+### Status
+- [ ] Local?
+- [x] Should be merged to upstream?
+- [ ] Resolves issue(s) with our side of things
+- [ ] Hack
## `insert-ifdef-serenity.patch`
This patch adds several defines in order to omit things not supported by SerenityOS.
+
+### Status
+- [ ] Local?
+- [ ] Should be merged to upstream?
+- [X] Resolves issue(s) with our side of things
+- [x] Hack
+
+## `remove-version-script.patch`
+
+Instructs the linker to not build LLVM shared libraries (`libclang.so`, `libLTO.so`, etc.) with
+symbol versioning, which our dynamic linker does not support.
+
+### Status
+- [ ] Local?
+- [x] Should be merged to upstream?
+- [X] Resolves issue(s) with our side of things
+- [ ] Hack
+
+## `remove-wstring.patch`
+
+Removes `std::wstring`s from the source code, as our libstdc++ does not support it.
+
+### Status
+- [ ] Local?
+- [ ] Should be merged to upstream?
+- [X] Resolves issue(s) with our side of things
+- [X] Hack
+
+## `toolchain.patch`
+
+Adds support for the `$arch-pc-serenity` target to the Clang front end. This makes the compiler
+look for libraries and headers in the right places, and enables some security mitigations, like
+stack-smashing protection and building position-independent executables by default.
+
+### Status
+- [ ] Local?
+- [x] Should be merged to upstream?
+- [ ] Resolves issue(s) with our side of things
+- [ ] Hack
diff --git a/Ports/llvm/patches/build-crt.patch b/Ports/llvm/patches/build-crt.patch
new file mode 100644
index 0000000000..e589ffca63
--- /dev/null
+++ b/Ports/llvm/patches/build-crt.patch
@@ -0,0 +1,13 @@
+diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
+index 39b9120f0..1a49ac3e5 100644
+--- a/compiler-rt/cmake/config-ix.cmake
++++ b/compiler-rt/cmake/config-ix.cmake
+@@ -684,7 +684,7 @@ endif()
+
+ # TODO: Add builtins support.
+
+-if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux" AND NOT LLVM_USE_SANITIZER)
++if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux|SerenityOS" AND NOT LLVM_USE_SANITIZER)
+ set(COMPILER_RT_HAS_CRT TRUE)
+ else()
+ set(COMPILER_RT_HAS_CRT FALSE)
diff --git a/Ports/llvm/patches/insert-ifdef-serenity.patch b/Ports/llvm/patches/insert-ifdef-serenity.patch
index eb59fc498f..318382c0cd 100644
--- a/Ports/llvm/patches/insert-ifdef-serenity.patch
+++ b/Ports/llvm/patches/insert-ifdef-serenity.patch
@@ -1,19 +1,8 @@
-diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/SmallVector.cpp llvm-project-llvmorg-12.0.0/llvm/lib/Support/SmallVector.cpp
---- llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/SmallVector.cpp 2021-04-06 19:38:18.000000000 +0300
-+++ llvm-project-llvmorg-12.0.0/llvm/lib/Support/SmallVector.cpp 2021-06-09 16:18:35.039546181 +0300
-@@ -132,7 +132,7 @@
- // Both uint32_t and uint64_t instantiations are needed for 64-bit builds.
- // This instantiation will never be used in 32-bit builds, and will cause
- // warnings when sizeof(Size_T) > sizeof(size_t).
--#if SIZE_MAX > UINT32_MAX
-+#if SIZE_MAX > UINT32_MAX && !defined(__serenity__)
- template class llvm::SmallVectorBase<uint64_t>;
-
- // Assertions to ensure this #if stays in sync with SmallVectorSizeType.
-diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Path.inc llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Path.inc
---- llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Path.inc 2021-04-06 19:38:18.000000000 +0300
-+++ llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Path.inc 2021-06-09 16:24:37.446095863 +0300
-@@ -108,7 +108,7 @@
+diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
+index c37b3a546..e51badb34 100644
+--- a/llvm/lib/Support/Unix/Path.inc
++++ b/llvm/lib/Support/Unix/Path.inc
+@@ -109,7 +109,7 @@ typedef uint_t uint;
#endif
#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \
@@ -22,7 +11,7 @@ diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Path.inc l
#define STATVFS_F_FLAG(vfs) (vfs).f_flag
#else
#define STATVFS_F_FLAG(vfs) (vfs).f_flags
-@@ -524,7 +524,7 @@
+@@ -531,7 +531,7 @@ static bool is_local_impl(struct STATVFS &Vfs) {
// vmount entry not found; "remote" is the conservative answer.
return false;
@@ -31,10 +20,11 @@ diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Path.inc l
// The file system can have an arbitrary structure on z/OS; must go with the
// conservative answer.
return false;
-diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Program.inc llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Program.inc
---- llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Program.inc 2021-04-06 19:38:18.000000000 +0300
-+++ llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Program.inc 2021-06-10 11:04:28.765989133 +0300
-@@ -335,7 +335,7 @@
+diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
+index be59bb023..ff8931308 100644
+--- a/llvm/lib/Support/Unix/Program.inc
++++ b/llvm/lib/Support/Unix/Program.inc
+@@ -335,7 +335,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program,
namespace llvm {
namespace sys {
@@ -43,7 +33,7 @@ diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Program.in
using ::wait4;
#else
static pid_t (wait4)(pid_t pid, int *status, int options, struct rusage *usage);
-@@ -344,7 +344,7 @@
+@@ -344,7 +344,7 @@ static pid_t (wait4)(pid_t pid, int *status, int options, struct rusage *usage);
} // namespace sys
} // namespace llvm
@@ -52,7 +42,7 @@ diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Program.in
#ifndef _ALL_SOURCE
extern "C" pid_t (wait4)(pid_t pid, int *status, int options,
struct rusage *usage);
-@@ -357,7 +357,7 @@
+@@ -357,7 +357,7 @@ pid_t (llvm::sys::wait4)(pid_t pid, int *status, int options,
// AIX wait4 does not work well with WNOHANG.
if (!(options & WNOHANG))
@@ -61,7 +51,7 @@ diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Program.in
// For WNOHANG, we use waitid (which supports WNOWAIT) until the child process
// has terminated.
-@@ -374,7 +374,7 @@
+@@ -374,7 +374,7 @@ pid_t (llvm::sys::wait4)(pid_t pid, int *status, int options,
// The child has already terminated, so a blocking wait on it is okay in the
// absence of indiscriminate `wait` calls from the current process (which
// would cause the call here to fail with ECHILD).
@@ -70,7 +60,7 @@ diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Program.in
}
#endif
-@@ -519,10 +519,10 @@
+@@ -534,10 +534,10 @@ llvm::sys::writeFileWithEncoding(StringRef FileName, StringRef Contents,
bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
ArrayRef<StringRef> Args) {
@@ -83,27 +73,29 @@ diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/Unix/Program.in
// This the same baseline used by xargs.
long EffectiveArgMax = 128 * 1024;
-diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/tools/llvm-jitlink/llvm-jitlink.cpp llvm-project-llvmorg-12.0.0/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
---- llvm-orig/llvm-project-llvmorg-12.0.0/llvm/tools/llvm-jitlink/llvm-jitlink.cpp 2021-04-06 19:38:18.000000000 +0300
-+++ llvm-project-llvmorg-12.0.0/llvm/tools/llvm-jitlink/llvm-jitlink.cpp 2021-06-09 19:52:15.384543089 +0300
-@@ -660,7 +660,7 @@
+diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+index 7f197a50c..03bf029db 100644
+--- a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
++++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+@@ -50,7 +50,7 @@ void printErrorAndExit(Twine ErrMsg) {
+ }
- Expected<std::unique_ptr<TargetProcessControl>>
- LLVMJITLinkRemoteTargetProcessControl::ConnectToExecutor() {
+ int openListener(std::string Host, std::string PortStr) {
-#ifndef LLVM_ON_UNIX
+#if !defined(LLVM_ON_UNIX) || defined(__serenity__)
// FIXME: Add TCP support for Windows.
- return make_error<StringError>("-" + OutOfProcessExecutorConnect.ArgStr +
- " not supported on non-unix platforms",
-diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp llvm-project-llvmorg-12.0.0/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
---- llvm-orig/llvm-project-llvmorg-12.0.0/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp 2021-04-06 19:38:18.000000000 +0300
-+++ llvm-project-llvmorg-12.0.0/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp 2021-06-09 16:43:06.154952293 +0300
-@@ -45,7 +45,7 @@
- }
+ printErrorAndExit("listen option not supported");
+ return 0;
+diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+index 8bd384ec7..a28e938ec 100644
+--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
++++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+@@ -770,7 +770,7 @@ static Expected<int> connectTCPSocket(std::string Host, std::string PortStr) {
- int openListener(std::string Host, int Port) {
+ Expected<std::unique_ptr<ExecutorProcessControl>>
+ LLVMJITLinkRemoteExecutorProcessControl::ConnectToExecutor() {
-#ifndef LLVM_ON_UNIX
+#if !defined(LLVM_ON_UNIX) || defined(__serenity__)
// FIXME: Add TCP support for Windows.
- printErrorAndExit("listen option not supported");
- return 0;
+ return make_error<StringError>("-" + OutOfProcessExecutorConnect.ArgStr +
+ " not supported on non-unix platforms",
diff --git a/Ports/llvm/patches/remove-version-script.patch b/Ports/llvm/patches/remove-version-script.patch
new file mode 100644
index 0000000000..99954ee959
--- /dev/null
+++ b/Ports/llvm/patches/remove-version-script.patch
@@ -0,0 +1,35 @@
+diff --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt
+index bf88dca0a..dfac32b16 100644
+--- a/clang/tools/libclang/CMakeLists.txt
++++ b/clang/tools/libclang/CMakeLists.txt
+@@ -80,7 +80,7 @@ if(MSVC)
+ set(LLVM_EXPORTED_SYMBOL_FILE)
+ endif()
+
+-if (UNIX AND NOT APPLE)
++if (UNIX AND NOT APPLE AND NOT SERENITYOS)
+ set(LLVM_EXPORTED_SYMBOL_FILE)
+ set(USE_VERSION_SCRIPT ${LLVM_HAVE_LINK_VERSION_SCRIPT})
+ endif()
+diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt
+index 76b9a25cb..808838926 100644
+--- a/llvm/tools/llvm-shlib/CMakeLists.txt
++++ b/llvm/tools/llvm-shlib/CMakeLists.txt
+@@ -33,7 +33,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
+ add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${INSTALL_WITH_TOOLCHAIN} ${SOURCES})
+
+ list(REMOVE_DUPLICATES LIB_NAMES)
+- if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU)
++ if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU) OR (SERENITYOS)
+ OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
+ OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
+ OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
+@@ -46,7 +46,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
+
+ # GNU ld doesn't resolve symbols in the version script.
+ set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
+- if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
++ if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW AND NOT SERENITYOS)
+ # Solaris ld does not accept global: *; so there is no way to version *all* global symbols
+ set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
+ endif()
diff --git a/Ports/llvm/patches/toolchain.patch b/Ports/llvm/patches/toolchain.patch
new file mode 120000
index 0000000000..20ae89f0f3
--- /dev/null
+++ b/Ports/llvm/patches/toolchain.patch
@@ -0,0 +1 @@
+../../../Toolchain/Patches/llvm.patch \ No newline at end of file