RFR: 8328630: Add logging when needed symbols in dll are missing. [v2]

Robbin Ehn rehn at openjdk.org
Mon Mar 25 07:51:22 UTC 2024


On Mon, 25 Mar 2024 01:15:49 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> Here is the data: Avg:187.913 ns Sum:40965 ns
>> 
>> Want me to add the guard? I don't mind.
>
> Sorry Robbin can you just re-explain why we need the initial call to `dl_error` here please. If the `dl_sym` is successful then we shouldn't be checking `dl_error`; and if not successful then `dl_error` should be returning that most recent failure.

Hey, David, sure.

The dl error string is only cleared by dlerror.
It can be set by dlopen/dlsym/dlclose on error (but never cleared by these).
If someone used any of these before your call and failed, skipped calling dlerror,
there might be a pending error string.

dlsym returns NULL on ERROR, but the value of a symbol may also be NULL.

This means we need to use both dlerror return value plus dlsym return value to figure out what was going on.
dlsym = NULL, dlerror = NULL   => symbol was NULL
dlsym = NULL, dlerror = "error" => real error
dlsym = pointer, dlerror = ignored = found usable symbol

"Since the value of the symbol could actually be NULL (so that a NULL return from dlsym() need not indicate an error), the correct way to test for an error is to call dlerror() to clear any old error conditions, then call dlsym(), and then call dlerror() again, saving its return value into a variable, and check whether this saved value is not NULL."

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18404#discussion_r1537161892


More information about the hotspot-runtime-dev mailing list