diff --git a/common/autoconf/libraries.m4 b/common/autoconf/libraries.m4 index 6efae578ea..4ed8b4fdd6 100644 --- a/common/autoconf/libraries.m4 +++ b/common/autoconf/libraries.m4 @@ -988,12 +988,161 @@ AC_DEFUN_ONCE([LIB_SETUP_STATIC_LINK_LIBSTDCPP], fi AC_SUBST(STATIC_CXX_SETTING) + AC_ARG_WITH(libffi, [AS_HELP_STRING([--with-libffi], + [specify prefix directory for the libffi package + (expecting the libraries under PATH/lib and the headers under PATH/include)])]) + AC_ARG_WITH(libffi-include, [AS_HELP_STRING([--with-libffi-include], + [specify directory for the libffi include files])]) + AC_ARG_WITH(libffi-lib, [AS_HELP_STRING([--with-libffi-lib], + [specify directory for the libffi library])]) + AC_ARG_ENABLE(libffi-bundling, [AS_HELP_STRING([--enable-libffi-bundling], + [enable bundling of libffi.so to make the built JDK runnable on more systems])]) + + # Check if ffi is needed if test "x$JVM_VARIANT_ZERO" = xtrue || test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then - # Figure out LIBFFI_CFLAGS and LIBFFI_LIBS - PKG_CHECK_MODULES([LIBFFI], [libffi]) + NEEDS_LIB_FFI=true + else + NEEDS_LIB_FFI=false + fi + + if test "x$NEEDS_LIB_FFI" = xfalse; then + if test "x${with_libffi}" != x || test "x${with_libffi_include}" != x || test "x${with_libffi_lib}" != x; then + AC_MSG_WARN([libffi not used, so --with-libffi is ignored]) + fi + LIBFFI_CFLAGS= + LIBFFI_LIBS= + else + LIBFFI_FOUND=no + if test "x${with_libffi}" = xno || test "x${with_libffi_include}" = xno || test "x${with_libffi_lib}" = xno; then + AC_MSG_ERROR([It is not possible to disable the use of libffi. Remove the --without-libffi option.]) + fi + + if test "x${with_libffi}" != x; then + LIBFFI_LIB_PATH="${with_libffi}/lib" + LIBFFI_LIBS="-L${with_libffi}/lib -lffi" + LIBFFI_CFLAGS="-I${with_libffi}/include" + LIBFFI_FOUND=yes + fi + if test "x${with_libffi_include}" != x; then + LIBFFI_CFLAGS="-I${with_libffi_include}" + LIBFFI_FOUND=yes + fi + if test "x${with_libffi_lib}" != x; then + LIBFFI_LIB_PATH="${with_libffi_lib}" + LIBFFI_LIBS="-L${with_libffi_lib} -lffi" + LIBFFI_FOUND=yes + fi + # Do not try pkg-config if we have a sysroot set. + if test "x$SYSROOT" = x; then + if test "x$LIBFFI_FOUND" = xno; then + # Figure out LIBFFI_CFLAGS and LIBFFI_LIBS + PKG_CHECK_MODULES([LIBFFI], [libffi], [LIBFFI_FOUND=yes], [LIBFFI_FOUND=no]) + fi + fi + if test "x$LIBFFI_FOUND" = xno; then + AC_CHECK_HEADERS([ffi.h], + [ + LIBFFI_FOUND=yes + LIBFFI_CFLAGS= + LIBFFI_LIBS=-lffi + ], + [LIBFFI_FOUND=no] + ) + fi + if test "x$LIBFFI_FOUND" = xno; then + HELP_MSG_MISSING_DEPENDENCY([ffi]) + AC_MSG_ERROR([Could not find libffi! $HELP_MSG]) + fi + + AC_MSG_CHECKING([if libffi works]) + AC_LANG_PUSH(C) + OLD_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $LIBFFI_CFLAGS" + OLD_LIBS="$LIBS" + LIBS="$LIBS $LIBFFI_LIBS" + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], + [ + ffi_call(NULL, NULL, NULL, NULL); + return 0; + ])], + [LIBFFI_WORKS=yes], + [LIBFFI_WORKS=no] + ) + CFLAGS="$OLD_CFLAGS" + LIBS="$OLD_LIBS" + AC_LANG_POP(C) + AC_MSG_RESULT([$LIBFFI_WORKS]) + + if test "x$LIBFFI_WORKS" = xno; then + HELP_MSG_MISSING_DEPENDENCY([ffi]) + AC_MSG_ERROR([Found libffi but could not link and compile with it. $HELP_MSG]) + fi + + AC_MSG_CHECKING([if libffi should be bundled]) + if test "x$enable_libffi_bundling" = "x"; then + AC_MSG_RESULT([no]) + ENABLE_LIBFFI_BUNDLING=false + elif test "x$enable_libffi_bundling" = "xno"; then + AC_MSG_RESULT([no, forced]) + ENABLE_LIBFFI_BUNDLING=false + elif test "x$enable_libffi_bundling" = "xyes"; then + AC_MSG_RESULT([yes, forced]) + ENABLE_LIBFFI_BUNDLING=true + else + AC_MSG_ERROR([Invalid value for --enable-libffi-bundling]) + fi + + # Find the libffi.so.X to bundle + if test "x${ENABLE_LIBFFI_BUNDLING}" = "xtrue"; then + AC_MSG_CHECKING([for libffi lib file location]) + if test "x${LIBFFI_LIB_PATH}" != x; then + if test -e ${LIBFFI_LIB_PATH}/libffi.so.?; then + LIBFFI_LIB_FILE="${LIBFFI_LIB_PATH}/libffi.so.?" + else + AC_MSG_ERROR([Could not locate libffi.so.? for bundling in ${LIBFFI_LIB_PATH}]) + fi + else + # If we don't have an explicit path, look in a few obvious places + if test "x${OPENJDK_TARGET_CPU}" = "xx86"; then + if test -e ${SYSROOT}/usr/lib/libffi.so.? ; then + LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/libffi.so.?" + elif test -e ${SYSROOT}/usr/lib/i386-linux-gnu/libffi.so.? ; then + LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/i386-linux-gnu/libffi.so.?" + else + AC_MSG_ERROR([Could not locate libffi.so.? for bundling]) + fi + elif test "x${OPENJDK_TARGET_CPU}" = "xx86_64"; then + if test -e ${SYSROOT}/usr/lib64/libffi.so.? ; then + LIBFFI_LIB_FILE="${SYSROOT}/usr/lib64/libffi.so.?" + elif test -e ${SYSROOT}/usr/lib/x86_64-linux-gnu/libffi.so.? ; then + LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/x86_64-linux-gnu/libffi.so.?" + else + AC_MSG_ERROR([Could not locate libffi.so.? for bundling]) + fi + else + # Fallback on the default /usr/lib dir + if test -e ${SYSROOT}/usr/lib/libffi.so.? ; then + LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/libffi.so.?" + else + AC_MSG_ERROR([Could not locate libffi.so.? for bundling]) + fi + fi + fi + # Make sure the wildcard is evaluated + LIBFFI_LIB_FILE="$(ls ${LIBFFI_LIB_FILE})" + LIBFFI_LIB_DIR="$(dirname ${LIBFFI_LIB_FILE})" + LIBFFI_LIB_FILE="$(basename ${LIBFFI_LIB_FILE})" + AC_MSG_RESULT([${LIBFFI_LIB_FILE} in ${LIBFFI_LIB_DIR}]) + fi fi + AC_SUBST(LIBFFI_CFLAGS) + AC_SUBST(LIBFFI_LIBS) + AC_SUBST(ENABLE_LIBFFI_BUNDLING) + AC_SUBST(LIBFFI_LIB_DIR) + AC_SUBST(LIBFFI_LIB_FILE) + if test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then AC_CHECK_PROG([LLVM_CONFIG], [llvm-config], [llvm-config]) diff --git a/common/autoconf/spec.gmk.in b/common/autoconf/spec.gmk.in index 9573bb2cbd..8da3ac32a0 100644 --- a/common/autoconf/spec.gmk.in +++ b/common/autoconf/spec.gmk.in @@ -311,6 +311,11 @@ FONTCONFIG_CFLAGS:=@FONTCONFIG_CFLAGS@ CUPS_CFLAGS:=@CUPS_CFLAGS@ ALSA_LIBS:=@ALSA_LIBS@ ALSA_CFLAGS:=@ALSA_CFLAGS@ +LIBFFI_LIBS:=@LIBFFI_LIBS@ +LIBFFI_CFLAGS:=@LIBFFI_CFLAGS@ +ENABLE_LIBFFI_BUNDLING:=@ENABLE_LIBFFI_BUNDLING@ +LIBFFI_LIB_DIR:=@LIBFFI_LIB_DIR@ +LIBFFI_LIB_FILE:=@LIBFFI_LIB_FILE@ PACKAGE_PATH=@PACKAGE_PATH@ diff --git a/hotspot/make/Makefile b/hotspot/make/Makefile index ad195763be..b9114cb99a 100644 --- a/hotspot/make/Makefile +++ b/hotspot/make/Makefile @@ -476,6 +476,8 @@ $(EXPORT_INCLUDE_DIR)/%: $(ZERO_BUILD_DIR)/../generated/jvmtifiles/% # Unix $(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(ZERO_BUILD_DIR)/%.$(LIBRARY_SUFFIX) $(install-file) +$(EXPORT_JRE_LIB_ARCH_DIR)/$(LIBFFI_LIB_FILE): $(LIBFFI_LIB_DIR)/$(LIBFFI_LIB_FILE) + $(install-file) $(EXPORT_JRE_LIB_ARCH_DIR)/%.debuginfo: $(ZERO_BUILD_DIR)/%.debuginfo $(install-file) $(EXPORT_JRE_LIB_ARCH_DIR)/%.diz: $(ZERO_BUILD_DIR)/%.diz diff --git a/hotspot/make/aix/makefiles/defs.make b/hotspot/make/aix/makefiles/defs.make index b12c9c8df2..db10f6a68f 100644 --- a/hotspot/make/aix/makefiles/defs.make +++ b/hotspot/make/aix/makefiles/defs.make @@ -220,4 +220,7 @@ ADD_SA_BINARIES/zero = EXPORT_LIST += $(ADD_SA_BINARIES/$(HS_ARCH)) +ifeq ($(ENABLE_LIBFFI_BUNDLING), true) + EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/$(LIBFFI_LIB_FILE) +endif diff --git a/hotspot/make/bsd/makefiles/defs.make b/hotspot/make/bsd/makefiles/defs.make index 7cd21cc175..23436f12d8 100644 --- a/hotspot/make/bsd/makefiles/defs.make +++ b/hotspot/make/bsd/makefiles/defs.make @@ -364,6 +364,10 @@ ADD_SA_BINARIES/zero = EXPORT_LIST += $(ADD_SA_BINARIES/$(HS_ARCH)) +ifeq ($(ENABLE_LIBFFI_BUNDLING), true) + EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/$(LIBFFI_LIB_FILE) +endif + # Universal build settings ifeq ($(OS_VENDOR), Darwin) # Build universal binaries by default on Mac OS X diff --git a/hotspot/make/linux/makefiles/defs.make b/hotspot/make/linux/makefiles/defs.make index ec414639d2..0baa4f068d 100644 --- a/hotspot/make/linux/makefiles/defs.make +++ b/hotspot/make/linux/makefiles/defs.make @@ -333,4 +333,6 @@ ADD_SA_BINARIES/zero = EXPORT_LIST += $(ADD_SA_BINARIES/$(HS_ARCH)) - +ifeq ($(ENABLE_LIBFFI_BUNDLING), true) + EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/$(LIBFFI_LIB_FILE) +endif diff --git a/hotspot/make/solaris/makefiles/defs.make b/hotspot/make/solaris/makefiles/defs.make index c88351c82b..cb838e854d 100644 --- a/hotspot/make/solaris/makefiles/defs.make +++ b/hotspot/make/solaris/makefiles/defs.make @@ -304,3 +304,7 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) endif endif EXPORT_LIST += $(EXPORT_LIB_DIR)/sa-jdi.jar + +ifeq ($(ENABLE_LIBFFI_BUNDLING), true) + EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/$(LIBFFI_LIB_FILE) +endif diff --git a/hotspot/make/windows/makefiles/defs.make b/hotspot/make/windows/makefiles/defs.make index 6b36f0e2bc..6f42c7ad37 100644 --- a/hotspot/make/windows/makefiles/defs.make +++ b/hotspot/make/windows/makefiles/defs.make @@ -300,6 +300,10 @@ ifeq ($(BUILD_WIN_SA), 1) MAKE_ARGS += BUILD_WIN_SA=1 endif +ifeq ($(ENABLE_LIBFFI_BUNDLING), true) + EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/$(LIBFFI_LIB_FILE) +endif + # Propagate compiler and tools paths from configure to nmake. # Need to make sure they contain \\ and not /. ifneq ($(SPEC),) diff --git a/jdk/make/Images.gmk b/jdk/make/Images.gmk index 2e378c9134..0edefd7b5c 100644 --- a/jdk/make/Images.gmk +++ b/jdk/make/Images.gmk @@ -249,7 +249,8 @@ endif ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris),) # If Linux or Solaris JDK_LIB_FILES += $(LIBRARY_PREFIX)jli$(SHARED_LIBRARY_SUFFIX) \ - $(LIBRARY_PREFIX)jawt$(SHARED_LIBRARY_SUFFIX) + $(LIBRARY_PREFIX)jawt$(SHARED_LIBRARY_SUFFIX) \ + $(LIBFFI_LIB_FILE) endif # Find all files to copy from $(JDK_OUTPUTDIR)/lib diff --git a/jdk/make/Import.gmk b/jdk/make/Import.gmk index b115fa7f86..29fa2662a6 100644 --- a/jdk/make/Import.gmk +++ b/jdk/make/Import.gmk @@ -114,7 +114,7 @@ endef # # Import hotspot # -HOTSPOT_IMPORT_FILES := $(addprefix $(LIBRARY_PREFIX), jvm.* saproc.* jsig.* sawindbg.* jvm_db.* jvm_dtrace.*) \ +HOTSPOT_IMPORT_FILES := $(addprefix $(LIBRARY_PREFIX), jvm.* saproc.* jsig.* sawindbg.* jvm_db.* jvm_dtrace.* ffi.*) \ Xusage.txt sa-jdi.jar ifeq ($(OPENJDK_TARGET_OS), macosx) diff --git a/make/devkit/Tools.gmk b/make/devkit/Tools.gmk index c2460105b7..cf2ef251ac 100644 --- a/make/devkit/Tools.gmk +++ b/make/devkit/Tools.gmk @@ -82,8 +82,8 @@ RPM_LIST := \ libXi libXi-devel \ libXdmcp libXdmcp-devel \ libXau libXau-devel \ - libgcc - + libgcc \ + libffi libffi-devel ifeq ($(ARCH),x86_64) RPM_DIR ?= $(RPM_DIR_x86_64) @@ -203,6 +203,18 @@ $(libs) : $(rpms) @mkdir -p $(SYSROOT)/usr/lib @touch $@ +########################################################################################## +# Create links for ffi header files so that they become visible by default when using the +# devkit. + +$(SYSROOT)/usr/include/ffi.h: $(rpms) + cd $(@D) && rm $(@F) && ln -s ../lib/libffi-*/include/$(@F) . + +$(SYSROOT)/usr/include/ffitarget.h: $(rpms) + cd $(@D) && rm $(@F) && ln -s ../lib/libffi-*/include/$(@F) . + +SYSROOT_LINKS += $(SYSROOT)/usr/include/ffi.h $(SYSROOT)/usr/include/ffitarget.h + ########################################################################################## # Define marker files for each source package to be compiled @@ -479,7 +491,7 @@ rpms : $(rpms) libs : $(libs) sysroot : rpms libs gcc : sysroot $(gcc) $(gccpatch) -all : binutils gcc bfdlib $(PREFIX)/devkit.info +all : binutils gcc bfdlib $(PREFIX)/devkit.info $(SYSROOT_LINKS) # this is only built for host. so separate. ccache : $(ccache)