0
0
mirror of https://github.com/termux/termux-packages.git synced 2025-05-12 11:23:30 +00:00
Files
termux-packages/packages/ghc/hadrian-fix-packages-settings.patch
Aditya Alok e21578f662 bump(main/ghc): 9.12.2
Patched `rts` heap reservation logic on Android:

  * Need for patch

  - There seems to be a bug on Android. Sometimes simple commands like `ghc --help` usage 90% - 100% cpu and hangs.

  - It doesn't happen every time, but ~25% of the times (at least in my
    testing).

  * Cause of the bug

  - The function `osReserveHeapMemory` tries to allocate virtual space starting
    from `0x4200000000`. The allocated space has to start at an address >= this address.

  - If the kernel doesn't allocate inside this space, it keeps on repeating the
    `mmap` call with increasing starting point.

  - Now, on Android the kernel sometimes return an address above (as in counting)
    this `hint` address. It repeatedly returns the same address for subsequent calls.

  - Thus, an infinite loop occurs.

  References:
    - 383be28ffd/rts/posix/OSMem.c (L461)
    - https://github.com/termux/termux-packages/pull/22991#issuecomment-2759137291

  * Solution (proposed by Robert Kirkman):

  - It introduces a new helper function `osTryReserveHeapMemoryRecursive`.
    This transforms the heap reservation logic into a recursive one.

  - `osTryReserveHeapMemory()` is run multiple times without unmapping the
    undesired addresses. Thus, forcing the kernel to map subsequent calls of
    `mmap` to a new, unique address until an address above the `0x4200000000`
    mark is obtained.

  - After which each recursive call unmaps its undesired address before returning
    the desired address (in order from last mapped to first mapped).

  References:
    - https://gitlab.haskell.org/ghc/ghc/-/merge_requests/14164
    - https://github.com/termux/termux-packages/pull/22991#issuecomment-2761325484

Co-authored-by: Robert Kirkman <rkirkman@termux.dev>
Signed-off-by: Aditya Alok <alok@termux.dev>
2025-04-08 18:17:01 +02:00

47 lines
2.4 KiB
Diff

--- ghc-9.12.2/hadrian/src/Settings/Packages.hs 2025-03-29 15:32:47.000000000 +0530
+++ ghc-9.12.2.mod/hadrian/src/Settings/Packages.hs 2025-04-07 15:06:41.398290889 +0530
@@ -85,8 +85,8 @@
-- (#14335) and completely untested in CI for cross
-- backends at the moment, so we might as well disable it
-- for cross GHC.
- [ andM [expr ghcWithInterpreter, notStage0, notCross] `cabalFlag` "internal-interpreter"
- , notM cross `cabalFlag` "terminfo"
+ [ andM [expr ghcWithInterpreter, notStage0] `cabalFlag` "internal-interpreter"
+ , notStage0 `cabalFlag` "terminfo"
, arg "-build-tool-depends"
, flag UseLibzstd `cabalFlag` "with-libzstd"
-- ROMES: While the boot compiler is not updated wrt -this-unit-id
@@ -121,7 +121,7 @@
-------------------------------- ghcPkg --------------------------------
, package ghcPkg ?
- builder (Cabal Flags) ? notM cross `cabalFlag` "terminfo"
+ builder (Cabal Flags) ? notStage0 `cabalFlag` "terminfo"
-------------------------------- ghcPrim -------------------------------
, package ghcPrim ? mconcat
@@ -213,7 +213,7 @@
-- dependencies.
-- TODO: Perhaps the user should rather be responsible for this?
, package haskeline ?
- builder (Cabal Flags) ? notM cross `cabalFlag` "terminfo"
+ builder (Cabal Flags) ? notStage0 `cabalFlag` "terminfo"
-------------------------------- terminfo ------------------------------
, package terminfo ?
@@ -374,10 +374,10 @@
, input "**/RtsUtils.c" ? pure
[ "-DProjectVersion=" ++ show projectVersion
- , "-DHostPlatform=" ++ show hostPlatform
- , "-DHostArch=" ++ show hostArch
- , "-DHostOS=" ++ show hostOs
- , "-DHostVendor=" ++ show hostVendor
+ , "-DHostPlatform=" ++ show targetPlatform
+ , "-DHostArch=" ++ show targetArch
+ , "-DHostOS=" ++ show targetOs
+ , "-DHostVendor=" ++ show targetVendor
, "-DBuildPlatform=" ++ show buildPlatform
, "-DBuildArch=" ++ show buildArch
, "-DBuildOS=" ++ show buildOs