Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more aarch64-linux stuff. Take 2 #2116

Merged
merged 48 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
baf9679
Fix ghc:-dynamic-system-linker for android
angerman Oct 23, 2023
7fdd675
Set -dynamic-system-linker if musl and not x86_64
angerman Nov 15, 2023
d9aa2d3
add parens
angerman Nov 29, 2023
5ab1d85
Add iserv-syms.patch
angerman Nov 29, 2023
893cf77
Add iserv/proxy_args logic to linux as well (same as weindows)
angerman Nov 29, 2023
c5a8548
Add keep cafs.
angerman Nov 29, 2023
ddc7583
bump flakes
angerman Nov 29, 2023
9806bd7
Let's try using it directly.
angerman Nov 29, 2023
9db06d5
cleanup
angerman Nov 29, 2023
378bafc
bump iserv
angerman Nov 29, 2023
4bebd67
ifdLevel 1
hamishmack Nov 30, 2023
44c4a16
ifdLevel 2
hamishmack Nov 30, 2023
3feec6e
ifdLevel 3
hamishmack Nov 30, 2023
4819428
Add static-external-plugin logic for cross compilers.
angerman Dec 9, 2023
8167144
Fix musl copy
angerman Feb 6, 2024
928b0d8
Fix x86_64-musl
angerman Feb 6, 2024
644564d
initial iserv-proxy
angerman Feb 9, 2024
b04fdf0
Add deadbeef patches
angerman Feb 14, 2024
a1b7204
Add pool allocator patch
angerman Feb 14, 2024
1b3373f
Drop duplicates.
angerman Feb 14, 2024
d17ec60
Fix alignment
angerman Feb 15, 2024
670a0d3
ifdLevel 0
hamishmack Feb 15, 2024
8711455
ifdLevel 1
hamishmack Feb 15, 2024
0bbb09f
ifdLevel 2
hamishmack Feb 15, 2024
b98a468
ifdLevel 3
hamishmack Feb 16, 2024
754ffaf
Add more 9.6 patches :facepalm:
angerman Feb 21, 2024
754644f
Update patches
angerman Feb 21, 2024
bf901a1
Add pool alignment and hidden support for 9.6
angerman Feb 23, 2024
07319e0
fixup! Set -dynamic-system-linker if musl and not x86_64
angerman Feb 24, 2024
8aa793d
Use gold with musl. Seems like the bug has been resolved.
angerman Feb 26, 2024
cbe8f37
Fixup patch
angerman Feb 26, 2024
81eacab
Extend patch range to cover 8.10 as well
angerman Feb 27, 2024
5c4491b
apparently this doesn't apply to 9.8 :(
angerman Feb 28, 2024
d857ef7
Sigh, ffs. gold still broken with the NCG.
angerman Feb 29, 2024
5069d91
Reduce allocation to 512MB not 1G
angerman Mar 14, 2024
af3a4a8
Fix up pool allocator stuff.
angerman Mar 18, 2024
9f55274
From 8.10, not 9.10 :facepalm:
angerman Mar 19, 2024
929fc64
rm -rf materialized/dummy-ghc
hamishmack May 14, 2024
c8d55d0
Merge remote-tracking branch 'origin/master' into angerman/fix-aarch6…
hamishmack May 14, 2024
a34601e
nix flake update iserv-proxy
hamishmack May 14, 2024
ac1a04e
Merge remote-tracking branch 'origin/master' into angerman/fix-aarch6…
hamishmack May 15, 2024
24fc6fa
Merge remote-tracking branch 'origin/master' into angerman/fix-aarch6…
hamishmack May 17, 2024
3f16530
Fix for non SECTION_POOL sections
hamishmack May 21, 2024
8975f35
Exclude pool related patches for non aarch64 target platforms
hamishmack May 21, 2024
5661558
Avoid gold for llvm+musl builds
hamishmack May 21, 2024
a2612aa
Use +dynamic-system-linker for aarch64 -> aarch64 musl
hamishmack May 21, 2024
f1504e9
Include fixes for ghc 9.10 as well
hamishmack May 22, 2024
a210027
Include fixes for ghc 9.10 as well
hamishmack May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions compiler/ghc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ let self =
, useLdGold ?
# might be better check to see if cc is clang/llvm?
# use gold as the linker on linux to improve link times
# do not use it on musl due to a ld.gold bug. See: <https://sourceware.org/bugzilla/show_bug.cgi?id=22266>.
(stdenv.targetPlatform.isLinux && !stdenv.targetPlatform.isAndroid && !stdenv.targetPlatform.isMusl)
# do not use ld.gold 2.3 with musl due to a ld.gold bug.
# See: <https://sourceware.org/bugzilla/show_bug.cgi?id=22266>.
# Note that this bug was resolved in 2017.
( stdenv.targetPlatform.isLinux
# don't use gold on android.
&& !stdenv.targetPlatform.isAndroid
# don't use gold with with musl. Still seems to be
# affected by 22266.
&& !stdenv.targetPlatform.isMusl)

, ghc-version ? src-spec.version
, ghc-version-date ? null
Expand Down Expand Up @@ -314,6 +321,11 @@ let
# `-fexternal-dynamic-refs` causes `undefined reference` errors when building GHC cross compiler for windows
+ lib.optionalString (enableRelocatedStaticLibs && targetPlatform.isx86_64 && !targetPlatform.isWindows)
" '*.*.ghc.*.opts += -fexternal-dynamic-refs'"
# The fact that we need to set this here is pretty idiotic. GHC should figure this out on it's own.
# Either have a runtime flag/setting to disable it or if dlopen fails, remember that it failed and
# fall back to non-dynamic. We only have dynamic linker with musl if host and target arch match.
+ lib.optionalString (targetPlatform.isAndroid || (targetPlatform.isMusl && haskell-nix.haskellLib.isCrossTarget))
" '*.ghc.cabal.configure.opts += --flags=-dynamic-system-linker'"
# The following is required if we build on aarch64-darwin for aarch64-iOS. Otherwise older
# iPhones/iPads/... won't understand the compiled code, as the compiler will emit LDSETALH
# + lib.optionalString (targetPlatform.???) "'*.rts.ghc.c.opts += -optc-mcpu=apple-a7 -optc-march=armv8-a+norcpc'"
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions overlays/bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,34 @@ in {
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.6.4" && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/2adc050857a9c1b992040fbfd55fbe65b2851b19.patch
++ final.lib.optional (versionAtLeast "8.10.7" && versionLessThan "9.0" && final.stdenv.targetPlatform.isAarch64 && final.stdenv.targetPlatform.isMusl && final.stdenv.targetPlatform != final.stdenv.hostPlatform) ./patches/ghc/ghc-8.10-aarch64-musl-gettimeofday.patch

# This one will lead to segv's on darwin, when calling `strlen` during lookupStrHashTable. `strlen` ends up being called with 0x0.
# This patch will allow adding additional symbols to iserv, instead of having to patch them into GHC all the time.
++ final.lib.optional (versionAtLeast "9.6.1" && versionLessThan"9.11" && (final.stdenv.targetPlatform != final.stdenv.hostPlatform) && (final.stdenv.targetPlatform.isAndroid || final.stdenv.targetPlatform.isLinux) && (final.stdenv.targetPlatform.isAarch64 || final.stdenv.targetPlatform.is32bit)) ./patches/ghc/iserv-syms.patch
# Allow loading static external plugins into cross compilers
++ final.lib.optional (versionAtLeast "9.6.1" && versionLessThan"9.11" && (final.stdenv.targetPlatform != final.stdenv.hostPlatform)) ./patches/ghc/5c80a27488acfe3610ddfcb99a1e961002e386d0.patch
++ final.lib.optional (versionAtLeast "9.6.1" && versionLessThan"9.11" && (final.stdenv.targetPlatform != final.stdenv.hostPlatform)) ./patches/ghc/f8beb54a1d5725bd0d8a4b0a909d1b41d742b50b.patch
++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "9.11" && (final.stdenv.targetPlatform.isAndroid && final.stdenv.targetPlatform.is32bit || final.stdenv.targetPlatform.isMusl)) ./patches/ghc/ghc-9.6-missing-symbols-deadbeef.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && final.stdenv.targetPlatform.isMusl && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/ghc-9.6-linker-pool-allocator.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && final.stdenv.targetPlatform.isMusl && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/ghc-9.6-linker-pool-allocator-2.patch

++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.8" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-0001-Refactor-IServ.hs.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-0002-Drop-spurious-8-byte-offset-from-elf_plt.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && final.stdenv.targetPlatform.isMusl && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/ghc-9.6-0003-Better-pool-alignment.-We-still-hardcode-section-ali.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && final.stdenv.targetPlatform.isMusl && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/ghc-9.6-0007-fixup-Better-pool-alignment.-We-still-hardcode-secti.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && final.stdenv.targetPlatform.isMusl && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/ghc-9.6-0008-pool-improvements.patch
# these two are abit questionable. They are pretty rough, and assume static binary as well as posix.
# ++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-0004-ghcidladdr.patch
# ++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-0005-Better-interpreter-debugging.-Needs-ghcidladdr.patch

# Fix docs/users_guide/rtd-theme/layout.html to work with sphinx 7
++ fromUntil "9.0" "9.8" ./patches/ghc/docs-sphinx-7.patch
++ fromUntil "9.8" "9.9" ./patches/ghc/docs-sphinx-7-ghc98.patch

# These two patches are needed for libblst, which has now hidden symbols, which the linker doesn't know how to deal with.
++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "8.11") ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols.patch
++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "8.11") ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-2.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.8" && (final.stdenv.targetPlatform.isWindows || final.stdenv.targetPlatform.isMusl)) ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.8" && (final.stdenv.targetPlatform.isWindows || final.stdenv.targetPlatform.isMusl)) ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols-2.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && (final.stdenv.targetPlatform.isWindows || final.stdenv.targetPlatform.isMusl)) ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols.patch
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.11" && (final.stdenv.targetPlatform.isWindows || final.stdenv.targetPlatform.isMusl)) ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols-2.patch
++ fromUntil "9.9" "9.12" ./patches/ghc/ghc-9.9-Cabal-3.11.patch
++ fromUntil "9.8" "9.9" ./patches/ghc/ghc-9.8-text-upper-bound.patch
++ fromUntil "9.10" "9.12" ./patches/ghc/ghc-9.10-containers-upper-bound.patch
Expand Down
10 changes: 8 additions & 2 deletions overlays/linux-cross.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ let
in
writeShellScriptBin ("iserv-wrapper" + lib.optionalString enableProfiling "-prof") ''
set -euo pipefail
ISERV_ARGS=''${ISERV_ARGS:-}
PROXY_ARGS=''${PROXY_ARGS:-}
# Unset configure flags as configure should have run already
unset configureFlags
PORT=$((5000 + $RANDOM % 5000))
(>&2 echo "---> Starting ${interpreter.exeName} on port $PORT")
${qemu}/bin/qemu-${qemuSuffix} ${interpreter.override (lib.optionalAttrs hostPlatform.isAndroid { setupBuildFlags = ["--ghc-option=-optl-static" ];})}/bin/${interpreter.exeName} tmp $PORT &
${qemu}/bin/qemu-${qemuSuffix} ${interpreter.override
(lib.optionalAttrs hostPlatform.isAndroid {
setupBuildFlags = ["--ghc-option=-optl-static" ] ++ lib.optional hostPlatform.isAarch32 "--ghc-option=-optl-no-pie";
enableDebugRTS = true;
})}/bin/${interpreter.exeName} tmp $PORT $ISERV_ARGS &
(>&2 echo "---| ${interpreter.exeName} should have started on $PORT")
RISERV_PID="$!"
${iserv-proxy}/bin/iserv-proxy $@ 127.0.0.1 "$PORT"
${iserv-proxy}/bin/iserv-proxy $@ 127.0.0.1 "$PORT" $PROXY_ARGS
(>&2 echo "---> killing ${interpreter.exeName}...")
kill $RISERV_PID
'';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
From 5c80a27488acfe3610ddfcb99a1e961002e386d0 Mon Sep 17 00:00:00 2001
From: Luite Stegeman <[email protected]>
Date: Fri, 8 Dec 2023 11:24:05 +0100
Subject: [PATCH] Allow stage1 compilers to load plugins with -fplugin-library

This exposes the GHCi.ObjLink module even if no internal
interpreter is available. This may be unsafe.
---
compiler/GHC/Driver/Plugins.hs | 9 +++------
libraries/ghci/ghci.cabal.in | 2 +-
2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/compiler/GHC/Driver/Plugins.hs b/compiler/GHC/Driver/Plugins.hs
index ddf47c05ce4..2f3bf44b408 100644
--- a/compiler/GHC/Driver/Plugins.hs
+++ b/compiler/GHC/Driver/Plugins.hs
@@ -1,7 +1,7 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE CPP #-}

-#if defined(HAVE_INTERNAL_INTERPRETER) && defined(CAN_LOAD_DLL)
+#if defined(CAN_LOAD_DLL)
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE UnboxedTuples #-}
@@ -103,7 +103,7 @@ import qualified Data.Semigroup

import Control.Monad

-#if defined(HAVE_INTERNAL_INTERPRETER) && defined(CAN_LOAD_DLL)
+#if defined(CAN_LOAD_DLL)
import GHCi.ObjLink
import GHC.Exts (addrToAny#, Ptr(..))
import GHC.Utils.Encoding
@@ -372,10 +372,7 @@ defaultFrontendPlugin = FrontendPlugin { frontend = \_ _ -> return () }
-- | Load external plugins
loadExternalPlugins :: [ExternalPluginSpec] -> IO [ExternalPlugin]
loadExternalPlugins [] = return []
-#if !defined(HAVE_INTERNAL_INTERPRETER)
-loadExternalPlugins _ = do
- panic "loadExternalPlugins: can't load external plugins with GHC built without internal interpreter"
-#elif !defined(CAN_LOAD_DLL)
+#if !defined(CAN_LOAD_DLL)
loadExternalPlugins _ = do
panic "loadExternalPlugins: loading shared libraries isn't supported by this compiler"
#else
diff --git a/libraries/ghci/ghci.cabal.in b/libraries/ghci/ghci.cabal.in
index 565b4198dea..6854a6bc561 100644
--- a/libraries/ghci/ghci.cabal.in
+++ b/libraries/ghci/ghci.cabal.in
@@ -52,7 +52,6 @@ library
exposed-modules:
GHCi.Run
GHCi.CreateBCO
- GHCi.ObjLink
GHCi.Signals
GHCi.StaticPtrTable
GHCi.TH
@@ -63,6 +62,7 @@ library
GHCi.InfoTable

exposed-modules:
+ GHCi.ObjLink
GHCi.BreakArray
GHCi.BinaryArray
GHCi.Message
--
GitLab

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
From f8beb54a1d5725bd0d8a4b0a909d1b41d742b50b Mon Sep 17 00:00:00 2001
From: Luite Stegeman <[email protected]>
Date: Fri, 8 Dec 2023 12:12:20 +0100
Subject: [PATCH] External plugins: try loading archive if loading dynamic
library fails

---
compiler/GHC/Driver/Plugins.hs | 27 ++++++++++-----------------
1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/compiler/GHC/Driver/Plugins.hs b/compiler/GHC/Driver/Plugins.hs
index 2f3bf44b408..8b06e8b16d5 100644
--- a/compiler/GHC/Driver/Plugins.hs
+++ b/compiler/GHC/Driver/Plugins.hs
@@ -1,12 +1,9 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE CPP #-}

-#if defined(CAN_LOAD_DLL)
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE UnboxedTuples #-}
-#endif
-

-- | Definitions for writing /plugins/ for GHC. Plugins can hook into
-- several areas of the compiler. See the 'Plugin' type. These plugins
@@ -103,11 +100,9 @@ import qualified Data.Semigroup

import Control.Monad

-#if defined(CAN_LOAD_DLL)
import GHCi.ObjLink
import GHC.Exts (addrToAny#, Ptr(..))
import GHC.Utils.Encoding
-#endif


-- | Command line options gathered from the -PModule.Name:stuff syntax
@@ -372,10 +367,6 @@ defaultFrontendPlugin = FrontendPlugin { frontend = \_ _ -> return () }
-- | Load external plugins
loadExternalPlugins :: [ExternalPluginSpec] -> IO [ExternalPlugin]
loadExternalPlugins [] = return []
-#if !defined(CAN_LOAD_DLL)
-loadExternalPlugins _ = do
- panic "loadExternalPlugins: loading shared libraries isn't supported by this compiler"
-#else
loadExternalPlugins ps = do
-- initialize the linker
initObjLinker RetainCAFs
@@ -400,17 +391,19 @@ loadExternalPlugins ps = do

loadExternalPluginLib :: FilePath -> IO ()
loadExternalPluginLib path = do
- -- load library
+ -- XXX we should probably use the filename to determine whether
+ -- the plugin is an archive or dynamic lib
+
+ -- try loading it as a dynamic library
loadDLL path >>= \case
- Just errmsg -> pprPanic "loadExternalPluginLib"
- (vcat [ text "Can't load plugin library"
- , text " Library path: " <> text path
- , text " Error : " <> text errmsg
- ])
- Nothing -> do
+ Just _errmsg ->
+ -- if that fails, try loading it as an archive
+ loadArchive path >> resolve
+ Nothing -> resolve
+ where
+ resolve = do
-- resolve objects
resolveObjs >>= \case
True -> return ()
False -> pprPanic "loadExternalPluginLib" (text "Unable to resolve objects for library: " <> text path)

-#endif
--
GitLab

Loading