On Wed, 4 Sep 2024 23:24:13 GMT, Jiangli Zhou <jian...@openjdk.org> wrote:

>> As a prerequisite for Hermetic Java, we need a statically linked `java` 
>> launcher. It should behave like the normal, dynamically linked `java` 
>> launcher, except that all JDK native libraries should be statically, not 
>> dynamically, linked.
>> 
>> This patch is the first step towards this goal. It will generate a 
>> `static-jdk` image with a statically linked launcher. This launcher is 
>> missing several native libs, however, and does therefore not behave like a 
>> proper dynamic java. One of the reasons for this is that local symbol hiding 
>> in static libraries are not implemented yet, which causes symbol clashes 
>> when linking all static libraries together. This will be addressed in an 
>> upcoming patch. 
>> 
>> All changes in the `src` directory are copied from, or inspired by, changes 
>> made in [the hermetic-java-runtime branch in Project 
>> Leyden](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> make/StaticLibs.gmk line 1:
> 
>> 1: #
> 
> Perhaps also consider adopting StaticLink.gmk file name from the 
> https://github.com/openjdk/leyden/tree/hermetic-java-runtime/ branch, as we 
> are mostly doing the static linking here. Creating the static libs is handled 
> elsewhere.

My intention is to move all relevant handling of static linking into this file.

> make/StaticLibs.gmk line 118:
> 
>> 116:     OPTIMIZATION := HIGH, \
>> 117:     STATIC_LAUNCHER := true, \
>> 118:     LDFLAGS := $(JAVASTATIC_LINK_LDFLAGS), \
> 
> I could be missing something, but I don't see where is 
> $JAVASTATIC_LINK_LDFLAGS defined.
> 
> On a related notes, I think we need to include $JVM_LDFLAGS when linking the 
> static "java". See 
> https://bugs.openjdk.org/browse/JDK-8339522?focusedId=14702923&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14702923.

You are right, this is dead code. Thanks for spotting this. 

During my experimentation, I tried passing along LDFLAGS from the individual 
libraries as well, but it turned out not to be a good idea -- the way we have 
used them were to modify some special properties on a single dynamic library, 
which did not apply to the static library as a whole.

However, there is a risk that we in the future need to add LDFLAGS to a library 
that also needs to be carried over to the static launcher. If this happens, I 
guess we need to separate between LDFLAGS_ONLY_FOR_THIS_DLL and 
LDFLAGS_ALSO_FOR_STATIC_LINKING.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20837#discussion_r1745180739
PR Review Comment: https://git.openjdk.org/jdk/pull/20837#discussion_r1745180044

Reply via email to