[commit: ghc] master: Allow the GHCi Linker to resolve related dependencies when loading DLLs (6e6438e)

git at git.haskell.org git at git.haskell.org
Sat Nov 7 13:00:04 UTC 2015


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/6e6438e15f33cb94ad6338e950e693f59d046385/ghc

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

commit 6e6438e15f33cb94ad6338e950e693f59d046385
Author: Tamar Christina <tamar at zhox.com>
Date:   Sat Nov 7 03:51:43 2015 -0500

    Allow the GHCi Linker to resolve related dependencies when loading DLLs
    
    Summary:
    GHCi does not correctly tell the Windows Loader how to handle dependencies to DLL's
    that are not on the standard Windows load path:
    
    1. The directory from which the application loaded.
    2. The current directory.
    3. The system directory. Use the GetSystemDirectory function to get the path of this directory.
    4. The 16-bit system directory. There is no function that obtains the path of this directory,
       but it is searched.
    5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
    6. The directories that are listed in the PATH environment variable.
       Note that this does not include the per-application path specified by the
       AppPaths registry key. The App Paths key is not used when computing the DLL search path.
    
    So what this means is given two DLLs `A` and `B` and `B` depending on `A`.
    If we put both DLLs into a new folder bin and then call GHC with:
    
    `ghc -L$(PWD)/bin -lB`
    
    the loading will fail as the Windows loader will try to load the dependency of `B` and fail
    since it cannot find `A`.
    
    *IMPORTANT* this patch drops XP Support.
    The  APIs being used were natively added to Windows 8+ and backported to Windows 7 and Vista
    via a mandatory security patch (in 2011). This means that there is a chance that KB2533623 has
    not been installed on certain machines. For those machines I display a warning and
    temporarily expand the `PATH` to allow it to load.
    
    This patch will make sure that paths provided by the user with `-L` *and* the folder in which a
    DLL is found are added to the search path. It does so using one of two methods depending upon how
    new of a Windows version we are running on:
    
    - If the APIs are available it will use `addDllDirectory` and `removeDllDirectory`.
       The order of which these directories are searched is nondeterministic.
    - If the APIs are not available it means that we're running on a pretty old unpatched machine.
      But if it's being used in an environment with no internet access it may be the case.
      So if the APIs are not available we temporarily extend the `PATH` with the directories.
      A warning is also displayed to the user informing them that the linking may fail,
      and if it does, install the needed patch. The `PATH` variable has limitations.
    
    Test Plan:
    ./validate
    
    Added two new test T10955 and T10955dyn
    
    Reviewers: erikd, bgamari, thomie, hvr, austin
    
    Reviewed By: erikd, thomie
    
    Subscribers: #ghc_windows_task_force
    
    Differential Revision: https://phabricator.haskell.org/D1340
    
    GHC Trac Issues: #10955


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

6e6438e15f33cb94ad6338e950e693f59d046385
 compiler/ghci/Linker.hs                            |  86 +++++----
 compiler/ghci/ObjLink.hs                           |  47 +++--
 includes/rts/Linker.h                              |  11 ++
 rts/Linker.c                                       | 199 +++++++++++++++++++--
 rts/RtsSymbols.c                                   |   4 +-
 rts/ghc.mk                                         |  15 +-
 testsuite/tests/ghci/linking/dyn/B.c               |  21 +++
 testsuite/tests/ghci/linking/dyn/Makefile          |  45 ++++-
 testsuite/tests/ghci/linking/dyn/T10955.script     |   5 +
 .../linking/dyn/T10955.stdout}                     |   0
 testsuite/tests/ghci/linking/dyn/T10955dyn.hs      |   7 +
 .../linking/dyn/T10955dyn.stdout}                  |   0
 testsuite/tests/ghci/linking/dyn/all.T             |  26 ++-
 13 files changed, 384 insertions(+), 82 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 6e6438e15f33cb94ad6338e950e693f59d046385


More information about the ghc-commits mailing list