serenity/Toolchain/Patches/llvm/0005-libcxx-Add-support-for-SerenityOS.patch
Dan Klishch fa1eef8bbe Toolchain: Update LLVM to 18.1.3
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.
2024-04-18 13:14:33 -06:00

133 lines
5.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Daniel Bertalan <dani@danielbertalan.dev>
Date: Thu, 14 Apr 2022 10:17:13 +0200
Subject: [PATCH] [libcxx] Add support for SerenityOS
This commit teaches libc++ about what features are available in our
LibC, namely:
* We do not have locale support, so no-op shims should be used in place
of the C locale API.
* The number of errno constants defined by us is given by the value of
the `ELAST` macro.
* Multithreading is implemented though the pthread library.
* Use libc++'s builtin character type table instead of the one provided
by LibC as there's a lot of extra porting work to convince the rest of
locale.cpp to use our character type table properly.
---
libcxx/include/CMakeLists.txt | 1 +
libcxx/include/__config | 5 +++--
libcxx/include/__locale | 2 ++
libcxx/include/__support/serenity/xlocale.h | 24 +++++++++++++++++++++
libcxx/include/locale | 2 +-
libcxx/src/include/config_elast.h | 2 ++
6 files changed, 33 insertions(+), 3 deletions(-)
create mode 100644 libcxx/include/__support/serenity/xlocale.h
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index ed721d467e94..5641e32b1343 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -675,6 +675,7 @@ set(files
__support/musl/xlocale.h
__support/newlib/xlocale.h
__support/openbsd/xlocale.h
+ __support/serenity/xlocale.h
__support/win32/locale_win32.h
__support/xlocale/__nop_locale_mgmt.h
__support/xlocale/__posix_l_fallback.h
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 8b2eaf69d170..53a09f46eaf7 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1103,7 +1103,8 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
defined(__APPLE__) || \
defined(__MVS__) || \
defined(_AIX) || \
- defined(__EMSCRIPTEN__)
+ defined(__EMSCRIPTEN__) || \
+ defined(__serenity__)
// clang-format on
# define _LIBCPP_HAS_THREAD_API_PTHREAD
# elif defined(__Fuchsia__)
@@ -1176,7 +1177,7 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
# endif
# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
- defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
+ defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) || defined(__serenity__)
# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
# endif
diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index 3ba7ac18b0b3..9a68dade7fef 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -51,6 +51,8 @@
# include <__support/musl/xlocale.h>
#elif defined(_LIBCPP_HAS_MUSL_LIBC)
# include <__support/musl/xlocale.h>
+#elif defined(__serenity__)
+# include <__support/serenity/xlocale.h>
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/__support/serenity/xlocale.h b/libcxx/include/__support/serenity/xlocale.h
new file mode 100644
index 000000000000..67c85bf641e2
--- /dev/null
+++ b/libcxx/include/__support/serenity/xlocale.h
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_SERENITY_XLOCALE_H
+#define _LIBCPP_SUPPORT_SERENITY_XLOCALE_H
+
+#if defined(__serenity__)
+
+# include <__support/xlocale/__nop_locale_mgmt.h>
+# include <__support/xlocale/__posix_l_fallback.h>
+# include <__support/xlocale/__strtonum_fallback.h>
+# include <clocale>
+# include <cstdlib>
+# include <ctype.h>
+# include <cwctype>
+
+#endif // __serenity__
+
+#endif
diff --git a/libcxx/include/locale b/libcxx/include/locale
index 9e97eb9f3395..4bcdc13c1967 100644
--- a/libcxx/include/locale
+++ b/libcxx/include/locale
@@ -217,7 +217,7 @@ template <class charT> class messages_byname;
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
// Most unix variants have catopen. These are the specific ones that don't.
-# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
+# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__) && !defined(__serenity__)
# define _LIBCPP_HAS_CATOPEN 1
# include <nl_types.h>
# endif
diff --git a/libcxx/src/include/config_elast.h b/libcxx/src/include/config_elast.h
index 899e124ad261..11d930bc8a3c 100644
--- a/libcxx/src/include/config_elast.h
+++ b/libcxx/src/include/config_elast.h
@@ -35,6 +35,8 @@
# define _LIBCPP_ELAST 4095
#elif defined(__APPLE__)
// No _LIBCPP_ELAST needed on Apple
+#elif defined(__serenity__)
+// No _LIBCPP_ELAST needed on SerenityOS
#elif defined(__MVS__)
# define _LIBCPP_ELAST 1160
#elif defined(_LIBCPP_MSVCRT_LIKE)
--
2.44.0