Hi,
Wikipedia has to say:
The ld dynamic linker does not search DT_RUNPATH locations for
transitive dependencies, unlike DT_RPATH
And refers to this Ubuntu issue:
https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/1253638
The TL;DR version:
RUNPATH definitions only apply to direct dependencies and RPATH applies
also to transitive dependencies.
There are more subtle differences, but it is the key point from my POV.
Testing can be done by following this stackoverflow answer:
https://stackoverflow.com/questions/13769141/can-i-change-rpath-in-an-already-compiled-binary
matthias@enterprise:~$ readelf -d /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java | grep "R*PATH"
0x000000000000001d (RUNPATH) Bibliothek runpath: [$ORIGIN/../lib/jli:$ORIGIN/../lib]
matthias@enterprise:~$ sudo patchelf --remove-rpath /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java
matthias@enterprise:~$ readelf -d /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java | grep "R*PATH"
matthias@enterprise:~$ sudo patchelf --force-rpath --set-rpath '$ORIGIN/../lib/jli:$ORIGIN/../lib' /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java
matthias@enterprise:~$ readelf -d /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java | grep "R*PATH"
0x000000000000000f (RPATH) Bibliothek rpath: [$ORIGIN/../lib/jli:$ORIGIN/../lib]
matthias@enterprise:~$
This moves the RUNPATH to RPATH and in my tests this is enough to fix
the issue.
So this is my take on the situation:
- Native#getWindowHandle0 calls into the native object libjnidispatch.so
- libjnidispatch.so tries to load libjawt.so
so the loading object of libjawt.so is libjnidispatch.so and here comes
the difference between RPATH and RUNPATH into play.
RPATH comes from the java binary and thus points to the right directory
(for the Ubuntu JDK: /usr/lib/jvm/java-1.11.0-openjdk-
amd64/bin/../lib). It is transitive thus libjawt is found.
RUNPATH is not transitive and the calling binary is libjnidispatch.so.
This library has no RUNPATH and no RPATH set, so dl_open must find the
library by conventional means.
So IMHO the distribution build is broken. I think it is a reasonable
expectation, that I can load jawt in a headful environment without
jumping through hoops.
Greetings
Matthias