summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Trommler <ptrommler@acm.org>2015-03-14 09:05:41 +0100
committerHerbert Valerio Riedel <hvr@gnu.org>2015-03-14 09:05:47 +0100
commit1b7f59769052fd8193c6acc561216e070d0ca335 (patch)
treea152d77a8424300a77a1c933d8f4dd8912d226d1
parentcc07a0ba64b554ffd1ff85757b02cd79d30ed57a (diff)
downloadhaskell-1b7f59769052fd8193c6acc561216e070d0ca335.tar.gz
Link temporary shared objects with `--no-as-needed`
Some ELF link editors default to `--as-needed` and record only those libraries in DT_NEEDED tags that are needed to resolve undefined symbols in the shared object to be created. In Template Haskell we rely on all symbols that were defined in modules compiled so far to be available in the current temporary shared object. To prevent the link editor from dropping the DT_NEEDED tag for the previously linked temporary shared object we need to override the link editors default and specify `--no-as-needed` on the command line. This is for GNU ld and GOLD ld. This addresses #10110 TODO: regression test Reviewed By: hvr Differential Revision: https://phabricator.haskell.org/D731
-rw-r--r--compiler/main/SysTools.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index aba4a1b06b..e6e7fa6ca5 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -690,7 +690,7 @@ in terror).
{- Note [Run-time linker info]
-See also: Trac #5240, Trac #6063
+See also: Trac #5240, Trac #6063, Trac #10110
Before 'runLink', we need to be sure to get the relevant information
about the linker we're using at runtime to see if we need any extra
@@ -717,6 +717,13 @@ We cache the LinkerInfo inside DynFlags, since clients may link
multiple times. The definition of LinkerInfo is there to avoid a
circular dependency.
+Some distributions change the link editor's default handling of
+ELF DT_NEEDED tags to include only those shared objects that are
+needed to resolve undefined symbols. For Template Haskell we need
+the last temporary shared library also if it is not needed for the
+currently linked temporary shared library. We specify --no-as-needed
+to override the default. This flag exists in GNU ld and GNU gold.
+
-}
@@ -753,12 +760,14 @@ getLinkerInfo' dflags = do
| any ("GNU ld" `isPrefixOf`) stdo =
-- GNU ld specifically needs to use less memory. This especially
-- hurts on small object files. Trac #5240.
+ -- Set DT_NEEDED for all shared libraries. Trac #10110.
return (GnuLD $ map Option ["-Wl,--hash-size=31",
- "-Wl,--reduce-memory-overheads"])
+ "-Wl,--reduce-memory-overheads",
+ "-Wl,--no-as-needed"])
| any ("GNU gold" `isPrefixOf`) stdo =
- -- GNU gold does not require any special arguments.
- return (GnuGold [])
+ -- GNU gold only needs --no-as-needed. Trac #10110.
+ return (GnuGold [Option "-Wl,--no-as-needed"])
-- Unknown linker.
| otherwise = fail "invalid --version output, or linker is unsupported"
@@ -875,7 +884,7 @@ runLink dflags args = do
linkargs <- neededLinkArgs `fmap` getLinkerInfo dflags
let (p,args0) = pgm_l dflags
args1 = map Option (getOpts dflags opt_l)
- args2 = args0 ++ args1 ++ args ++ linkargs
+ args2 = args0 ++ linkargs ++ args1 ++ args
mb_env <- getGccEnv args2
runSomethingFiltered dflags ld_filter "Linker" p args2 mb_env
where