On Wed, Jul 19, 2023 at 02:29:47PM +0200, Jeremie Courreges-Anglas wrote:
> 
> Since upstream webkit(gtk) switched to JIT by default on riscv64,
> www/webkitgtk4 doesn't build on riscv64.
> 
>   
> http://build-failures.rhaalovely.net/riscv64/2023-06-30/www/webkitgtk4%2Cwebkitgtk41.log
> 
> LowLevelInterpreter.asm doesn't seem fit for architectures that use the
> C_LOOP interpreter (powerpc, powerpc64, sparc64...) instead of JIT.
> Some fix might be needed here.
> 
> Regarding riscv64, I suggest we go with the flow and enable the JIT on
> riscv64.  The diff below drops one patch and adds another one:
> RISCV64Assembler.h assumes that intptr_t and int64_t are the same type,
> which isn't the case on OpenBSD (long vs long long) ; I merely added
> workarounds.  Obviously MachineContext.h needs definitions for riscv64
> too, I hope I haven't messed on of these.
> 
> Using this diff, libexec/jsc computes 1+1 without crashing.  Sadly I was
> not able to test libexec/MiniBrowser over SSH X11 forwarding (WebProcess
> appears to crash with an X11 error[0], just like on amd64).
> 
> ok?

Yup.

> 
> [0] https://pbot.rmdir.de/IdcxBLvuqtLXUwmqtqHt1A
> 
> 
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/www/webkitgtk4/Makefile,v
> retrieving revision 1.194
> diff -u -p -r1.194 Makefile
> --- Makefile  5 Jul 2023 03:53:26 -0000       1.194
> +++ Makefile  16 Jul 2023 13:28:32 -0000
> @@ -111,10 +111,10 @@ CONFIGURE_ARGS +=       -DUSE_WPE_RENDERER=OFF
>  CONFIGURE_ARGS +=    -DENABLE_GAMEPAD=OFF
>  
>  # sync with Source/JavaScriptCore/assembler/MacroAssembler.h
> -# native support for riscv64 in LLInt fails to link with relocation errors
>  .if ${MACHINE_ARCH} != "aarch64" && ${MACHINE_ARCH} != "amd64" && \
>      ${MACHINE_ARCH} != "arm" && ${MACHINE_ARCH} != "i386" && \
> -    ${MACHINE_ARCH} != "mips64" && ${MACHINE_ARCH} != "mips64el"
> +    ${MACHINE_ARCH} != "mips64" && ${MACHINE_ARCH} != "mips64el" && \
> +    ${MACHINE_ARCH} != "riscv64"
>  # #error "The MacroAssembler is not supported on this platform."
>  CONFIGURE_ARGS +=    -DENABLE_JIT=OFF
>  CONFIGURE_ARGS +=    -DENABLE_C_LOOP=ON
> Index: patches/patch-Source_JavaScriptCore_assembler_RISCV64Assembler_h
> ===================================================================
> RCS file: patches/patch-Source_JavaScriptCore_assembler_RISCV64Assembler_h
> diff -N patches/patch-Source_JavaScriptCore_assembler_RISCV64Assembler_h
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-Source_JavaScriptCore_assembler_RISCV64Assembler_h  19 Jul 
> 2023 12:29:14 -0000
> @@ -0,0 +1,55 @@
> +Add definitions to work around type assumptions: on OpenBSD intptr_t is a 
> long
> +and int64_t is a long long.
> +
> +Index: Source/JavaScriptCore/assembler/RISCV64Assembler.h
> +--- Source/JavaScriptCore/assembler/RISCV64Assembler.h.orig
> ++++ Source/JavaScriptCore/assembler/RISCV64Assembler.h
> +@@ -186,7 +186,7 @@ struct ImmediateBase {
> + 
> +     template<typename T>
> +     static auto isValid(T immValue)
> +-        -> std::enable_if_t<(std::is_same_v<T, int32_t> || 
> std::is_same_v<T, int64_t>), bool>
> ++        -> std::enable_if_t<(std::is_same_v<T, int32_t> || 
> std::is_same_v<T, int64_t> || std::is_same_v<T, intptr_t>), bool>
> +     {
> +         constexpr unsigned shift = sizeof(T) * 8 - immediateSize;
> +         return immValue == ((immValue << shift) >> shift);
> +@@ -209,6 +209,14 @@ struct ImmediateBase {
> +     }
> + 
> +     template<typename ImmediateType>
> ++    static ImmediateType v(intptr_t immValue)
> ++    {
> ++        ASSERT(isValid(immValue));
> ++        intptr_t value = *reinterpret_cast<intptr_t*>(&immValue);
> ++        return ImmediateType(uint32_t(value & immediateMask<intptr_t>()));
> ++    }
> ++
> ++    template<typename ImmediateType>
> +     static ImmediateType v(int64_t immValue)
> +     {
> +         ASSERT(isValid(immValue));
> +@@ -310,7 +318,7 @@ struct JImmediate : ImmediateBase<21> {
> + };
> + 
> + struct ImmediateDecomposition {
> +-    template<typename T, typename = std::enable_if_t<(std::is_same_v<T, 
> int32_t> || std::is_same_v<T, int64_t>)>>
> ++    template<typename T, typename = std::enable_if_t<(std::is_same_v<T, 
> int32_t> || std::is_same_v<T, int64_t> || std::is_same_v<T, intptr_t>)>>
> +     explicit ImmediateDecomposition(T immediate)
> +         : upper(UImmediate(0))
> +         , lower(IImmediate(0))
> +@@ -2182,7 +2190,15 @@ class RISCV64Assembler { (public)
> +             : ImmediateLoader(int64_t(imm))
> +         { }
> + 
> ++        ImmediateLoader(intptr_t imm)
> ++            : ImmediateLoader(int64_t(imm))
> ++        { }
> ++
> +         ImmediateLoader(PlaceholderTag, int32_t imm)
> ++            : ImmediateLoader(Placeholder, int64_t(imm))
> ++        { }
> ++
> ++        ImmediateLoader(PlaceholderTag, intptr_t imm)
> +             : ImmediateLoader(Placeholder, int64_t(imm))
> +         { }
> + 
> Index: patches/patch-Source_JavaScriptCore_runtime_MachineContext_h
> ===================================================================
> RCS file: 
> /cvs/ports/www/webkitgtk4/patches/patch-Source_JavaScriptCore_runtime_MachineContext_h,v
> retrieving revision 1.11
> diff -u -p -r1.11 patch-Source_JavaScriptCore_runtime_MachineContext_h
> --- patches/patch-Source_JavaScriptCore_runtime_MachineContext_h      17 Sep 
> 2022 08:13:54 -0000      1.11
> +++ patches/patch-Source_JavaScriptCore_runtime_MachineContext_h      19 Jul 
> 2023 11:44:32 -0000
> @@ -1,7 +1,7 @@
>  Index: Source/JavaScriptCore/runtime/MachineContext.h
>  --- Source/JavaScriptCore/runtime/MachineContext.h.orig
>  +++ Source/JavaScriptCore/runtime/MachineContext.h
> -@@ -193,6 +193,22 @@ static inline void*& stackPointerImpl(mcontext_t& mach
> +@@ -193,6 +193,24 @@ static inline void*& stackPointerImpl(mcontext_t& mach
>   #error Unknown Architecture
>   #endif
>   
> @@ -17,6 +17,8 @@ Index: Source/JavaScriptCore/runtime/Mac
>  +    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_sp);
>  +#elif CPU(MIPS)
>  +    return reinterpret_cast<void*&>((uintptr_t&) 
> machineContext.mc_regs[29]);
> ++#elif CPU(RISCV64)
> ++    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_sp);
>  +#else
>  +#error Unknown Architecture
>  +#endif
> @@ -24,7 +26,7 @@ Index: Source/JavaScriptCore/runtime/Mac
>   #elif OS(FUCHSIA) || OS(LINUX)
>   
>   #if CPU(X86)
> -@@ -338,6 +354,22 @@ static inline void*& framePointerImpl(mcontext_t& mach
> +@@ -338,6 +356,24 @@ static inline void*& framePointerImpl(mcontext_t& mach
>   #error Unknown Architecture
>   #endif
>   
> @@ -40,6 +42,8 @@ Index: Source/JavaScriptCore/runtime/Mac
>  +    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_x[29]);
>  +#elif CPU(MIPS)
>  +    return reinterpret_cast<void*&>((uintptr_t&) 
> machineContext.mc_regs[30]);
> ++#elif CPU(RISCV64)
> ++    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_s[0]);
>  +#else
>  +#error Unknown Architecture
>  +#endif
> @@ -47,7 +51,7 @@ Index: Source/JavaScriptCore/runtime/Mac
>   #elif OS(FUCHSIA) || OS(LINUX)
>   
>   // The following sequence depends on glibc's sys/ucontext.h.
> -@@ -496,6 +528,22 @@ static inline void*& instructionPointerImpl(mcontext_t
> +@@ -496,6 +532,24 @@ static inline void*& instructionPointerImpl(mcontext_t
>   #error Unknown Architecture
>   #endif
>   
> @@ -63,6 +67,8 @@ Index: Source/JavaScriptCore/runtime/Mac
>  +    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_elr);
>  +#elif CPU(MIPS)
>  +    return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_pc);
> ++#elif CPU(RISCV64)
> ++    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_sepc);
>  +#else
>  +#error Unknown Architecture
>  +#endif
> @@ -70,7 +76,7 @@ Index: Source/JavaScriptCore/runtime/Mac
>   #elif OS(FUCHSIA) || OS(LINUX)
>   
>   // The following sequence depends on glibc's sys/ucontext.h.
> -@@ -652,6 +700,22 @@ inline void*& argumentPointer<1>(mcontext_t& machineCo
> +@@ -652,6 +706,24 @@ inline void*& argumentPointer<1>(mcontext_t& machineCo
>   #error Unknown Architecture
>   #endif
>   
> @@ -86,6 +92,8 @@ Index: Source/JavaScriptCore/runtime/Mac
>  +    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_x[1]);
>  +#elif CPU(MIPS)
>  +    return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_regs[5]);
> ++#elif CPU(RISCV64)
> ++    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_a[1]);
>  +#else
>  +#error Unknown Architecture
>  +#endif
> @@ -93,12 +101,10 @@ Index: Source/JavaScriptCore/runtime/Mac
>   #elif OS(FUCHSIA) || OS(LINUX)
>   
>   // The following sequence depends on glibc's sys/ucontext.h.
> -@@ -765,6 +829,22 @@ inline void*& llintInstructionPointer(mcontext_t& mach
> -     return reinterpret_cast<void*&>((uintptr_t&) 
> machineContext.__gregs[_REG_R8]);
> - #elif CPU(ARM64)
> +@@ -767,6 +839,24 @@ inline void*& llintInstructionPointer(mcontext_t& mach
>       return reinterpret_cast<void*&>((uintptr_t&) 
> machineContext.mc_gpregs.gp_x[4]);
> -+#elif CPU(MIPS)
> -+    return reinterpret_cast<void*&>((uintptr_t&) 
> machineContext.mc_regs[12]);
> + #elif CPU(MIPS)
> +     return reinterpret_cast<void*&>((uintptr_t&) 
> machineContext.mc_regs[12]);
>  +#else
>  +#error Unknown Architecture
>  +#endif
> @@ -113,6 +119,10 @@ Index: Source/JavaScriptCore/runtime/Mac
>  +    return reinterpret_cast<void*&>((uintptr_t&) 
> machineContext.__gregs[_REG_R8]);
>  +#elif CPU(ARM64)
>  +    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_x[4]);
> - #elif CPU(MIPS)
> -     return reinterpret_cast<void*&>((uintptr_t&) 
> machineContext.mc_regs[12]);
> ++#elif CPU(MIPS)
> ++    return reinterpret_cast<void*&>((uintptr_t&) 
> machineContext.mc_regs[12]);
> ++#elif CPU(RISCV64)
> ++    return reinterpret_cast<void*&>((uintptr_t&) machineContext.sc_a[3]);
>   #else
> + #error Unknown Architecture
> + #endif
> Index: patches/patch-Source_WTF_wtf_PlatformHave_h
> ===================================================================
> RCS file: 
> /cvs/ports/www/webkitgtk4/patches/patch-Source_WTF_wtf_PlatformHave_h,v
> retrieving revision 1.9
> diff -u -p -r1.9 patch-Source_WTF_wtf_PlatformHave_h
> --- patches/patch-Source_WTF_wtf_PlatformHave_h       7 Apr 2023 14:49:49 
> -0000       1.9
> +++ patches/patch-Source_WTF_wtf_PlatformHave_h       18 Jul 2023 15:50:11 
> -0000
> @@ -1,18 +0,0 @@
> -Undo parts of upstream commit 6c2615dd66a12e9a10d7867241cc3bedfb2b2473 [0]
> -Machine context definitions were only added for Linux.
> -[0] 
> https://github.com/WebKit/WebKit/commit/6c2615dd66a12e9a10d7867241cc3bedfb2b2473
> -
> -Index: Source/WTF/wtf/PlatformHave.h
> ---- Source/WTF/wtf/PlatformHave.h.orig
> -+++ Source/WTF/wtf/PlatformHave.h
> -@@ -229,6 +229,10 @@
> - #define HAVE_MACHINE_CONTEXT 1
> - #endif
> - 
> -+#if OS(OPENBSD) && CPU(RISCV64)
> -+#undef HAVE_MACHINE_CONTEXT
> -+#endif
> -+
> - #if OS(DARWIN) || (OS(LINUX) && defined(__GLIBC__) && !defined(__UCLIBC__) 
> && !CPU(MIPS))
> - #define HAVE_BACKTRACE 1
> - #endif
> 
> -- 
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

-- 
Antoine

Reply via email to