0
0
mirror of https://github.com/termux/termux-packages.git synced 2025-05-10 11:35:44 +00:00
Files
termux-packages/packages/ghc/hadrian-bindist-use-host-ghc-pkg.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

23 lines
1.3 KiB
Diff

--- ghc-9.12.1/hadrian/src/Rules/BinaryDist.hs 2025-02-24 22:46:43.666788988 +0530
+++ ghc-9.12.1.mod/hadrian/src/Rules/BinaryDist.hs 2025-02-25 16:56:59.718827035 +0530
@@ -231,6 +231,6 @@
--
-- N.B. the ghc-pkg executable may be prefixed with a target triple
-- (c.f. #20267).
- ghcPkgName <- programName (vanillaContext Stage1 ghcPkg)
- cmd_ (bindistFilesDir -/- "bin" -/- ghcPkgName) ["recache"]
+ stage0ghcPkgPath <- programPath =<< programContext (Stage0 InTreeLibs) ghcPkg
+ cmd_ stage0ghcPkgPath ["recache"]
--- ghc-9.12.1/hadrian/bindist/Makefile 2025-02-24 22:46:43.665077469 +0530
+++ ghc-9.12.1.mod/hadrian/bindist/Makefile 2025-02-24 22:46:44.140454443 +0530
@@ -253,7 +253,7 @@
@echo "Updating the package DB"
$(foreach p, $(PKG_CONFS),\
$(call patchpackageconf,$(shell echo $(notdir $p) | sed 's/-[0-9.]*-[0-9a-zA-Z]*\.conf//g'),$(shell echo "$p" | sed 's:\0xxx\0: :g'),$(docdir),$(shell mk/relpath.sh "$(ActualLibsDir)" "$(docdir)"),$(shell echo $(notdir $p) | sed 's/.conf//g')))
- '$(DESTDIR)$(ActualBinsDir)/$(CrossCompilePrefix)ghc-pkg' --global-package-db "$(DESTDIR)$(ActualLibsDir)/package.conf.d" recache
+ '$(HOST_GHC_PKG)' --global-package-db "$(DESTDIR)$(ActualLibsDir)/package.conf.d" recache
.PHONY: install_mingw
install_mingw: