diff options
| author | Simon Marlow <marlowsd@gmail.com> | 2017-03-02 16:17:12 -0500 |
|---|---|---|
| committer | Ben Gamari <ben@smart-cactus.org> | 2017-03-02 19:58:01 -0500 |
| commit | a6874e546294173c166859769dd8054887a6ded7 (patch) | |
| tree | fa2b2000ff6b4dcab30807adf3f8e3685550b9cf /compiler | |
| parent | 57d969ec9bea8ca44e735845e9aa91292fe5e75b (diff) | |
| download | haskell-a6874e546294173c166859769dd8054887a6ded7.tar.gz | |
Add -fwhole-archive-hs-libs
We're building a demo to show how to hot-swap Haskell code in a
running process, and unfortunately it wasn't possible to convince GHC
to generate the correct linker command line without this extra knob.
Test Plan:
Tested it on a hot-swapping demo (which is not released yet, but will
be shortly)
Reviewers: niteria, austin, erikd, JonCoens, bgamari
Reviewed By: bgamari
Subscribers: Phyx, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3136
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/main/DriverPipeline.hs | 26 | ||||
| -rw-r--r-- | compiler/main/DynFlags.hs | 4 |
2 files changed, 24 insertions, 6 deletions
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs index ca82e73f87..57a50827b6 100644 --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -1815,15 +1815,28 @@ linkBinary' staticLink dflags o_files dep_packages = do in ["-L" ++ l] ++ ["-Xlinker", "-rpath", "-Xlinker", libpath] | otherwise = ["-L" ++ l] - let dead_strip = if osSubsectionsViaSymbols (platformOS platform) - then ["-Wl,-dead_strip"] - else [] + let + dead_strip + | gopt Opt_WholeArchiveHsLibs dflags = [] + | otherwise = if osSubsectionsViaSymbols (platformOS platform) + then ["-Wl,-dead_strip"] + else [] let lib_paths = libraryPaths dflags let lib_path_opts = map ("-L"++) lib_paths extraLinkObj <- mkExtraObjToLinkIntoBinary dflags noteLinkObjs <- mkNoteObjsToLinkIntoBinary dflags dep_packages + let + (pre_hs_libs, post_hs_libs) + | gopt Opt_WholeArchiveHsLibs dflags + = if platformOS platform == OSDarwin + then (["-Wl,-all_load"], []) + -- OS X does not have a flag to turn off -all_load + else (["-Wl,--whole-archive"], ["-Wl,--no-whole-archive"]) + | otherwise + = ([],[]) + pkg_link_opts <- do (package_hs_libs, extra_libs, other_flags) <- getPackageLinkOpts dflags dep_packages return $ if staticLink @@ -1832,7 +1845,9 @@ linkBinary' staticLink dflags o_files dep_packages = do -- HS packages, because libtool doesn't accept other options. -- In the case of iOS these need to be added by hand to the -- final link in Xcode. - else other_flags ++ dead_strip ++ package_hs_libs ++ extra_libs + else other_flags ++ dead_strip + ++ pre_hs_libs ++ package_hs_libs ++ post_hs_libs + ++ extra_libs -- -Wl,-u,<sym> contained in other_flags -- needs to be put before -l<package>, -- otherwise Solaris linker fails linking @@ -1934,7 +1949,8 @@ linkBinary' staticLink dflags o_files dep_packages = do then ["-Wl,-read_only_relocs,suppress"] else []) - ++ (if sLdIsGnuLd mySettings + ++ (if sLdIsGnuLd mySettings && + not (gopt Opt_WholeArchiveHsLibs dflags) then ["-Wl,--gc-sections"] else []) diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 442bbb984c..e96bf69d31 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -515,6 +515,7 @@ data GeneralFlag | Opt_ExternalInterpreter | Opt_OptimalApplicativeDo | Opt_VersionMacros + | Opt_WholeArchiveHsLibs -- PreInlining is on by default. The option is there just to see how -- bad things get if you turn it off! @@ -3705,7 +3706,8 @@ fFlagsDeps = [ flagSpec "solve-constant-dicts" Opt_SolveConstantDicts, flagSpec "show-warning-groups" Opt_ShowWarnGroups, flagSpec "hide-source-paths" Opt_HideSourcePaths, - flagSpec "show-hole-constraints" Opt_ShowHoleConstraints + flagSpec "show-hole-constraints" Opt_ShowHoleConstraints, + flagSpec "whole-archive-hs-libs" Opt_WholeArchiveHsLibs ] -- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@ |
