<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hey David,</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">AFAICS java.library.path (and sun.boot.library.path) are input<br>properties that can be set by the user. There are no "default" values<br>for these properties as such.<br></blockquote><div><br></div><div>Although they can be set by the user, they have default values.<br></div><div>For Linux, the default value is set here:<br></div><div><br></div><div>    <a href="https://github.com/openjdk/jdk/blob/1cf9335b24639938aa64250d6862d9636f8605f8/src/hotspot/os/linux/os_linux.cpp#L532-L555">https://github.com/openjdk/jdk/blob/1cf9335b24639938aa64250d6862d9636f8605f8/src/hotspot/os/linux/os_linux.cpp#L532-L555</a><br></div><div><br></div><div>The default value on Linux is the LD_LIBRARY_PATH environment variable and the paths I mentioned earlier.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The library loading will ultimately rely<br>on the behaviour of dlopen, if no additional paths have been set, so it<br>seems to me what you really want is for dlopen to act "the same way"<br>that ld does. Note that dlopen will already check the contents of<br>/etc/ld.so.cache<br></blockquote><div><br></div><div>System.loadLibrary looks for the library in sun.boot.library.path and java.library.path and passes the full path to the library to dlopen:</div><div><br></div></div></div></div></div></div></div></div></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><a href="https://github.com/openjdk/jdk/blob/1cf9335b24639938aa64250d6862d9636f8605f8/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java#L246-L254">https://github.com/openjdk/jdk/blob/1cf9335b24639938aa64250d6862d9636f8605f8/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java#L246-L254</a><br></div><div><br></div></div></div></div></div></div></div></div></div></div></div></blockquote>Therefore, the behavior of finding native libraries has nothing to do with the behavior of dlopen, only sun.boot.library.path and java.library.path.</div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This does not seem practical. On my system ld.so.conf just contains<br><br>include ld.so.conf.d/*.conf<br><br>so now we (hotspot) have to read the top-level file, parse it, interpret<br>it and then recursively read, parse and interpret more files.<br></blockquote><div><br></div><div>Yes, this is exactly the behavior I want. </div><div><br></div><div>Glavo </div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 2, 2024 at 10:08 AM David Holmes <<a href="mailto:david.holmes@oracle.com">david.holmes@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Glavo,<br>
<br>
On 24/12/2023 4:18 am, Glavo wrote:<br>
> Hi,<br>
> <br>
> There are already many Linux distributions that are following the <br>
> multiarch-spec[1] and adding the following paths to the default library <br>
> path list:<br>
> <br>
>   * /usr/local/lib/<triplet><br>
>   * /lib/<triplet><br>
>   * /usr/lib/<triplet><br>
> <br>
> But OpenJDK doesn't add these paths to the java.library.path by default, <br>
> so System.loadLibrary(String) has annoying behavior differences with ld.<br>
<br>
AFAICS java.library.path (and sun.boot.library.path) are input <br>
properties that can be set by the user. There are no "default" values <br>
for these properties as such. The library loading will ultimately rely <br>
on the behaviour of dlopen, if no additional paths have been set, so it <br>
seems to me what you really want is for dlopen to act "the same way" <br>
that ld does. Note that dlopen will already check the contents of <br>
/etc/ld.so.cache<br>
<br>
> Many libraries already installed on the system cannot be found by <br>
> System.loadLibrary(String).<br>
> <br>
> I wish OpenJDK would parse the /etc/ld.so.conf to get the full library <br>
> path list so it would be consistent with the behavior of ld.<br>
> Can anyone consider this suggestion?<br>
<br>
This does not seem practical. On my system ld.so.conf just contains<br>
<br>
include ld.so.conf.d/*.conf<br>
<br>
so now we (hotspot) have to read the top-level file, parse it, interpret <br>
it and then recursively read, parse and interpret more files.<br>
<br>
Cheers,<br>
David<br>
----<br>
<br>
<br>
> Glavo<br>
> <br>
> [1]: <a href="https://wiki.ubuntu.com/MultiarchSpec" rel="noreferrer" target="_blank">https://wiki.ubuntu.com/MultiarchSpec</a> <br>
> <<a href="https://wiki.ubuntu.com/MultiarchSpec" rel="noreferrer" target="_blank">https://wiki.ubuntu.com/MultiarchSpec</a>><br>
</blockquote></div>