--- old/common/autoconf/configure.ac 2015-10-15 12:34:41.888995037 -0400 +++ new/common/autoconf/configure.ac 2015-10-15 12:34:40.604922823 -0400 @@ -155,6 +155,9 @@ # ############################################################################### +# See if we are doing a complete static build or not +JDKOPT_SETUP_STATIC_BUILD + # First determine the toolchain type (compiler family) TOOLCHAIN_DETERMINE_TOOLCHAIN_TYPE --- old/common/autoconf/flags.m4 2015-10-15 12:34:45.865218651 -0400 +++ new/common/autoconf/flags.m4 2015-10-15 12:34:44.569145762 -0400 @@ -220,7 +220,11 @@ if test "x$OPENJDK_TARGET_OS" = xmacosx; then # Linking is different on MacOSX - SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG" + if test "x$BUILD_STATIC" = xtrue; then + SHARED_LIBRARY_FLAGS ='-undefined dynamic_lookup' + else + SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG" + fi SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker @loader_path/.' SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN" SET_SHARED_LIBRARY_NAME='-Xlinker -install_name -Xlinker @rpath/[$]1' @@ -695,7 +699,9 @@ COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK \ -I${JDK_TOPDIR}/src/java.base/share/native/include \ -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS/native/include \ - -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/include" + -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/include \ + -I${JDK_TOPDIR}/src/java.base/share/native/libjava \ + -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/libjava" # The shared libraries are compiled using the picflag. CFLAGS_JDKLIB="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA" --- old/common/autoconf/generated-configure.sh 2015-10-15 12:34:49.909446089 -0400 +++ new/common/autoconf/generated-configure.sh 2015-10-15 12:34:48.581371401 -0400 @@ -803,6 +803,7 @@ SHARED_LIBRARY_SUFFIX LIBRARY_PREFIX TOOLCHAIN_TYPE +BUILD_STATIC BUILD_HOTSPOT HOTSPOT_DIST BUILD_OUTPUT @@ -1074,6 +1075,7 @@ with_override_nashorn with_override_jdk with_import_hotspot +enable_static_build with_toolchain_type with_extra_cflags with_extra_cxxflags @@ -1849,6 +1851,7 @@ run the Queens test after Hotspot build [disabled] --enable-unlimited-crypto Enable unlimited crypto policy [disabled] + --enable-static-build enable static library build [disabled] --disable-warnings-as-errors do not consider native warnings to be an error [enabled] @@ -3977,6 +3980,15 @@ # +################################################################################ +# +# Static build support. When enabled will generate static +# libraries instead of shared libraries for all JDK libs. +# + + + + # # Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -4587,7 +4599,7 @@ #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1444643341 +DATE_WHEN_GENERATED=1444855180 ############################################################################### # @@ -27243,6 +27255,40 @@ # ############################################################################### +# See if we are doing a complete static build or not + + # Check whether --enable-static-build was given. +if test "${enable_static_build+set}" = set; then : + enableval=$enable_static_build; +fi + + BUILD_STATIC=false + if test "x$enable_static_build" = "xyes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if static build is enabled" >&5 +$as_echo_n "checking if static build is enabled... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + if test "x$OPENJDK_TARGET_OS" != "xmacosx"; then + as_fn_error $? "--enable-static-build is only supported for macosx builds" "$LINENO" 5 + fi + BUILD_STATIC_CFLAGS="-DSTATIC_BUILD=1" + LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS $BUILD_STATIC_CFLAGS" + LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS $BUILD_STATIC_CFLAGS" + CFLAGS_JDKLIB_EXTRA="$CFLAGS_JDKLIB_EXTRA $BUILD_STATIC_CFLAGS" + CXXFLAGS_JDKLIB_EXTRA="$CXXFLAGS_JDKLIB_EXTRA $BUILD_STATIC_CFLAGS" + BUILD_STATIC=true + elif test "x$enable_static_build" = "xno"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if static build is enabled" >&5 +$as_echo_n "checking if static build is enabled... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + elif test "x$enable_static_build" != "x"; then + as_fn_error $? "--enable-static-build can only be assigned \"yes\" or \"no\"" "$LINENO" 5 + fi + + + + # First determine the toolchain type (compiler family) @@ -27351,8 +27397,19 @@ OBJ_SUFFIX='.o' EXE_SUFFIX='' if test "x$OPENJDK_TARGET_OS" = xmacosx; then - SHARED_LIBRARY='lib$1.dylib' - SHARED_LIBRARY_SUFFIX='.dylib' + # For full static builds, we're overloading the SHARED_LIBRARY + # variables in order to limit the amount of changes required. + # It would be better to remove SHARED and just use LIBRARY and + # LIBRARY_SUFFIX for libraries that can be built either + # shared or static and use STATIC_* for libraries that are + # always built statically. + if test "x$BUILD_STATIC" = xtrue; then + SHARED_LIBRARY='lib$1.a' + SHARED_LIBRARY_SUFFIX='.a' + else + SHARED_LIBRARY='lib$1.dylib' + SHARED_LIBRARY_SUFFIX='.dylib' + fi fi fi @@ -42751,7 +42808,11 @@ if test "x$OPENJDK_TARGET_OS" = xmacosx; then # Linking is different on MacOSX - SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG" + if test "x$BUILD_STATIC" = xtrue; then + SHARED_LIBRARY_FLAGS ='-undefined dynamic_lookup' + else + SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG" + fi SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker @loader_path/.' SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN" SET_SHARED_LIBRARY_NAME='-Xlinker -install_name -Xlinker @rpath/$1' @@ -43255,7 +43316,9 @@ COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK \ -I${JDK_TOPDIR}/src/java.base/share/native/include \ -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS/native/include \ - -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/include" + -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/include \ + -I${JDK_TOPDIR}/src/java.base/share/native/libjava \ + -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/libjava" # The shared libraries are compiled using the picflag. CFLAGS_JDKLIB="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA" --- old/common/autoconf/jdk-options.m4 2015-10-15 12:34:54.665713573 -0400 +++ new/common/autoconf/jdk-options.m4 2015-10-15 12:34:53.369640683 -0400 @@ -665,3 +665,37 @@ AC_SUBST(GCOV_ENABLED) ]) + +################################################################################ +# +# Static build support. When enabled will generate static +# libraries instead of shared libraries for all JDK libs. +# +AC_DEFUN_ONCE([JDKOPT_SETUP_STATIC_BUILD], +[ + AC_ARG_ENABLE([static-build], [AS_HELP_STRING([--enable-static-build], + [enable static library build @<:@disabled@:>@])]) + BUILD_STATIC=false + if test "x$enable_static_build" = "xyes"; then + AC_MSG_CHECKING([if static build is enabled]) + AC_MSG_RESULT([yes]) + if test "x$OPENJDK_TARGET_OS" != "xmacosx"; then + AC_MSG_ERROR([--enable-static-build is only supported for macosx builds]) + fi + BUILD_STATIC_CFLAGS="-DSTATIC_BUILD=1" + LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS $BUILD_STATIC_CFLAGS" + LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS $BUILD_STATIC_CFLAGS" + CFLAGS_JDKLIB_EXTRA="$CFLAGS_JDKLIB_EXTRA $BUILD_STATIC_CFLAGS" + CXXFLAGS_JDKLIB_EXTRA="$CXXFLAGS_JDKLIB_EXTRA $BUILD_STATIC_CFLAGS" + BUILD_STATIC=true + elif test "x$enable_static_build" = "xno"; then + AC_MSG_CHECKING([if static build is enabled]) + AC_MSG_RESULT([no]) + elif test "x$enable_static_build" != "x"; then + AC_MSG_ERROR([--enable-static-build can only be assigned "yes" or "no"]) + fi + + AC_SUBST(BUILD_STATIC) +]) + + --- old/common/autoconf/spec.gmk.in 2015-10-15 12:34:58.641937186 -0400 +++ new/common/autoconf/spec.gmk.in 2015-10-15 12:34:57.353864748 -0400 @@ -422,6 +422,7 @@ STATIC_LIBRARY_SUFFIX:=@STATIC_LIBRARY_SUFFIX@ EXE_SUFFIX:=@EXE_SUFFIX@ OBJ_SUFFIX:=@OBJ_SUFFIX@ +BUILD_STATIC:=@BUILD_STATIC@ STRIPFLAGS:=@STRIPFLAGS@ --- old/common/autoconf/toolchain.m4 2015-10-15 12:35:02.662163276 -0400 +++ new/common/autoconf/toolchain.m4 2015-10-15 12:35:01.350089487 -0400 @@ -72,8 +72,19 @@ OBJ_SUFFIX='.o' EXE_SUFFIX='' if test "x$OPENJDK_TARGET_OS" = xmacosx; then - SHARED_LIBRARY='lib[$]1.dylib' - SHARED_LIBRARY_SUFFIX='.dylib' + # For full static builds, we're overloading the SHARED_LIBRARY + # variables in order to limit the amount of changes required. + # It would be better to remove SHARED and just use LIBRARY and + # LIBRARY_SUFFIX for libraries that can be built either + # shared or static and use STATIC_* for libraries that are + # always built statically. + if test "x$BUILD_STATIC" = xtrue; then + SHARED_LIBRARY='lib[$]1.a' + SHARED_LIBRARY_SUFFIX='.a' + else + SHARED_LIBRARY='lib[$]1.dylib' + SHARED_LIBRARY_SUFFIX='.dylib' + fi fi fi --- old/make/Main.gmk 2015-10-15 12:35:07.154415911 -0400 +++ new/make/Main.gmk 2015-10-15 12:35:05.614329299 -0400 @@ -93,7 +93,10 @@ unpack-sec: +($(CD) $(JDK_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f UnpackSecurity.gmk) -ALL_TARGETS += import-hotspot unpack-sec +generate-exported-symbols: + +($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f BuildStatic.gmk) + +ALL_TARGETS += import-hotspot unpack-sec generate-exported-symbols ################################################################################ # Gensrc targets, generating source before java compilation can be done @@ -364,10 +367,16 @@ import-hotspot: hotspot + generate-exported-symbols: java.base-libs jdk.jdwp.agent-libs + $(LIBS_TARGETS): import-hotspot $(LAUNCHER_TARGETS): java.base-libs + ifeq ($(BUILD_STATIC), true) + $(LAUNCHER_TARGETS): generate-exported-symbols + endif + # The demos are currently linking to libjvm and libjava, just like all other # jdk libs, even though they don't need to. To avoid warnings, make sure they # aren't built until after libjava and libjvm are available to link to. --- old/make/common/NativeCompilation.gmk 2015-10-15 12:35:11.150640650 -0400 +++ new/make/common/NativeCompilation.gmk 2015-10-15 12:35:09.842567087 -0400 @@ -35,6 +35,31 @@ endif ################################################################################ +# Create exported symbols file for static libraries +################################################################################ + +# get the exported symbols from mapfiles and if there +# is no mapfile, get them from the archive +define GetSymbols + $(RM) $$(@D)/$$(basename $$(@F)).symbols; \ + if [ ! -z $$($1_MAPFILE) -a -e $$($1_MAPFILE) ]; then \ + $(ECHO) "Getting symbols from mapfile $$($1_MAPFILE)"; \ + $(AWK) '/global:/','/local:/' $$($1_MAPFILE) | \ + $(SED) -e 's/#.*//;s/global://;s/local://;s/\;//;s/^[ ]*/_/;/^_$$$$/d' | \ + $(EGREP) -v "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" > \ + $$(@D)/$$(basename $$(@F)).symbols || true; \ + $(NM) $$($1_TARGET) | $(GREP) " T " | \ + $(EGREP) "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" | \ + $(CUT) -d ' ' -f 3 >> $$(@D)/$$(basename $$(@F)).symbols || true;\ + else \ + $(ECHO) "Getting symbols from nm"; \ + $(NM) -m $$($1_TARGET) | $(GREP) "__TEXT" | \ + $(EGREP) -v "non-external|private extern|__TEXT,__eh_frame" | \ + $(SED) -e 's/.* //' > $$(@D)/$$(basename $$(@F)).symbols; \ + fi +endef + +################################################################################ # Define a native toolchain configuration that can be used by # SetupNativeCompilation calls # @@ -275,6 +300,15 @@ SetupNativeCompilation = $(NamedParamsMacroTemplate) define SetupNativeCompilationBody + # If we're doing a static build and producing a library + # force it to be a static library and remove the -l libraries + ifeq ($(BUILD_STATIC), true) + ifneq ($$($1_LIBRARY),) + $1_STATIC_LIBRARY := $$($1_LIBRARY) + $1_LIBRARY := + endif + endif + ifneq (,$$($1_BIN)) $$(error BIN has been replaced with OBJECT_DIR) endif @@ -496,6 +530,12 @@ $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER) endif + # Pass the library name for static JNI library naming + ifneq ($$($1_STATIC_LIBRARY),) + $1_EXTRA_CFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY) + $1_EXTRA_CXXFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY) + endif + # Pick up disabled warnings, if possible on this platform. ifneq ($(DISABLE_WARNING_PREFIX),) $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE))) @@ -726,7 +766,10 @@ $(ECHO) $(LOG_INFO) "Archiving $$($1_STATIC_LIBRARY)" $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \ $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \ - $$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)) + $$($1_RES)) + ifeq ($(BUILD_STATIC), true) + $(GetSymbols) + endif endif ifneq (,$$($1_PROGRAM)) --- /dev/null 2015-09-28 11:47:54.419050997 -0400 +++ new/make/BuildStatic.gmk 2015-10-15 12:35:13.850792502 -0400 @@ -0,0 +1,54 @@ +# +# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +default: all + +include $(SPEC) +include MakeBase.gmk + +################################################################################ +# +# Concatenate exported.symbols files for modules into a single global file. +# + +GLOBAL_SYMBOLS_FILE := $(SUPPORT_OUTPUTDIR)/build-static/exported.symbols + +EXPORTED_SYMBOLS_MODULES := java.base jdk.jdwp.agent + +MODULES_SYMBOLS_FILES := $(foreach module, $(EXPORTED_SYMBOLS_MODULES), \ + $(SUPPORT_OUTPUTDIR)/modules_libs/$(module)/$(module).symbols) + +$(GLOBAL_SYMBOLS_FILE): $(MODULES_SYMBOLS_FILES) + $(ECHO) $(LOG_INFO) "Generating global exported.symbols file" + $(MKDIR) -p $(@D) + $(CAT) $^ > $@ + +TARGETS += $(GLOBAL_SYMBOLS_FILE) + +################################################################################ + +all: $(TARGETS) + +.PHONY: default all