Skip to content

Commit 1f0df60

Browse files
committed
fix: apply -rdynamic unconditionally for GHC API programs
The previous fix checked `ways_ `hasWay` WayDyn` but this condition fails when the test isn't compiled with -dynamic flag, even when linking against dynamic libraries. In a dynamic-only GHC build, tests compiled without -dynamic would not get -rdynamic added. Changed condition from: ways_ `hasWay` WayDyn && any ((== "ghc") . unitPackageNameString) pkgs to: blm /= FullyStatic && any ((== "ghc") . unitPackageNameString) pkgs This ensures -rdynamic is added for any non-static executable linking against the ghc package, regardless of -dynamic flag. This matches the approach in ghc-iserv.cabal.in which applies these flags unconditionally. The GHC API may load shared libraries at runtime via dlopen() (for GHCi, Template Haskell, etc.) even when the executable wasn't compiled with -dynamic. Only FullyStatic executables can skip this since they won't load dynamic libraries.
1 parent 7c565de commit 1f0df60

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler/GHC/Linker/Static.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ Platform-specific solutions:
8282
macOS: -flat_namespace (makes all symbols visible across namespaces)
8383
Windows: not needed (--enable-auto-import handles this)
8484
85+
We apply this unconditionally for non-static executables linking against the
86+
ghc package, regardless of whether -dynamic is passed. This is because the
87+
GHC API may load shared libraries at runtime (via dlopen) even when the
88+
executable itself wasn't compiled with -dynamic. We only skip this for
89+
FullyStatic executables since they won't be loading dynamic libraries.
90+
8591
This is the same issue that ghc-iserv faces, and is documented in
8692
utils/ghc-iserv/ghc-iserv.cabal.in as Note [ghc-iserv and dynamic symbol export].
8793
-}
@@ -271,7 +277,7 @@ linkBinary' staticLink logger tmpfs dflags blm unit_env o_files dep_units = do
271277
else [])
272278

273279
-- See Note [Export dynamic symbols for GHC API programs]
274-
++ (if ways_ `hasWay` WayDyn &&
280+
++ (if blm /= FullyStatic &&
275281
any ((== "ghc") . unitPackageNameString) pkgs
276282
then case platformOS platform of
277283
os | osElfTarget os -> ["-rdynamic"]

0 commit comments

Comments
 (0)