On Tue, 3 Sep 2024 12:50:01 GMT, Magnus Ihse Bursie <i...@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. make/StaticLibs.gmk line 71: > 69: # libsspi_bridge has name conflicts with sunmscapi > 70: BROKEN_STATIC_LIBS += sspi_bridge > 71: # These libs define DllMain which conflict with Hotspot I'm not aware of the DllMain issue with static linking these libs. Could you please explain? The libawt.a and libdt_socket.a are statically linked with `javastatic` in https://github.com/openjdk/leyden/tree/hermetic-java-runtime/ branch. make/StaticLibs.gmk line 74: > 72: BROKEN_STATIC_LIBS += awt dt_shmem dt_socket javaaccessbridge > 73: # These libs are dependent on any of the above disabled libs > 74: BROKEN_STATIC_LIBS += fontmanager jawt lcms net nio Which specific dependent cause these libs being excluded? In https://github.com/openjdk/leyden/tree/hermetic-java-runtime/ branch, these JDK libs (except `libjawt.a`) are statically linked into `javastatic`. 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. make/modules/java.desktop/lib/AwtLibraries.gmk line 176: > 174: > 175: ifneq ($(ENABLE_HEADLESS_ONLY), true) > 176: # We cannot link with both awt_headless and awt_xawt at the same time Just a note on that. It's doable to link with both awt_headless and awt_xawt with some work. I did some quick experiments on that during the initial investigation for hermetic/static Java. src/java.base/unix/native/libjli/java_md.c line 300: > 298: char jvmcfg[], jint so_jvmcfg) { > 299: /* Compute/set the name of the executable. This is needed for macOS. > */ > 300: SetExecname(*pargv); Why is `SetExecname()` needed for the static case? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/20837#discussion_r1744614583 PR Review Comment: https://git.openjdk.org/jdk/pull/20837#discussion_r1744604685 PR Review Comment: https://git.openjdk.org/jdk/pull/20837#discussion_r1744603414 PR Review Comment: https://git.openjdk.org/jdk/pull/20837#discussion_r1744611776 PR Review Comment: https://git.openjdk.org/jdk/pull/20837#discussion_r1744616878 PR Review Comment: https://git.openjdk.org/jdk/pull/20837#discussion_r1744620611