8307858: [REDO] JDK-8307194 Add make target for optionally building a complete set of all JDK and hotspot libjvm static libraries

Co-authored-by: Erik Joelsson <erikj@openjdk.org>
Reviewed-by: erikj
This commit is contained in:
Jiangli Zhou 2023-06-12 16:22:24 +00:00
parent a6ad42e00e
commit 45414fc2df
10 changed files with 190 additions and 51 deletions

View File

@ -43,10 +43,10 @@ $(eval $(call SetupCopyFiles, COPY_JDK_IMG, \
TARGETS += $(COPY_JDK_IMG) TARGETS += $(COPY_JDK_IMG)
$(eval $(call SetupCopyFiles, COPY_STATIC_LIBS, \ $(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, \ DEST := $(GRAAL_BUILDER_IMAGE_DIR)/lib, \
FILES := $(filter %$(STATIC_LIBRARY_SUFFIX), \ FILES := $(filter %$(STATIC_LIBRARY_SUFFIX), \
$(call FindFiles, $(STATIC_LIBS_IMAGE_DIR)/lib)), \ $(call FindFiles, $(STATIC_LIBS_GRAAL_IMAGE_DIR)/lib)), \
)) ))
TARGETS += $(COPY_STATIC_LIBS) TARGETS += $(COPY_STATIC_LIBS)

View File

@ -233,6 +233,7 @@ ALL_TARGETS += $(LAUNCHER_TARGETS)
HOTSPOT_VARIANT_TARGETS := $(addprefix hotspot-, $(JVM_VARIANTS)) HOTSPOT_VARIANT_TARGETS := $(addprefix hotspot-, $(JVM_VARIANTS))
HOTSPOT_VARIANT_GENSRC_TARGETS := $(addsuffix -gensrc, $(HOTSPOT_VARIANT_TARGETS)) HOTSPOT_VARIANT_GENSRC_TARGETS := $(addsuffix -gensrc, $(HOTSPOT_VARIANT_TARGETS))
HOTSPOT_VARIANT_LIBS_TARGETS := $(addsuffix -libs, $(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 define DeclareHotspotGensrcRecipe
hotspot-$1-gensrc: hotspot-$1-gensrc:
@ -251,6 +252,14 @@ endef
$(foreach v, $(JVM_VARIANTS), $(eval $(call DeclareHotspotLibsRecipe,$v))) $(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, \ $(eval $(call SetupTarget, hotspot-ide-project, \
MAKEFILE := ide/visualstudio/hotspot/CreateVSProject, \ MAKEFILE := ide/visualstudio/hotspot/CreateVSProject, \
DEPS := hotspot exploded-image, \ DEPS := hotspot exploded-image, \
@ -298,7 +307,7 @@ $(eval $(call SetupTarget, eclipse-shared-mixed-env, \
)) ))
ALL_TARGETS += $(HOTSPOT_VARIANT_TARGETS) $(HOTSPOT_VARIANT_GENSRC_TARGETS) \ 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 # Help and user support
@ -462,6 +471,12 @@ $(eval $(call SetupTarget, symbols-image, \
$(eval $(call SetupTarget, static-libs-image, \ $(eval $(call SetupTarget, static-libs-image, \
MAKEFILE := StaticLibsImage, \ 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, \ $(eval $(call SetupTarget, mac-jdk-bundle, \
@ -489,7 +504,7 @@ $(eval $(call SetupTarget, exploded-image-optimize, \
$(eval $(call SetupTarget, graal-builder-image, \ $(eval $(call SetupTarget, graal-builder-image, \
MAKEFILE := GraalBuilderImage, \ MAKEFILE := GraalBuilderImage, \
DEPS := jdk-image static-libs-image, \ DEPS := jdk-image static-libs-graal-image, \
)) ))
ifeq ($(JCOV_ENABLED), true) ifeq ($(JCOV_ENABLED), true)
@ -889,6 +904,7 @@ else
$(foreach v, $(JVM_VARIANTS), \ $(foreach v, $(JVM_VARIANTS), \
$(eval hotspot-$v-gensrc: java.base-copy buildtools-hotspot) \ $(eval hotspot-$v-gensrc: java.base-copy buildtools-hotspot) \
$(eval hotspot-$v-libs: hotspot-$v-gensrc java.base-copy) \ $(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. # 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) 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 bootcycle-images: jdk-image
@ -1097,6 +1115,7 @@ hotspot: $(HOTSPOT_VARIANT_TARGETS)
$(foreach v, $(JVM_VARIANTS), \ $(foreach v, $(JVM_VARIANTS), \
$(eval hotspot-libs: hotspot-$v-libs) \ $(eval hotspot-libs: hotspot-$v-libs) \
$(eval hotspot-gensrc: hotspot-$v-gensrc) \ $(eval hotspot-gensrc: hotspot-$v-gensrc) \
$(eval hotspot-static-libs: hotspot-$v-static-libs) \
) )
gensrc: $(GENSRC_TARGETS) 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 packages all our deliverables as tar.gz bundles.
all-bundles: product-bundles test-bundles docs-bundles static-libs-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 \ copy java libs static-libs launchers jmods \
jdk.jdwp.agent-gensrc $(ALL_MODULES) demos \ jdk.jdwp.agent-gensrc $(ALL_MODULES) demos \
exploded-image-base exploded-image runnable-buildjdk \ 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. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -38,19 +38,43 @@ ALL_MODULES = $(call FindAllModules)
TARGETS := 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), \ $(foreach m, $(ALL_MODULES), \
$(eval $(call SetupCopyFiles, COPY_STATIC_LIBS_$m, \ $(eval $(call SetupCopyFiles, COPY_STATIC_LIBS_$m, \
FLATTEN := true, \ FLATTEN := true, \
SRC := $(SUPPORT_OUTPUTDIR)/native/$m, \ SRC := $(SUPPORT_OUTPUTDIR)/native/$m, \
DEST := $(STATIC_LIBS_IMAGE_DIR)/lib, \ DEST := $(IMAGE_DEST_DIR), \
FILES := $(filter %$(STATIC_LIBRARY_SUFFIX), \ FILES := $(filter %$(STATIC_LIBRARY_SUFFIX), \
$(call FindFiles, $(SUPPORT_OUTPUTDIR)/native/$m/*/static)), \ $(call FindFiles, $(SUPPORT_OUTPUTDIR)/native/$m/*/static)), \
)) \ )) \
$(eval TARGETS += $$(COPY_STATIC_LIBS_$m)) \ $(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) all: $(TARGETS)
.PHONY: all .PHONY: all

View File

@ -72,9 +72,14 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
BASIC_LDFLAGS_JVM_ONLY="" BASIC_LDFLAGS_JVM_ONLY=""
LDFLAGS_CXX_PARTIAL_LINKING="$MACHINE_FLAG -r"
elif test "x$TOOLCHAIN_TYPE" = xclang; then elif test "x$TOOLCHAIN_TYPE" = xclang; then
BASIC_LDFLAGS_JVM_ONLY="-mno-omit-leaf-frame-pointer -mstack-alignment=16 \ BASIC_LDFLAGS_JVM_ONLY="-mno-omit-leaf-frame-pointer -mstack-alignment=16 \
-fPIC" -fPIC"
LDFLAGS_CXX_PARTIAL_LINKING="$MACHINE_FLAG -r"
if test "x$OPENJDK_TARGET_OS" = xaix; then if test "x$OPENJDK_TARGET_OS" = xaix; then
BASIC_LDFLAGS="-Wl,-b64 -Wl,-brtl -Wl,-bnorwexec -Wl,-bnolibpath -Wl,-bnoexpall \ BASIC_LDFLAGS="-Wl,-b64 -Wl,-brtl -Wl,-bnorwexec -Wl,-bnolibpath -Wl,-bnoexpall \
-Wl,-bernotok -Wl,-bdatapsize:64k -Wl,-btextpsize:64k -Wl,-bstackpsize:64k" -Wl,-bernotok -Wl,-bdatapsize:64k -Wl,-btextpsize:64k -Wl,-bstackpsize:64k"
@ -161,6 +166,7 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
# Export some intermediate variables for compatibility # Export some intermediate variables for compatibility
LDFLAGS_CXX_JDK="$BASIC_LDFLAGS_ONLYCXX $BASIC_LDFLAGS_ONLYCXX_JDK_ONLY $DEBUGLEVEL_LDFLAGS_JDK_ONLY" LDFLAGS_CXX_JDK="$BASIC_LDFLAGS_ONLYCXX $BASIC_LDFLAGS_ONLYCXX_JDK_ONLY $DEBUGLEVEL_LDFLAGS_JDK_ONLY"
AC_SUBST(LDFLAGS_CXX_JDK) AC_SUBST(LDFLAGS_CXX_JDK)
AC_SUBST(LDFLAGS_CXX_PARTIAL_LINKING)
]) ])
################################################################################ ################################################################################

View File

@ -301,6 +301,7 @@ AC_DEFUN_ONCE([FLAGS_PRE_TOOLCHAIN],
EXTRA_LDFLAGS="$MACHINE_FLAG $USER_LDFLAGS" EXTRA_LDFLAGS="$MACHINE_FLAG $USER_LDFLAGS"
EXTRA_ASFLAGS="$USER_ASFLAGS" EXTRA_ASFLAGS="$USER_ASFLAGS"
AC_SUBST(MACHINE_FLAG)
AC_SUBST(EXTRA_CFLAGS) AC_SUBST(EXTRA_CFLAGS)
AC_SUBST(EXTRA_CXXFLAGS) AC_SUBST(EXTRA_CXXFLAGS)
AC_SUBST(EXTRA_LDFLAGS) AC_SUBST(EXTRA_LDFLAGS)

View File

@ -546,6 +546,8 @@ JVM_LIBS := @JVM_LIBS@
BASIC_ASFLAGS := @BASIC_ASFLAGS@ BASIC_ASFLAGS := @BASIC_ASFLAGS@
MACHINE_FLAG := @MACHINE_FLAG@
# These flags might contain variables set by a custom extension that is included later. # These flags might contain variables set by a custom extension that is included later.
EXTRA_CFLAGS = @EXTRA_CFLAGS@ EXTRA_CFLAGS = @EXTRA_CFLAGS@
EXTRA_CXXFLAGS = @EXTRA_CXXFLAGS@ EXTRA_CXXFLAGS = @EXTRA_CXXFLAGS@
@ -572,6 +574,9 @@ JDKEXE_LIBS:=@JDKEXE_LIBS@
# LDFLAGS specific to C++ linking. # LDFLAGS specific to C++ linking.
LDFLAGS_CXX_JDK:=@LDFLAGS_CXX_JDK@ LDFLAGS_CXX_JDK:=@LDFLAGS_CXX_JDK@
# LDFLAGS specific to partial linking.
LDFLAGS_CXX_PARTIAL_LINKING:=@LDFLAGS_CXX_PARTIAL_LINKING@
# Sometimes a different linker is needed for c++ libs # Sometimes a different linker is needed for c++ libs
LDCXX := @LDCXX@ LDCXX := @LDCXX@
# The flags for linking libstdc++ linker. # The flags for linking libstdc++ linker.
@ -928,6 +933,10 @@ DOCS_OUTPUTDIR := $(DOCS_JDK_IMAGE_DIR)
STATIC_LIBS_IMAGE_SUBDIR := static-libs STATIC_LIBS_IMAGE_SUBDIR := static-libs
STATIC_LIBS_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/$(STATIC_LIBS_IMAGE_SUBDIR) 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
GRAAL_BUILDER_IMAGE_SUBDIR := graal-builder-jdk GRAAL_BUILDER_IMAGE_SUBDIR := graal-builder-jdk
GRAAL_BUILDER_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/$(GRAAL_BUILDER_IMAGE_SUBDIR) 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. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # 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 Header file to use as precompiled header
# PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH # 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 # 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 # After being called, some variables are exported from this macro, all prefixed
# with parameter 1 followed by a '_': # with parameter 1 followed by a '_':
@ -726,6 +727,12 @@ define SetupNativeCompilationBody
endif endif
# Sort to remove duplicates and provide a reproducible order on the input files to the linker. # 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)) $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 # Pickup extra OPENJDK_TARGET_OS_TYPE, OPENJDK_TARGET_OS, TOOLCHAIN_TYPE and
# OPENJDK_TARGET_OS plus OPENJDK_TARGET_CPU pair dependent variables for CFLAGS. # OPENJDK_TARGET_OS plus OPENJDK_TARGET_CPU pair dependent variables for CFLAGS.
@ -1130,9 +1137,60 @@ define SetupNativeCompilationBody
endif endif
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
# If we are building static library, 'AR' on macosx may not support @-file.
ifeq ($$($1_TYPE), STATIC_LIBRARY)
ifeq ($(call isTargetOs, macosx), true)
$1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
endif
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) ifeq ($$($1_TYPE), STATIC_LIBRARY)
# Include partial linking when building the static library with clang on linux.
ifeq ($(call isTargetOs, linux), true)
ifneq ($(findstring $(TOOLCHAIN_TYPE), clang), )
$1_ENABLE_PARTIAL_LINKING := true
endif
endif
$1_VARDEPS := $$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $$($1_LIBS) \ $1_VARDEPS := $$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $$($1_LIBS) \
$$($1_EXTRA_LIBS) $$($1_EXTRA_LIBS)
ifeq ($$($1_ENABLE_PARTIAL_LINKING), true)
$1_VARDEPS += $$($1_LD) $$($1_SYSROOT_LDFLAGS)
endif
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
@ -1145,11 +1203,35 @@ define SetupNativeCompilationBody
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP) $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
$1_AR_OBJ_ARG := $$($1_LD_OBJ_ARG)
# With clang on linux, partial linking is enabled and 'AR' takes the output
# object from the partial linking step.
ifeq ($$($1_ENABLE_PARTIAL_LINKING), true)
$1_TARGET_RELOCATABLE := $$($1_OBJECT_DIR)/$$($1_PREFIX)$$($1_NAME)_relocatable$(OBJ_SUFFIX)
$1_AR_OBJ_ARG := $$($1_TARGET_RELOCATABLE)
endif
$$($1_TARGET): $$($1_TARGET_DEPS) $$($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 LogInfo, Building static library $$($1_BASENAME))
$$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR)) $$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
# Do partial linking.
ifeq ($$($1_ENABLE_PARTIAL_LINKING), true)
$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_partial_link, \
$(if $$($1_LINK_OBJS_RELATIVE), $$(CD) $$(OUTPUTDIR) ; ) \
$$($1_LD) $(LDFLAGS_CXX_PARTIAL_LINKING) $$($1_SYSROOT_LDFLAGS) \
$(LD_OUT_OPTION)$$($1_TARGET_RELOCATABLE) \
$$($1_LD_OBJ_ARG))
endif
$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \ $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
$$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \ $(if $$($1_LINK_OBJS_RELATIVE), $$(CD) $$(OUTPUTDIR) ; ) \
$$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_AR_OBJ_ARG) \
$$($1_RES)) $$($1_RES))
ifeq ($(STATIC_BUILD), true) ifeq ($(STATIC_BUILD), true)
ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true) ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
@ -1201,40 +1283,6 @@ define SetupNativeCompilationBody
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).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_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
$$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE) $$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)

View File

@ -139,6 +139,13 @@ JVM_STRIPFLAGS ?= $(STRIPFLAGS)
# This source set is reused so save in cache. # This source set is reused so save in cache.
$(call FillFindCache, $(JVM_SRC_DIRS)) $(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 # Now set up the actual compilation of the main hotspot native library
@ -190,6 +197,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJVM, \
RC_FILEDESC := $(HOTSPOT_VM_DISTRO) $(OPENJDK_TARGET_CPU_BITS)-Bit $(JVM_VARIANT) VM, \ RC_FILEDESC := $(HOTSPOT_VM_DISTRO) $(OPENJDK_TARGET_CPU_BITS)-Bit $(JVM_VARIANT) VM, \
PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \ PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \ 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 # 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) LIBJLI_CFLAGS += $(LIBZ_CFLAGS)
ifneq ($(USE_EXTERNAL_LIBZ), true) 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 += \ LIBJLI_EXTRA_FILES += \
$(addprefix $(TOPDIR)/src/java.base/share/native/libzip/zlib/, \ $(addprefix $(TOPDIR)/src/java.base/share/native/libzip/zlib/, \
inflate.c \ $(LIBJLI_EXTRA_FILE_LIST))
inftrees.c \
inffast.c \ # Do not include these libz objects in the static libjli library.
zadler32.c \ # When statically linking the java launcher with all JDK and VM
zcrc32.c \ # static libraries, we use the --whole-archive linker option.
zutil.c \ # 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 endif
$(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \ $(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \
@ -180,6 +184,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \
LIBS_aix := $(LIBDL),\ LIBS_aix := $(LIBDL),\
LIBS_macosx := -framework Cocoa -framework Security -framework ApplicationServices, \ LIBS_macosx := -framework Cocoa -framework Security -framework ApplicationServices, \
LIBS_windows := advapi32.lib comctl32.lib user32.lib, \ LIBS_windows := advapi32.lib comctl32.lib user32.lib, \
STATIC_LIB_EXCLUDE_OBJS := $(LIBJLI_STATIC_EXCLUDE_OBJS), \
)) ))
TARGETS += $(BUILD_LIBJLI) TARGETS += $(BUILD_LIBJLI)

View File

@ -221,6 +221,14 @@ ifeq ($(call isTargetOs, windows macosx), false)
LIBAWT_XAWT_LIBS += -lpthread LIBAWT_XAWT_LIBS += -lpthread
endif 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, \ $(eval $(call SetupJdkLibrary, BUILD_LIBAWT_XAWT, \
NAME := awt_xawt, \ NAME := awt_xawt, \
EXTRA_SRC := $(LIBAWT_XAWT_EXTRA_SRC), \ EXTRA_SRC := $(LIBAWT_XAWT_EXTRA_SRC), \
@ -255,6 +263,7 @@ ifeq ($(call isTargetOs, windows macosx), false)
$(call SET_SHARED_LIBRARY_ORIGIN) \ $(call SET_SHARED_LIBRARY_ORIGIN) \
-L$(INSTALL_LIBRARIES_HERE), \ -L$(INSTALL_LIBRARIES_HERE), \
LIBS := $(X_LIBS) $(LIBAWT_XAWT_LIBS), \ LIBS := $(X_LIBS) $(LIBAWT_XAWT_LIBS), \
STATIC_LIB_EXCLUDE_OBJS := $(LIBAWT_XAWT_STATIC_EXCLUDE_OBJS), \
)) ))
$(BUILD_LIBAWT_XAWT): $(call FindLib, java.base, java) $(BUILD_LIBAWT_XAWT): $(call FindLib, java.base, java)
@ -378,6 +387,14 @@ ifeq ($(call isTargetOs, windows macosx), false)
LIBAWT_HEADLESS_CFLAGS := $(CUPS_CFLAGS) $(FONTCONFIG_CFLAGS) $(X_CFLAGS) \ LIBAWT_HEADLESS_CFLAGS := $(CUPS_CFLAGS) $(FONTCONFIG_CFLAGS) $(X_CFLAGS) \
-DHEADLESS=true -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, \ $(eval $(call SetupJdkLibrary, BUILD_LIBAWT_HEADLESS, \
NAME := awt_headless, \ NAME := awt_headless, \
EXTRA_SRC := $(LIBAWT_HEADLESS_EXTRA_SRC), \ EXTRA_SRC := $(LIBAWT_HEADLESS_EXTRA_SRC), \
@ -393,6 +410,7 @@ ifeq ($(call isTargetOs, windows macosx), false)
LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \ LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
LIBS_unix := -lawt -ljvm -ljava, \ LIBS_unix := -lawt -ljvm -ljava, \
LIBS_linux := $(LIBM) $(LIBDL), \ LIBS_linux := $(LIBM) $(LIBDL), \
STATIC_LIB_EXCLUDE_OBJS := $(LIBAWT_HEADLESS_STATIC_EXCLUDE_OBJS), \
)) ))
$(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT) $(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT)