Skip to content

Commit c1c8064

Browse files
Suchismith Royjerboaa
authored andcommitted
8320005: Allow loading of shared objects with .a extension on AIX
Reviewed-by: sgehwolf Backport-of: e85355ada4ac1061c49ee9f1247d37a437c7b5ab
1 parent d0d9a15 commit c1c8064

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

hotspot/src/os/aix/vm/os_aix.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright 2012, 2014 SAP AG. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -1452,7 +1452,7 @@ bool os::dll_address_to_library_name(address addr, char* buf,
14521452

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

14571457
if (ebuf && ebuflen > 0) {
14581458
ebuf[0] = '\0';
@@ -1480,6 +1480,26 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
14801480
}
14811481
return NULL;
14821482
}
1483+
// Load library named <filename>
1484+
// If filename matches <name>.so, and loading fails, repeat with <name>.a.
1485+
void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
1486+
void* result = nullptr;
1487+
char* const file_path = strdup(filename);
1488+
char* const pointer_to_dot = strrchr(file_path, '.');
1489+
const char old_extension[] = ".so";
1490+
const char new_extension[] = ".a";
1491+
STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension));
1492+
// First try to load the existing file.
1493+
result = dll_load_library(filename, ebuf, ebuflen);
1494+
// If the load fails,we try to reload by changing the extension to .a for .so files only.
1495+
// Shared object in .so format dont have braces, hence they get removed for archives with members.
1496+
if (result == nullptr && pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) {
1497+
snprintf(pointer_to_dot, sizeof(old_extension), "%s", new_extension);
1498+
result = dll_load_library(file_path, ebuf, ebuflen);
1499+
}
1500+
FREE_C_HEAP_ARRAY(char, file_path);
1501+
return result;
1502+
}
14831503

14841504
// Glibc-2.0 libdl is not MT safe. If you are building with any glibc,
14851505
// chances are you might want to run the generated bits against glibc-2.0

0 commit comments

Comments
 (0)