From d3d5cfe523de751b89208b6f3940ee79b093304d Mon Sep 17 00:00:00 2001 From: suchismith1993 Date: Mon, 25 Mar 2024 12:56:35 +0000 Subject: [PATCH] Backport e85355ada4ac1061c49ee9f1247d37a437c7b5ab --- src/hotspot/os/aix/os_aix.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/hotspot/os/aix/os_aix.cpp b/src/hotspot/os/aix/os_aix.cpp index 104bf127c27..7104b7e3b81 100644 --- a/src/hotspot/os/aix/os_aix.cpp +++ b/src/hotspot/os/aix/os_aix.cpp @@ -1144,12 +1144,13 @@ bool os::dll_address_to_library_name(address addr, char* buf, return AixSymbols::get_module_name(addr, buf, buflen); } + + // Loads .dll/.so and in case of error it checks if .dll/.so was built // for the same architecture as Hotspot is running on. -void *os::dll_load(const char *filename, char *ebuf, int ebuflen) { - +static void* dll_load_library(const char *filename, char *ebuf, int ebuflen) { + printf("cjeclomg dll_load here %s",filename); log_info(os)("attempting shared library load of %s", filename); - if (ebuf && ebuflen > 0) { ebuf[0] = '\0'; ebuf[ebuflen - 1] = '\0'; @@ -1160,6 +1161,9 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) { return NULL; } + + + // RTLD_LAZY is currently not implemented. The dl is loaded immediately with all its dependants. void * result= ::dlopen(filename, RTLD_LAZY); if (result != NULL) { @@ -1184,6 +1188,26 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) { return NULL; } +// Load library named +// If filename matches .so, and loading fails, repeat with .a. +void *os::dll_load(const char *filename, char *ebuf, int ebuflen) { + void* result = nullptr; + char* const file_path = strdup(filename); + char* const pointer_to_dot = strrchr(file_path, '.'); + const char old_extension[] = ".so"; + const char new_extension[] = ".a"; + STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension)); + // First try to load the existing file. + result = dll_load_library(filename, ebuf, ebuflen); + // If the load fails,we try to reload by changing the extension to .a for .so files only. + // Shared object in .so format dont have braces, hence they get removed for archives with members. + if (result == nullptr && pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) { + snprintf(pointer_to_dot, sizeof(old_extension), "%s", new_extension); + result = dll_load_library(file_path, ebuf, ebuflen); + } + FREE_C_HEAP_ARRAY(char, file_path); + return result; +} void os::print_dll_info(outputStream *st) { st->print_cr("Dynamic libraries:"); LoadedLibraries::print(st);