RFR: JDK-8293659: Improve UnsatisfiedLinkError error message to include dlopen error details

Thomas Stuefe stuefe at openjdk.org
Sat Sep 17 07:03:48 UTC 2022


On Thu, 15 Sep 2022 17:56:09 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> When trying to load a x64 lib on macOS aarch64 one got previously this detailed message before [JDK-8275703](https://bugs.openjdk.org/browse/JDK-8275703):
>> 
>> java.lang.UnsatisfiedLinkError: /testing/jco3/macOsx64/libsapjco3.dylib: dlopen(/testing/jco3/macOsx64/libsapjco3.dylib, 1): no suitable image found. Did find:
>
> Adding the background and details for this review:
> 
> The `throwException` parameter in `JVM_LoadLibrary` was added to support dynamic linker cache.   dlopen may succeed when the given path does not exist but in the dynamic linker cache.   `System::loadLibrary` on macOS that supports dynamic linker cache calls `JVM_LoadLibrary` with `throwException == false` and so VM doesn't throw  `UnsatisfiedLinkException`.  Instead the libraries code throws `UnsatisfiedLinkException` if it fails to load the library.
> 
> For this issue,  a library to be loaded exists.    A simple fix is to call `JVM_LoadLibrary` with throwException = true (if file exists) such that the VM throws `UnsatisfiedLinkException` with the detailed error message.

Hi @mlchung,

I tried to understand this, and your fix for JDK-8275703 (https://github.com/openjdk/jdk/pull/6127). What I don't understand is why we suppressed the exception in JVM_LoadLibrary in the first place.

So, in Big Sur dlopen could succeed if the library is not present in the file system. Therefore we have to omit the file exists check before attempting to dlopen. That makes sense.

Then we attempt to load the library, dive into JVM_LoadLibrary->os::dll_load(), and do a dlopen(), which could succeed or fail. If it succeeds, all is well. If it fails, os::dll_load() just returns dlerror() to JVM_LoadLibrary, which packs the error string into an exception and throws it.

But why did we have to prevent the exception in JVM_LoadLibrary at that point? As it is now, we don't get error details on systems with a dynamic loader cache, since we throw away the dlerror output?

-------------

PR: https://git.openjdk.org/jdk/pull/10286


More information about the core-libs-dev mailing list