summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Ananyin <ananinegor@gmail.com>2021-06-10 20:38:00 +0300
committerLinus Groh <mail@linusgroh.de>2021-06-10 20:21:08 +0100
commit023df8e596aab8ad054a4fb8921c0a4890a78ac1 (patch)
tree859cf8f231b656dc4dc18d2898979d239c85e8ef
parent794cf8eef47ca4f8d20ee94c18c6dce664d34c78 (diff)
downloadserenity-023df8e596aab8ad054a4fb8921c0a4890a78ac1.zip
Ports: Add LLVM port
-rw-r--r--Ports/AvailablePorts.md1
-rw-r--r--Ports/llvm/ReadMe.md5
-rwxr-xr-xPorts/llvm/package.sh42
-rw-r--r--Ports/llvm/patches/ReadMe.md9
-rw-r--r--Ports/llvm/patches/insert-ifdef-serenity.patch109
-rw-r--r--Ports/llvm/patches/remove-wstring.patch69
6 files changed, 235 insertions, 0 deletions
diff --git a/Ports/AvailablePorts.md b/Ports/AvailablePorts.md
index 3e33cfde9d..6349e87527 100644
--- a/Ports/AvailablePorts.md
+++ b/Ports/AvailablePorts.md
@@ -73,6 +73,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 | http://llvm.org/ |
| [`lua`](lua/) | Lua | 5.3.5 | https://www.lua.org/ |
| [`m4`](m4/) | GNU M4 | 1.4.9 | https://www.gnu.org/software/m4/ |
| [`make`](make/) | GNU make | 4.3 | https://www.gnu.org/software/make/ |
diff --git a/Ports/llvm/ReadMe.md b/Ports/llvm/ReadMe.md
new file mode 100644
index 0000000000..286d6218f1
--- /dev/null
+++ b/Ports/llvm/ReadMe.md
@@ -0,0 +1,5 @@
+# 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
new file mode 100755
index 0000000000..e9c1db9873
--- /dev/null
+++ b/Ports/llvm/package.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env -S bash ../.port_include.sh
+port=llvm
+useconfigure=true
+version=12.0.0
+workdir=llvm-project-llvmorg-${version}
+configopts="-DCMAKE_TOOLCHAIN_FILE=$SERENITY_SOURCE_DIR/Toolchain/CMake/CMakeToolchain.txt"
+files="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${version}.zip llvm.zip f77723b70a5d4ab14899feda87d6cf601612165899abb2f6c7b670e517f45e2d"
+auth_type=sha256
+
+pre_patch() {
+ host_env
+ mkdir -p llvm-host
+ cmake ${workdir}/llvm \
+ -B llvm-host \
+ -DLLVM_ENABLE_PROJECTS=clang
+ make -C llvm-host -j $(nproc) llvm-tblgen clang-tblgen
+ target_env
+}
+
+configure() {
+ mkdir -p llvm-build
+ cmake ${workdir}/llvm \
+ -B llvm-build $configopts \
+ -DCMAKE_BUILD_TYPE=MinSizeRel \
+ -DLLVM_TARGETS_TO_BUILD=X86 \
+ -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_INCLUDE_BENCHMARKS=OFF \
+ -DLLVM_INCLUDE_TESTS=OFF \
+ -DCLANG_TABLEGEN=$(pwd)/llvm-host/bin/clang-tblgen
+}
+
+build() {
+ make -C llvm-build -j $(nproc) --no-print-directory
+}
+
+install() {
+ make -C llvm-build -j $(nproc) --no-print-directory install
+}
diff --git a/Ports/llvm/patches/ReadMe.md b/Ports/llvm/patches/ReadMe.md
new file mode 100644
index 0000000000..154a20d834
--- /dev/null
+++ b/Ports/llvm/patches/ReadMe.md
@@ -0,0 +1,9 @@
+# Patches for LLVM on SerenityOS
+
+## `remove-wstring.patch`
+
+Removes `wstring`s from the source code, as SerenityOS doesn't support them yet.
+
+## `insert-ifdef-serenity.patch`
+
+This patch adds several defines in order to omit things not supported by SerenityOS.
diff --git a/Ports/llvm/patches/insert-ifdef-serenity.patch b/Ports/llvm/patches/insert-ifdef-serenity.patch
new file mode 100644
index 0000000000..eb59fc498f
--- /dev/null
+++ b/Ports/llvm/patches/insert-ifdef-serenity.patch
@@ -0,0 +1,109 @@
+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 @@
+ #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
+@@ -524,7 +524,7 @@
+
+ // vmount entry not found; "remote" is the conservative answer.
+ return false;
+-#elif defined(__MVS__)
++#elif defined(__MVS__) || defined(__serenity__)
+ // 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 @@
+ namespace llvm {
+ namespace sys {
+
+-#ifndef _AIX
++#if !defined(_AIX) && !defined(__serenity__)
+ using ::wait4;
+ #else
+ static pid_t (wait4)(pid_t pid, int *status, int options, struct rusage *usage);
+@@ -344,7 +344,7 @@
+ } // namespace sys
+ } // namespace llvm
+
+-#ifdef _AIX
++#if defined(_AIX) || defined(__serenity__)
+ #ifndef _ALL_SOURCE
+ extern "C" pid_t (wait4)(pid_t pid, int *status, int options,
+ struct rusage *usage);
+@@ -357,7 +357,7 @@
+
+ // AIX wait4 does not work well with WNOHANG.
+ if (!(options & WNOHANG))
+- return ::wait4(pid, status, options, usage);
++ return ::waitpid(pid, status, options);
+
+ // For WNOHANG, we use waitid (which supports WNOWAIT) until the child process
+ // has terminated.
+@@ -374,7 +374,7 @@
+ // 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).
+- return ::wait4(pid, status, options & ~WNOHANG, usage);
++ return ::waitpid(pid, status, options & ~WNOHANG);
+ }
+ #endif
+
+@@ -519,10 +519,10 @@
+
+ bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
+ ArrayRef<StringRef> Args) {
+- static long ArgMax = sysconf(_SC_ARG_MAX);
++ static long ArgMax = 4096;
+ // POSIX requires that _POSIX_ARG_MAX is 4096, which is the lowest possible
+ // value for ARG_MAX on a POSIX compliant system.
+- static long ArgMin = _POSIX_ARG_MAX;
++ static long ArgMin = 4096;
+
+ // 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 @@
+
+ Expected<std::unique_ptr<TargetProcessControl>>
+ LLVMJITLinkRemoteTargetProcessControl::ConnectToExecutor() {
+-#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 @@
+ }
+
+ int openListener(std::string Host, int Port) {
+-#ifndef LLVM_ON_UNIX
++#if !defined(LLVM_ON_UNIX) || defined(__serenity__)
+ // FIXME: Add TCP support for Windows.
+ printErrorAndExit("listen option not supported");
+ return 0;
diff --git a/Ports/llvm/patches/remove-wstring.patch b/Ports/llvm/patches/remove-wstring.patch
new file mode 100644
index 0000000000..b40d849120
--- /dev/null
+++ b/Ports/llvm/patches/remove-wstring.patch
@@ -0,0 +1,69 @@
+diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/include/llvm/Support/SwapByteOrder.h llvm-project-llvmorg-12.0.0/llvm/include/llvm/Support/SwapByteOrder.h
+--- llvm-orig/llvm-project-llvmorg-12.0.0/llvm/include/llvm/Support/SwapByteOrder.h 2021-04-06 19:38:18.000000000 +0300
++++ llvm-project-llvmorg-12.0.0/llvm/include/llvm/Support/SwapByteOrder.h 2021-06-09 16:00:20.111549941 +0300
+@@ -22,7 +22,7 @@
+ #endif
+
+ #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \
+- defined(__Fuchsia__) || defined(__EMSCRIPTEN__)
++ defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__serenity__)
+ #include <endian.h>
+ #elif defined(_AIX)
+ #include <sys/machine.h>
+diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/include/llvm/Support/ConvertUTF.h llvm-project-llvmorg-12.0.0/llvm/include/llvm/Support/ConvertUTF.h
+--- llvm-orig/llvm-project-llvmorg-12.0.0/llvm/include/llvm/Support/ConvertUTF.h 2021-04-06 19:38:18.000000000 +0300
++++ llvm-project-llvmorg-12.0.0/llvm/include/llvm/Support/ConvertUTF.h 2021-06-09 16:04:10.069288846 +0300
+@@ -200,19 +200,19 @@
+ * Converts a UTF-8 StringRef to a std::wstring.
+ * \return true on success.
+ */
+-bool ConvertUTF8toWide(llvm::StringRef Source, std::wstring &Result);
++bool ConvertUTF8toWide(llvm::StringRef Source, std::string &Result);
+
+ /**
+ * Converts a UTF-8 C-string to a std::wstring.
+ * \return true on success.
+ */
+-bool ConvertUTF8toWide(const char *Source, std::wstring &Result);
++bool ConvertUTF8toWide(const char *Source, std::string &Result);
+
+ /**
+ * Converts a std::wstring to a UTF-8 encoded std::string.
+ * \return true on success.
+ */
+-bool convertWideToUTF8(const std::wstring &Source, std::string &Result);
++bool convertWideToUTF8(const std::string &Source, std::string &Result);
+
+
+ /**
+diff -ruN llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/ConvertUTFWrapper.cpp llvm-project-llvmorg-12.0.0/llvm/lib/Support/ConvertUTFWrapper.cpp
+--- llvm-orig/llvm-project-llvmorg-12.0.0/llvm/lib/Support/ConvertUTFWrapper.cpp 2021-04-06 19:38:18.000000000 +0300
++++ llvm-project-llvmorg-12.0.0/llvm/lib/Support/ConvertUTFWrapper.cpp 2021-06-09 16:15:53.330400711 +0300
+@@ -196,15 +196,15 @@
+ Result.clear();
+ return false;
+ }
+- Result.resize(reinterpret_cast<wchar_t *>(ResultPtr) - &Result[0]);
++ Result.resize(reinterpret_cast<char *>(ResultPtr) - &Result[0]);
+ return true;
+ }
+
+-bool ConvertUTF8toWide(llvm::StringRef Source, std::wstring &Result) {
++bool ConvertUTF8toWide(llvm::StringRef Source, std::string &Result) {
+ return ConvertUTF8toWideInternal(Source, Result);
+ }
+
+-bool ConvertUTF8toWide(const char *Source, std::wstring &Result) {
++bool ConvertUTF8toWide(const char *Source, std::string &Result) {
+ if (!Source) {
+ Result.clear();
+ return true;
+@@ -212,7 +212,7 @@
+ return ConvertUTF8toWide(llvm::StringRef(Source), Result);
+ }
+
+-bool convertWideToUTF8(const std::wstring &Source, std::string &Result) {
++bool convertWideToUTF8(const std::string &Source, std::string &Result) {
+ if (sizeof(wchar_t) == 1) {
+ const UTF8 *Start = reinterpret_cast<const UTF8 *>(Source.data());
+ const UTF8 *End =