Files
termux-packages/packages/ghc/disable-no-pie.patch
termux-pacman-bot 7a4ab56ecb 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 16:42:00 +00:00

19 lines
784 B
Diff

--- ghc-9.12.1/m4/fp_gcc_supports_no_pie.m4 2025-02-24 22:46:43.263794157 +0530
+++ ghc-9.12.1.mod/m4/fp_gcc_supports_no_pie.m4 2025-03-25 14:39:14.331731419 +0530
@@ -6,15 +6,6 @@
[
AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([whether CC supports -no-pie])
- echo 'int main() { return 0; }' > conftest.c
- "$CC" $CONF_GCC_CC_OPTS_STAGE2 -c conftest.c
- # Some GCC versions only warn when passed an unrecognized flag.
- if "$CC" $CONF_GCC_LINKER_OPTS_STAGE2 -no-pie -Werror conftest.o -o conftest > conftest.txt 2>&1 && ! grep -i unrecognized conftest.txt > /dev/null 2>&1; then
- CONF_GCC_SUPPORTS_NO_PIE=YES
- AC_MSG_RESULT([yes])
- else
CONF_GCC_SUPPORTS_NO_PIE=NO
AC_MSG_RESULT([no])
- fi
- rm -f conftest.c conftest.o conftest
])