From b0b0bbe0ad217f9239282898ae65e7767d4704d9 Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 27 Apr 2021 22:58:48 +0200 Subject: [PATCH] webkit2gtk: work out the remaining musl stack size problems --- srcpkgs/webkit2gtk/patches/musl-fixes.patch | 80 +++++++++++++ .../webkit2gtk/patches/musl-stack-fix.patch | 74 ++++++++++++ .../patches/musl-thread-stack.patch | 113 ------------------ .../webkit2gtk/patches/musl-wordsize.patch | 59 +++++++++ srcpkgs/webkit2gtk/template | 8 +- 5 files changed, 214 insertions(+), 120 deletions(-) create mode 100644 srcpkgs/webkit2gtk/patches/musl-fixes.patch create mode 100644 srcpkgs/webkit2gtk/patches/musl-stack-fix.patch delete mode 100644 srcpkgs/webkit2gtk/patches/musl-thread-stack.patch create mode 100644 srcpkgs/webkit2gtk/patches/musl-wordsize.patch diff --git a/srcpkgs/webkit2gtk/patches/musl-fixes.patch b/srcpkgs/webkit2gtk/patches/musl-fixes.patch new file mode 100644 index 0000000000..b87497c99b --- /dev/null +++ b/srcpkgs/webkit2gtk/patches/musl-fixes.patch @@ -0,0 +1,80 @@ +Upstream: yes + +--- Source/JavaScriptCore/runtime/MachineContext.h ++++ Source/JavaScriptCore/runtime/MachineContext.h +@@ -196,7 +196,7 @@ static inline void*& stackPointerImpl(mcontext_t& machineContext) + #error Unknown Architecture + #endif + +-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) ++#elif OS(FUCHSIA) || OS(LINUX) + + #if CPU(X86) + return reinterpret_cast((uintptr_t&) machineContext.gregs[REG_ESP]); +@@ -347,7 +347,7 @@ static inline void*& framePointerImpl(mcontext_t& machineContext) + #error Unknown Architecture + #endif + +-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) ++#elif OS(FUCHSIA) || OS(LINUX) + + // The following sequence depends on glibc's sys/ucontext.h. + #if CPU(X86) +@@ -498,7 +498,7 @@ static inline void*& instructionPointerImpl(mcontext_t& machineContext) + #error Unknown Architecture + #endif + +-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) ++#elif OS(FUCHSIA) || OS(LINUX) + + // The following sequence depends on glibc's sys/ucontext.h. + #if CPU(X86) +@@ -656,7 +656,7 @@ inline void*& argumentPointer<1>(mcontext_t& machineContext) + #error Unknown Architecture + #endif + +-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) ++#elif OS(FUCHSIA) || OS(LINUX) + + // The following sequence depends on glibc's sys/ucontext.h. + #if CPU(X86) +@@ -773,7 +773,7 @@ inline void*& llintInstructionPointer(mcontext_t& machineContext) + #error Unknown Architecture + #endif + +-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) ++#elif OS(FUCHSIA) || OS(LINUX) + + // The following sequence depends on glibc's sys/ucontext.h. + #if CPU(X86) +--- Source/WebCore/xml/XPathGrammar.cpp ++++ Source/WebCore/xml/XPathGrammar.cpp +@@ -966,7 +966,7 @@ int yydebug; + #if YYERROR_VERBOSE + + # ifndef yystrlen +-# if defined __GLIBC__ && defined _STRING_H ++# if defined __linux__ && defined _STRING_H + # define yystrlen strlen + # else + /* Return the length of YYSTR. */ +@@ -989,7 +989,7 @@ yystrlen (yystr) + # endif + + # ifndef yystpcpy +-# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE ++# if defined __linux__ && defined _STRING_H && defined _GNU_SOURCE + # define yystpcpy stpcpy + # else + /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in +--- Source/WTF/wtf/PlatformHave.h ++++ Source/WTF/wtf/PlatformHave.h +@@ -206,7 +206,7 @@ + #define HAVE_HOSTED_CORE_ANIMATION 1 + #endif + +-#if OS(DARWIN) || OS(FUCHSIA) || ((OS(FREEBSD) || defined(__GLIBC__) || defined(__BIONIC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS))) ++#if OS(DARWIN) || OS(FUCHSIA) || ((OS(FREEBSD) || OS(LINUX)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS))) + #define HAVE_MACHINE_CONTEXT 1 + #endif + diff --git a/srcpkgs/webkit2gtk/patches/musl-stack-fix.patch b/srcpkgs/webkit2gtk/patches/musl-stack-fix.patch new file mode 100644 index 0000000000..0ca82cb50d --- /dev/null +++ b/srcpkgs/webkit2gtk/patches/musl-stack-fix.patch @@ -0,0 +1,74 @@ +https://bugs.webkit.org/show_bug.cgi?id=225099 + +From ab7e2bfae280b151ac173d6fc9d8eaa3da2e92a8 Mon Sep 17 00:00:00 2001 +From: q66 +Date: Tue, 27 Apr 2021 22:51:22 +0200 +Subject: [PATCH] fix stack size issues on musl + +--- + Source/WTF/wtf/StackBounds.cpp | 26 +++++++++++++++++++++++++- + Source/WTF/wtf/Threading.cpp | 4 ++++ + 2 files changed, 29 insertions(+), 1 deletion(-) + +diff --git Source/WTF/wtf/StackBounds.cpp Source/WTF/wtf/StackBounds.cpp +index e6f7095..58bdb18 100644 +--- Source/WTF/wtf/StackBounds.cpp ++++ Source/WTF/wtf/StackBounds.cpp +@@ -36,6 +36,12 @@ + #include + #endif + ++#if OS(LINUX) ++#include ++#include ++#include ++#endif ++ + #endif + + namespace WTF { +@@ -107,7 +113,25 @@ StackBounds StackBounds::newThreadStackBounds(PlatformThreadHandle thread) + + StackBounds StackBounds::currentThreadStackBoundsInternal() + { +- return newThreadStackBounds(pthread_self()); ++ auto ret = newThreadStackBounds(pthread_self()); ++#if OS(LINUX) ++ // on glibc, pthread_attr_getstack will generally return the limit size (minus a guard page) ++ // for the main thread; this is however not necessarily always true on every libc - for example ++ // on musl, it will return the currently reserved size - since the stack bounds are expected to ++ // be constant (and they are for every thread except main, which is allowed to grow), check ++ // resource limits and use that as the boundary instead (and prevent stack overflows in JSC) ++ if (getpid() == static_cast(syscall(SYS_gettid))) { ++ void* origin = ret.origin(); ++ rlimit limit; ++ getrlimit(RLIMIT_STACK, &limit); ++ rlim_t size = limit.rlim_cur; ++ // account for a guard page ++ size -= static_cast(sysconf(_SC_PAGESIZE)); ++ void* bound = static_cast(origin) - size; ++ return StackBounds { origin, bound }; ++ } ++#endif ++ return ret; + } + + #elif OS(WINDOWS) +diff --git Source/WTF/wtf/Threading.cpp Source/WTF/wtf/Threading.cpp +index 99d09c0..362bf35 100644 +--- Source/WTF/wtf/Threading.cpp ++++ Source/WTF/wtf/Threading.cpp +@@ -58,6 +58,10 @@ static Optional stackSize(ThreadType threadType) + + #if defined(DEFAULT_THREAD_STACK_SIZE_IN_KB) && DEFAULT_THREAD_STACK_SIZE_IN_KB > 0 + return DEFAULT_THREAD_STACK_SIZE_IN_KB * 1024; ++#elif OS(LINUX) && !defined(__BIONIC__) && !defined(__GLIBC__) ++ // on libc's other than glibc and bionic (e.g. musl) we are either unsure how big ++ // the default thread stack is, or we know it's too small - pick a robust default ++ return 1 * MB; + #else + // Use the platform's default stack size + return WTF::nullopt; +-- +2.30.1 + diff --git a/srcpkgs/webkit2gtk/patches/musl-thread-stack.patch b/srcpkgs/webkit2gtk/patches/musl-thread-stack.patch deleted file mode 100644 index a0acbde956..0000000000 --- a/srcpkgs/webkit2gtk/patches/musl-thread-stack.patch +++ /dev/null @@ -1,113 +0,0 @@ -Source: https://github.com/WebKit/WebKit/commit/6884d13 (tweaked values) - -diff --git Source/JavaScriptCore/runtime/MachineContext.h Source/JavaScriptCore/runtime/MachineContext.h -index ead9cdf..86b36ca 100644 ---- Source/JavaScriptCore/runtime/MachineContext.h -+++ Source/JavaScriptCore/runtime/MachineContext.h -@@ -196,7 +196,7 @@ static inline void*& stackPointerImpl(mcontext_t& machineContext) - #error Unknown Architecture - #endif - --#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) -+#elif OS(FUCHSIA) || OS(LINUX) - - #if CPU(X86) - return reinterpret_cast((uintptr_t&) machineContext.gregs[REG_ESP]); -@@ -347,7 +347,7 @@ static inline void*& framePointerImpl(mcontext_t& machineContext) - #error Unknown Architecture - #endif - --#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) -+#elif OS(FUCHSIA) || OS(LINUX) - - // The following sequence depends on glibc's sys/ucontext.h. - #if CPU(X86) -@@ -498,7 +498,7 @@ static inline void*& instructionPointerImpl(mcontext_t& machineContext) - #error Unknown Architecture - #endif - --#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) -+#elif OS(FUCHSIA) || OS(LINUX) - - // The following sequence depends on glibc's sys/ucontext.h. - #if CPU(X86) -@@ -656,7 +656,7 @@ inline void*& argumentPointer<1>(mcontext_t& machineContext) - #error Unknown Architecture - #endif - --#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) -+#elif OS(FUCHSIA) || OS(LINUX) - - // The following sequence depends on glibc's sys/ucontext.h. - #if CPU(X86) -@@ -773,7 +773,7 @@ inline void*& llintInstructionPointer(mcontext_t& machineContext) - #error Unknown Architecture - #endif - --#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__) -+#elif OS(FUCHSIA) || OS(LINUX) - - // The following sequence depends on glibc's sys/ucontext.h. - #if CPU(X86) -diff --git Source/JavaScriptCore/runtime/OptionsList.h Source/JavaScriptCore/runtime/OptionsList.h -index bc1cedb..f4a86a5 100644 ---- Source/JavaScriptCore/runtime/OptionsList.h -+++ Source/JavaScriptCore/runtime/OptionsList.h -@@ -71,6 +71,18 @@ JS_EXPORT_PRIVATE bool canUseJITCage(); - // On instantiation of the first VM instance, the Options will be write protected - // and cannot be modified thereafter. - -+#if OS(LINUX) && !defined(__BIONIC__) && !defined(__GLIBC__) -+// non-glibc/non-android options on linux ( musl ) -+constexpr unsigned jscMaxPerThreadStack = 2 * MB; -+constexpr unsigned jscSoftReservedZoneSize = 64 * KB; -+constexpr unsigned jscReservedZoneSize = 32 * KB; -+#else -+// default -+constexpr unsigned jscMaxPerThreadStack = 5 * MB; -+constexpr unsigned jscSoftReservedZoneSize = 128 * KB; -+constexpr unsigned jscReservedZoneSize = 64 * KB; -+#endif -+ - #define FOR_EACH_JSC_OPTION(v) \ - v(Bool, useKernTCSM, defaultTCSMValue(), Normal, "Note: this needs to go before other options since they depend on this value.") \ - v(Bool, validateOptions, false, Normal, "crashes if mis-typed JSC options were passed to the VM") \ -@@ -86,9 +98,9 @@ JS_EXPORT_PRIVATE bool canUseJITCage(); - \ - v(Bool, reportMustSucceedExecutableAllocations, false, Normal, nullptr) \ - \ -- v(Unsigned, maxPerThreadStackUsage, 5 * MB, Normal, "Max allowed stack usage by the VM") \ -- v(Unsigned, softReservedZoneSize, 128 * KB, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \ -- v(Unsigned, reservedZoneSize, 64 * KB, Normal, "The amount of stack space we guarantee to our clients (and to interal VM code that does not call out to clients).") \ -+ v(Unsigned, maxPerThreadStackUsage, jscMaxPerThreadStack, Normal, "Max allowed stack usage by the VM") \ -+ v(Unsigned, softReservedZoneSize, jscSoftReservedZoneSize, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \ -+ v(Unsigned, reservedZoneSize, jscReservedZoneSize, Normal, "The amount of stack space we guarantee to our clients (and to interal VM code that does not call out to clients).") \ - \ - v(Bool, crashOnDisallowedVMEntry, ASSERT_ENABLED, Normal, "Forces a crash if we attempt to enter the VM when disallowed") \ - v(Bool, crashIfCantAllocateJITMemory, false, Normal, nullptr) \ -diff --git Source/WTF/wtf/PlatformHave.h Source/WTF/wtf/PlatformHave.h -index 41afbb4..ab5263c 100644 ---- Source/WTF/wtf/PlatformHave.h -+++ Source/WTF/wtf/PlatformHave.h -@@ -206,7 +206,7 @@ - #define HAVE_HOSTED_CORE_ANIMATION 1 - #endif - --#if OS(DARWIN) || OS(FUCHSIA) || ((OS(FREEBSD) || defined(__GLIBC__) || defined(__BIONIC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS))) -+#if OS(DARWIN) || OS(FUCHSIA) || ((OS(FREEBSD) || OS(LINUX)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS))) - #define HAVE_MACHINE_CONTEXT 1 - #endif - -diff --git Source/WTF/wtf/Threading.cpp Source/WTF/wtf/Threading.cpp -index 99d09c0..723a8f4 100644 ---- Source/WTF/wtf/Threading.cpp -+++ Source/WTF/wtf/Threading.cpp -@@ -52,6 +52,8 @@ static Optional stackSize(ThreadType threadType) - #elif OS(DARWIN) && ASAN_ENABLED - if (threadType == ThreadType::Compiler) - return 1 * MB; // ASan needs more stack space (especially on Debug builds). -+#elif OS(LINUX) && !defined(__BIONIC__) && !defined(__GLIBC__) // MUSL default thread stack size. -+ return 2 * MB; - #else - UNUSED_PARAM(threadType); - #endif diff --git a/srcpkgs/webkit2gtk/patches/musl-wordsize.patch b/srcpkgs/webkit2gtk/patches/musl-wordsize.patch new file mode 100644 index 0000000000..069abd753d --- /dev/null +++ b/srcpkgs/webkit2gtk/patches/musl-wordsize.patch @@ -0,0 +1,59 @@ +Upstream: yes + +From 1b7144916774dbb4cc4705ba9a4377844e35f47d Mon Sep 17 00:00:00 2001 +From: q66 +Date: Tue, 27 Apr 2021 22:56:33 +0200 +Subject: [PATCH] remove __WORDSIZE usage + +--- + Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp | 6 +++--- + Source/WebCore/rendering/RenderLayerBacking.h | 2 +- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp +index cfe3698..e5bc870 100644 +--- Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp ++++ Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp +@@ -39,7 +39,7 @@ namespace CryptoAlgorithmAES_GCMInternal { + static const char* const ALG128 = "A128GCM"; + static const char* const ALG192 = "A192GCM"; + static const char* const ALG256 = "A256GCM"; +-#if __WORDSIZE >= 64 ++#if CPU(ADDRESS64) + static const uint64_t PlainTextMaxLength = 549755813632ULL; // 2^39 - 256 + #endif + static const uint8_t DefaultTagLength = 128; +@@ -77,7 +77,7 @@ void CryptoAlgorithmAES_GCM::encrypt(const CryptoAlgorithmParameters& parameters + + auto& aesParameters = downcast(parameters); + +-#if __WORDSIZE >= 64 ++#if CPU(ADDRESS64) + if (plainText.size() > PlainTextMaxLength) { + exceptionCallback(OperationError); + return; +@@ -120,7 +120,7 @@ void CryptoAlgorithmAES_GCM::decrypt(const CryptoAlgorithmParameters& parameters + return; + } + +-#if __WORDSIZE >= 64 ++#if CPU(ADDRESS64) + if (aesParameters.ivVector().size() > UINT64_MAX) { + exceptionCallback(OperationError); + return; +diff --git Source/WebCore/rendering/RenderLayerBacking.h Source/WebCore/rendering/RenderLayerBacking.h +index 9960724..193c5d1 100644 +--- Source/WebCore/rendering/RenderLayerBacking.h ++++ Source/WebCore/rendering/RenderLayerBacking.h +@@ -43,7 +43,7 @@ class TiledBacking; + class TransformationMatrix; + + +-#if __WORDSIZE == 64 && PLATFORM(COCOA) ++#if CPU(ADDRESS64) && PLATFORM(COCOA) + #define USE_OWNING_LAYER_BEAR_TRAP 1 + #define BEAR_TRAP_VALUE 0xEEEEEEEEEEEEEEEE + #else +-- +2.30.1 + diff --git a/srcpkgs/webkit2gtk/template b/srcpkgs/webkit2gtk/template index 5a2621b6c9..270d2a4f5f 100644 --- a/srcpkgs/webkit2gtk/template +++ b/srcpkgs/webkit2gtk/template @@ -2,7 +2,7 @@ # ping q66 before touching this pkgname=webkit2gtk version=2.32.0 -revision=2 +revision=3 wrksrc="webkitgtk-${version}" build_style=cmake build_helper="gir" @@ -48,12 +48,6 @@ desc_option_sampling_profiler="Sampling profiler support (JIT + glibc only)" desc_option_minibrowser="Build the minibrowser" export CFLAGS="-DNDEBUG" - -if [ "$XBPS_TARGET_LIBC" = "musl" ]; then - # this is not defined on musl and is occasionally used - export CFLAGS+=" -D__WORDSIZE=${XBPS_TARGET_WORDSIZE}" -fi - export CXXFLAGS="$CFLAGS" # WebKitCCache.cmake set this variable