Commit 495ef783 authored by Iavor S. Diatchki's avatar Iavor S. Diatchki
Browse files

Merge branch 'master' of ssh://darcs.haskell.org/srv/darcs/ghc

parents 2ec32a8e e9f38cb9
......@@ -500,7 +500,10 @@ $(foreach way,$$(compiler_stage3_WAYS),\
compiler/prelude/PrimOp_HC_OPTS += -fforce-recomp
# LibFFI.hs #includes ffi.h
ifneq "$(UseSystemLibFFI)" "YES"
compiler/stage2/build/LibFFI.hs : $(libffi_HEADERS)
endif
# On Windows it seems we also need to link directly to libffi
ifeq "$(HostOS_CPP)" "mingw32"
define windowsDynLinkToFfi
......
......@@ -8,13 +8,6 @@
#include <ffi.h>
{-# OPTIONS -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and
-- detab the module (please do the detabbing in a separate patch). See
-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSp
-- for details
module LibFFI (
ForeignCallToken,
prepForeignCall
......@@ -23,12 +16,11 @@ module LibFFI (
import TyCon
import ForeignCall
import Panic
-- import Outputable
import DynFlags
import Control.Monad
import Foreign
import Foreign.C
import Text.Printf
----------------------------------------------------------------------------
......@@ -45,17 +37,17 @@ prepForeignCall dflags cconv arg_types result_type
= do
let n_args = length arg_types
arg_arr <- mallocArray n_args
let init_arg (ty,n) = pokeElemOff arg_arr n (primRepToFFIType dflags ty)
mapM_ init_arg (zip arg_types [0..])
let init_arg ty n = pokeElemOff arg_arr n (primRepToFFIType dflags ty)
zipWithM_ init_arg arg_types [0..]
cif <- mallocBytes (#const sizeof(ffi_cif))
let abi = convToABI cconv
let res_ty = primRepToFFIType dflags result_type
r <- ffi_prep_cif cif abi (fromIntegral n_args) res_ty arg_arr
if (r /= fFI_OK)
then throwGhcException (InstallationError
(printf "prepForeignCallFailed: %d" (show r)))
then throwGhcException (InstallationError
("prepForeignCallFailed: " ++ show r))
else return cif
convToABI :: CCallConv -> C_ffi_abi
convToABI CCallConv = fFI_DEFAULT_ABI
#if defined(mingw32_HOST_OS) && defined(i386_HOST_ARCH)
......@@ -69,7 +61,7 @@ primRepToFFIType :: DynFlags -> PrimRep -> Ptr C_ffi_type
primRepToFFIType dflags r
= case r of
VoidRep -> ffi_type_void
IntRep -> signed_word
IntRep -> signed_word
WordRep -> unsigned_word
Int64Rep -> ffi_type_sint64
Word64Rep -> ffi_type_uint64
......@@ -118,10 +110,10 @@ fFI_STDCALL = (#const FFI_STDCALL)
#endif
-- ffi_status ffi_prep_cif(ffi_cif *cif,
-- ffi_abi abi,
-- unsigned int nargs,
-- ffi_type *rtype,
-- ffi_type **atypes);
-- ffi_abi abi,
-- unsigned int nargs,
-- ffi_type *rtype,
-- ffi_type **atypes);
foreign import ccall "ffi_prep_cif"
ffi_prep_cif :: Ptr C_ffi_cif -- cif
......@@ -134,9 +126,9 @@ foreign import ccall "ffi_prep_cif"
-- Currently unused:
-- void ffi_call(ffi_cif *cif,
-- void (*fn)(),
-- void *rvalue,
-- void **avalue);
-- void (*fn)(),
-- void *rvalue,
-- void **avalue);
-- foreign import ccall "ffi_call"
-- ffi_call :: Ptr C_ffi_cif -- cif
......
......@@ -86,6 +86,61 @@ AC_ARG_WITH([ghc],
fi
WithGhc="$GHC"])
# system libffi
AC_ARG_WITH([system-libffi],
[AC_HELP_STRING([--with-system-libffi],
[Use system provided libffi for RTS [default=no]])
])
AS_IF([test "x$with_system_libffi" = "xyes"],
[UseSystemLibFFI="YES"], [UseSystemLibFFI="NO"]
)
AC_SUBST(UseSystemLibFFI)
AC_ARG_WITH([ffi-includes],
[AC_HELP_STRING([--with-ffi-includes=ARG]
[Find includes for libffi in ARG [default=system default]])
],
[
if test "x$UseSystemLibFFI" != "xYES"; then
AC_MSG_WARN([--with-ffi-includes will be ignored, --with-system-libffi not set])
else
FFIIncludeDir="$withval"
LIBFFI_CFLAGS="-I $withval"
fi
])
AC_SUBST(FFIIncludeDir)
AC_ARG_WITH([ffi-libraries],
[AC_HELP_STRING([--with-ffi-libraries=ARG]
[Find libffi in ARG [default=system default]])
],
[
if test "x$UseSystemLibFFI" != "xYES"; then
AC_MSG_WARN([--with-ffi-libraries will be ignored, --with-system-libffi not set])
else
FFILibDir="$withval" LIBFFI_LDFLAGS="-L$withval"
fi
])
AC_SUBST(FFILibDir)
AS_IF([test "$UseSystemLibFFI" = "YES"], [
CFLAGS2="$CFLAGS"
CFLAGS="$LIBFFI_CFLAGS $CFLAGS"
LDFLAGS2="$LDFLAGS"
LDFLAGS="$LIBFFI_LDFLAGS $LDFLAGS"
AC_CHECK_LIB(ffi, ffi_call,
[AC_CHECK_HEADERS([ffi.h], [break], [])
AC_DEFINE([HAVE_LIBFFI], [1], [Define to 1 if you have libffi.])],
[AC_MSG_ERROR([Cannot find system libffi])])
CFLAGS="$CFLAGS2"
LDFLAGS="$LDFLAGS2"
])
dnl ** Tell the make system which OS we are using
dnl $OSTYPE is set by the operating system to "msys" or "cygwin" or something
......
......@@ -52,7 +52,7 @@
# * For each package:
# o configure, generate package-data.mk and inplace-pkg-info
# o register each package into inplace/lib/package.conf
# * build libffi
# * build libffi (if not disabled by --with-system-libffi)
# * With bootstrapping compiler:
# o Build libraries/{filepath,hpc,Cabal}
# o Build compiler (stage 1)
......@@ -1044,6 +1044,7 @@ unix-binary-dist-prep:
echo "BUILD_DOCBOOK_PDF = $(BUILD_DOCBOOK_PDF)" >> $(BIN_DIST_MK)
echo "BUILD_MAN = $(BUILD_MAN)" >> $(BIN_DIST_MK)
echo "GHC_CABAL_INPLACE = utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist" >> $(BIN_DIST_MK)
echo "UseSystemLibFFI = $(UseSystemLibFFI)" >> $(BIN_DIST_MK)
cd $(BIN_DIST_PREP_DIR) && autoreconf
$(call removeFiles,$(BIN_DIST_PREP_TAR))
# h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
......
......@@ -380,6 +380,13 @@ GhcRtsWithPapi = NO
PapiLibDir=
PapiIncludeDir=
# Configuration for libffi
UseSystemLibFFI=@UseSystemLibFFI@
# Flags to go into package.conf for rts
FFILibDir=@FFILibDir@
FFIIncludeDir=@FFIIncludeDir@
################################################################################
#
# Paths (see paths.mk)
......
......@@ -107,8 +107,10 @@ $(foreach lib,$(ALL_RTS_DEF_LIBNAMES),$(eval $(call make-importlib-def,$(lib))))
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)" $@
......@@ -121,6 +123,7 @@ rts/dist/build/libffi$(soext): libffi/build/inst/lib/libffi$(soext)
rts/dist/build/$(LIBFFI_DLL): libffi/build/inst/bin/$(LIBFFI_DLL)
cp $< $@
endif
endif
#-----------------------------------------------------------------------------
# Building one way
......@@ -177,6 +180,12 @@ endif
rts_dist_$1_CC_OPTS += -DRtsWay=\"rts_$1\"
ifneq "$(UseSystemLibFFI)" "YES"
rts_dist_FFI_SO = rts/dist/build/libffi$(soext)
else
rts_dist_FFI_SO =
endif
# Making a shared library for the RTS.
ifneq "$$(findstring dyn, $1)" ""
ifeq "$$(HostOS_CPP)" "mingw32"
......@@ -185,10 +194,10 @@ $$(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
$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend rts/dist/build/libffi$$(soext)
$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend $$(rts_dist_FFI_SO)
"$$(RM)" $$(RM_OPTS) $$@
"$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
-no-auto-link-packages -Lrts/dist/build -lffi `cat rts/libs.depend` $$(rts_$1_OBJS) \
-no-auto-link-packages $$(LIBFFI_LIBS) `cat rts/libs.depend` $$(rts_$1_OBJS) \
$$(rts_$1_DTRACE_OBJS) -o $$@
endif
else
......@@ -377,10 +386,16 @@ rts/dist/build/AutoApply_HC_OPTS += -fno-PIC -static
endif
endif
# add CFLAGS for libffi
# ffi.h triggers prototype warnings, so disable them here:
rts/Interpreter_CC_OPTS += -Wno-strict-prototypes
rts/Adjustor_CC_OPTS += -Wno-strict-prototypes
rts/sm/Storage_CC_OPTS += -Wno-strict-prototypes
ifeq "$(UseSystemLibFFI)" "YES"
LIBFFI_CFLAGS = $(addprefix -I,$(FFIIncludeDir))
else
LIBFFI_CFLAGS =
endif
rts/Interpreter_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
rts/Adjustor_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
rts/sm/Storage_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
# inlining warnings happen in Compact
rts/sm/Compact_CC_OPTS += -Wno-inline
......@@ -438,6 +453,21 @@ rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
endif
#-----------------------------------------------------------------------------
# Use system provided libffi
ifeq "$(UseSystemLibFFI)" "YES"
rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=$(FFIIncludeDir)
rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=$(FFILibDir)
else # UseSystemLibFFI==YES
rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=""
rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=""
endif
# -----------------------------------------------------------------------------
# dependencies
......@@ -463,7 +493,10 @@ endif
$(eval $(call dependencies,rts,dist,1))
$(rts_dist_depfile_c_asm) : $(libffi_HEADERS) $(DTRACEPROBES_H)
$(rts_dist_depfile_c_asm) : $(DTRACEPROBES_H)
ifneq "$(UseSystemLibFFI)" "YES"
$(rts_dist_depfile_c_asm) : $(libffi_HEADERS)
endif
# -----------------------------------------------------------------------------
# compile dtrace probes if dtrace is supported
......@@ -515,7 +548,9 @@ RTS_INSTALL_LIBS += $(ALL_RTS_LIBS)
RTS_INSTALL_LIBS += $(wildcard rts/dist/build/libffi$(soext)*)
RTS_INSTALL_LIBS += $(wildcard rts/dist/build/$(LIBFFI_DLL))
ifneq "$(UseSystemLibFFI)" "YES"
install: install_libffi_headers
endif
.PHONY: install_libffi_headers
install_libffi_headers :
......
......@@ -33,6 +33,9 @@ extra-libraries:
#ifdef HAVE_LIBDL
, "dl"
#endif
#ifdef HAVE_LIBFFI
, "ffi"
#endif
#ifdef mingw32_HOST_OS
,"wsock32" /* for the linker */
,"gdi32" /* for the linker */
......
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