Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
f7be53ac
Commit
f7be53ac
authored
Jan 28, 2014
by
Christiaan Baaij
Committed by
Austin Seipp
Jan 28, 2014
Browse files
Fix inplace dynamic linking on OS X (#8266)
Signed-off-by:
Austin Seipp
<
austin@well-typed.com
>
parent
943f22a4
Changes
9
Hide whitespace changes
Inline
Side-by-side
compiler/main/DriverPipeline.hs
View file @
f7be53ac
...
...
@@ -1785,6 +1785,15 @@ linkBinary' staticLink dflags o_files dep_packages = do
then
[]
else
[
"-Wl,-rpath-link"
,
"-Wl,"
++
l
]
in
[
"-L"
++
l
]
++
rpathlink
++
rpath
|
osMachOTarget
(
platformOS
platform
)
&&
dynLibLoader
dflags
==
SystemDependent
&&
not
(
gopt
Opt_Static
dflags
)
&&
gopt
Opt_RPath
dflags
=
let
libpath
=
if
gopt
Opt_RelativeDynlibPaths
dflags
then
"@loader_path"
</>
(
l
`
makeRelativeTo
`
full_output_fn
)
else
l
in
[
"-L"
++
l
]
++
[
"-Wl,-rpath"
,
"-Wl,"
++
libpath
]
|
otherwise
=
[
"-L"
++
l
]
let
lib_paths
=
libraryPaths
dflags
...
...
@@ -1920,13 +1929,6 @@ linkBinary' staticLink dflags o_files dep_packages = do
then
[
"-Wl,-read_only_relocs,suppress"
]
else
[]
)
++
(
if
platformOS
platform
==
OSDarwin
&&
not
staticLink
&&
not
(
gopt
Opt_Static
dflags
)
&&
gopt
Opt_RPath
dflags
then
[
"-Wl,-rpath"
,
"-Wl,"
++
topDir
dflags
]
else
[]
)
++
o_files
++
lib_path_opts
)
++
extra_ld_inputs
...
...
compiler/main/SysTools.lhs
View file @
f7be53ac
...
...
@@ -1293,7 +1293,8 @@ linkDynLib dflags0 o_files dep_packages
let pkg_lib_paths = collectLibraryPaths pkgs
let pkg_lib_path_opts = concatMap get_pkg_lib_path_opts pkg_lib_paths
get_pkg_lib_path_opts l
| osElfTarget (platformOS (targetPlatform dflags)) &&
| ( osElfTarget (platformOS (targetPlatform dflags)) ||
osMachOTarget (platformOS (targetPlatform dflags)) ) &&
dynLibLoader dflags == SystemDependent &&
not (gopt Opt_Static dflags)
= ["-L" ++ l, "-Wl,-rpath", "-Wl," ++ l]
...
...
@@ -1390,9 +1391,7 @@ linkDynLib dflags0 o_files dep_packages
instName <- case dylibInstallName dflags of
Just n -> return n
Nothing -> do
pwd <- getCurrentDirectory
return $ pwd `combine` output_fn
Nothing -> return $ "@rpath" `combine` (takeFileName output_fn)
runLink dflags (
map Option verbFlags
++ [ Option "-dynamiclib"
...
...
compiler/utils/Platform.hs
View file @
f7be53ac
...
...
@@ -12,6 +12,7 @@ module Platform (
target32Bit
,
isARM
,
osElfTarget
,
osMachOTarget
,
platformUsesFrameworks
,
platformBinariesAreStaticLibs
,
)
...
...
@@ -129,6 +130,11 @@ osElfTarget OSUnknown = False
-- portability, otherwise we have to answer this question for every
-- new platform we compile on (even unreg).
-- | This predicate tells us whether the OS support Mach-O shared libraries.
osMachOTarget
::
OS
->
Bool
osMachOTarget
OSDarwin
=
True
osMachOTarget
_
=
False
osUsesFrameworks
::
OS
->
Bool
osUsesFrameworks
OSDarwin
=
True
osUsesFrameworks
OSiOS
=
True
...
...
ghc.mk
View file @
f7be53ac
...
...
@@ -282,11 +282,6 @@ include rules/dependencies.mk
include
rules/build-dependencies.mk
include
rules/include-dependencies.mk
# -----------------------------------------------------------------------------
# Dynamic library references
include
rules/relative-dynlib-references.mk
# -----------------------------------------------------------------------------
# Build package-data.mk files
...
...
rts/ghc.mk
View file @
f7be53ac
...
...
@@ -117,7 +117,7 @@ else
rts/dist/build/lib$(LIBFFI_NAME)$(soext)
:
libffi/build/inst/lib/lib$(LIBFFI_NAME)$(soext)
cp
libffi/build/inst/lib/lib
$(LIBFFI_NAME)$(soext)
*
rts/dist/build
ifeq
"$(TargetOS_CPP)" "darwin"
install_name_tool
-id
@rpath/
rts-
$(rts_VERSION)
/
lib
$(LIBFFI_NAME)$(soext)
rts/dist/build/lib
$(LIBFFI_NAME)$(soext)
install_name_tool
-id
@rpath/lib
$(LIBFFI_NAME)$(soext)
rts/dist/build/lib
$(LIBFFI_NAME)$(soext)
endif
endif
endif
...
...
@@ -197,6 +197,9 @@ LIBFFI_LIBS = -Lrts/dist/build -l$$(LIBFFI_NAME)
ifeq
"$$(TargetElf)" "YES"
LIBFFI_LIBS
+=
-optl-Wl
,-rpath
-optl-Wl
,
'$$$$ORIGIN'
-optl-Wl
,-zorigin
endif
ifeq
"$(TargetOS_CPP)" "darwin"
LIBFFI_LIBS
+=
-optl-Wl
,-rpath
-optl-Wl
,@loader_path
endif
else
# flags will be taken care of in rts/dist/libs.depend
...
...
@@ -207,7 +210,6 @@ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/dist/libs.depend $$(
"
$
$(rts_dist_HC)
"
-package-name
rts
-shared
-dynamic
-dynload
deploy
\
-no-auto-link-packages
$
$(LIBFFI_LIBS)
`
cat
rts/dist/libs.depend
`
$$
(
rts_
$1_OBJS
)
\
$$
(
rts_
$1_DTRACE_OBJS
)
-o
$$
@
$(
call
relative-dynlib-references,rts,dist,1,
$1
)
endif
else
$$(rts_$1_LIB)
:
$$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS)
...
...
rules/build-package-way.mk
View file @
f7be53ac
...
...
@@ -91,7 +91,6 @@ $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
$
$(
addprefix
-l
,
$$
(
$1_$2_EXTRA_LIBRARIES
))
$
$(
addprefix
-L
,
$$
(
$1_$2_EXTRA_LIBDIRS
))
\
-no-auto-link-packages
\
-o
$$
@
$(
call
relative-dynlib-references,
$1
,
$2
,
$4
)
endif
else
# Build the ordinary .a library
...
...
rules/build-prog.mk
View file @
f7be53ac
...
...
@@ -261,10 +261,6 @@ ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
$1/$2/build/tmp/$$($1_$2_PROG)
:
$$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_C_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
$
$(
call
cmd,
$1_$2_HC
)
-o
$$
@
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_ALL_HC_OPTS
)
$
$(LD_OPTS)
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_GHC_LD_OPTS
)
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_HS_OBJS
)
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_C_OBJS
)
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_S_OBJS
)
$$
(
$1_$2_OTHER_OBJS
)
$
$(
addprefix
-l
,
$$
(
$1_$2_EXTRA_LIBRARIES
))
ifeq
"$$($1_$2_PROGRAM_WAY)" "dyn"
$(call
relative-dynlib-references,$1,$2,$3)
$(call
relative-dynlib-path,$3)
endif
else
$1/$2/build/tmp/$$($1_$2_PROG)
:
$$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_C_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
$
$(
call
cmd,
$1_$2_CC
)
-o
$$
@
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_ALL_CC_OPTS
)
$
$(LD_OPTS)
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_HS_OBJS
)
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_C_OBJS
)
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_S_OBJS
)
$$
(
$1_$2_OTHER_OBJS
)
$$
(
$1_$2_
$$
(
$1_$2_PROGRAM_WAY
)
_EXTRA_CC_OPTS
)
$
$(
addprefix
-l
,
$$
(
$1_$2_EXTRA_LIBRARIES
))
...
...
rules/distdir-way-opts.mk
View file @
f7be53ac
...
...
@@ -138,7 +138,9 @@ $1_$2_$3_GHC_LD_OPTS += \
-fno-use-rpaths
\
$
$(
foreach
d,
$$
(
$1_$2_TRANSITIVE_DEPS
)
,-optl-Wl
$
$(comma)
-rpath
-optl-Wl
$
$(comma)
'$$$$ORIGIN/../$$d'
)
-optl-Wl
,-zorigin
else
ifeq
"$$(TargetOS_CPP)" "darwin"
$1_$2_$3_GHC_LD_OPTS
+=
-optl-Wl
,-headerpad_max_install_names
$1_$2_$3_GHC_LD_OPTS
+=
\
-fno-use-rpaths
\
$
$(
foreach
d,
$$
(
$1_$2_TRANSITIVE_DEPS
)
,-optl-Wl
$
$(comma)
-rpath
-optl-Wl
$
$(comma)
'@loader_path/../$$d'
)
endif
endif
endif
...
...
rules/relative-dynlib-references.mk
deleted
100644 → 0
View file @
943f22a4
# -----------------------------------------------------------------------------
#
# (c) 2009 The University of Glasgow
#
# This file is part of the GHC build system.
#
# To understand how the build system works and how to modify it, see
# http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
# http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
#
# -----------------------------------------------------------------------------
# Make dynlib references use relative paths, so that everything works
# without the build tree.
define
relative-dynlib-references
# $1 = dir
# $2 = distdir
# $3 = GHC stage to use (0 == bootstrapping compiler)
# $4 = RTSway
ifeq
"$$(TargetOS_CPP)" "darwin"
ifneq
"$3" "0"
# Use relative paths for all the libraries
ifneq
"$$($1_$2_TRANSITIVE_DEP_NAMES)" ""
install_name_tool
$$(foreach
d,$$($1_$2_TRANSITIVE_DEP_NAMES),
-change
$$(TOP)/$$($$($$d_INSTALL_INFO)_dyn_LIB)
@rpath/$$d-$$($$($$d_INSTALL_INFO)_VERSION)/$$($$($$d_INSTALL_INFO)_dyn_LIB_NAME))
$$@
endif
# Change absolute library name/path to a relative name/path
ifeq
"$$($1_$2_PROGNAME)" ""
ifeq
"$1" "rts"
install_name_tool
-id
@rpath/rts-$$(rts_VERSION)/$$(rts_$4_LIB_NAME)
$$@
else
install_name_tool
-id
@rpath/$$($1_PACKAGE)-$$($1_$2_VERSION)/$$($1_$2_dyn_LIB_NAME)
$$@
endif
endif
# Use relative paths for the RTS. Rather than try to work out which RTS
# way is being linked, we just change it for all ways
install_name_tool
$$(foreach
w,$$(rts_WAYS),
-change
$$(TOP)/$$(rts_$$w_LIB)
@rpath/rts-$$(rts_VERSION)/$$(rts_$$w_LIB_NAME))
$$@
install_name_tool
-change
$$(TOP)/$$(wildcard
libffi/build/inst/lib/libffi.*.dylib)
@rpath/rts-$$(rts_VERSION)/libffi.dylib
$$@
endif
endif
endef
define
relative-dynlib-path
# $1 = GHC stage to use (0 == bootstrapping compiler)
ifeq
"$$(TargetOS_CPP)" "darwin"
ifneq
"$1" "0"
install_name_tool
-rpath
$$(TOP)/inplace/lib
@loader_path/..
$$@
endif
endif
endef
darchon
@trac-darchon
mentioned in issue
#8721
·
Jan 31, 2014
mentioned in issue
#8721
mentioned in issue #8721
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment