Skip to content

Commit 6808c5c

Browse files
Suchismith RoyTheRealMDoerr
authored andcommitted
8320005: Allow loading of shared objects with .a extension on AIX
Backport-of: e85355ada4ac1061c49ee9f1247d37a437c7b5ab
1 parent 910eb0e commit 6808c5c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/hotspot/os/aix/os_aix.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,10 +1313,9 @@ bool os::dll_address_to_library_name(address addr, char* buf,
13131313

13141314
// Loads .dll/.so and in case of error it checks if .dll/.so was built
13151315
// for the same architecture as Hotspot is running on.
1316-
void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
1316+
static void* dll_load_library(const char *filename, char *ebuf, int ebuflen) {
13171317

13181318
log_info(os)("attempting shared library load of %s", filename);
1319-
13201319
if (ebuf && ebuflen > 0) {
13211320
ebuf[0] = '\0';
13221321
ebuf[ebuflen - 1] = '\0';
@@ -1359,6 +1358,26 @@ void* os::dll_lookup(void* handle, const char* name) {
13591358
void* os::get_default_process_handle() {
13601359
return (void*)::dlopen(NULL, RTLD_LAZY);
13611360
}
1361+
// Load library named <filename>
1362+
// If filename matches <name>.so, and loading fails, repeat with <name>.a.
1363+
void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
1364+
void* result = nullptr;
1365+
char* const file_path = strdup(filename);
1366+
char* const pointer_to_dot = strrchr(file_path, '.');
1367+
const char old_extension[] = ".so";
1368+
const char new_extension[] = ".a";
1369+
STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension));
1370+
// First try to load the existing file.
1371+
result = dll_load_library(filename, ebuf, ebuflen);
1372+
// If the load fails,we try to reload by changing the extension to .a for .so files only.
1373+
// Shared object in .so format dont have braces, hence they get removed for archives with members.
1374+
if (result == nullptr && pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) {
1375+
snprintf(pointer_to_dot, sizeof(old_extension), "%s", new_extension);
1376+
result = dll_load_library(file_path, ebuf, ebuflen);
1377+
}
1378+
FREE_C_HEAP_ARRAY(char, file_path);
1379+
return result;
1380+
}
13621381

13631382
void os::print_dll_info(outputStream *st) {
13641383
st->print_cr("Dynamic libraries:");

0 commit comments

Comments
 (0)