Commit c6a3e227 authored by Peter Trommler's avatar Peter Trommler 🥁 Committed by Ben Gamari

Link command line libs to temp so

Symbols in libraries specified on the GHCis command line are
not available to compiled modules because shared libraries
are loaded with local scope. So we link all libraries specified
on the command line into each temporary shared library.

Test Plan: validate

Reviewers: simonmar, hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #10458
parent faf3f96f
......@@ -846,6 +846,8 @@ dynLoadObjs _ pls [] = return pls
dynLoadObjs hsc_env pls objs = do
let dflags = hsc_dflags hsc_env
let platform = targetPlatform dflags
let minus_ls = [ lib | Option ('-':'l':lib) <- ldInputs dflags ]
let minus_big_ls = [ lib | Option ('-':'L':lib) <- ldInputs dflags ]
(soFile, libPath , libName) <- newTempLibName dflags (soExt platform)
let
dflags2 = dflags {
......@@ -863,7 +865,17 @@ dynLoadObjs hsc_env pls objs = do
, Option ("-Wl," ++ lp)
, Option ("-l" ++ l)
])
(temp_sos pls),
(temp_sos pls)
++ concatMap
(\lp ->
[ Option ("-L" ++ lp)
, Option ("-Wl,-rpath")
, Option ("-Wl," ++ lp)
])
minus_big_ls
++ map (\l -> Option ("-l" ++ l)) minus_ls,
-- Add -l options and -L options from dflags.
--
-- When running TH for a non-dynamic way, we still
-- need to make -l flags to link against the dynamic
-- libraries, so we need to add WayDyn to ways.
......
......@@ -39,6 +39,13 @@ compile_libAS:
'$(TEST_HC)' $(MY_TEST_HC_OPTS) -shared A.c -o $(call DLL,AS)
rm -f libAS*.a
.PHONY: compile_libT10458
compile_libT10458:
rm -rf T10458dir
mkdir T10458dir
'$(TEST_HC)' $(MY_TEST_HC_OPTS) -odir "T10458dir" -shared A.c -o "T10458dir/$(call DLL,AS)"
rm -f T10458dir/libAS*.a
.PHONY: compile_libAB_dep
compile_libAB_dep:
rm -rf bin_dep
......
module T10458 (callSO) where
import Foreign
import Foreign.C.Types
foreign import ccall "foo" dle :: IO CInt
callSO :: IO CInt
callSO = dle
:set -fobject-code
:load T10458
callSO
......@@ -27,3 +27,10 @@ test('T10955dyn',
[extra_clean(['bin_dyn/*', 'bin_dyn'])],
run_command,
['$MAKE -s --no-print-directory compile_libAB_dyn'])
test('T10458',
[unless(doing_ghci, skip),
extra_clean(['libAS.*']),
pre_cmd('$MAKE -s --no-print-directory compile_libT10458'),
extra_hc_opts('-L$PWD/T10458dir -lAS')],
ghci_script, ['T10458.script'])
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