Skip to content

Commit 1964954

Browse files
committed
8307194: Add make target for optionally building a complete set of all JDK and hotspot libjvm static libraries
Reviewed-by: erikj, sgehwolf
1 parent 9af1787 commit 1964954

File tree

8 files changed

+144
-51
lines changed

8 files changed

+144
-51
lines changed

make/GraalBuilderImage.gmk

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ $(eval $(call SetupCopyFiles, COPY_JDK_IMG, \
4343
TARGETS += $(COPY_JDK_IMG)
4444

4545
$(eval $(call SetupCopyFiles, COPY_STATIC_LIBS, \
46-
SRC := $(STATIC_LIBS_IMAGE_DIR)/lib, \
46+
SRC := $(STATIC_LIBS_GRAAL_IMAGE_DIR)/lib, \
4747
DEST := $(GRAAL_BUILDER_IMAGE_DIR)/lib, \
4848
FILES := $(filter %$(STATIC_LIBRARY_SUFFIX), \
49-
$(call FindFiles, $(STATIC_LIBS_IMAGE_DIR)/lib)), \
49+
$(call FindFiles, $(STATIC_LIBS_GRAAL_IMAGE_DIR)/lib)), \
5050
))
5151
TARGETS += $(COPY_STATIC_LIBS)
5252

make/Main.gmk

+24-4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ ALL_TARGETS += $(LAUNCHER_TARGETS)
233233
HOTSPOT_VARIANT_TARGETS := $(addprefix hotspot-, $(JVM_VARIANTS))
234234
HOTSPOT_VARIANT_GENSRC_TARGETS := $(addsuffix -gensrc, $(HOTSPOT_VARIANT_TARGETS))
235235
HOTSPOT_VARIANT_LIBS_TARGETS := $(addsuffix -libs, $(HOTSPOT_VARIANT_TARGETS))
236+
HOTSPOT_VARIANT_STATIC_LIBS_TARGETS := $(addsuffix -static-libs, $(HOTSPOT_VARIANT_TARGETS))
236237

237238
define DeclareHotspotGensrcRecipe
238239
hotspot-$1-gensrc:
@@ -251,6 +252,14 @@ endef
251252

252253
$(foreach v, $(JVM_VARIANTS), $(eval $(call DeclareHotspotLibsRecipe,$v)))
253254

255+
define DeclareHotspotStaticLibsRecipe
256+
hotspot-$1-static-libs:
257+
+($(CD) $(TOPDIR)/make/hotspot && $(MAKE) $(MAKE_ARGS) -f lib/CompileLibraries.gmk \
258+
JVM_VARIANT=$1 STATIC_LIBS=true)
259+
endef
260+
261+
$(foreach v, $(JVM_VARIANTS), $(eval $(call DeclareHotspotStaticLibsRecipe,$v)))
262+
254263
$(eval $(call SetupTarget, hotspot-ide-project, \
255264
MAKEFILE := ide/visualstudio/hotspot/CreateVSProject, \
256265
DEPS := hotspot exploded-image, \
@@ -298,7 +307,7 @@ $(eval $(call SetupTarget, eclipse-shared-mixed-env, \
298307
))
299308

300309
ALL_TARGETS += $(HOTSPOT_VARIANT_TARGETS) $(HOTSPOT_VARIANT_GENSRC_TARGETS) \
301-
$(HOTSPOT_VARIANT_LIBS_TARGETS)
310+
$(HOTSPOT_VARIANT_LIBS_TARGETS) $(HOTSPOT_VARIANT_STATIC_LIBS_TARGETS)
302311

303312
################################################################################
304313
# Help and user support
@@ -462,6 +471,12 @@ $(eval $(call SetupTarget, symbols-image, \
462471

463472
$(eval $(call SetupTarget, static-libs-image, \
464473
MAKEFILE := StaticLibsImage, \
474+
TARGET := static-libs-image, \
475+
))
476+
477+
$(eval $(call SetupTarget, static-libs-graal-image, \
478+
MAKEFILE := StaticLibsImage, \
479+
TARGET := static-libs-graal-image, \
465480
))
466481

467482
$(eval $(call SetupTarget, mac-jdk-bundle, \
@@ -489,7 +504,7 @@ $(eval $(call SetupTarget, exploded-image-optimize, \
489504

490505
$(eval $(call SetupTarget, graal-builder-image, \
491506
MAKEFILE := GraalBuilderImage, \
492-
DEPS := jdk-image static-libs-image, \
507+
DEPS := jdk-image static-libs-graal-image, \
493508
))
494509

495510
ifeq ($(JCOV_ENABLED), true)
@@ -889,6 +904,7 @@ else
889904
$(foreach v, $(JVM_VARIANTS), \
890905
$(eval hotspot-$v-gensrc: java.base-copy buildtools-hotspot) \
891906
$(eval hotspot-$v-libs: hotspot-$v-gensrc java.base-copy) \
907+
$(eval hotspot-$v-static-libs: hotspot-$v-gensrc java.base-copy) \
892908
)
893909

894910
# If not already set, set the JVM variant target so that the JVM will be built.
@@ -1047,7 +1063,9 @@ else
10471063

10481064
symbols-image: $(LIBS_TARGETS) $(LAUNCHER_TARGETS)
10491065

1050-
static-libs-image: $(STATIC_LIBS_TARGETS)
1066+
static-libs-image: hotspot-static-libs $(STATIC_LIBS_TARGETS)
1067+
1068+
static-libs-graal-image: $(STATIC_LIBS_TARGETS)
10511069

10521070
bootcycle-images: jdk-image
10531071

@@ -1097,6 +1115,7 @@ hotspot: $(HOTSPOT_VARIANT_TARGETS)
10971115
$(foreach v, $(JVM_VARIANTS), \
10981116
$(eval hotspot-libs: hotspot-$v-libs) \
10991117
$(eval hotspot-gensrc: hotspot-$v-gensrc) \
1118+
$(eval hotspot-static-libs: hotspot-$v-static-libs) \
11001119
)
11011120

11021121
gensrc: $(GENSRC_TARGETS)
@@ -1259,7 +1278,8 @@ all-images: product-images test-image all-docs-images
12591278
# all-bundles packages all our deliverables as tar.gz bundles.
12601279
all-bundles: product-bundles test-bundles docs-bundles static-libs-bundles
12611280

1262-
ALL_TARGETS += buildtools hotspot hotspot-libs hotspot-gensrc gensrc gendata \
1281+
ALL_TARGETS += buildtools hotspot hotspot-libs hotspot-static-libs \
1282+
hotspot-gensrc gensrc gendata \
12631283
copy java libs static-libs launchers jmods \
12641284
jdk.jdwp.agent-gensrc $(ALL_MODULES) demos \
12651285
exploded-image-base exploded-image runnable-buildjdk \

make/StaticLibsImage.gmk

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -38,19 +38,43 @@ ALL_MODULES = $(call FindAllModules)
3838

3939
TARGETS :=
4040

41+
ifneq ($(filter static-libs-image, $(MAKECMDGOALS)), )
42+
IMAGE_DEST_DIR=$(STATIC_LIBS_IMAGE_DIR)/lib
43+
else ifneq ($(filter static-libs-graal-image, $(MAKECMDGOALS)), )
44+
IMAGE_DEST_DIR=$(STATIC_LIBS_GRAAL_IMAGE_DIR)/lib
45+
endif
46+
47+
# Copy JDK static libs to the image.
4148
$(foreach m, $(ALL_MODULES), \
4249
$(eval $(call SetupCopyFiles, COPY_STATIC_LIBS_$m, \
4350
FLATTEN := true, \
4451
SRC := $(SUPPORT_OUTPUTDIR)/native/$m, \
45-
DEST := $(STATIC_LIBS_IMAGE_DIR)/lib, \
52+
DEST := $(IMAGE_DEST_DIR), \
4653
FILES := $(filter %$(STATIC_LIBRARY_SUFFIX), \
4754
$(call FindFiles, $(SUPPORT_OUTPUTDIR)/native/$m/*/static)), \
4855
)) \
4956
$(eval TARGETS += $$(COPY_STATIC_LIBS_$m)) \
57+
$(eval STATIC_LIBS_TARGETS += $$(COPY_STATIC_LIBS_$m)) \
5058
)
5159

60+
ifneq ($(filter static-libs-image, $(MAKECMDGOALS)), )
61+
# Copy libjvm static library to the image.
62+
$(foreach v, $(JVM_VARIANTS), \
63+
$(eval $(call SetupCopyFiles, COPY_STATIC_LIBS_$v, \
64+
SRC := $(HOTSPOT_OUTPUTDIR)/variant-$v/libjvm/objs/static, \
65+
DEST := $(IMAGE_DEST_DIR)/$v, \
66+
FILES := $(wildcard $(HOTSPOT_OUTPUTDIR)/variant-$v/libjvm/objs/static/*$(STATIC_LIBRARY_SUFFIX)), \
67+
)) \
68+
$(eval TARGETS += $$(COPY_STATIC_LIBS_$v)) \
69+
$(eval HOTSPOT_VARIANT_STATIC_LIBS_TARGETS += $$(COPY_STATIC_LIBS_$v)) \
70+
)
71+
endif
72+
5273
################################################################################
5374

75+
static-libs-image: $(HOTSPOT_VARIANT_STATIC_LIBS_TARGETS) $(STATIC_LIBS_TARGETS)
76+
static-libs-graal-image: $(STATIC_LIBS_TARGETS)
77+
5478
all: $(TARGETS)
5579

5680
.PHONY: all

make/autoconf/spec.gmk.in

+4
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,10 @@ DOCS_OUTPUTDIR := $(DOCS_JDK_IMAGE_DIR)
928928
STATIC_LIBS_IMAGE_SUBDIR := static-libs
929929
STATIC_LIBS_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/$(STATIC_LIBS_IMAGE_SUBDIR)
930930

931+
# Graal static libs image
932+
STATIC_LIBS_GRAAL_IMAGE_SUBDIR := static-libs-graal
933+
STATIC_LIBS_GRAAL_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/$(STATIC_LIBS_GRAAL_IMAGE_SUBDIR)
934+
931935
# Graal builder image
932936
GRAAL_BUILDER_IMAGE_SUBDIR := graal-builder-jdk
933937
GRAAL_BUILDER_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/$(GRAAL_BUILDER_IMAGE_SUBDIR)

make/common/NativeCompilation.gmk

+50-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -548,6 +548,7 @@ endef
548548
# PRECOMPILED_HEADER Header file to use as precompiled header
549549
# PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
550550
# BUILD_INFO_LOG_MACRO Overrides log level of the build info log message, default LogWarn
551+
# STATIC_LIB_EXCLUDE_OBJS exclude objects that matches from static library
551552
#
552553
# After being called, some variables are exported from this macro, all prefixed
553554
# with parameter 1 followed by a '_':
@@ -726,6 +727,12 @@ define SetupNativeCompilationBody
726727
endif
727728
# Sort to remove duplicates and provide a reproducible order on the input files to the linker.
728729
$1_ALL_OBJS := $$(sort $$($1_EXPECTED_OBJS) $$($1_EXTRA_OBJECT_FILES))
730+
ifeq ($(STATIC_LIBS), true)
731+
# Exclude the object files that match with $1_STATIC_LIB_EXCLUDE_OBJS.
732+
ifneq ($$($1_STATIC_LIB_EXCLUDE_OBJS), )
733+
$1_ALL_OBJS := $$(call not-containing, $$($1_STATIC_LIB_EXCLUDE_OBJS), $$($1_ALL_OBJS))
734+
endif
735+
endif
729736

730737
# Pickup extra OPENJDK_TARGET_OS_TYPE, OPENJDK_TARGET_OS, TOOLCHAIN_TYPE and
731738
# OPENJDK_TARGET_OS plus OPENJDK_TARGET_CPU pair dependent variables for CFLAGS.
@@ -1130,6 +1137,40 @@ define SetupNativeCompilationBody
11301137
endif
11311138
endif
11321139

1140+
$1_LD_OBJ_ARG := $$($1_ALL_OBJS)
1141+
1142+
# If there are many object files, use an @-file...
1143+
ifneq ($$(word 17, $$($1_ALL_OBJS)), )
1144+
$1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt
1145+
ifneq ($(COMPILER_COMMAND_FILE_FLAG), )
1146+
$1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST)
1147+
else
1148+
# ...except for toolchains which don't support them.
1149+
$1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
1150+
endif
1151+
endif
1152+
1153+
# Unfortunately the @-file trick does not work reliably when using clang.
1154+
# Clang does not propagate the @-file parameter to the ld sub process, but
1155+
# instead puts the full content on the command line. At least the llvm ld
1156+
# does not even support an @-file.
1157+
#
1158+
# When linking a large amount of object files, we risk hitting the limit
1159+
# of the command line length even on posix systems if the path length of
1160+
# the output dir is very long due to our use of absolute paths. To
1161+
# mitigate this, use paths relative to the output dir when linking over
1162+
# 500 files with clang and the output dir path is deep.
1163+
ifneq ($$(word 500, $$($1_ALL_OBJS)), )
1164+
ifeq ($$(TOOLCHAIN_TYPE), clang)
1165+
# There is no strlen function in make, but checking path depth is a
1166+
# reasonable approximation.
1167+
ifneq ($$(word 10, $$(subst /, ,$$(OUTPUTDIR))), )
1168+
$1_LINK_OBJS_RELATIVE := true
1169+
$1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1170+
endif
1171+
endif
1172+
endif
1173+
11331174
ifeq ($$($1_TYPE), STATIC_LIBRARY)
11341175
$1_VARDEPS := $$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $$($1_LIBS) \
11351176
$$($1_EXTRA_LIBS)
@@ -1146,10 +1187,17 @@ define SetupNativeCompilationBody
11461187
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
11471188

11481189
$$($1_TARGET): $$($1_TARGET_DEPS)
1190+
ifneq ($$($1_OBJ_FILE_LIST), )
1191+
ifeq ($$($1_LINK_OBJS_RELATIVE), true)
1192+
$$(eval $$(call ListPathsSafely, $1_ALL_OBJS_RELATIVE, $$($1_OBJ_FILE_LIST)))
1193+
else
1194+
$$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
1195+
endif
1196+
endif
11491197
$$(call LogInfo, Building static library $$($1_BASENAME))
11501198
$$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
11511199
$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1152-
$$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
1200+
$$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) \
11531201
$$($1_RES))
11541202
ifeq ($(STATIC_BUILD), true)
11551203
ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
@@ -1201,40 +1249,6 @@ define SetupNativeCompilationBody
12011249
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
12021250
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
12031251

1204-
$1_LD_OBJ_ARG := $$($1_ALL_OBJS)
1205-
1206-
# If there are many object files, use an @-file...
1207-
ifneq ($$(word 17, $$($1_ALL_OBJS)), )
1208-
$1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt
1209-
ifneq ($(COMPILER_COMMAND_FILE_FLAG), )
1210-
$1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST)
1211-
else
1212-
# ...except for toolchains which don't support them.
1213-
$1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
1214-
endif
1215-
endif
1216-
1217-
# Unfortunately the @-file trick does not work reliably when using clang.
1218-
# Clang does not propagate the @-file parameter to the ld sub process, but
1219-
# instead puts the full content on the command line. At least the llvm ld
1220-
# does not even support an @-file.
1221-
#
1222-
# When linking a large amount of object files, we risk hitting the limit
1223-
# of the command line length even on posix systems if the path length of
1224-
# the output dir is very long due to our use of absolute paths. To
1225-
# mitigate this, use paths relative to the output dir when linking over
1226-
# 500 files with clang and the output dir path is deep.
1227-
ifneq ($$(word 500, $$($1_ALL_OBJS)), )
1228-
ifeq ($$(TOOLCHAIN_TYPE), clang)
1229-
# There is no strlen function in make, but checking path depth is a
1230-
# reasonable approximation.
1231-
ifneq ($$(word 10, $$(subst /, ,$$(OUTPUTDIR))), )
1232-
$1_LINK_OBJS_RELATIVE := true
1233-
$1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1234-
endif
1235-
endif
1236-
endif
1237-
12381252
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
12391253
$$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)
12401254

make/hotspot/lib/CompileJvm.gmk

+8
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ JVM_STRIPFLAGS ?= $(STRIPFLAGS)
139139
# This source set is reused so save in cache.
140140
$(call FillFindCache, $(JVM_SRC_DIRS))
141141

142+
# The global operator new functions defined in operator_new.cpp are intended
143+
# to detect and prevent the VM code from calling them. See more details in
144+
# operator_new.cpp. Exclude operator_new.o when statically linking the VM
145+
# code with JDK natives, as the JDK natives might need to call the global
146+
# operator new.
147+
LIBJVM_STATIC_EXCLUDE_OBJS := operator_new.o
148+
142149
################################################################################
143150
# Now set up the actual compilation of the main hotspot native library
144151

@@ -186,6 +193,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJVM, \
186193
RC_FILEDESC := $(HOTSPOT_VM_DISTRO) $(OPENJDK_TARGET_CPU_BITS)-Bit $(JVM_VARIANT) VM, \
187194
PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
188195
PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \
196+
STATIC_LIB_EXCLUDE_OBJS := $(LIBJVM_STATIC_EXCLUDE_OBJS), \
189197
))
190198

191199
# Always recompile abstract_vm_version.cpp if libjvm needs to be relinked. This ensures

make/modules/java.base/lib/CoreLibraries.gmk

+12-7
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,19 @@ endif
153153
LIBJLI_CFLAGS += $(LIBZ_CFLAGS)
154154

155155
ifneq ($(USE_EXTERNAL_LIBZ), true)
156+
# Extra files from the zlib.
157+
LIBJLI_EXTRA_FILE_LIST := inflate.c inftrees.c inffast.c zadler32.c zcrc32.c zutil.c
158+
156159
LIBJLI_EXTRA_FILES += \
157160
$(addprefix $(TOPDIR)/src/java.base/share/native/libzip/zlib/, \
158-
inflate.c \
159-
inftrees.c \
160-
inffast.c \
161-
zadler32.c \
162-
zcrc32.c \
163-
zutil.c \
164-
)
161+
$(LIBJLI_EXTRA_FILE_LIST))
162+
163+
# Do not include these libz objects in the static libjli library.
164+
# When statically linking the java launcher with all JDK and VM
165+
# static libraries, we use the --whole-archive linker option.
166+
# The duplicate objects in different static libraries cause linking
167+
# errors due to duplicate symbols.
168+
LIBJLI_STATIC_EXCLUDE_OBJS := $(subst .c,$(OBJ_SUFFIX),$(LIBJLI_EXTRA_FILE_LIST))
165169
endif
166170

167171
$(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \
@@ -180,6 +184,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \
180184
LIBS_aix := $(LIBDL),\
181185
LIBS_macosx := -framework Cocoa -framework Security -framework ApplicationServices, \
182186
LIBS_windows := advapi32.lib comctl32.lib user32.lib, \
187+
STATIC_LIB_EXCLUDE_OBJS := $(LIBJLI_STATIC_EXCLUDE_OBJS), \
183188
))
184189

185190
TARGETS += $(BUILD_LIBJLI)

make/modules/java.desktop/lib/Awt2dLibraries.gmk

+18
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ ifeq ($(call isTargetOs, windows macosx), false)
218218
LIBAWT_XAWT_LIBS += -lpthread
219219
endif
220220

221+
# These are the object files provided by the awt native
222+
# library. Do not include these external (non-awt_xawt library)
223+
# objects in the static library. When statically linking the java
224+
# launcher with all JDK and VM static libraries, we use the
225+
# --whole-archive linker option. The duplicate objects in different
226+
# static libraries cause linking errors due to duplicate symbols.
227+
LIBAWT_XAWT_STATIC_EXCLUDE_OBJS := systemScale.o
228+
221229
$(eval $(call SetupJdkLibrary, BUILD_LIBAWT_XAWT, \
222230
NAME := awt_xawt, \
223231
EXTRA_SRC := $(LIBAWT_XAWT_EXTRA_SRC), \
@@ -244,6 +252,7 @@ ifeq ($(call isTargetOs, windows macosx), false)
244252
$(call SET_SHARED_LIBRARY_ORIGIN) \
245253
-L$(INSTALL_LIBRARIES_HERE), \
246254
LIBS := $(X_LIBS) $(LIBAWT_XAWT_LIBS), \
255+
STATIC_LIB_EXCLUDE_OBJS := $(LIBAWT_XAWT_STATIC_EXCLUDE_OBJS), \
247256
))
248257

249258
$(BUILD_LIBAWT_XAWT): $(call FindLib, java.base, java)
@@ -367,6 +376,14 @@ ifeq ($(call isTargetOs, windows macosx), false)
367376
LIBAWT_HEADLESS_CFLAGS := $(CUPS_CFLAGS) $(FONTCONFIG_CFLAGS) $(X_CFLAGS) \
368377
-DHEADLESS=true
369378

379+
# These are the object files provided by the awt native
380+
# library. Do not include these external (non-awt_headless library)
381+
# objects in the static library. When statically linking the java
382+
# launcher with all JDK and VM static libraries, we use the
383+
# --whole-archive linker option. The duplicate objects in different
384+
# static libraries cause linking errors due to duplicate symbols.
385+
LIBAWT_HEADLESS_STATIC_EXCLUDE_OBJS := systemScale.o
386+
370387
$(eval $(call SetupJdkLibrary, BUILD_LIBAWT_HEADLESS, \
371388
NAME := awt_headless, \
372389
EXTRA_SRC := $(LIBAWT_HEADLESS_EXTRA_SRC), \
@@ -382,6 +399,7 @@ ifeq ($(call isTargetOs, windows macosx), false)
382399
LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
383400
LIBS_unix := -lawt -ljvm -ljava, \
384401
LIBS_linux := $(LIBM) $(LIBDL), \
402+
STATIC_LIB_EXCLUDE_OBJS := $(LIBAWT_HEADLESS_STATIC_EXCLUDE_OBJS), \
385403
))
386404

387405
$(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT)

0 commit comments

Comments
 (0)