From 7da453bdc49783bd840f33fec102c68135700f6c Mon Sep 17 00:00:00 2001 From: Peter Trommler Date: Sun, 2 Jan 2022 11:53:05 +0100 Subject: [PATCH] ghc: fix build on big-endian architectures Add patch Disable-unboxed-arrays.patch for ghc issue #16998 https://gitlab.haskell.org/ghc/ghc/-/issues/16998. This patch has been accepted upstream as https://github.com/haskell/containers/commit/f5a511f1ff2cf16e710342948792cb8d7576e27c Refresh patches ppc64-be-elfv2.patch, sphinx-unicode.patch so they apply cleanly again. --- .../ghc/patches/Disable-unboxed-arrays.patch | 33 +++++++ srcpkgs/ghc/patches/ppc64-be-elfv2.patch | 98 +++++++++---------- srcpkgs/ghc/patches/sphinx-unicode.patch | 13 ++- 3 files changed, 90 insertions(+), 54 deletions(-) create mode 100644 srcpkgs/ghc/patches/Disable-unboxed-arrays.patch diff --git a/srcpkgs/ghc/patches/Disable-unboxed-arrays.patch b/srcpkgs/ghc/patches/Disable-unboxed-arrays.patch new file mode 100644 index 000000000000..46c2cf1091da --- /dev/null +++ b/srcpkgs/ghc/patches/Disable-unboxed-arrays.patch @@ -0,0 +1,33 @@ +From c74cdea9e6804d10660035700136975cfd39da8d Mon Sep 17 00:00:00 2001 +From: Peter Trommler +Date: Fri, 31 Dec 2021 18:20:45 +0100 +Subject: [PATCH] Disable unboxed arrays on big-endian + +Unboxed arrays are broken on big-endian architectures, see +https://gitlab.haskell.org/ghc/ghc/-/issues/16998 for details. +This patch makes the use of unboxed arrays conditional on +little-endian architecture. + +Fixes #673 + +diff --git a/libraries/containers/containers/include/containers.h b/libraries/containers/containers/include/containers.h +index cd201ca..fc2a0e8 100644 +--- a/libraries/containers/containers/include/containers.h ++++ b/libraries/containers/containers/include/containers.h +@@ -35,7 +35,13 @@ + + #ifdef __GLASGOW_HASKELL__ + # define USE_ST_MONAD 1 ++#ifndef WORDS_BIGENDIAN ++/* ++ * Unboxed arrays are broken on big-endian architectures. ++ * See https://gitlab.haskell.org/ghc/ghc/-/issues/16998 ++ */ + # define USE_UNBOXED_ARRAYS 1 + #endif ++#endif + + #endif +-- +2.31.1 + diff --git a/srcpkgs/ghc/patches/ppc64-be-elfv2.patch b/srcpkgs/ghc/patches/ppc64-be-elfv2.patch index c9bd2583abe0..f7c4d3491dff 100644 --- a/srcpkgs/ghc/patches/ppc64-be-elfv2.patch +++ b/srcpkgs/ghc/patches/ppc64-be-elfv2.patch @@ -13,11 +13,11 @@ Subject: [PATCH] fix up runtime for ppc64 BE ELFv2 + ensure it's used rts/StgCRunAsm.S | 2 +- 7 files changed, 26 insertions(+), 34 deletions(-) -diff --git a/aclocal.m4 b/aclocal.m4 -index 41cecf0..ba08bd2 100644 ---- a/aclocal.m4 -+++ b/aclocal.m4 -@@ -190,7 +190,7 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS], +Index: ghc-8.10.4/aclocal.m4 +=================================================================== +--- ghc-8.10.4.orig/aclocal.m4 ++++ ghc-8.10.4/aclocal.m4 +@@ -199,7 +199,7 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_V test -z "[$]2" || eval "[$]2=ArchPPC" ;; powerpc64) @@ -26,11 +26,11 @@ index 41cecf0..ba08bd2 100644 ;; powerpc64le) test -z "[$]2" || eval "[$]2=\"ArchPPC_64 {ppc_64ABI = ELF_V2}\"" -diff --git a/configure b/configure -index 183e661..8aae1bc 100755 ---- a/configure -+++ b/configure -@@ -9868,7 +9868,7 @@ $as_echo "done" >&6; } +Index: ghc-8.10.4/configure +=================================================================== +--- ghc-8.10.4.orig/configure ++++ ghc-8.10.4/configure +@@ -10296,7 +10296,7 @@ $as_echo "done" >&6; } test -z "$2" || eval "$2=ArchPPC" ;; powerpc64) @@ -39,10 +39,10 @@ index 183e661..8aae1bc 100755 ;; powerpc64le) test -z "$2" || eval "$2=\"ArchPPC_64 {ppc_64ABI = ELF_V2}\"" -diff --git a/libraries/ghci/GHCi/InfoTable.hsc b/libraries/ghci/GHCi/InfoTable.hsc -index ec3c18a..0359be7 100644 ---- a/libraries/ghci/GHCi/InfoTable.hsc -+++ b/libraries/ghci/GHCi/InfoTable.hsc +Index: ghc-8.10.4/libraries/ghci/GHCi/InfoTable.hsc +=================================================================== +--- ghc-8.10.4.orig/libraries/ghci/GHCi/InfoTable.hsc ++++ ghc-8.10.4/libraries/ghci/GHCi/InfoTable.hsc @@ -228,30 +228,22 @@ mkJumpToAddr a = case platform of , fromIntegral w64 , fromIntegral (w64 `shiftR` 32) ] @@ -85,15 +85,15 @@ index ec3c18a..0359be7 100644 + in Right [ 0x3D800000 .|. hi16 w32, + 0x618C0000 .|. lo16 w32, + 0x7D8903A6, 0x4E800420 ] - + ArchPPC64LE -> -- The ABI requires r12 to point to the function's entry point. -diff --git a/rts/Adjustor.c b/rts/Adjustor.c -index d360cfe..ab7ede7 100644 ---- a/rts/Adjustor.c -+++ b/rts/Adjustor.c +Index: ghc-8.10.4/rts/Adjustor.c +=================================================================== +--- ghc-8.10.4.orig/rts/Adjustor.c ++++ ghc-8.10.4/rts/Adjustor.c @@ -49,7 +49,7 @@ Haskell side. - + #if defined(i386_HOST_ARCH) extern void adjustorCode(void); -#elif defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) @@ -104,16 +104,16 @@ index d360cfe..ab7ede7 100644 @@ -278,7 +278,7 @@ __asm__("obscure_ccall_ret_code:\n\t" extern void obscure_ccall_ret_code(void); #endif - + -#if defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) +#if defined(powerpc_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF != 2)) #if !(defined(powerpc_HOST_ARCH) && defined(linux_HOST_OS)) - + /* !!! !!! WARNING: !!! !!! @@ -318,7 +318,7 @@ typedef struct AdjustorStub { } AdjustorStub; #endif - + -#if defined(i386_HOST_ARCH) || defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) +#if defined(i386_HOST_ARCH) || defined(powerpc_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF != 2)) static int totalArgumentSize(char *typeString) @@ -128,13 +128,13 @@ index d360cfe..ab7ede7 100644 STG_UNUSED #endif ) -@@ -1007,7 +1007,7 @@ TODO: Depending on how much allocation overhead stgMallocBytes uses for +@@ -1007,7 +1007,7 @@ TODO: Depending on how much allocation o } } - + -#elif defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) -+#elif defined(powerpc_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF != 2)) - ++#elif defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) && (_CALL_ELF !=2)) + #define OP_LO(op,lo) ((((unsigned)(op)) << 16) | (((unsigned)(lo)) & 0xFFFF)) #define OP_HI(op,hi) ((((unsigned)(op)) << 16) | (((unsigned)(hi)) >> 16)) @@ -1271,7 +1271,7 @@ freeHaskellFunctionPtr(void* ptr) @@ -146,49 +146,49 @@ index d360cfe..ab7ede7 100644 if ( ((AdjustorStub*)ptr)->code != (StgFunPtr) &adjustorCode ) { errorBelch("freeHaskellFunctionPtr: not for me, guv! %p\n", ptr); return; -diff --git a/rts/AdjustorAsm.S b/rts/AdjustorAsm.S -index 2795b83..63cfe91 100644 ---- a/rts/AdjustorAsm.S -+++ b/rts/AdjustorAsm.S +Index: ghc-8.10.4/rts/AdjustorAsm.S +=================================================================== +--- ghc-8.10.4.orig/rts/AdjustorAsm.S ++++ ghc-8.10.4/rts/AdjustorAsm.S @@ -2,7 +2,7 @@ - + /* ******************************** PowerPC ******************************** */ - + -#if defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) +#if defined(powerpc_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF != 2)) #if !(defined(powerpc_HOST_ARCH) && defined(linux_HOST_OS)) /* The following code applies, with some differences, to all powerpc platforms except for powerpc32-linux, -diff --git a/rts/StgCRun.c b/rts/StgCRun.c -index 934926e..2ff8662 100644 ---- a/rts/StgCRun.c -+++ b/rts/StgCRun.c -@@ -717,7 +717,7 @@ StgRunIsImplementedInAssembler(void) +Index: ghc-8.10.4/rts/StgCRun.c +=================================================================== +--- ghc-8.10.4.orig/rts/StgCRun.c ++++ ghc-8.10.4/rts/StgCRun.c +@@ -726,7 +726,7 @@ StgRunIsImplementedInAssembler(void) Everything is in assembler, so we don't have to deal with GCC... -------------------------------------------------------------------------- */ - + -#if defined(powerpc64_HOST_ARCH) +#if defined(powerpc64_HOST_ARCH) && (_CALL_ELF != 2) - + static void GNUC3_ATTRIBUTE(used) StgRunIsImplementedInAssembler(void) -@@ -842,7 +842,7 @@ StgRunIsImplementedInAssembler(void) - +@@ -851,7 +851,7 @@ StgRunIsImplementedInAssembler(void) + #endif - + -#if defined(powerpc64le_HOST_ARCH) +#if defined(powerpc64le_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF == 2)) /* ----------------------------------------------------------------------------- PowerPC 64 little endian architecture - -diff --git a/rts/StgCRunAsm.S b/rts/StgCRunAsm.S -index 9274a44..3b4fc33 100644 ---- a/rts/StgCRunAsm.S -+++ b/rts/StgCRunAsm.S + +Index: ghc-8.10.4/rts/StgCRunAsm.S +=================================================================== +--- ghc-8.10.4.orig/rts/StgCRunAsm.S ++++ ghc-8.10.4/rts/StgCRunAsm.S @@ -5,7 +5,7 @@ * then functions StgRun/StgReturn are implemented in file StgCRun.c */ #if !defined(USE_MINIINTERPRETER) - + -#if defined(powerpc64le_HOST_ARCH) +#if defined(powerpc64le_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF == 2)) # if defined(linux_HOST_OS) diff --git a/srcpkgs/ghc/patches/sphinx-unicode.patch b/srcpkgs/ghc/patches/sphinx-unicode.patch index 0286b9c2bd31..84bafaaa658a 100644 --- a/srcpkgs/ghc/patches/sphinx-unicode.patch +++ b/srcpkgs/ghc/patches/sphinx-unicode.patch @@ -1,17 +1,20 @@ -diff -rpU2 ghc-8.8.4-orig/docs/users_guide/conf.py ghc-8.8.4/docs/users_guide/conf.py ---- ghc-8.8.4-orig/docs/users_guide/conf.py 2020-07-08 16:43:03.000000000 +0000 -+++ ghc-8.8.4/docs/users_guide/conf.py 2021-07-10 20:25:33.536928487 +0000 -@@ -78,5 +78,5 @@ latex_elements = { +Index: ghc-8.10.4/docs/users_guide/conf.py +=================================================================== +--- ghc-8.10.4.orig/docs/users_guide/conf.py ++++ ghc-8.10.4/docs/users_guide/conf.py +@@ -100,13 +100,13 @@ htmlhelp_basename = 'GHCUsersGuide' + latex_elements = { 'inputenc': '', 'utf8extra': '', - 'preamble': ''' + 'preamble': r''' \usepackage{fontspec} \usepackage{makeidx} -@@ -84,5 +84,5 @@ latex_elements = { + \setsansfont{DejaVu Sans} \setromanfont{DejaVu Serif} \setmonofont{DejaVu Sans Mono} -\setlength{\\tymin}{45pt} +\setlength{\tymin}{45pt} ''', } +