Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change how we handle libffi

I think overall the new approach is simpler. Rather than unpacking
the libffi.a and putting the .o files into our libHSrts.a, we just
use the libffi.a.

This change also means that when compiling programs for the dyn
way, they get explicitly linked against libffi.so (rather than
relying on librts.so being linked against it). This might
fix a problem on FreeBSD, where programs cannot find libffi.so.
  • Loading branch information...
commit b30015e78db99d79cdb48c6c810e3fd49573c5cd 1 parent f4a2796
@igfoo igfoo authored
Showing with 33 additions and 20 deletions.
  1. +10 −2 compiler/main/Packages.lhs
  2. +22 −17 rts/ghc.mk
  3. +1 −1  rts/package.conf.in
View
12 compiler/main/Packages.lhs
@@ -896,8 +896,16 @@ packageHsLibs dflags p = map (mkDynName . addSuffix) (hsLibraries p)
tag = mkBuildTag (filter (not . wayRTSOnly) ways2)
rts_tag = mkBuildTag ways2
- mkDynName | gopt Opt_Static dflags = id
- | otherwise = (++ ("-ghc" ++ cProjectVersion))
+ mkDynName x
+ | gopt Opt_Static dflags = x
+ | "HS" `isPrefixOf` x = x ++ "-ghc" ++ cProjectVersion
+ -- For non-Haskell libraries, we use the name "Cfoo". The .a
+ -- file is libCfoo.a, and the .so is libfoo.so. That way the
+ -- linker knows what we mean for the vanilla (-lCfoo) and dyn
+ -- (-lfoo) ways. We therefore need to strip the 'C' off here.
+ | Just x' <- stripPrefix "C" x = x'
+ | otherwise
+ = panic ("Don't understand library name " ++ x)
addSuffix rts@"HSrts" = rts ++ (expandTag rts_tag)
addSuffix other_lib = other_lib ++ (expandTag tag)
View
39 rts/ghc.mk
@@ -104,13 +104,6 @@ endif
ifneq "$(BINDIST)" "YES"
ifneq "$(UseSystemLibFFI)" "YES"
-rts_ffi_objs_stamp = rts/dist/ffi/stamp
-rts_ffi_objs = rts/dist/ffi/*.o
-
-$(rts_ffi_objs_stamp): $(libffi_STATIC_LIB) $(TOUCH_DEP) | $$(dir $$@)/.
- cd rts/dist/ffi && $(AR) x ../../../$(libffi_STATIC_LIB)
- "$(TOUCH_CMD)" $@
-
# This is a little hacky. We don't know the SO version, so we only
# depend on libffi.so, but copy libffi.so*
rts/dist/build/libffi$(soext): libffi/build/inst/lib/libffi$(soext)
@@ -174,8 +167,8 @@ endif
rts_dist_$1_CC_OPTS += -DRtsWay=\"rts_$1\"
-ifneq "$(UseSystemLibFFI)" "YES"
-rts_dist_FFI_SO = rts/dist/build/libffi$(soext)
+ifneq "$$(UseSystemLibFFI)" "YES"
+rts_dist_FFI_SO = rts/dist/build/libffi$$(soext)
else
rts_dist_FFI_SO =
endif
@@ -188,7 +181,7 @@ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend rts/dist/b
"$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
-no-auto-link-packages -Lrts/dist/build -l$(LIBFFI_WINDOWS_LIB) `cat rts/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) -o $$@
else
-ifneq "$(UseSystemLibFFI)" "YES"
+ifneq "$$(UseSystemLibFFI)" "YES"
LIBFFI_LIBS = -Lrts/dist/build -lffi
ifeq "$$(TargetElf)" "YES"
LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,'$$$$ORIGIN'
@@ -205,10 +198,17 @@ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend $$(rts_d
$$(rts_$1_DTRACE_OBJS) -o $$@
endif
else
-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) $$(rts_ffi_objs_stamp)
+$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS)
"$$(RM)" $$(RM_OPTS) $$@
- echo $$(rts_ffi_objs) $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
+ echo $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
$$(AR_OPTS_STAGE1) $$(EXTRA_AR_ARGS_STAGE1) $$@
+
+ifneq "$$(UseSystemLibFFI)" "YES"
+$$(rts_$1_LIB) : rts/dist/build/libCffi$$($1_libsuf)
+rts/dist/build/libCffi$$($1_libsuf): libffi/build/inst/lib/libffi.a
+ cp $$< $$@
+endif
+
endif
endif
@@ -459,13 +459,15 @@ endif
ifeq "$(UseSystemLibFFI)" "YES"
-rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=$(FFIIncludeDir)
-rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=$(FFILibDir)
+rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=$(FFIIncludeDir)
+rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=$(FFILibDir)
+rts_PACKAGE_CPP_OPTS += '-DFFI_LIB='
else # UseSystemLibFFI==YES
-rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=""
-rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=""
+rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=
+rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=
+rts_PACKAGE_CPP_OPTS += '-DFFI_LIB="Cffi"'
endif
@@ -544,8 +546,11 @@ rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
# installing
RTS_INSTALL_LIBS += $(ALL_RTS_LIBS)
+ifneq "$(UseSystemLibFFI)" "YES"
RTS_INSTALL_LIBS += $(wildcard rts/dist/build/libffi$(soext)*)
-RTS_INSTALL_LIBS += $(wildcard rts/dist/build/$(LIBFFI_DLL))
+RTS_INSTALL_LIBS += $(foreach w,$(filter-out dyn,$(rts_WAYS)),rts/dist/build/libffi$($w_libsuf))
+RTS_INSTALL_LIBS += rts/dist/build/$(LIBFFI_DLL)
+endif
ifneq "$(UseSystemLibFFI)" "YES"
install: install_libffi_headers
View
2  rts/package.conf.in
@@ -21,7 +21,7 @@ library-dirs: LIB_DIR"/rts-1.0" PAPI_LIB_DIR
library-dirs: TOP"/rts/dist/build" PAPI_LIB_DIR
#endif
-hs-libraries: "HSrts"
+hs-libraries: "HSrts" FFI_LIB
extra-libraries:
#ifdef HAVE_LIBM
Please sign in to comment.
Something went wrong with that request. Please try again.