Skip to content

Commit 2dd15cf

Browse files
committed
8346719: Add relaunchers to the static JDK image for missing executables
Reviewed-by: alanb, erikj
1 parent c9a9816 commit 2dd15cf

File tree

14 files changed

+678
-190
lines changed

14 files changed

+678
-190
lines changed

make/Main.gmk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,9 @@ $(eval $(call SetupTarget, symbols-image, \
461461
TARGET := symbols, \
462462
))
463463

464-
$(eval $(call SetupTarget, static-launcher, \
464+
$(eval $(call SetupTarget, static-launchers, \
465465
MAKEFILE := StaticLibs, \
466-
TARGET := static-launcher, \
466+
TARGET := static-launchers, \
467467
DEPS := hotspot-static-libs static-libs, \
468468
))
469469

@@ -1290,7 +1290,7 @@ ifeq ($(call isTargetOs, macosx), true)
12901290
legacy-images: mac-legacy-jre-bundle
12911291
endif
12921292

1293-
static-exploded-image: static-launcher exploded-image
1293+
static-exploded-image: static-launchers exploded-image
12941294

12951295
# These targets build the various documentation images
12961296
docs-jdk-image: docs-jdk

make/StaticLibs.gmk

Lines changed: 107 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ ifneq ($(word 2, $(wildcard $(HOTSPOT_STATIC_LIB_PATH))), )
4848
endif
4949

5050
# Find all modules with static libraries
51-
STATIC_LIB_MODULES := $(patsubst $(SUPPORT_OUTPUTDIR)/modules_static-libs/%, \
52-
%, $(wildcard $(SUPPORT_OUTPUTDIR)/modules_static-libs/*))
51+
STATIC_LIB_MODULES := $(sort $(patsubst $(SUPPORT_OUTPUTDIR)/modules_static-libs/%, \
52+
%, $(wildcard $(SUPPORT_OUTPUTDIR)/modules_static-libs/*)))
5353

5454
# Filter out known broken libraries. This is a temporary measure until
5555
# proper support for these libraries can be provided.
@@ -123,13 +123,18 @@ else
123123
$(error Unsupported platform)
124124
endif
125125

126+
################################################################################
127+
# Build the java static launcher
128+
################################################################################
126129
$(eval $(call SetupBuildLauncher, java, \
127130
ENABLE_ARG_FILES := true, \
128131
EXPAND_CLASSPATH_WILDCARDS := true, \
129132
EXTRA_RCFLAGS := $(JAVA_RCFLAGS), \
130133
VERSION_INFO_RESOURCE := $(JAVA_VERSION_INFO_RESOURCE), \
131134
OPTIMIZATION := HIGH, \
135+
MACOSX_PRIVILEGED := true, \
132136
STATIC_LAUNCHER := true, \
137+
CFLAGS := -DSTATIC_BUILD, \
133138
LDFLAGS := $(LDFLAGS_STATIC_JDK), \
134139
LIBS := $(STATIC_LIBS) $(EXTERNAL_LIBS), \
135140
LINK_TYPE := C++, \
@@ -146,7 +151,53 @@ TARGETS += $(java)
146151

147152
JAVA_LAUNCHER := $(BUILD_LAUNCHER_java_TARGET)
148153

149-
static-launcher: $(java)
154+
static-launchers: $(java)
155+
156+
################################################################################
157+
# Build relaunchers (thin wrappers calling the java binary) for all other
158+
# JDK launchers.
159+
################################################################################
160+
161+
RELAUNCHER_SRC := $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/launcher
162+
163+
# $1: The module name
164+
# $2: The launcher name
165+
define SetupRelauncher
166+
$1_$2_LAUNCHER_ARGS_LINE := $$(call ReadFile, $$(SUPPORT_OUTPUTDIR)/static-native/relaunchers/$1/$2-relauncher-arguments.txt)
167+
# Restore |||| with space
168+
$1_$2_LAUNCHER_ARGS := '{ $$(subst ||||,$(SPACE),$$(strip $$(foreach a, $$($1_$2_LAUNCHER_ARGS_LINE), "-J$$a"$$(COMMA) )) ) }'
169+
170+
$$(eval $$(call SetupJdkExecutable, BUILD_relauncher_$2, \
171+
NAME := $2, \
172+
EXTRA_FILES := $$(RELAUNCHER_SRC)/relauncher.c, \
173+
CFLAGS := -DLAUNCHER_ARGS=$$($1_$2_LAUNCHER_ARGS), \
174+
LIBS_windows := shlwapi.lib, \
175+
OUTPUT_DIR := $$(STATIC_LAUNCHER_OUTPUT_DIR), \
176+
OBJECT_DIR := $$(STATIC_LAUNCHER_OUTPUT_DIR)/relaunchers/$2, \
177+
))
178+
179+
TARGETS += $$(BUILD_relauncher_$2)
180+
181+
RELAUNCHERS += $$(BUILD_relauncher_$2_TARGET)
182+
static-launchers: $$(BUILD_relauncher_$2)
183+
endef
184+
185+
# Find all modules with launchers
186+
LAUNCHER_MODULES := $(sort $(patsubst $(SUPPORT_OUTPUTDIR)/modules_static-launchers/%, \
187+
%, $(wildcard $(SUPPORT_OUTPUTDIR)/modules_static-launchers/*)))
188+
189+
# Find launchers for each module
190+
$(foreach module, $(LAUNCHER_MODULES), \
191+
$(eval LAUNCHERS_$(module) := $(if $(wildcard \
192+
$(SUPPORT_OUTPUTDIR)/modules_static-launchers/$(module)/module-included-launchers.txt), \
193+
$(shell cat \
194+
$(SUPPORT_OUTPUTDIR)/modules_static-launchers/$(module)/module-included-launchers.txt))) \
195+
)
196+
197+
# For all launchers (except java and javaw), setup a relauncher build
198+
$(foreach module, $(LAUNCHER_MODULES), \
199+
$(foreach launcher, $(filter-out java javaw, $(LAUNCHERS_$(module))), \
200+
$(eval $(call SetupRelauncher,$(module),$(launcher)))))
150201

151202
################################################################################
152203
#
@@ -188,26 +239,72 @@ TARGETS += $(copy-from-jdk-image)
188239

189240
$(copy-from-jdk-image): | static-jdk-info
190241

191-
$(eval $(call SetupCopyFiles, copy-static-launcher, \
192-
FILES := $(JAVA_LAUNCHER), \
242+
$(eval $(call SetupCopyFiles, copy-static-launchers, \
243+
FILES := $(JAVA_LAUNCHER) $(RELAUNCHERS), \
193244
DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \
194245
))
195246

196-
TARGETS += $(copy-static-launcher)
247+
TARGETS += $(copy-static-launchers)
197248

198-
$(eval $(call SetupCopyFiles, copy-static-launcher-debuginfo, \
249+
$(eval $(call SetupCopyFiles, copy-static-launchers-debuginfo, \
199250
SRC := $(STATIC_LAUNCHER_OUTPUT_DIR), \
200251
DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \
201252
FILES := $(call FindDebuginfoFiles, $(STATIC_LAUNCHER_OUTPUT_DIR)), \
202253
))
203254

204-
TARGETS += $(copy-static-launcher-debuginfo)
255+
TARGETS += $(copy-static-launchers-debuginfo)
256+
257+
# Copy the microsoft runtime libraries on windows
258+
ifeq ($(call isTargetOs, windows), true)
259+
# Chmod to avoid permission issues if bundles are unpacked on unix platforms.
260+
# Use separate macro calls in case the source files are not in the same
261+
# directory.
262+
$(eval $(call SetupCopyFiles, copy-windows-msvcr, \
263+
DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \
264+
FILES := $(MSVCR_DLL), \
265+
MACRO := copy-and-chmod-executable, \
266+
))
267+
268+
TARGETS += $(copy-windows-msvcr)
269+
270+
$(eval $(call SetupCopyFiles, copy-windows-vcruntime, \
271+
DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \
272+
FILES := $(VCRUNTIME_1_DLL), \
273+
MACRO := copy-and-chmod-executable, \
274+
))
275+
276+
TARGETS += $(copy-windows-vcruntime)
277+
278+
$(eval $(call SetupCopyFiles, copy-windows-msvcp, \
279+
DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \
280+
FILES := $(MSVCP_DLL), \
281+
MACRO := copy-and-chmod-executable, \
282+
))
283+
284+
TARGETS += $(copy-windows-msvcp)
285+
286+
copy-windows-libs := $(copy-windows-msvcr) $(copy-windows-vcruntime) $(copy-windows-msvcp)
287+
288+
ifneq ($(UCRT_DLL_DIR), )
289+
$(eval $(call SetupCopyFiles, copy-windows-ucrt, \
290+
DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \
291+
SRC := $(UCRT_DLL_DIR), \
292+
FILES := $(wildcard $(UCRT_DLL_DIR)/*.dll), \
293+
MACRO := copy-and-chmod-executable, \
294+
))
295+
296+
TARGETS += $(copy-windows-ucrt)
297+
298+
copy-windows-libs += $(copy-windows-ucrt)
299+
endif
300+
endif
205301

206-
static-jdk-image: $(copy-from-jdk-image) $(copy-static-launcher) $(copy-static-launcher-debuginfo)
302+
static-jdk-image: $(copy-from-jdk-image) $(copy-static-launchers) \
303+
$(copy-static-launchers-debuginfo) $(copy-windows-libs)
207304

208305
TARGETS += static-jdk-image
209306

210-
.PHONY: static-launcher static-jdk-image
307+
.PHONY: static-launchers static-jdk-image
211308

212309
################################################################################
213310

make/common/modules/LauncherCommon.gmk

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ LAUNCHER_CFLAGS += -I$(TOPDIR)/src/java.base/share/native/launcher \
4343
MACOSX_PLIST_DIR := $(TOPDIR)/src/java.base/macosx/native/launcher
4444
JAVA_MANIFEST := $(TOPDIR)/src/java.base/windows/native/launcher/java.manifest
4545

46+
INCLUDED_LAUNCHERS_FILE := $(SUPPORT_OUTPUTDIR)/modules_static-launchers/$(MODULE)/module-included-launchers.txt
47+
INCLUDED_LAUNCHERS :=
48+
4649
################################################################################
4750
# Build standard launcher.
4851

@@ -74,29 +77,45 @@ define SetupBuildLauncherBody
7477

7578
$1_MAIN_MODULE := $(MODULE)
7679

80+
$1_RELAUNCHER_ARGUMENTS :=
81+
7782
ifneq ($$($1_MAIN_CLASS), )
7883
$1_JAVA_ARGS += -Xms8m
7984
$1_LAUNCHER_CLASS := -m $$($1_MAIN_MODULE)/$$($1_MAIN_CLASS)
8085
endif
8186

82-
ifeq ($$($1_EXPAND_CLASSPATH_WILDCARDS), true)
83-
$1_CFLAGS += -DEXPAND_CLASSPATH_WILDCARDS
87+
ifeq ($$($1_ENABLE_ARG_FILES), true)
88+
$1_CFLAGS += -DDISABLE_ARGFILE=JNI_FALSE
89+
else
90+
$1_CFLAGS += -DDISABLE_ARGFILE=JNI_TRUE
91+
# This must be the first argument given, if it should be present
92+
$1_RELAUNCHER_ARGUMENTS += -DjavaLauncherArgFiles=false
8493
endif
8594

86-
ifeq ($$($1_ENABLE_ARG_FILES), true)
87-
$1_CFLAGS += -DENABLE_ARG_FILES
95+
ifeq ($$($1_EXPAND_CLASSPATH_WILDCARDS), true)
96+
$1_CFLAGS += -DCLASSPATH_WILDCARDS=JNI_TRUE
97+
else
98+
$1_CFLAGS += -DCLASSPATH_WILDCARDS=JNI_FALSE
99+
$1_RELAUNCHER_ARGUMENTS += -DjavaLauncherWildcards=false
88100
endif
89101

102+
$1_RELAUNCHER_ARGUMENTS += -DjavaLauncherProgname=$1
103+
90104
ifeq ($(call isTargetOs, windows), true)
91105
ifeq ($$($1_WINDOWS_JAVAW), true)
92106
$1_CFLAGS += -DJAVAW
93107
endif
94108
endif
95109

96110
ifneq ($$($1_JAVA_ARGS), )
97-
$1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \
98-
$$(addprefix -J, $$($1_JAVA_ARGS)) $$($1_LAUNCHER_CLASS), "$$a"$(COMMA) )) }'
111+
$1_PREFIXED_JAVA_ARGS := $$(addprefix -J, $$($1_JAVA_ARGS)) \
112+
$$($1_LAUNCHER_CLASS)
113+
$1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, $$($1_PREFIXED_JAVA_ARGS), \
114+
"$$a"$(COMMA) )) }'
99115
$1_CFLAGS += -DJAVA_ARGS=$$($1_JAVA_ARGS_STR)
116+
# To preserve spaces, substitute them with a hopefully unique pattern
117+
$1_RELAUNCHER_ARGUMENTS += \
118+
-DjavaLauncherArgs=$$(subst $$(SPACE),||||,$$($1_PREFIXED_JAVA_ARGS))
100119
endif
101120

102121
ifeq ($(call isTargetOs, macosx), true)
@@ -172,8 +191,28 @@ define SetupBuildLauncherBody
172191
))
173192

174193
$1 += $$(BUILD_LAUNCHER_$1)
194+
195+
$1_RELAUNCHER_ARGUMENTS_FILE := \
196+
$$(SUPPORT_OUTPUTDIR)/static-native/relaunchers/$$(MODULE)/$1-relauncher-arguments.txt
197+
198+
$1_VARDEPS := $$($1_RELAUNCHER_ARGUMENTS)
199+
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
200+
$$($1_RELAUNCHER_ARGUMENTS_FILE).vardeps)
201+
202+
$$($1_RELAUNCHER_ARGUMENTS_FILE):
203+
$$(call MakeDir, $$(@D))
204+
$$(ECHO) '$$($1_RELAUNCHER_ARGUMENTS)' > $$@
205+
206+
$1 += $$($1_RELAUNCHER_ARGUMENTS_FILE)
207+
175208
TARGETS += $$($1)
176209

210+
# Record the fact that this launcher is part of the current module.
211+
INCLUDED_LAUNCHERS += $1
212+
213+
# Add a dependency from this launcher to the launcher list
214+
$$(INCLUDED_LAUNCHERS_FILE): $$($1)
215+
177216
$$(BUILD_LAUNCHER_$1): $$(BUILD_PLIST_$1)
178217

179218
ifeq ($(call isTargetOs, macosx), true)
@@ -242,5 +281,14 @@ endif
242281

243282
################################################################################
244283

284+
# We need to keep track of which launchers are created by this module. This
285+
# information is required for static builds, to know which relaunchers to
286+
# create. The file module-included-launchers.txt is then read in StaticLibs.gmk.
287+
$(INCLUDED_LAUNCHERS_FILE):
288+
$(call MakeDir, $(@D))
289+
$(ECHO) $(INCLUDED_LAUNCHERS) > $@
290+
291+
TARGETS += $(INCLUDED_LAUNCHERS_FILE)
292+
245293
endif # include guard
246294
include MakeIncludeEnd.gmk

make/modules/java.base/Launcher.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ifeq ($(call isTargetOs, linux), true)
7373

7474
$(eval $(call SetupJdkExecutable, BUILD_JEXEC, \
7575
NAME := jexec, \
76-
SRC := $(TOPDIR)/src/$(MODULE)/unix/native/launcher, \
76+
EXTRA_FILES := $(TOPDIR)/src/$(MODULE)/unix/native/launcher/jexec.c, \
7777
OPTIMIZATION := LOW, \
7878
EXTRA_HEADER_DIRS := libjli, \
7979
CFLAGS_linux := -fPIC, \

make/modules/jdk.jpackage/Lib.gmk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
################################################################################
2727

28-
include LauncherCommon.gmk
2928
include LibCommon.gmk
3029

3130
JPACKAGE_OUTPUT_DIR := \

src/java.base/share/native/launcher/defines.h

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)