Commit 795be0ea authored by Tamar Christina's avatar Tamar Christina
Browse files

Align GHCi's library search order more closely with LDs

Summary:
Given a static library and an import library in the same folder. e.g.

```
libfoo.a
libfoo.dll.a
```

running `ghci -lfoo` we should prefer the import library `libfoo.dll.a`
over `libfoo.a` because we prefer having to just load the DLL.
And not having to do any linking.

This also more closely emulated the behaviour of LD, which has a search order of

```
libxxx.dll.a
xxx.dll.a
libxxx.a
cygxxx.dll (*)
libxxx.dll
xxx.dll
```

Test Plan: ./validate

Reviewers: RyanGlScott, austin, hvr, bgamari, erikd, simonmar

Reviewed By: RyanGlScott

Subscribers: thomie, #ghc_windows_task_force

Differential Revision: https://phabricator.haskell.org/D2651

GHC Trac Issues: #12771
parent 80d4a033
......@@ -1281,7 +1281,8 @@ loadFrameworks hsc_env platform pkg
-- If it isn't present, we assume that addDLL in the RTS can find it,
-- which generally means that it should be a dynamic library in the
-- standard system search path.
-- For GHCi we tend to prefer dynamic libraries over static ones as
-- they are easier to load and manage, have less overhead.
locateLib :: HscEnv -> Bool -> [FilePath] -> String -> IO LibrarySpec
locateLib hsc_env is_hs dirs lib
| not is_hs
......@@ -1290,16 +1291,16 @@ locateLib hsc_env is_hs dirs lib
-- then look in library-dirs for a static library (libfoo.a)
-- then look in library-dirs and inplace GCC for a dynamic library (libfoo.so)
-- then check for system dynamic libraries (e.g. kernel32.dll on windows)
-- then try "gcc --print-file-name" to search gcc's search path
-- then try looking for import libraries on Windows (.dll.a, .lib)
-- then try "gcc --print-file-name" to search gcc's search path
-- then look in library-dirs and inplace GCC for a static library (libfoo.a)
-- for a dynamic library (#5289)
-- otherwise, assume loadDLL can find it
--
= findDll `orElse`
findSysDll `orElse`
tryGcc `orElse`
tryImpLib `orElse`
tryGcc `orElse`
findArchive `orElse`
assumeDll
......
TOP=../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
T12771:
'$(TEST_CC)' -c foo.c -o foo.o
'$(AR)' rsc libfoo.a foo.o
'$(TEST_HC)' -shared foo_dll.c -o libfoo-1.dll
mv libfoo-1.dll.a libfoo.dll.a
echo main | '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) main.hs -lfoo -L"$(PWD)"
test('T12771', [ extra_clean(['libfoo.a', 'libfoo-1.dll', 'foo.o', 'main.o'])
, extra_files(['foo.c', 'main.hs', 'foo_dll.c'])
, unless(opsys('mingw32'), skip)
],
run_command, ['$MAKE -s --no-print-directory T12771'])
extern int bar();
int foo ()
{
return bar();
}
module Main where
foreign import ccall "foo" c_foo :: Int
main = print c_foo
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment