[commit: ghc] master: Fix obscure problem with using the system linker (#8935) (383733b)

git at git.haskell.org git at git.haskell.org
Sun Nov 30 18:01:41 UTC 2014


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/383733b9191a36e2d3f757700842dbc3855911d9/ghc

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

commit 383733b9191a36e2d3f757700842dbc3855911d9
Author: Peter Trommler <ptrommler at acm.org>
Date:   Sun Nov 30 12:00:39 2014 -0600

    Fix obscure problem with using the system linker (#8935)
    
    Summary:
    In a statically linked GHCi symbol `environ` resolves to NULL when
    called from a Haskell script.
    
    When resolving symbols in a Haskell script we need to search the
    executable program and its dependent (DT_NEEDED) shared libraries
    first and then search the loaded libraries.
    
    We want to be able to override functions in loaded libraries later.
    Libraries must be opened with local scope (RTLD_LOCAL) and not global.
    The latter adds all symbols to the executable program's symbols where
    they are then searched in loading order. We want reverse loading order.
    
    When libraries are loaded with local scope the dynamic linker
    cannot use symbols in that library when resolving the dependencies
    in another shared library. This changes the way files compiled to
    object code must be linked into temporary shared libraries. We link
    with the last temporary shared library created so far if it exists.
    Since each temporary shared library is linked to the previous temporary
    shared library the dynamic linker finds the latest definition of a
    symbol by following the dependency chain.
    
    See also Note [RTLD_LOCAL] for a summary of the problem and solution.
    
    Cherry-picked commit 2f8b4c
    
    Changed linker argument ordering
    
    On some ELF systems GNU ld (and others?) default to
    --as-needed and the order of libraries in the link
    matters.
    
    The last temporary shared library, must appear
    before all other libraries. Switching the position
    of extra_ld_inputs and lib_path_objs does that.
    
    Fixes #8935 and #9186
    
    Reviewers: austin, hvr, rwbarton, simonmar
    
    Reviewed By: simonmar
    
    Subscribers: thomie, carter, simonmar
    
    Differential Revision: https://phabricator.haskell.org/D349
    
    GHC Trac Issues: #8935, #9186, #9480


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

383733b9191a36e2d3f757700842dbc3855911d9
 compiler/ghci/Linker.hs    | 74 ++++++++++++++++++++++++++++++++--------------
 compiler/main/SysTools.lhs |  3 +-
 rts/Linker.c               | 43 +++++++++++++++++++++------
 3 files changed, 87 insertions(+), 33 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc 383733b9191a36e2d3f757700842dbc3855911d9


More information about the ghc-commits mailing list