8352064: AIX: now also able to build static-jdk image with a statically linked launcher

Reviewed-by: mdoerr, mbaesken, ihse
This commit is contained in:
Joachim Kern 2025-03-24 16:15:36 +00:00
parent 5709f79cf8
commit d8c2f59a1b
5 changed files with 65 additions and 5 deletions

View File

@ -1321,10 +1321,7 @@ endif
################################################################################ ################################################################################
# all-images builds all our deliverables as images. # all-images builds all our deliverables as images.
all-images: product-images test-image all-docs-images all-images: product-images static-jdk-image test-image all-docs-images
ifeq ($(call isTargetOs, linux macosx windows), true)
all-images: static-jdk-image
endif
# 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

View File

@ -31,6 +31,7 @@ include CopyFiles.gmk
include DebugInfoUtils.gmk include DebugInfoUtils.gmk
include Modules.gmk include Modules.gmk
include modules/LauncherCommon.gmk include modules/LauncherCommon.gmk
include Execute.gmk
################################################################################ ################################################################################
# #
@ -68,6 +69,10 @@ else ifeq ($(call isTargetOs, windows), true)
BROKEN_STATIC_LIBS += sspi_bridge BROKEN_STATIC_LIBS += sspi_bridge
# dt_shmem define jdwpTransport_OnLoad which conflict with dt_socket # dt_shmem define jdwpTransport_OnLoad which conflict with dt_socket
BROKEN_STATIC_LIBS += dt_shmem BROKEN_STATIC_LIBS += dt_shmem
else ifeq ($(call isTargetOs, aix), true)
# libsplashscreen has a name conflict with libawt in the function
# BitmapToYXBandedRectangles, so we exclude it for now.
BROKEN_STATIC_LIBS += splashscreen
endif endif
$(foreach module, $(STATIC_LIB_MODULES), \ $(foreach module, $(STATIC_LIB_MODULES), \
@ -99,6 +104,18 @@ else ifeq ($(call isTargetOs, linux), true)
STATIC_LIBS := -Wl,--export-dynamic -Wl,--whole-archive $(STATIC_LIB_FILES) -Wl,--no-whole-archive STATIC_LIBS := -Wl,--export-dynamic -Wl,--whole-archive $(STATIC_LIB_FILES) -Wl,--no-whole-archive
else ifeq ($(call isTargetOs, windows), true) else ifeq ($(call isTargetOs, windows), true)
STATIC_LIBS := $(addprefix -wholearchive:, $(STATIC_LIB_FILES)) STATIC_LIBS := $(addprefix -wholearchive:, $(STATIC_LIB_FILES))
else ifeq ($(call isTargetOs, aix), true)
# on AIX we have to generate export files for all static libs, because we have no whole-archive linker flag
$(foreach lib, $(STATIC_LIB_FILES), \
$(eval $(call SetupExecute, generate_export_list_$(notdir $(lib)), \
INFO := Generating export list for $(notdir $(lib)), \
DEPS := $(lib), \
OUTPUT_FILE := $(lib).exp, \
COMMAND := ( $(AR) $(ARFLAGS) -w $(lib) | $(GREP) -v '^\.' | $(AWK) '{print $$1}' | $(SORT) -u > $(lib).exp ), \
)) \
$(eval STATIC_LIB_EXPORT_FILES += $(lib).exp) \
)
STATIC_LIBS := -Wl,-bexpfull $(STATIC_LIB_FILES) $(addprefix -Wl$(COMMA)-bE:, $(STATIC_LIB_EXPORT_FILES))
else else
$(error Unsupported platform) $(error Unsupported platform)
endif endif
@ -118,6 +135,9 @@ $(eval $(call SetupBuildLauncher, java, \
)) ))
$(java): $(STATIC_LIB_FILES) $(java): $(STATIC_LIB_FILES)
ifeq ($(call isTargetOs, aix), true)
$(java): $(STATIC_LIB_EXPORT_FILES)
endif
TARGETS += $(java) TARGETS += $(java)

View File

@ -167,6 +167,14 @@ endif
ifeq ($(call isTargetOs, aix), true) ifeq ($(call isTargetOs, aix), true)
# AIX requires a static libjli because the compiler doesn't support '-rpath' # AIX requires a static libjli because the compiler doesn't support '-rpath'
BUILD_LIBJLI_TYPE := STATIC_LIBRARY BUILD_LIBJLI_TYPE := STATIC_LIBRARY
# This is the object file to provide the dladdr API, which is not
# part of AIX. It occurs several times in the jdk code base.
# Do not include it. 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 += java_md_aix.o
endif endif
$(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \ $(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \

View File

@ -95,6 +95,16 @@ ifeq ($(call isTargetOs, windows), true)
$(TOPDIR)/src/$(MODULE)/windows/native/libawt/windows/awt.rc $(TOPDIR)/src/$(MODULE)/windows/native/libawt/windows/awt.rc
endif endif
# This is the object file to provide the dladdr API, which is not
# part of AIX. It occurs several times in the jdk code base.
# Do not include it. 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.
ifeq ($(call isTargetOs, aix), true)
LIBAWT_STATIC_EXCLUDE_OBJS := porting_aix.o
endif
# -fgcse-after-reload improves performance of MaskFill in Java2D by 20% for # -fgcse-after-reload improves performance of MaskFill in Java2D by 20% for
# some gcc # some gcc
$(eval $(call SetupJdkLibrary, BUILD_LIBAWT, \ $(eval $(call SetupJdkLibrary, BUILD_LIBAWT, \
@ -140,6 +150,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBAWT, \
user32.lib uuid.lib winmm.lib winspool.lib, \ user32.lib uuid.lib winmm.lib winspool.lib, \
VERSIONINFO_RESOURCE := $(LIBAWT_VERSIONINFO_RESOURCE), \ VERSIONINFO_RESOURCE := $(LIBAWT_VERSIONINFO_RESOURCE), \
EXTRA_RCFLAGS := $(LIBAWT_RCFLAGS), \ EXTRA_RCFLAGS := $(LIBAWT_RCFLAGS), \
STATIC_LIB_EXCLUDE_OBJS := $(LIBAWT_STATIC_EXCLUDE_OBJS), \
)) ))
TARGETS += $(BUILD_LIBAWT) TARGETS += $(BUILD_LIBAWT)

View File

@ -42,6 +42,9 @@
// For loadquery() // For loadquery()
#include <sys/ldr.h> #include <sys/ldr.h>
// For getargs()
#include <procinfo.h>
// Use raw malloc instead of os::malloc - this code gets used for error reporting. // Use raw malloc instead of os::malloc - this code gets used for error reporting.
// A class to "intern" eternal strings. // A class to "intern" eternal strings.
@ -205,6 +208,22 @@ static bool reload_table() {
trcVerbose("loadquery buffer size is %zu.", buflen); trcVerbose("loadquery buffer size is %zu.", buflen);
// the entry for the executable itself does not contain a path.
// instead we retrieve the path of the executable with the getargs API.
static char pgmpath[PATH_MAX+1] = "";
static char* pgmbase = nullptr;
if (pgmpath[0] == 0) {
procentry64 PInfo;
PInfo.pi_pid = ::getpid();
if (0 == ::getargs(&PInfo, sizeof(PInfo), (char*)pgmpath, PATH_MAX) && *pgmpath) {
pgmpath[PATH_MAX] = '\0';
pgmbase = strrchr(pgmpath, '/');
if (pgmbase != nullptr) {
pgmbase += 1;
}
}
}
// Iterate over the loadquery result. For details see sys/ldr.h on AIX. // Iterate over the loadquery result. For details see sys/ldr.h on AIX.
ldi = (struct ld_info*) buffer; ldi = (struct ld_info*) buffer;
@ -223,7 +242,12 @@ static bool reload_table() {
lm->data = ldi->ldinfo_dataorg; lm->data = ldi->ldinfo_dataorg;
lm->data_len = ldi->ldinfo_datasize; lm->data_len = ldi->ldinfo_datasize;
lm->path = g_stringlist.add(ldi->ldinfo_filename); if (pgmbase != nullptr && 0 == strcmp(pgmbase, ldi->ldinfo_filename)) {
lm->path = g_stringlist.add(pgmpath);
} else {
lm->path = g_stringlist.add(ldi->ldinfo_filename);
}
if (!lm->path) { if (!lm->path) {
log_warning(os)("OOM."); log_warning(os)("OOM.");
free(lm); free(lm);