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

David Holmes dholmes at openjdk.org
Thu Mar 28 12:29:32 UTC 2024


On Thu, 28 Mar 2024 09:26:54 GMT, Robbin Ehn <rehn at openjdk.org> wrote:

>> 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."
>
> Make sense?

Not from a programming perspective! That would be like successful syscalls not resetting errno to zero. Then again maybe they don't? Hmmm.

If this returns the last error that ever happened then all uses of the potential error producing functions should always be followed by a call to `dlerror` if an error occurred. I'm guessing we don't actually do that? So the one place we do check has to make a dummy call to clear the error first - blegghh! :(

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

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


More information about the hotspot-runtime-dev mailing list