8232748: Build static versions of certain JDK libraries

Reviewed-by: ihse, bobv
This commit is contained in:
Erik Joelsson 2019-10-29 12:01:14 -07:00
parent 4095f60323
commit 0b33bc1617
12 changed files with 225 additions and 27 deletions

View File

@ -314,6 +314,27 @@ endif
################################################################################
ifneq ($(filter static-libs-bundles, $(MAKECMDGOALS)), )
STATIC_LIBS_BUNDLE_FILES := $(call FindFiles, $(STATIC_LIBS_IMAGE_DIR))
ifeq ($(OPENJDK_TARGET_OS)-$(DEBUG_LEVEL), macosx-release)
STATIC_LIBS_BUNDLE_SUBDIR := $(JDK_MACOSX_CONTENTS_SUBDIR)/Home
else
STATIC_LIBS_BUNDLE_SUBDIR := $(JDK_BUNDLE_SUBDIR)
endif
$(eval $(call SetupBundleFile, BUILD_STATIC_LIBS_BUNDLE, \
BUNDLE_NAME := $(STATIC_LIBS_BUNDLE_NAME), \
FILES := $(STATIC_LIBS_BUNDLE_FILES), \
BASE_DIRS := $(STATIC_LIBS_IMAGE_DIR), \
SUBDIR := $(STATIC_LIBS_BUNDLE_SUBDIR), \
))
STATIC_LIBS_TARGETS += $(BUILD_STATIC_LIBS_BUNDLE)
endif
################################################################################
# Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, Bundles.gmk))
@ -323,6 +344,8 @@ product-bundles: $(PRODUCT_TARGETS)
legacy-bundles: $(LEGACY_TARGETS)
test-bundles: $(TEST_TARGETS)
docs-bundles: $(DOCS_TARGETS)
static-libs-bundles: $(STATIC_LIBS_TARGETS)
jcov-bundles: $(JCOV_TARGETS)
.PHONY: all default product-bundles test-bundles docs-bundles jcov-bundles
.PHONY: all default product-bundles test-bundles docs-bundles \
static-libs-bundles jcov-bundles

View File

@ -43,7 +43,7 @@ help:
$(info $(_) make images # Create a complete jdk image)
$(info $(_) # (alias for product-images))
$(info $(_) make <name>-image # Build just the image for any of: )
$(info $(_) # jdk, test, docs, symbols, legacy-jre)
$(info $(_) # jdk, test, docs, symbols, legacy-jre, static-libs)
$(info $(_) make <phase> # Build the specified phase and everything it depends on)
$(info $(_) # (gensrc, java, copy, libs, launchers, gendata, rmic))
$(info $(_) make *-only # Applies to most targets and disables building the)

View File

@ -217,6 +217,21 @@ $(eval $(call DeclareRecipesForPhase, LIBS, \
ALL_TARGETS += $(LIBS_TARGETS)
################################################################################
# Targets for compiling static versions of certain native libraries. These do
# not end up in the jmods or the normal JDK image, but are instead bundled into
# a special deliverable.
$(eval $(call DeclareRecipesForPhase, STATIC_LIBS, \
TARGET_SUFFIX := static-libs, \
FILE_PREFIX := Lib, \
MAKE_SUBDIR := lib, \
CHECK_MODULES := $(STATIC_LIBS_MODULES), \
USE_WRAPPER := true, \
EXTRA_ARGS := STATIC_LIBS=true, \
))
ALL_TARGETS += $(STATIC_LIBS_TARGETS)
################################################################################
# Targets for compiling native executables
$(eval $(call DeclareRecipesForPhase, LAUNCHER, \
@ -377,6 +392,9 @@ legacy-jre-image:
symbols-image:
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Images.gmk symbols)
static-libs-image:
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f StaticLibsImage.gmk)
mac-jdk-bundle:
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f MacBundles.gmk jdk-bundle)
@ -396,7 +414,7 @@ endif
ALL_TARGETS += store-source-revision create-source-revision-tracker bootcycle-images zip-security \
zip-source jrtfs-jar jdk-image legacy-jre-image \
symbols-image mac-jdk-bundle mac-legacy-jre-bundle \
symbols-image static-libs-image mac-jdk-bundle mac-legacy-jre-bundle \
release-file exploded-image-optimize jcov-image
################################################################################
@ -614,12 +632,16 @@ test-bundles:
docs-bundles:
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk docs-bundles)
static-libs-bundles:
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk static-libs-bundles)
ifeq ($(JCOV_ENABLED), true)
jcov-bundles:
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk jcov-bundles)
endif
ALL_TARGETS += product-bundles legacy-bundles test-bundles docs-bundles jcov-bundles
ALL_TARGETS += product-bundles legacy-bundles test-bundles docs-bundles \
static-libs-bundles jcov-bundles
################################################################################
# Install targets
@ -796,6 +818,10 @@ else
vscode-project-rtags: compile-commands
vscode-project-ccls: compile-commands
# The -static-libs targets depend on -java as well as java.base-copy.
$(foreach m, $(filter $(JAVA_MODULES), $(STATIC_LIBS_MODULES)), \
$(eval $m-static-libs: $m-java java.base-copy))
# Jmods cannot be created until we have the jmod tool ready to run. During
# a normal build we run it from the exploded image, but when cross compiling
# it's run from the buildjdk, which is either created at build time or user
@ -858,6 +884,8 @@ else
legacy-jre-image: jmods release-file
symbols-image: $(LIBS_TARGETS) $(LAUNCHER_TARGETS)
static-libs-image: $(STATIC_LIBS_TARGETS)
mac-jdk-bundle: jdk-image
mac-legacy-jre-bundle: legacy-jre-image
@ -946,6 +974,8 @@ else
jcov-bundles: jcov-image
static-libs-bundles: static-libs-image
generate-summary: jmods buildtools-modules
update-x11wrappers: java.base-copy buildtools-jdk
@ -984,6 +1014,8 @@ rmic: $(RMIC_TARGETS)
libs: $(LIBS_TARGETS)
static-libs: $(STATIC_LIBS_TARGETS)
launchers: $(LAUNCHER_TARGETS)
jmods: $(JMOD_TARGETS)
@ -1094,10 +1126,10 @@ endif
all-images: product-images test-image docs-image
# all-bundles packages all our deliverables as tar.gz bundles.
all-bundles: product-bundles test-bundles docs-bundles
all-bundles: product-bundles test-bundles docs-bundles static-libs-bundles
ALL_TARGETS += buildtools hotspot hotspot-libs hotspot-gensrc gensrc gendata \
copy java rmic libs launchers jmods \
copy java rmic libs static-libs launchers jmods \
jdk.jdwp.agent-gensrc $(ALL_MODULES) demos \
exploded-image-base exploded-image \
create-buildjdk docs-jdk-api docs-javase-api docs-reference-api docs-jdk \

View File

@ -133,7 +133,7 @@ define DeclareRecipeForModuleMakefile
$$(addprefix -I, $$(PHASE_MAKEDIRS) \
$$(addsuffix /$$($1_MAKE_SUBDIR), $$(PHASE_MAKEDIRS)) \
) \
MODULE=$2 MAKEFILE_PREFIX=$$($1_FILE_PREFIX))
MODULE=$2 MAKEFILE_PREFIX=$$($1_FILE_PREFIX) $$($1_EXTRA_ARGS))
else
+($(CD) $$(dir $$(firstword $$(wildcard $$(addsuffix \
/$$($1_MAKE_SUBDIR)/$$($1_FILE_PREFIX)-$2.gmk, $$(PHASE_MAKEDIRS))))) \
@ -142,7 +142,7 @@ define DeclareRecipeForModuleMakefile
$$(addprefix -I, $$(PHASE_MAKEDIRS) \
$$(addsuffix /$$($1_MAKE_SUBDIR), $$(PHASE_MAKEDIRS)) \
) \
MODULE=$2 \
MODULE=$2 $$($1_EXTRA_ARGS) \
)
endif
@ -182,12 +182,13 @@ endef
# CHECK_MODULES : List of modules to try
# MULTIPLE_MAKEFILES : Set to true to handle makefiles for the same module and
# phase in multiple repos
# EXTRA_ARGS : Add extra make args to each makefile call
# Exported variables:
# $1_MODULES : All modules that had rules generated
# $1_TARGETS : All targets generated
define DeclareRecipesForPhase
$(foreach i,2 3 4 5 6 7, $(if $(strip $($i)),$(strip $1)_$(strip $($i)))$(NEWLINE))
$(if $(8),$(error Internal makefile error: Too many arguments to \
$(foreach i,2 3 4 5 6 7 8, $(if $(strip $($i)),$(strip $1)_$(strip $($i)))$(NEWLINE))
$(if $(9),$(error Internal makefile error: Too many arguments to \
DeclareRecipesForPhase, please update MakeHelper.gmk))
$$(foreach m, $$($(strip $1)_CHECK_MODULES), \

54
make/StaticLibsImage.gmk Normal file
View File

@ -0,0 +1,54 @@
#
# Copyright (c) 2019, 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.
#
# This makefile creates an image of the optional static versions of certain JDK
# libraries.
default: all
include $(SPEC)
include MakeBase.gmk
include Modules.gmk
################################################################################
TARGETS :=
$(foreach m, $(STATIC_LIBS_MODULES), \
$(eval $(call SetupCopyFiles, COPY_STATIC_LIBS_$m, \
FLATTEN := true, \
SRC := $(SUPPORT_OUTPUTDIR)/native/$m, \
DEST := $(STATIC_LIBS_IMAGE_DIR)/lib, \
FILES := $(filter %$(STATIC_LIBRARY_SUFFIX), \
$(call FindFiles, $(SUPPORT_OUTPUTDIR)/native/$m/*/static)), \
)) \
$(eval TARGETS += $$(COPY_STATIC_LIBS_$m)) \
)
################################################################################
all: $(TARGETS)
.PHONY: all

View File

@ -694,6 +694,20 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
OS_CFLAGS_JVM="$OS_CFLAGS_JVM -DNEEDS_LIBRT"
fi
fi
# Extra flags needed when building optional static versions of certain
# JDK libraries.
STATIC_LIBS_CFLAGS="-DSTATIC_BUILD=1"
if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
STATIC_LIBS_CFLAGS="$STATIC_LIBS_CFLAGS -ffunction-sections -fdata-sections"
fi
if test "x$TOOLCHAIN_TYPE" = xgcc; then
# Disable relax-relocation to enable compatibility with older linkers
RELAX_RELOCATIONS_FLAG="-Xassembler -mrelax-relocations=no"
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${RELAX_RELOCATIONS_FLAG}],
IF_TRUE: [STATIC_LIBS_CFLAGS="$STATIC_LIBS_CFLAGS ${RELAX_RELOCATIONS_FLAG}"])
fi
AC_SUBST(STATIC_LIBS_CFLAGS)
])
################################################################################

View File

@ -376,6 +376,8 @@ ENABLE_LIBFFI_BUNDLING:=@ENABLE_LIBFFI_BUNDLING@
LIBFFI_LIB_FILE:=@LIBFFI_LIB_FILE@
GRAALUNIT_LIB := @GRAALUNIT_LIB@
STATIC_LIBS_CFLAGS := @STATIC_LIBS_CFLAGS@
JMH_CORE_JAR := @JMH_CORE_JAR@
JMH_GENERATOR_JAR := @JMH_GENERATOR_JAR@
JMH_JOPT_SIMPLE_JAR := @JMH_JOPT_SIMPLE_JAR@
@ -892,6 +894,10 @@ DOCS_IMAGE_DIR = $(IMAGES_OUTPUTDIR)/$(DOCS_IMAGE_SUBDIR)
# Output docs directly into image
DOCS_OUTPUTDIR := $(DOCS_IMAGE_DIR)
# Static libs image
STATIC_LIBS_IMAGE_SUBDIR := static-libs
STATIC_LIBS_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/$(STATIC_LIBS_IMAGE_SUBDIR)
# Macosx bundles directory definitions
JDK_MACOSX_BUNDLE_SUBDIR=jdk-bundle
JRE_MACOSX_BUNDLE_SUBDIR=jre-bundle
@ -920,6 +926,7 @@ JDK_SYMBOLS_BUNDLE_NAME := jdk-$(BASE_NAME)_bin$(DEBUG_PART)-symbols.tar.gz
TEST_DEMOS_BUNDLE_NAME := jdk-$(BASE_NAME)_bin-tests-demos$(DEBUG_PART).tar.gz
TEST_BUNDLE_NAME := jdk-$(BASE_NAME)_bin-tests$(DEBUG_PART).tar.gz
DOCS_BUNDLE_NAME := jdk-$(BASE_NAME)_doc-api-spec$(DEBUG_PART).tar.gz
STATIC_LIBS_BUNDLE_NAME := jdk-$(BASE_NAME)_bin-static-libs$(DEBUG_PART).tar.gz
JCOV_BUNDLE_NAME := jdk-jcov-$(BASE_NAME)_bin$(DEBUG_PART).$(JDK_BUNDLE_EXTENSION)
JDK_BUNDLE := $(BUNDLES_OUTPUTDIR)/$(JDK_BUNDLE_NAME)

View File

@ -47,7 +47,8 @@ FindSrcDirsForComponent += \
$(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS_TYPE)/native/$(strip $2) \
$(TOPDIR)/src/$(strip $1)/share/native/$(strip $2)))
# Find a library
# Find a library. Used for declaring dependencies on libraries in different
# modules.
# Param 1 - module name
# Param 2 - library name
# Param 3 - optional subdir for library
@ -69,6 +70,12 @@ ifeq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
FindLib =
FindStaticLib =
endif
# If building static versions of libraries, make these return empty to avoid
# declaring dependencies.
ifeq ($(STATIC_LIBS), true)
FindLib =
FindStaticLib =
endif
GetJavaHeaderDir = \
$(wildcard $(SUPPORT_OUTPUTDIR)/headers/$(strip $1))

View File

@ -198,6 +198,21 @@ HOTSPOT_MODULES := \
jdk.internal.vm.compiler.management \
#
# The native dynamic libraries in these modules will also get built into static
# libraries for consumption by downstream projects that need to statically link
# the JDK libraries. Those static libraries are not part of the main JDK
# distribution.
STATIC_LIBS_MODULES := \
java.base \
jdk.crypto.ec \
jdk.security.auth \
java.prefs \
java.security.jgss \
java.smartcardio \
jdk.crypto.cryptoki \
jdk.net \
#
################################################################################
# Some platforms don't have the serviceability agent

View File

@ -453,6 +453,28 @@ define SetupNativeCompilationBody
endif
endif
$$(call SetIfEmpty, $1_COMPILE_WITH_DEBUG_SYMBOLS, $$(COMPILE_WITH_DEBUG_SYMBOLS))
# STATIC_LIBS is set from Main.gmk when building static versions of certain
# native libraries.
ifeq ($(STATIC_LIBS), true)
$1_TYPE := STATIC_LIBRARY
# The static versions need to be redirected to different output dirs, both
# to not interfere with the main build as well as to not end up inside the
# jmods.
$1_OBJECT_DIR := $$($1_OBJECT_DIR)/static
$1_OUTPUT_DIR := $$($1_OBJECT_DIR)
# For release builds where debug symbols are configured to be moved to
# separate debuginfo files, disable debug symbols for static libs instead.
# We don't currently support this configuration and we don't want symbol
# information in release builds unless explicitly asked to provide it.
ifeq ($(DEBUG_LEVEL), release)
ifeq ($(COPY_DEBUG_SYMBOLS), true)
$1_COMPILE_WITH_DEBUG_SYMBOLS := false
endif
endif
endif
ifeq ($$($1_TYPE), EXECUTABLE)
$1_PREFIX :=
ifeq ($$($1_SUFFIX), )
@ -592,6 +614,9 @@ define SetupNativeCompilationBody
$1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release)
$1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU)_release)
endif
ifeq ($(STATIC_LIBS), true)
$1_EXTRA_CFLAGS += $$(STATIC_LIBS_CFLAGS)
endif
# Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS.
$1_EXTRA_CXXFLAGS := $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS))
@ -605,6 +630,9 @@ define SetupNativeCompilationBody
$1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release)
$1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release)
endif
ifeq ($(STATIC_LIBS), true)
$1_EXTRA_CXXFLAGS += $$(STATIC_LIB_CFLAGS)
endif
# If no C++ flags are explicitly set, default to using the C flags.
# After that, we can set additional C++ flags that should not interfere
@ -616,7 +644,7 @@ define SetupNativeCompilationBody
$1_EXTRA_CXXFLAGS := $$($1_EXTRA_CFLAGS)
endif
ifeq ($(COMPILE_WITH_DEBUG_SYMBOLS), true)
ifeq ($$($1_COMPILE_WITH_DEBUG_SYMBOLS), true)
$1_EXTRA_CFLAGS += $$(CFLAGS_DEBUG_SYMBOLS)
$1_EXTRA_CXXFLAGS += $$(CFLAGS_DEBUG_SYMBOLS)
$1_EXTRA_ASFLAGS += $$(ASFLAGS_DEBUG_SYMBOLS)

View File

@ -247,7 +247,7 @@ var getJibProfilesCommon = function (input, data) {
// These are the base setttings for all the main build profiles.
common.main_profile_base = {
dependencies: ["boot_jdk", "gnumake", "jtreg", "jib", "autoconf", "jmh", "jcov"],
default_make_targets: ["product-bundles", "test-bundles"],
default_make_targets: ["product-bundles", "test-bundles", "static-libs-bundles"],
configure_args: concat(["--enable-jtreg-failure-handler"],
"--with-exclude-translations=de,es,fr,it,ko,pt_BR,sv,ca,tr,cs,sk,ja_JP_A,ja_JP_HA,ja_JP_HI,ja_JP_I,zh_TW,zh_HK",
"--disable-manpages",
@ -320,6 +320,14 @@ var getJibProfilesCommon = function (input, data) {
subdir: jdk_subdir,
exploded: "images/jdk"
},
static_libs: {
local: "bundles/\\(jdk.*bin-static-libs.tar.gz\\)",
remote: [
"bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-static-libs.tar.gz",
"bundles/" + pf + "/\\1"
],
subdir: jdk_subdir,
},
}
};
};
@ -361,6 +369,14 @@ var getJibProfilesCommon = function (input, data) {
subdir: jdk_subdir,
exploded: "images/jdk"
},
static_libs: {
local: "bundles/\\(jdk.*bin-static-libs-debug.tar.gz\\)",
remote: [
"bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-static-libs-debug.tar.gz",
"bundles/" + pf + "/\\1"
],
subdir: jdk_subdir,
},
}
};
};

View File

@ -148,26 +148,27 @@ ifeq ($(call isTargetOsType, unix), true)
############################################################################
# Create symlinks to libjsig in each JVM variant sub dir
LIB_OUTPUTDIR := $(call FindLibDirForModule, java.base)
ifneq ($(STATIC_LIBS), true)
LIB_OUTPUTDIR := $(call FindLibDirForModule, java.base)
# $1 variant subdir
define CreateSymlinks
# Always symlink from libdir/variant/libjsig.so -> ../libjsig.so.
$(LIB_OUTPUTDIR)/$1/$(call SHARED_LIBRARY,jsig): \
$(LIB_OUTPUTDIR)/$(call SHARED_LIBRARY,jsig)
# $1 variant subdir
define CreateSymlinks
# Always symlink from libdir/variant/libjsig.so -> ../libjsig.so.
$(LIB_OUTPUTDIR)/$1/$(call SHARED_LIBRARY,jsig): \
$(LIB_OUTPUTDIR)/$(call SHARED_LIBRARY,jsig)
$$(call MakeDir, $$(@D))
$(RM) $$@
$(LN) -s ../$$(@F) $$@
TARGETS += $(LIB_OUTPUTDIR)/$1/$(call SHARED_LIBRARY,jsig)
endef
# The subdir is the same as the variant for client and minimal, for all
# others it's server.
VARIANT_SUBDIRS := $(filter client minimal, $(JVM_VARIANTS)) \
$(if $(filter-out client minimal, $(JVM_VARIANTS)), server)
$(foreach v, $(VARIANT_SUBDIRS), $(eval $(call CreateSymlinks,$v)))
TARGETS += $(LIB_OUTPUTDIR)/$1/$(call SHARED_LIBRARY,jsig)
endef
# The subdir is the same as the variant for client and minimal, for all
# others it's server.
VARIANT_SUBDIRS := $(filter client minimal, $(JVM_VARIANTS)) \
$(if $(filter-out client minimal, $(JVM_VARIANTS)), server)
$(foreach v, $(VARIANT_SUBDIRS), $(eval $(call CreateSymlinks,$v)))
endif
############################################################################
endif