Skip to content

Add linker pool allocator for aarch64 under qemu (cf GHC #24432)#2493

Merged
hamishmack merged 20 commits intomasterfrom
hkm/fix-android-th
Apr 27, 2026
Merged

Add linker pool allocator for aarch64 under qemu (cf GHC #24432)#2493
hamishmack merged 20 commits intomasterfrom
hkm/fix-android-th

Conversation

@hamishmack
Copy link
Copy Markdown
Collaborator

When running the GHC RTS linker under qemu user-mode emulation, mmap hint addresses are ignored, causing allocations to scatter across the address space. This leads to ADR_GOT_PAGE relocation overflow (±4GB range exceeded) on aarch64.

This patch pre-allocates a single contiguous 512MB RWX pool and sub-allocates from it for all linker needs: sections, GOT, BSS, and COMMON symbols. The pool is split into RW (growing down) and RX (growing up) halves, guaranteeing all allocations stay close.

Also fixes GOT slot allocation for STB_LOCAL symbols (e.g. approx_tab in Android NDK's libm.a) which have GOT-relative relocations but were not assigned GOT slots.

Applied to GHC 9.6.7, 9.8.3+, 9.10.2+ (versions that already use m32 for regular sections but missed BSS, COMMON, and GOT).

Enables android and aarch64-cross TH tests (annotations, js-template-haskell, th-dlls) that were previously disabled due to iserv hanging under qemu.

When running the GHC RTS linker under qemu user-mode emulation,
mmap hint addresses are ignored, causing allocations to scatter
across the address space. This leads to ADR_GOT_PAGE relocation
overflow (±4GB range exceeded) on aarch64.

This patch pre-allocates a single contiguous 512MB RWX pool and
sub-allocates from it for all linker needs: sections, GOT, BSS,
and COMMON symbols. The pool is split into RW (growing down) and
RX (growing up) halves, guaranteeing all allocations stay close.

Also fixes GOT slot allocation for STB_LOCAL symbols (e.g.
approx_tab in Android NDK's libm.a) which have GOT-relative
relocations but were not assigned GOT slots.

Applied to GHC 9.6.7, 9.8.3+, 9.10.2+ (versions that already use
m32 for regular sections but missed BSS, COMMON, and GOT).

Enables android and aarch64-cross TH tests (annotations,
js-template-haskell, th-dlls) that were previously disabled due to
iserv hanging under qemu.
@hamishmack hamishmack requested a review from angerman April 9, 2026 11:55
hamishmack and others added 19 commits April 13, 2026 19:38
Update nixpkgs-unstable and nixpkgs-2511 pins and fix the resulting
evaluation warnings for deprecated package names. Uses
backwards-compatible fallback patterns so older nixpkgs still works:

- Replace xorg.* references with (pkgs.newName or pkgs.xorg.oldName)
- Add xorgCompat set in pkgconf-nixpkgs-map.nix to map deprecated
  xorg attribute names to their new top-level equivalents
- Update renamed packages (enchant2, unixODBC, goocanvas, etc.)
  using a prefer helper that selects the new name when available
GHC 9.6.x and 9.8.x utils/hp2ps/Utilities.c uses K&R-style
extern declarations for malloc/realloc without including <stdlib.h>.
GCC 15 treats these as zero-argument functions, causing build failure.
nixpkgs 26.05 removed 'pie' from the hardening system entirely -- PIE
is now enabled by default in compilers. Any mention of 'pie' in either
hardeningEnable or hardeningDisable triggers a deprecation warning:

  "The 'pie' hardening flag has been removed in favor of enabling PIE
   by default in compilers and should no longer be used."

This causes ~68 warnings per evaluation for projects with musl
cross-compilation, which is every haskell.nix project using
crossPlatforms with musl64 or aarch64-multiplatform-musl.

Remove the two places where 'pie' was added to hardeningDisable:
- builder/comp-builder.nix: every Haskell component on musl
- compiler/ghc/default.nix: GHC itself on musl targets
Only disable pie for musl when the toolchain still has it as a
default hardening flag (nixpkgs <= 25.05). On newer nixpkgs where
pie was removed from the hardening system, skip it to avoid the
deprecation warning.
Wine 11.0 renamed DOS_PATHNAME_TYPE to RTL_PATH_TYPE and changed
the enum values (DEVICE_PATH -> RtlPathTypeLocalDevice). Add a
new patch variant for wine >= 11.0 that uses the new API names.
The 'static' parameter was removed from zlib in nixpkgs-unstable.
Setting 'shared = false' is sufficient to get a static-only build
and works across all nixpkgs versions.
Emscripten 4.0+ moved emnm from share/emscripten/emnm to
share/emscripten/tools/emnm.py. Use builtins.pathExists to
select the correct path for backwards compatibility.
- libffi, gmp: disable doCheck when cross-compiling since test
  binaries can't execute on the build host
- ncurses: disable broken symlink check when cross-compiling to
  avoid case-sensitive symlink target mismatch
Hadrian builds terminfo unconditionally for stage0, passing the same
--with-curses-libraries to both stage0 (host compiler) and stage1
(target compiler). Before GHC 9.15 (which has MR 13932), this cannot
work when the host and target have different ncurses (e.g. glibc vs
musl), because the host compiler can't link against target static libs.

Matching nixpkgs common-hadrian.nix:
- Disable enableTerminfo when platform configs differ (cross builds)
  for GHC < 9.15
- Gate --with-curses-libraries on enableTerminfo so it's not passed
  in cross builds (avoiding the stage0 ABI mismatch)
- Keep ncurses in libDeps unconditionally (not gated on enableTerminfo)
  since hadrian builds terminfo for stage0 regardless, and
  depsTargetTarget needs target ncurses for stage1
The K&R-style extern void* malloc() in utils/hp2ps/Utilities.c
is present in all GHC versions from 8.10.7 through 9.12.3.
It was fixed with a proper prototype in 9.10.2 and fully fixed
with #include <stdlib.h> in 9.10.3 and 9.12.4+.
Wine 11.0 removed the wine64 binary, unifying it into wine.
Use wine64Packages.minimal (for 64-bit support) and lib.getExe
to pick the correct binary name via meta.mainProgram.
Also patch wine64Packages.minimal with the same fixes as
winePackages.minimal.
@hamishmack hamishmack merged commit 044c939 into master Apr 27, 2026
6295 of 6798 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants