Skip to content

Commit d8c2f59

Browse files
author
Joachim Kern
committed
8352064: AIX: now also able to build static-jdk image with a statically linked launcher
Reviewed-by: mdoerr, mbaesken, ihse
1 parent 5709f79 commit d8c2f59

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
lines changed

make/Main.gmk

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,10 +1321,7 @@ endif
13211321
################################################################################
13221322

13231323
# all-images builds all our deliverables as images.
1324-
all-images: product-images test-image all-docs-images
1325-
ifeq ($(call isTargetOs, linux macosx windows), true)
1326-
all-images: static-jdk-image
1327-
endif
1324+
all-images: product-images static-jdk-image test-image all-docs-images
13281325

13291326
# all-bundles packages all our deliverables as tar.gz bundles.
13301327
all-bundles: product-bundles test-bundles docs-bundles static-libs-bundles

make/StaticLibs.gmk

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ include CopyFiles.gmk
3131
include DebugInfoUtils.gmk
3232
include Modules.gmk
3333
include modules/LauncherCommon.gmk
34+
include Execute.gmk
3435

3536
################################################################################
3637
#
@@ -68,6 +69,10 @@ else ifeq ($(call isTargetOs, windows), true)
6869
BROKEN_STATIC_LIBS += sspi_bridge
6970
# dt_shmem define jdwpTransport_OnLoad which conflict with dt_socket
7071
BROKEN_STATIC_LIBS += dt_shmem
72+
else ifeq ($(call isTargetOs, aix), true)
73+
# libsplashscreen has a name conflict with libawt in the function
74+
# BitmapToYXBandedRectangles, so we exclude it for now.
75+
BROKEN_STATIC_LIBS += splashscreen
7176
endif
7277

7378
$(foreach module, $(STATIC_LIB_MODULES), \
@@ -99,6 +104,18 @@ else ifeq ($(call isTargetOs, linux), true)
99104
STATIC_LIBS := -Wl,--export-dynamic -Wl,--whole-archive $(STATIC_LIB_FILES) -Wl,--no-whole-archive
100105
else ifeq ($(call isTargetOs, windows), true)
101106
STATIC_LIBS := $(addprefix -wholearchive:, $(STATIC_LIB_FILES))
107+
else ifeq ($(call isTargetOs, aix), true)
108+
# on AIX we have to generate export files for all static libs, because we have no whole-archive linker flag
109+
$(foreach lib, $(STATIC_LIB_FILES), \
110+
$(eval $(call SetupExecute, generate_export_list_$(notdir $(lib)), \
111+
INFO := Generating export list for $(notdir $(lib)), \
112+
DEPS := $(lib), \
113+
OUTPUT_FILE := $(lib).exp, \
114+
COMMAND := ( $(AR) $(ARFLAGS) -w $(lib) | $(GREP) -v '^\.' | $(AWK) '{print $$1}' | $(SORT) -u > $(lib).exp ), \
115+
)) \
116+
$(eval STATIC_LIB_EXPORT_FILES += $(lib).exp) \
117+
)
118+
STATIC_LIBS := -Wl,-bexpfull $(STATIC_LIB_FILES) $(addprefix -Wl$(COMMA)-bE:, $(STATIC_LIB_EXPORT_FILES))
102119
else
103120
$(error Unsupported platform)
104121
endif
@@ -118,6 +135,9 @@ $(eval $(call SetupBuildLauncher, java, \
118135
))
119136

120137
$(java): $(STATIC_LIB_FILES)
138+
ifeq ($(call isTargetOs, aix), true)
139+
$(java): $(STATIC_LIB_EXPORT_FILES)
140+
endif
121141

122142
TARGETS += $(java)
123143

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ endif
167167
ifeq ($(call isTargetOs, aix), true)
168168
# AIX requires a static libjli because the compiler doesn't support '-rpath'
169169
BUILD_LIBJLI_TYPE := STATIC_LIBRARY
170+
171+
# This is the object file to provide the dladdr API, which is not
172+
# part of AIX. It occurs several times in the jdk code base.
173+
# Do not include it. When statically linking the java
174+
# launcher with all JDK and VM static libraries, we use the
175+
# --whole-archive linker option. The duplicate objects in different
176+
# static libraries cause linking errors due to duplicate symbols.
177+
LIBJLI_STATIC_EXCLUDE_OBJS += java_md_aix.o
170178
endif
171179

172180
$(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ ifeq ($(call isTargetOs, windows), true)
9595
$(TOPDIR)/src/$(MODULE)/windows/native/libawt/windows/awt.rc
9696
endif
9797

98+
# This is the object file to provide the dladdr API, which is not
99+
# part of AIX. It occurs several times in the jdk code base.
100+
# Do not include it. When statically linking the java
101+
# launcher with all JDK and VM static libraries, we use the
102+
# --whole-archive linker option. The duplicate objects in different
103+
# static libraries cause linking errors due to duplicate symbols.
104+
ifeq ($(call isTargetOs, aix), true)
105+
LIBAWT_STATIC_EXCLUDE_OBJS := porting_aix.o
106+
endif
107+
98108
# -fgcse-after-reload improves performance of MaskFill in Java2D by 20% for
99109
# some gcc
100110
$(eval $(call SetupJdkLibrary, BUILD_LIBAWT, \
@@ -140,6 +150,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBAWT, \
140150
user32.lib uuid.lib winmm.lib winspool.lib, \
141151
VERSIONINFO_RESOURCE := $(LIBAWT_VERSIONINFO_RESOURCE), \
142152
EXTRA_RCFLAGS := $(LIBAWT_RCFLAGS), \
153+
STATIC_LIB_EXCLUDE_OBJS := $(LIBAWT_STATIC_EXCLUDE_OBJS), \
143154
))
144155

145156
TARGETS += $(BUILD_LIBAWT)

src/hotspot/os/aix/loadlib_aix.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
// For loadquery()
4343
#include <sys/ldr.h>
4444

45+
// For getargs()
46+
#include <procinfo.h>
47+
4548
// Use raw malloc instead of os::malloc - this code gets used for error reporting.
4649

4750
// A class to "intern" eternal strings.
@@ -205,6 +208,22 @@ static bool reload_table() {
205208

206209
trcVerbose("loadquery buffer size is %zu.", buflen);
207210

211+
// the entry for the executable itself does not contain a path.
212+
// instead we retrieve the path of the executable with the getargs API.
213+
static char pgmpath[PATH_MAX+1] = "";
214+
static char* pgmbase = nullptr;
215+
if (pgmpath[0] == 0) {
216+
procentry64 PInfo;
217+
PInfo.pi_pid = ::getpid();
218+
if (0 == ::getargs(&PInfo, sizeof(PInfo), (char*)pgmpath, PATH_MAX) && *pgmpath) {
219+
pgmpath[PATH_MAX] = '\0';
220+
pgmbase = strrchr(pgmpath, '/');
221+
if (pgmbase != nullptr) {
222+
pgmbase += 1;
223+
}
224+
}
225+
}
226+
208227
// Iterate over the loadquery result. For details see sys/ldr.h on AIX.
209228
ldi = (struct ld_info*) buffer;
210229

@@ -223,7 +242,12 @@ static bool reload_table() {
223242
lm->data = ldi->ldinfo_dataorg;
224243
lm->data_len = ldi->ldinfo_datasize;
225244

226-
lm->path = g_stringlist.add(ldi->ldinfo_filename);
245+
if (pgmbase != nullptr && 0 == strcmp(pgmbase, ldi->ldinfo_filename)) {
246+
lm->path = g_stringlist.add(pgmpath);
247+
} else {
248+
lm->path = g_stringlist.add(ldi->ldinfo_filename);
249+
}
250+
227251
if (!lm->path) {
228252
log_warning(os)("OOM.");
229253
free(lm);

0 commit comments

Comments
 (0)