From 0bf2650bb1a3d5dc0702ad75413aff3eb60fd206 Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Wed, 5 Jun 2019 16:53:52 +0200 Subject: [PATCH] 8224958: add os::dll_load calls to event log Reviewed-by: dholmes, mdoerr, stuefe --- src/hotspot/os/aix/os_aix.cpp | 9 ++++++-- src/hotspot/os/bsd/os_bsd.cpp | 30 ++++++++++++++++++++------- src/hotspot/os/linux/os_linux.cpp | 13 ++++++++++-- src/hotspot/os/solaris/os_solaris.cpp | 15 ++++++++++---- src/hotspot/os/windows/os_windows.cpp | 13 ++++++------ 5 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/hotspot/os/aix/os_aix.cpp b/src/hotspot/os/aix/os_aix.cpp index 9762e0787dd..0117f121950 100644 --- a/src/hotspot/os/aix/os_aix.cpp +++ b/src/hotspot/os/aix/os_aix.cpp @@ -1327,16 +1327,21 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) { // RTLD_LAZY is currently not implemented. The dl is loaded immediately with all its dependants. void * result= ::dlopen(filename, RTLD_LAZY); if (result != NULL) { + Events::log(NULL, "Loaded shared library %s", filename); // Reload dll cache. Don't do this in signal handling. LoadedLibraries::reload(); return result; } else { // error analysis when dlopen fails - const char* const error_report = ::dlerror(); - if (error_report && ebuf && ebuflen > 0) { + const char* error_report = ::dlerror(); + if (error_report == NULL) { + error_report = "dlerror returned no error description"; + } + if (ebuf != NULL && ebuflen > 0) { snprintf(ebuf, ebuflen - 1, "%s, LIBPATH=%s, LD_LIBRARY_PATH=%s : %s", filename, ::getenv("LIBPATH"), ::getenv("LD_LIBRARY_PATH"), error_report); } + Events::log(NULL, "Loading shared library %s failed, %s", filename, error_report); } return NULL; } diff --git a/src/hotspot/os/bsd/os_bsd.cpp b/src/hotspot/os/bsd/os_bsd.cpp index a707fe38452..713a9c0842c 100644 --- a/src/hotspot/os/bsd/os_bsd.cpp +++ b/src/hotspot/os/bsd/os_bsd.cpp @@ -1265,13 +1265,21 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { #else void * result= ::dlopen(filename, RTLD_LAZY); if (result != NULL) { + Events::log(NULL, "Loaded shared library %s", filename); // Successful loading return result; } - // Read system error message into ebuf - ::strncpy(ebuf, ::dlerror(), ebuflen-1); - ebuf[ebuflen-1]='\0'; + const char* error_report = ::dlerror(); + if (error_report == NULL) { + error_report = "dlerror returned no error description"; + } + if (ebuf != NULL && ebuflen > 0) { + // Read system error message into ebuf + ::strncpy(ebuf, error_report, ebuflen-1); + ebuf[ebuflen-1]='\0'; + } + Events::log(NULL, "Loading shared library %s failed, %s", filename, error_report); return NULL; #endif // STATIC_BUILD @@ -1283,16 +1291,24 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { #else void * result= ::dlopen(filename, RTLD_LAZY); if (result != NULL) { + Events::log(NULL, "Loaded shared library %s", filename); // Successful loading return result; } Elf32_Ehdr elf_head; - // Read system error message into ebuf - // It may or may not be overwritten below - ::strncpy(ebuf, ::dlerror(), ebuflen-1); - ebuf[ebuflen-1]='\0'; + const char* const error_report = ::dlerror(); + if (error_report == NULL) { + error_report = "dlerror returned no error description"; + } + if (ebuf != NULL && ebuflen > 0) { + // Read system error message into ebuf + ::strncpy(ebuf, error_report, ebuflen-1); + ebuf[ebuflen-1]='\0'; + } + Events::log(NULL, "Loading shared library %s failed, %s", filename, error_report); + int diag_msg_max_length=ebuflen-strlen(ebuf); char* diag_msg_buf=ebuf+strlen(ebuf); diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 8cb3221214f..439f6b781d1 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -1881,8 +1881,17 @@ void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) { void * result = ::dlopen(filename, RTLD_LAZY); if (result == NULL) { - ::strncpy(ebuf, ::dlerror(), ebuflen - 1); - ebuf[ebuflen-1] = '\0'; + const char* error_report = ::dlerror(); + if (error_report == NULL) { + error_report = "dlerror returned no error description"; + } + if (ebuf != NULL && ebuflen > 0) { + ::strncpy(ebuf, error_report, ebuflen-1); + ebuf[ebuflen-1]='\0'; + } + Events::log(NULL, "Loading shared library %s failed, %s", filename, error_report); + } else { + Events::log(NULL, "Loaded shared library %s", filename); } return result; } diff --git a/src/hotspot/os/solaris/os_solaris.cpp b/src/hotspot/os/solaris/os_solaris.cpp index 9c85277a037..4c0ade1d760 100644 --- a/src/hotspot/os/solaris/os_solaris.cpp +++ b/src/hotspot/os/solaris/os_solaris.cpp @@ -1528,15 +1528,22 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { void * result= ::dlopen(filename, RTLD_LAZY); if (result != NULL) { // Successful loading + Events::log(NULL, "Loaded shared library %s", filename); return result; } Elf32_Ehdr elf_head; + const char* error_report = ::dlerror(); + if (error_report == NULL) { + error_report = "dlerror returned no error description"; + } + if (ebuf != NULL && ebuflen > 0) { + ::strncpy(ebuf, error_report, ebuflen-1); + ebuf[ebuflen-1]='\0'; + } + + Events::log(NULL, "Loading shared library %s failed, %s", filename, error_report); - // Read system error message into ebuf - // It may or may not be overwritten below - ::strncpy(ebuf, ::dlerror(), ebuflen-1); - ebuf[ebuflen-1]='\0'; int diag_msg_max_length=ebuflen-strlen(ebuf); char* diag_msg_buf=ebuf+strlen(ebuf); diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 2a300e1e0d6..b3c89df7c50 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -1367,12 +1367,18 @@ static int _print_module(const char* fname, address base_address, void * os::dll_load(const char *name, char *ebuf, int ebuflen) { void * result = LoadLibrary(name); if (result != NULL) { + Events::log(NULL, "Loaded shared library %s", name); // Recalculate pdb search path if a DLL was loaded successfully. SymbolEngine::recalc_search_path(); return result; } - DWORD errcode = GetLastError(); + // Read system error message into ebuf + // It may or may not be overwritten below (in the for loop and just above) + lasterror(ebuf, (size_t) ebuflen); + ebuf[ebuflen - 1] = '\0'; + Events::log(NULL, "Loading shared library %s failed, error code %lu", name, errcode); + if (errcode == ERROR_MOD_NOT_FOUND) { strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1); ebuf[ebuflen - 1] = '\0'; @@ -1384,11 +1390,6 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) { // for an architecture other than Hotspot is running in // - then print to buffer "DLL was built for a different architecture" // else call os::lasterror to obtain system error message - - // Read system error message into ebuf - // It may or may not be overwritten below (in the for loop and just above) - lasterror(ebuf, (size_t) ebuflen); - ebuf[ebuflen - 1] = '\0'; int fd = ::open(name, O_RDONLY | O_BINARY, 0); if (fd < 0) { return NULL;