On Wed, 21 Aug 2024 22:14:40 GMT, Magnus Ihse Bursie <i...@openjdk.org> wrote:

>> As a preparation for Hermetic Java, we need to have a way to look up during 
>> runtime if we are using a statically linked library or not.
>> 
>> This change will be the first step needed towards compiling the object files 
>> only once, and then link them into either dynamic or static libraries. (The 
>> only exception will be the linktype.c[pp] files, which needs to be compiled 
>> twice, once for the dynamic libraries and once for the static libraries.) 
>> Getting there will require further work though. 
>> 
>> This is part of the changes that make up the draft PR 
>> https://github.com/openjdk/jdk/pull/19478, which I have broken out.
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Also update build to link properly

src/java.desktop/unix/native/libawt/awt/awt_LoadLibrary.c line 135:

> 133: #endif
> 134: 
> 135:     if (!JVM_IsStaticallyLinked()) {

These "cross-library" link-type probes are a challenge for GraalVM native 
image. In native image, we statically link most standard JNI libraries into the 
final executable. However in some cases, for example AWT, static linking is not 
feasible due to their dependencies. Thus, we resort to dynamic linking. Have a 
mix of static and dynamic linking means that `JVM_IsStaticallyLinked` should 
give different answers based on the caller. Example:
lets assume a follow-up change introduces a call to `JVM_IsStaticallyLinked` in 
libnet (which native image statically links):
* if `JVM_IsStaticallyLinked` is called from libawt.so, we want to answer 
`false`
* if `JVM_IsStaticallyLinked` is called from libnet.a, we want to answer `true`

Is the mixed linking use case is something that the Hermetic Java effort is 
having on its radar?

For this particular case, one solutions could be to avoid cross-library calls. 
I.e., instead of calling `JVM_IsStaticallyLinked`, have an 
`AWT_IsStaticallyLinked` that is local to the libawt. This is similar to the 
pattern also used for JLI.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20666#discussion_r1752023584

Reply via email to