8313616: support loading library members on AIX in os::dll_load

Reviewed-by: mdoerr
This commit is contained in:
Matthias Baesken 2023-08-10 12:06:43 +00:00
parent f47767ffef
commit 23fe2ece58
3 changed files with 22 additions and 11 deletions

View File

@ -29,13 +29,16 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <string.h> #include <string.h>
#include "runtime/arguments.hpp" #include "runtime/arguments.hpp"
#include "runtime/os.hpp"
dynamicOdm::dynamicOdm() { dynamicOdm::dynamicOdm() {
const char* libodmname = "/usr/lib/libodm.a(shr_64.o)"; const char* libodmname = "/usr/lib/libodm.a(shr_64.o)";
_libhandle = dlopen(libodmname, RTLD_MEMBER | RTLD_NOW); char ebuf[512];
void* _libhandle = os::dll_load(libodmname, ebuf, sizeof(ebuf));
if (!_libhandle) { if (!_libhandle) {
trcVerbose("Couldn't open %s", libodmname); trcVerbose("Cannot load %s (error %s)", libodmname, ebuf);
return; return;
} }
_odm_initialize = (fun_odm_initialize )dlsym(_libhandle, "odm_initialize" ); _odm_initialize = (fun_odm_initialize )dlsym(_libhandle, "odm_initialize" );

View File

@ -26,6 +26,7 @@
#include "libperfstat_aix.hpp" #include "libperfstat_aix.hpp"
#include "misc_aix.hpp" #include "misc_aix.hpp"
#include "runtime/os.hpp"
#include <dlfcn.h> #include <dlfcn.h>
@ -71,11 +72,11 @@ static fun_perfstat_reset_t g_fun_perfstat_reset = nullptr;
static fun_wpar_getcid_t g_fun_wpar_getcid = nullptr; static fun_wpar_getcid_t g_fun_wpar_getcid = nullptr;
bool libperfstat::init() { bool libperfstat::init() {
const char* libperfstat = "/usr/lib/libperfstat.a(shr_64.o)";
// Dynamically load the libperfstat porting library. char ebuf[512];
g_libhandle = dlopen("/usr/lib/libperfstat.a(shr_64.o)", RTLD_MEMBER | RTLD_NOW); g_libhandle = os::dll_load(libperfstat, ebuf, sizeof(ebuf));
if (!g_libhandle) { if (!g_libhandle) {
trcVerbose("Cannot load libperfstat.a (dlerror: %s)", dlerror()); trcVerbose("Cannot load %s (error: %s)", libperfstat, ebuf);
return false; return false;
} }

View File

@ -1101,8 +1101,6 @@ bool os::dll_address_to_library_name(address addr, char* buf,
return true; return true;
} }
// 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) { void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
log_info(os)("attempting shared library load of %s", filename); log_info(os)("attempting shared library load of %s", filename);
@ -1122,8 +1120,17 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
event.set_name(filename); event.set_name(filename);
#endif #endif
// RTLD_LAZY is currently not implemented. The dl is loaded immediately with all its dependants. // RTLD_LAZY has currently the same behavior as RTLD_NOW
void * result= ::dlopen(filename, RTLD_LAZY); // The dl is loaded immediately with all its dependants.
int dflags = RTLD_LAZY;
// check for filename ending with ')', it indicates we want to load
// a MEMBER module that is a member of an archive.
int flen = strlen(filename);
if (flen > 0 && filename[flen - 1] == ')') {
dflags |= RTLD_MEMBER;
}
void * result= ::dlopen(filename, dflags);
if (result != nullptr) { if (result != nullptr) {
Events::log_dll_message(nullptr, "Loaded shared library %s", filename); Events::log_dll_message(nullptr, "Loaded shared library %s", filename);
// Reload dll cache. Don't do this in signal handling. // Reload dll cache. Don't do this in signal handling.