From 45414fc2dfa41cbbfc6de7fec15eb47f41cf8986 Mon Sep 17 00:00:00 2001 From: Jiangli Zhou Date: Mon, 12 Jun 2023 16:22:24 +0000 Subject: [PATCH] 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 Reviewed-by: erikj --- make/GraalBuilderImage.gmk | 4 +- make/Main.gmk | 28 +++- make/StaticLibsImage.gmk | 28 +++- make/autoconf/flags-ldflags.m4 | 6 + make/autoconf/flags.m4 | 1 + make/autoconf/spec.gmk.in | 9 ++ make/common/NativeCompilation.gmk | 120 ++++++++++++------ make/hotspot/lib/CompileJvm.gmk | 8 ++ make/modules/java.base/lib/CoreLibraries.gmk | 19 ++- .../java.desktop/lib/Awt2dLibraries.gmk | 18 +++ 10 files changed, 190 insertions(+), 51 deletions(-) diff --git a/make/GraalBuilderImage.gmk b/make/GraalBuilderImage.gmk index 19c84c31181..8c4d66aa9d5 100644 --- a/make/GraalBuilderImage.gmk +++ b/make/GraalBuilderImage.gmk @@ -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) diff --git a/make/Main.gmk b/make/Main.gmk index 5f647c963b0..e13e6f47386 100644 --- a/make/Main.gmk +++ b/make/Main.gmk @@ -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 \ diff --git a/make/StaticLibsImage.gmk b/make/StaticLibsImage.gmk index 21c4608f4dd..44a4ba56782 100644 --- a/make/StaticLibsImage.gmk +++ b/make/StaticLibsImage.gmk @@ -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 diff --git a/make/autoconf/flags-ldflags.m4 b/make/autoconf/flags-ldflags.m4 index e5c345fdef1..b63a8727a34 100644 --- a/make/autoconf/flags-ldflags.m4 +++ b/make/autoconf/flags-ldflags.m4 @@ -72,9 +72,14 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER], BASIC_LDFLAGS_JVM_ONLY="" + LDFLAGS_CXX_PARTIAL_LINKING="$MACHINE_FLAG -r" + elif test "x$TOOLCHAIN_TYPE" = xclang; then BASIC_LDFLAGS_JVM_ONLY="-mno-omit-leaf-frame-pointer -mstack-alignment=16 \ -fPIC" + + LDFLAGS_CXX_PARTIAL_LINKING="$MACHINE_FLAG -r" + if test "x$OPENJDK_TARGET_OS" = xaix; then BASIC_LDFLAGS="-Wl,-b64 -Wl,-brtl -Wl,-bnorwexec -Wl,-bnolibpath -Wl,-bnoexpall \ -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 LDFLAGS_CXX_JDK="$BASIC_LDFLAGS_ONLYCXX $BASIC_LDFLAGS_ONLYCXX_JDK_ONLY $DEBUGLEVEL_LDFLAGS_JDK_ONLY" AC_SUBST(LDFLAGS_CXX_JDK) + AC_SUBST(LDFLAGS_CXX_PARTIAL_LINKING) ]) ################################################################################ diff --git a/make/autoconf/flags.m4 b/make/autoconf/flags.m4 index ddb2b4c8e0a..f56fbc9b1c4 100644 --- a/make/autoconf/flags.m4 +++ b/make/autoconf/flags.m4 @@ -301,6 +301,7 @@ AC_DEFUN_ONCE([FLAGS_PRE_TOOLCHAIN], EXTRA_LDFLAGS="$MACHINE_FLAG $USER_LDFLAGS" EXTRA_ASFLAGS="$USER_ASFLAGS" + AC_SUBST(MACHINE_FLAG) AC_SUBST(EXTRA_CFLAGS) AC_SUBST(EXTRA_CXXFLAGS) AC_SUBST(EXTRA_LDFLAGS) diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in index 0f85917814e..d147eb5a251 100644 --- a/make/autoconf/spec.gmk.in +++ b/make/autoconf/spec.gmk.in @@ -546,6 +546,8 @@ JVM_LIBS := @JVM_LIBS@ BASIC_ASFLAGS := @BASIC_ASFLAGS@ +MACHINE_FLAG := @MACHINE_FLAG@ + # These flags might contain variables set by a custom extension that is included later. EXTRA_CFLAGS = @EXTRA_CFLAGS@ EXTRA_CXXFLAGS = @EXTRA_CXXFLAGS@ @@ -572,6 +574,9 @@ JDKEXE_LIBS:=@JDKEXE_LIBS@ # LDFLAGS specific to C++ linking. 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 LDCXX := @LDCXX@ # 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_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) diff --git a/make/common/NativeCompilation.gmk b/make/common/NativeCompilation.gmk index 0d7ab6a7ef3..8a837243ee2 100644 --- a/make/common/NativeCompilation.gmk +++ b/make/common/NativeCompilation.gmk @@ -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,9 +1137,60 @@ 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 + + # 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) + # 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_EXTRA_LIBS) + ifeq ($$($1_ENABLE_PARTIAL_LINKING), true) + $1_VARDEPS += $$($1_LD) $$($1_SYSROOT_LDFLAGS) + endif $1_VARDEPS_FILE := $$(call DependOnVariable, $1_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_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) + 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)) + # 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, \ - $$($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)) ifeq ($(STATIC_BUILD), true) ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true) @@ -1201,40 +1283,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) diff --git a/make/hotspot/lib/CompileJvm.gmk b/make/hotspot/lib/CompileJvm.gmk index adb964d0538..9f95eccd5d9 100644 --- a/make/hotspot/lib/CompileJvm.gmk +++ b/make/hotspot/lib/CompileJvm.gmk @@ -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 @@ -190,6 +197,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 diff --git a/make/modules/java.base/lib/CoreLibraries.gmk b/make/modules/java.base/lib/CoreLibraries.gmk index 8b1a0a90fd4..0fe8e109f45 100644 --- a/make/modules/java.base/lib/CoreLibraries.gmk +++ b/make/modules/java.base/lib/CoreLibraries.gmk @@ -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) diff --git a/make/modules/java.desktop/lib/Awt2dLibraries.gmk b/make/modules/java.desktop/lib/Awt2dLibraries.gmk index 62b4477b8bf..5c1021886f6 100644 --- a/make/modules/java.desktop/lib/Awt2dLibraries.gmk +++ b/make/modules/java.desktop/lib/Awt2dLibraries.gmk @@ -221,6 +221,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), \ @@ -255,6 +263,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) @@ -378,6 +387,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), \ @@ -393,6 +410,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)