[commit: ghc] ghc-7.10: Link temporary shared objects with `--no-as-needed` (3ea3492)

git at git.haskell.org git at git.haskell.org
Sat Mar 14 08:11:11 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/3ea349220c3b72c97530c32c767e278570d497e4/ghc

>---------------------------------------------------------------

commit 3ea349220c3b72c97530c32c767e278570d497e4
Author: Peter Trommler <ptrommler at acm.org>
Date:   Sat Mar 14 09:05:41 2015 +0100

    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
    
    (cherry picked from commit 1b7f59769052fd8193c6acc561216e070d0ca335)


>---------------------------------------------------------------

3ea349220c3b72c97530c32c767e278570d497e4
 compiler/main/SysTools.hs | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index bef8d0c..26e8cf6 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -688,7 +688,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
@@ -715,6 +715,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.
+
 -}
 
 
@@ -751,12 +758,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"
@@ -873,7 +882,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



More information about the ghc-commits mailing list