diff --git a/src/os/bsd/vm/os_bsd.cpp b/src/os/bsd/vm/os_bsd.cpp index 1bea78444a8eb56614149ae3f4e1692e7d4332c7..47e5d16efdc820b6ccd2d54fe7acfee044132b85 100644 --- a/src/os/bsd/vm/os_bsd.cpp +++ b/src/os/bsd/vm/os_bsd.cpp @@ -1557,6 +1557,17 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) } #endif /* !__APPLE__ */ +void* os::get_default_process_handle() { +#ifdef __APPLE__ + // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY + // to avoid finding unexpected symbols on second (or later) + // loads of a library. + return (void*)::dlopen(NULL, RTLD_FIRST); +#else + return (void*)::dlopen(NULL, RTLD_LAZY); +#endif +} + // XXX: Do we need a lock around this as per Linux? void* os::dll_lookup(void* handle, const char* name) { return dlsym(handle, name); diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp index 1bb32901540d3be0c511dc297e3d664144da9158..54149e1825331655c701a4dd98445c881b25e0af 100644 --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -2104,6 +2104,9 @@ void* os::dll_lookup(void* handle, const char* name) { return res; } +void* os::get_default_process_handle() { + return (void*)::dlopen(NULL, RTLD_LAZY); +} static bool _print_ascii_file(const char* filename, outputStream* st) { int fd = ::open(filename, O_RDONLY); diff --git a/src/os/posix/vm/os_posix.cpp b/src/os/posix/vm/os_posix.cpp index 6aae96e9b8989ee6d10507dfcd3d51d59aa7a90c..633331728935616a5c46599bafbe64d329c066f4 100644 --- a/src/os/posix/vm/os_posix.cpp +++ b/src/os/posix/vm/os_posix.cpp @@ -262,10 +262,6 @@ FILE* os::open(int fd, const char* mode) { return ::fdopen(fd, mode); } -void* os::get_default_process_handle() { - return (void*)::dlopen(NULL, RTLD_LAZY); -} - // Builds a platform dependent Agent_OnLoad_ function name // which is used to find statically linked in agents. // Parameters: diff --git a/src/os/solaris/vm/os_solaris.cpp b/src/os/solaris/vm/os_solaris.cpp index 8e5984ffa3d93d609f20b2e8a13c24a535da39a9..a4d0178c8874c7e34ede94b1c63ad55292319ab3 100644 --- a/src/os/solaris/vm/os_solaris.cpp +++ b/src/os/solaris/vm/os_solaris.cpp @@ -2146,6 +2146,10 @@ void* os::dll_lookup(void* handle, const char* name) { return dlsym(handle, name); } +void* os::get_default_process_handle() { + return (void*)::dlopen(NULL, RTLD_LAZY); +} + int os::stat(const char *path, struct stat *sbuf) { char pathbuf[MAX_PATH]; if (strlen(path) > MAX_PATH - 1) {