On Tue, 15 Oct 2024 20:22:52 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).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Don't hardcode server variant

> > > When trying to sort out the LDFLAGS issues, it turned out that I could 
> > > not run the linux launcher at all, not even when checking out older 
> > > commits of this PR. I am almost at a loss here; I assume that this worked 
> > > when I created this PR (even though I only did ad hoc testing at the 
> > > time), and I'm not sure if my testing then was inadequate or if something 
> > > else has changed during that time with my environment.
> > > I'm trying to retrace my steps in how I got to this branch, but I have 
> > > unfortunately deleted much of the intermediate steps.
> > > @jianglizhou Can you check if you can build and run a simple 
> > > HelloWorld.java with the static launcher in this PR on linux? 
> > > `images/static-jdk/bin/java --version` works for me, but not 
> > > `images/static-jdk/bin/java HelloWorld.java`, which fails with an error 
> > > that indicates it cannot locate the jimage library.
> > 
> > 
> > @magicus I just noticed your above notes now (I'm been chasing an unrelated 
> > long G1 Evacuation Pause issue). I'll test your changes tomorrow. Will 
> > update you in the thread.
> 
> Sorry for the delay. I finally found some time to look into this today. 
> Running the latest `static-jdk` `bin/java` built from your branch fails for 
> me as well:
> 
> ```
> $ bin/java
> Error: failed , because bin/java: undefined symbol: JNI_CreateJavaVM
> ```
> 
> I only took a quick look, but I think this looks like 
> https://bugs.openjdk.org/browse/JDK-8339522 that I filed in September.
> 
> ```
> $ nm bin/java | grep JNI_CreateJavaVM
> 000000000162733c t JNI_CreateJavaVM
> 0000000001626e75 t _ZL22JNI_CreateJavaVM_innerPP7JavaVM_PPvS2_
> jianglizhou@leia:~/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/images/static-jdk$
>  nm -D bin/java | grep JNI_CreateJavaVM
> ```
> 
> The VM dynamic symbols are not exported properly. This is related to the 
> [#20837 
> (comment)](https://github.com/openjdk/jdk/pull/20837#discussion_r1744611776) 
> discussion comment thread.

Checking the `ld` command line, I think it is indeed 
https://bugs.openjdk.org/browse/JDK-8339522 issue. `-Wl,--exclude-libs,ALL` is 
included in the command:

$ cat ./support/static-native/launcher/BUILD_LAUNCHER_java_run_ld.cmdline
/usr/bin/gcc -Wl,-z,defs -Wl,-z,relro -Wl,-z,now -Wl,--no-as-needed 
-Wl,-z,noexecstack -m64 -pie -Wl,-z,defs -Wl,-z,relro -Wl,-z,now 
-Wl,--no-as-needed -Wl,--exclude-libs,ALL -Wl,-z,noexecstack -m64 
-Wl,-rpath,$ORIGIN -Wl,--disable-new-dtags -Wl,-rpath,$ORIGIN/../lib 
-Wl,--disable-new-dtags -o 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/static-native/launcher/java
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/static-native/launcher/main.o
 -Wl,--export-dynamic -Wl,--whole-archive 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.base/libverify/static/libverify.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.base/libjava/static/libjava.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.base/libzip/static/libzip.a
 /...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-sl
 owdebug/support/native/java.base/libjimage/static/libjimage.a 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.base/libjli/static/libjli.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.base/libnet/static/libnet.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.base/libnio/static/libnio.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.base/libjsig/static/libjsig.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.base/libsyslookup/static/libsyslookup.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.base/libsimdsort/static/libsimdsort.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.desktop/libawt/static/libawt.a
 /...jianglizhou/github/jdk_pull_20837/build/linux-x86_
 
64-server-slowdebug/support/native/java.desktop/libawt_xawt/static/libawt_xawt.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.desktop/libjawt/static/libjawt.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.desktop/libmlib_image/static/libmlib_image.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.desktop/liblcms/static/liblcms.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.desktop/libjavajpeg/static/libjavajpeg.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.desktop/libfontmanager/static/libfontmanager.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.desktop/libjsound/static/libjsound.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.instrument/libinstrume
 nt/static/libinstrument.a 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.management/libmanagement/static/libmanagement.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.prefs/libprefs/static/libprefs.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.rmi/librmi/static/librmi.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.security.jgss/libj2gss/static/libj2gss.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/java.smartcardio/libj2pcsc/static/libj2pcsc.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/jdk.attach/libattach/static/libattach.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/jdk.crypto.cryptoki/libj2pkcs11/static/libj2pkcs11.a
 /...jianglizhou/github/jdk_pull_20837/bu
 
ild/linux-x86_64-server-slowdebug/support/native/jdk.hotspot.agent/libsaproc/static/libsaproc.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/jdk.incubator.vector/libjsvml/static/libjsvml.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/jdk.jdwp.agent/libdt_socket/static/libdt_socket.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/jdk.jdwp.agent/libjdwp/static/libjdwp.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/jdk.management/libmanagement_ext/static/libmanagement_ext.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/jdk.management.agent/libmanagement_agent/static/libmanagement_agent.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/jdk.net/libextnet/static/libextnet.a
 /...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-serve
 r-slowdebug/support/native/jdk.sctp/libsctp/static/libsctp.a 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/support/native/jdk.security.auth/libjaas/static/libjaas.a
 
/...jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/hotspot/variant-server/libjvm/objs/static/libjvm.a
 -Wl,--no-whole-archive -lX11 -lXext -lXi -lXrender -lXtst -lasound -ldl 
-lfreetype -lm -lpthread -lrt -lz -static-libgcc -static-libstdc++ 
-l:libstdc++.a -lz -ldl -lpthread

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

PR Comment: https://git.openjdk.org/jdk/pull/20837#issuecomment-2436518730

Reply via email to