8307194: Add make target for optionally building a complete set of all JDK and hotspot libjvm static libraries

Reviewed-by: erikj, sgehwolf
This commit is contained in:
Jiangli Zhou 2023-05-10 17:26:02 +00:00
parent 9af1787ebe
commit 1964954da9
8 changed files with 144 additions and 51 deletions

View File

@ -43,10 +43,10 @@ $(eval $(call SetupCopyFiles, COPY_JDK_IMG, \
TARGETS += $(COPY_JDK_IMG)
$(eval $(call SetupCopyFiles, COPY_STATIC_LIBS, \
SRC := $(STATIC_LIBS_IMAGE_DIR)/lib, \
SRC := $(STATIC_LIBS_GRAAL_IMAGE_DIR)/lib, \
DEST := $(GRAAL_BUILDER_IMAGE_DIR)/lib, \
FILES := $(filter %$(STATIC_LIBRARY_SUFFIX), \
$(call FindFiles, $(STATIC_LIBS_IMAGE_DIR)/lib)), \
$(call FindFiles, $(STATIC_LIBS_GRAAL_IMAGE_DIR)/lib)), \
))
TARGETS += $(COPY_STATIC_LIBS)

View File

@ -233,6 +233,7 @@ ALL_TARGETS += $(LAUNCHER_TARGETS)
HOTSPOT_VARIANT_TARGETS := $(addprefix hotspot-, $(JVM_VARIANTS))
HOTSPOT_VARIANT_GENSRC_TARGETS := $(addsuffix -gensrc, $(HOTSPOT_VARIANT_TARGETS))
HOTSPOT_VARIANT_LIBS_TARGETS := $(addsuffix -libs, $(HOTSPOT_VARIANT_TARGETS))
HOTSPOT_VARIANT_STATIC_LIBS_TARGETS := $(addsuffix -static-libs, $(HOTSPOT_VARIANT_TARGETS))
define DeclareHotspotGensrcRecipe
hotspot-$1-gensrc:
@ -251,6 +252,14 @@ endef
$(foreach v, $(JVM_VARIANTS), $(eval $(call DeclareHotspotLibsRecipe,$v)))
define DeclareHotspotStaticLibsRecipe
hotspot-$1-static-libs:
+($(CD) $(TOPDIR)/make/hotspot && $(MAKE) $(MAKE_ARGS) -f lib/CompileLibraries.gmk \
JVM_VARIANT=$1 STATIC_LIBS=true)
endef
$(foreach v, $(JVM_VARIANTS), $(eval $(call DeclareHotspotStaticLibsRecipe,$v)))
$(eval $(call SetupTarget, hotspot-ide-project, \
MAKEFILE := ide/visualstudio/hotspot/CreateVSProject, \
DEPS := hotspot exploded-image, \
@ -298,7 +307,7 @@ $(eval $(call SetupTarget, eclipse-shared-mixed-env, \
))
ALL_TARGETS += $(HOTSPOT_VARIANT_TARGETS) $(HOTSPOT_VARIANT_GENSRC_TARGETS) \
$(HOTSPOT_VARIANT_LIBS_TARGETS)
$(HOTSPOT_VARIANT_LIBS_TARGETS) $(HOTSPOT_VARIANT_STATIC_LIBS_TARGETS)
################################################################################
# Help and user support
@ -462,6 +471,12 @@ $(eval $(call SetupTarget, symbols-image, \
$(eval $(call SetupTarget, static-libs-image, \
MAKEFILE := StaticLibsImage, \
TARGET := static-libs-image, \
))
$(eval $(call SetupTarget, static-libs-graal-image, \
MAKEFILE := StaticLibsImage, \
TARGET := static-libs-graal-image, \
))
$(eval $(call SetupTarget, mac-jdk-bundle, \
@ -489,7 +504,7 @@ $(eval $(call SetupTarget, exploded-image-optimize, \
$(eval $(call SetupTarget, graal-builder-image, \
MAKEFILE := GraalBuilderImage, \
DEPS := jdk-image static-libs-image, \
DEPS := jdk-image static-libs-graal-image, \
))
ifeq ($(JCOV_ENABLED), true)
@ -889,6 +904,7 @@ else
$(foreach v, $(JVM_VARIANTS), \
$(eval hotspot-$v-gensrc: java.base-copy buildtools-hotspot) \
$(eval hotspot-$v-libs: hotspot-$v-gensrc java.base-copy) \
$(eval hotspot-$v-static-libs: hotspot-$v-gensrc java.base-copy) \
)
# If not already set, set the JVM variant target so that the JVM will be built.
@ -1047,7 +1063,9 @@ else
symbols-image: $(LIBS_TARGETS) $(LAUNCHER_TARGETS)
static-libs-image: $(STATIC_LIBS_TARGETS)
static-libs-image: hotspot-static-libs $(STATIC_LIBS_TARGETS)
static-libs-graal-image: $(STATIC_LIBS_TARGETS)
bootcycle-images: jdk-image
@ -1097,6 +1115,7 @@ hotspot: $(HOTSPOT_VARIANT_TARGETS)
$(foreach v, $(JVM_VARIANTS), \
$(eval hotspot-libs: hotspot-$v-libs) \
$(eval hotspot-gensrc: hotspot-$v-gensrc) \
$(eval hotspot-static-libs: hotspot-$v-static-libs) \
)
gensrc: $(GENSRC_TARGETS)
@ -1259,7 +1278,8 @@ all-images: product-images test-image all-docs-images
# all-bundles packages all our deliverables as tar.gz bundles.
all-bundles: product-bundles test-bundles docs-bundles static-libs-bundles
ALL_TARGETS += buildtools hotspot hotspot-libs hotspot-gensrc gensrc gendata \
ALL_TARGETS += buildtools hotspot hotspot-libs hotspot-static-libs \
hotspot-gensrc gensrc gendata \
copy java libs static-libs launchers jmods \
jdk.jdwp.agent-gensrc $(ALL_MODULES) demos \
exploded-image-base exploded-image runnable-buildjdk \

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2019, 2023, 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
@ -38,19 +38,43 @@ ALL_MODULES = $(call FindAllModules)
TARGETS :=
ifneq ($(filter static-libs-image, $(MAKECMDGOALS)), )
IMAGE_DEST_DIR=$(STATIC_LIBS_IMAGE_DIR)/lib
else ifneq ($(filter static-libs-graal-image, $(MAKECMDGOALS)), )
IMAGE_DEST_DIR=$(STATIC_LIBS_GRAAL_IMAGE_DIR)/lib
endif
# Copy JDK static libs to the image.
$(foreach m, $(ALL_MODULES), \
$(eval $(call SetupCopyFiles, COPY_STATIC_LIBS_$m, \
FLATTEN := true, \
SRC := $(SUPPORT_OUTPUTDIR)/native/$m, \
DEST := $(STATIC_LIBS_IMAGE_DIR)/lib, \
DEST := $(IMAGE_DEST_DIR), \
FILES := $(filter %$(STATIC_LIBRARY_SUFFIX), \
$(call FindFiles, $(SUPPORT_OUTPUTDIR)/native/$m/*/static)), \
)) \
$(eval TARGETS += $$(COPY_STATIC_LIBS_$m)) \
$(eval STATIC_LIBS_TARGETS += $$(COPY_STATIC_LIBS_$m)) \
)
ifneq ($(filter static-libs-image, $(MAKECMDGOALS)), )
# Copy libjvm static library to the image.
$(foreach v, $(JVM_VARIANTS), \
$(eval $(call SetupCopyFiles, COPY_STATIC_LIBS_$v, \
SRC := $(HOTSPOT_OUTPUTDIR)/variant-$v/libjvm/objs/static, \
DEST := $(IMAGE_DEST_DIR)/$v, \
FILES := $(wildcard $(HOTSPOT_OUTPUTDIR)/variant-$v/libjvm/objs/static/*$(STATIC_LIBRARY_SUFFIX)), \
)) \
$(eval TARGETS += $$(COPY_STATIC_LIBS_$v)) \
$(eval HOTSPOT_VARIANT_STATIC_LIBS_TARGETS += $$(COPY_STATIC_LIBS_$v)) \
)
endif
################################################################################
static-libs-image: $(HOTSPOT_VARIANT_STATIC_LIBS_TARGETS) $(STATIC_LIBS_TARGETS)
static-libs-graal-image: $(STATIC_LIBS_TARGETS)
all: $(TARGETS)
.PHONY: all

View File

@ -928,6 +928,10 @@ DOCS_OUTPUTDIR := $(DOCS_JDK_IMAGE_DIR)
STATIC_LIBS_IMAGE_SUBDIR := static-libs
STATIC_LIBS_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/$(STATIC_LIBS_IMAGE_SUBDIR)
# Graal static libs image
STATIC_LIBS_GRAAL_IMAGE_SUBDIR := static-libs-graal
STATIC_LIBS_GRAAL_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/$(STATIC_LIBS_GRAAL_IMAGE_SUBDIR)
# Graal builder image
GRAAL_BUILDER_IMAGE_SUBDIR := graal-builder-jdk
GRAAL_BUILDER_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/$(GRAAL_BUILDER_IMAGE_SUBDIR)

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2023, 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
@ -548,6 +548,7 @@ endef
# PRECOMPILED_HEADER Header file to use as precompiled header
# PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
# BUILD_INFO_LOG_MACRO Overrides log level of the build info log message, default LogWarn
# STATIC_LIB_EXCLUDE_OBJS exclude objects that matches from static library
#
# After being called, some variables are exported from this macro, all prefixed
# with parameter 1 followed by a '_':
@ -726,6 +727,12 @@ define SetupNativeCompilationBody
endif
# Sort to remove duplicates and provide a reproducible order on the input files to the linker.
$1_ALL_OBJS := $$(sort $$($1_EXPECTED_OBJS) $$($1_EXTRA_OBJECT_FILES))
ifeq ($(STATIC_LIBS), true)
# Exclude the object files that match with $1_STATIC_LIB_EXCLUDE_OBJS.
ifneq ($$($1_STATIC_LIB_EXCLUDE_OBJS), )
$1_ALL_OBJS := $$(call not-containing, $$($1_STATIC_LIB_EXCLUDE_OBJS), $$($1_ALL_OBJS))
endif
endif
# Pickup extra OPENJDK_TARGET_OS_TYPE, OPENJDK_TARGET_OS, TOOLCHAIN_TYPE and
# OPENJDK_TARGET_OS plus OPENJDK_TARGET_CPU pair dependent variables for CFLAGS.
@ -1130,6 +1137,40 @@ define SetupNativeCompilationBody
endif
endif
$1_LD_OBJ_ARG := $$($1_ALL_OBJS)
# If there are many object files, use an @-file...
ifneq ($$(word 17, $$($1_ALL_OBJS)), )
$1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt
ifneq ($(COMPILER_COMMAND_FILE_FLAG), )
$1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST)
else
# ...except for toolchains which don't support them.
$1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
endif
endif
# Unfortunately the @-file trick does not work reliably when using clang.
# Clang does not propagate the @-file parameter to the ld sub process, but
# instead puts the full content on the command line. At least the llvm ld
# does not even support an @-file.
#
# When linking a large amount of object files, we risk hitting the limit
# of the command line length even on posix systems if the path length of
# the output dir is very long due to our use of absolute paths. To
# mitigate this, use paths relative to the output dir when linking over
# 500 files with clang and the output dir path is deep.
ifneq ($$(word 500, $$($1_ALL_OBJS)), )
ifeq ($$(TOOLCHAIN_TYPE), clang)
# There is no strlen function in make, but checking path depth is a
# reasonable approximation.
ifneq ($$(word 10, $$(subst /, ,$$(OUTPUTDIR))), )
$1_LINK_OBJS_RELATIVE := true
$1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
endif
endif
endif
ifeq ($$($1_TYPE), STATIC_LIBRARY)
$1_VARDEPS := $$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $$($1_LIBS) \
$$($1_EXTRA_LIBS)
@ -1146,10 +1187,17 @@ define SetupNativeCompilationBody
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
$$($1_TARGET): $$($1_TARGET_DEPS)
ifneq ($$($1_OBJ_FILE_LIST), )
ifeq ($$($1_LINK_OBJS_RELATIVE), true)
$$(eval $$(call ListPathsSafely, $1_ALL_OBJS_RELATIVE, $$($1_OBJ_FILE_LIST)))
else
$$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
endif
endif
$$(call LogInfo, Building static library $$($1_BASENAME))
$$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
$$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
$$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) \
$$($1_RES))
ifeq ($(STATIC_BUILD), true)
ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
@ -1201,40 +1249,6 @@ define SetupNativeCompilationBody
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
$1_LD_OBJ_ARG := $$($1_ALL_OBJS)
# If there are many object files, use an @-file...
ifneq ($$(word 17, $$($1_ALL_OBJS)), )
$1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt
ifneq ($(COMPILER_COMMAND_FILE_FLAG), )
$1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST)
else
# ...except for toolchains which don't support them.
$1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
endif
endif
# Unfortunately the @-file trick does not work reliably when using clang.
# Clang does not propagate the @-file parameter to the ld sub process, but
# instead puts the full content on the command line. At least the llvm ld
# does not even support an @-file.
#
# When linking a large amount of object files, we risk hitting the limit
# of the command line length even on posix systems if the path length of
# the output dir is very long due to our use of absolute paths. To
# mitigate this, use paths relative to the output dir when linking over
# 500 files with clang and the output dir path is deep.
ifneq ($$(word 500, $$($1_ALL_OBJS)), )
ifeq ($$(TOOLCHAIN_TYPE), clang)
# There is no strlen function in make, but checking path depth is a
# reasonable approximation.
ifneq ($$(word 10, $$(subst /, ,$$(OUTPUTDIR))), )
$1_LINK_OBJS_RELATIVE := true
$1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
endif
endif
endif
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
$$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)

View File

@ -139,6 +139,13 @@ JVM_STRIPFLAGS ?= $(STRIPFLAGS)
# This source set is reused so save in cache.
$(call FillFindCache, $(JVM_SRC_DIRS))
# The global operator new functions defined in operator_new.cpp are intended
# to detect and prevent the VM code from calling them. See more details in
# operator_new.cpp. Exclude operator_new.o when statically linking the VM
# code with JDK natives, as the JDK natives might need to call the global
# operator new.
LIBJVM_STATIC_EXCLUDE_OBJS := operator_new.o
################################################################################
# Now set up the actual compilation of the main hotspot native library
@ -186,6 +193,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJVM, \
RC_FILEDESC := $(HOTSPOT_VM_DISTRO) $(OPENJDK_TARGET_CPU_BITS)-Bit $(JVM_VARIANT) VM, \
PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \
STATIC_LIB_EXCLUDE_OBJS := $(LIBJVM_STATIC_EXCLUDE_OBJS), \
))
# Always recompile abstract_vm_version.cpp if libjvm needs to be relinked. This ensures

View File

@ -153,15 +153,19 @@ endif
LIBJLI_CFLAGS += $(LIBZ_CFLAGS)
ifneq ($(USE_EXTERNAL_LIBZ), true)
# Extra files from the zlib.
LIBJLI_EXTRA_FILE_LIST := inflate.c inftrees.c inffast.c zadler32.c zcrc32.c zutil.c
LIBJLI_EXTRA_FILES += \
$(addprefix $(TOPDIR)/src/java.base/share/native/libzip/zlib/, \
inflate.c \
inftrees.c \
inffast.c \
zadler32.c \
zcrc32.c \
zutil.c \
)
$(LIBJLI_EXTRA_FILE_LIST))
# Do not include these libz objects in the static libjli library.
# When statically linking the java launcher with all JDK and VM
# static libraries, we use the --whole-archive linker option.
# The duplicate objects in different static libraries cause linking
# errors due to duplicate symbols.
LIBJLI_STATIC_EXCLUDE_OBJS := $(subst .c,$(OBJ_SUFFIX),$(LIBJLI_EXTRA_FILE_LIST))
endif
$(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \
@ -180,6 +184,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \
LIBS_aix := $(LIBDL),\
LIBS_macosx := -framework Cocoa -framework Security -framework ApplicationServices, \
LIBS_windows := advapi32.lib comctl32.lib user32.lib, \
STATIC_LIB_EXCLUDE_OBJS := $(LIBJLI_STATIC_EXCLUDE_OBJS), \
))
TARGETS += $(BUILD_LIBJLI)

View File

@ -218,6 +218,14 @@ ifeq ($(call isTargetOs, windows macosx), false)
LIBAWT_XAWT_LIBS += -lpthread
endif
# These are the object files provided by the awt native
# library. Do not include these external (non-awt_xawt library)
# objects in the static library. When statically linking the java
# launcher with all JDK and VM static libraries, we use the
# --whole-archive linker option. The duplicate objects in different
# static libraries cause linking errors due to duplicate symbols.
LIBAWT_XAWT_STATIC_EXCLUDE_OBJS := systemScale.o
$(eval $(call SetupJdkLibrary, BUILD_LIBAWT_XAWT, \
NAME := awt_xawt, \
EXTRA_SRC := $(LIBAWT_XAWT_EXTRA_SRC), \
@ -244,6 +252,7 @@ ifeq ($(call isTargetOs, windows macosx), false)
$(call SET_SHARED_LIBRARY_ORIGIN) \
-L$(INSTALL_LIBRARIES_HERE), \
LIBS := $(X_LIBS) $(LIBAWT_XAWT_LIBS), \
STATIC_LIB_EXCLUDE_OBJS := $(LIBAWT_XAWT_STATIC_EXCLUDE_OBJS), \
))
$(BUILD_LIBAWT_XAWT): $(call FindLib, java.base, java)
@ -367,6 +376,14 @@ ifeq ($(call isTargetOs, windows macosx), false)
LIBAWT_HEADLESS_CFLAGS := $(CUPS_CFLAGS) $(FONTCONFIG_CFLAGS) $(X_CFLAGS) \
-DHEADLESS=true
# These are the object files provided by the awt native
# library. Do not include these external (non-awt_headless library)
# objects in the static library. When statically linking the java
# launcher with all JDK and VM static libraries, we use the
# --whole-archive linker option. The duplicate objects in different
# static libraries cause linking errors due to duplicate symbols.
LIBAWT_HEADLESS_STATIC_EXCLUDE_OBJS := systemScale.o
$(eval $(call SetupJdkLibrary, BUILD_LIBAWT_HEADLESS, \
NAME := awt_headless, \
EXTRA_SRC := $(LIBAWT_HEADLESS_EXTRA_SRC), \
@ -382,6 +399,7 @@ ifeq ($(call isTargetOs, windows macosx), false)
LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
LIBS_unix := -lawt -ljvm -ljava, \
LIBS_linux := $(LIBM) $(LIBDL), \
STATIC_LIB_EXCLUDE_OBJS := $(LIBAWT_HEADLESS_STATIC_EXCLUDE_OBJS), \
))
$(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT)