<div dir="ltr">Hi Jiangli,<div><br></div><div>Thanks for sharing this info. I am wondering if you somehow create a symbol map that is used at link time? We use the same static compilation concept in openjdk/mobile, but simply linking `-ljava -lnio -lnet` etc will not include the native functions (e.g. Java_java_lang_reflect_Array_get) that are part of e.g. libjava.a etc, because they are not referenced.</div><div>This can be solved by telling the linker to use force_load (linux) but preferably, we don't want to load symbols that are not used in the final image. There used to be a function in the OpenJDK build process that creates a map with relevant symbols per static library, but I'm not sure it is still used?</div><div><br></div><div>- Johan</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Oct 15, 2025 at 2:21 AM Jiangli Zhou <<a href="mailto:jianglizhou@google.com">jianglizhou@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">CC'ing <a href="mailto:leyden-dev@openjdk.org" target="_blank">leyden-dev@openjdk.org</a><br>
<br>
Hi Ioi,<br>
<br>
For the current state of  JDK static linking support, the<br>
<a href="https://github.com/openjdk/leyden/tree/hermetic-java-runtime" rel="noreferrer" target="_blank">https://github.com/openjdk/leyden/tree/hermetic-java-runtime</a> is about<br>
the same as the JDK mainline. Most of the JDK libraries and libjvm are<br>
statically linked with the launcher. Please see additional comments<br>
below.<br>
<br>
On Tue, Oct 14, 2025 at 10:04 AM <<a href="mailto:ioi.lam@oracle.com" target="_blank">ioi.lam@oracle.com</a>> wrote:<br>
><br>
> Hi Jiangli,<br>
><br>
> I tried building with<br>
> <a href="https://github.com/openjdk/leyden/tree/hermetic-java-runtime" rel="noreferrer" target="_blank">https://github.com/openjdk/leyden/tree/hermetic-java-runtime</a> to see if I<br>
> can get a completely statically linked JVM, but the JVM is still<br>
> dynamically linked to a few shared libraries.<br>
<br>
Could you please elaborate on the specific libraries that you are<br>
looking into static linking as well? Such as libm, libasound, X11, ,<br>
etc? What are the specific benefits for statically linking with those?<br>
<br>
Do you have some context or details on what you are looking for?<br>
<br>
><br>
> Is it possible to do a static link (with "gcc-static ...")?<br>
<br>
If I understand the question correctly, -static-libgcc is the default<br>
when building JDK on Linux. See<br>
<a href="https://github.com/openjdk/jdk/blob/3d95c83b14cf9a6f683776053e57c07b1847cc17/make/autoconf/lib-std.m4#L50" rel="noreferrer" target="_blank">https://github.com/openjdk/jdk/blob/3d95c83b14cf9a6f683776053e57c07b1847cc17/make/autoconf/lib-std.m4#L50</a>.<br>
It's the case with linking the libjvm.so as well. E.g.:<br>
<br>
  g++ ... -static-libgcc -shared ... -Wl,-soname=libjvm.so -o<br>
support/modules_libs/java.base/server/libjvm.so ... -lm -ldl -lpthread<br>
-lrt -static-libstdc++<br>
<br>
<br>
Thanks,<br>
Jiangli<br>
<br>
><br>
> Thanks<br>
><br>
> - Ioi<br>
><br>
> $ bash configure<br>
> $ cd build/linux-x64<br>
> $ make static-jdk-bundles<br>
> $ ls -l build/linux-x64/images/static-jdk/bin/java<br>
> -rwxr-xr-x. 1 opc opc 34915696 Oct 14 08:55<br>
> build/linux-x64/images/static-jdk/bin/java<br>
> $ ldd images/static-jdk/bin/java<br>
>      linux-vdso.so.1 (0x000075aad82ca000)<br>
>      libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x000075aad64c3000)<br>
>      libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x000075aad829e000)<br>
>      libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x000075aad828b000)<br>
>      libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1<br>
> (0x000075aad827f000)<br>
>      libXtst.so.6 => /lib/x86_64-linux-gnu/libXtst.so.6 (0x000075aad8277000)<br>
>      libasound.so.2 => /lib/x86_64-linux-gnu/libasound.so.2<br>
> (0x000075aad63b9000)<br>
>      libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x000075aad8270000)<br>
>      libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6<br>
> (0x000075aad62ed000)<br>
>      libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0<br>
> (0x000075aad826b000)<br>
>      librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x000075aad8266000)<br>
>      libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x000075aad824a000)<br>
>      libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x000075aad6204000)<br>
>      libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000075aad5e00000)<br>
>      /lib64/ld-linux-x86-64.so.2 (0x000075aad82cc000)<br>
>      libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x000075aad61db000)<br>
>      libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0<br>
> (0x000075aad8234000)<br>
>      libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16<br>
> (0x000075aad61a3000)<br>
>      libbrotlidec.so.1 => /lib/x86_64-linux-gnu/libbrotlidec.so.1<br>
> (0x000075aad6195000)<br>
>      libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x000075aad822c000)<br>
>      libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6<br>
> (0x000075aad618d000)<br>
>      libbrotlicommon.so.1 => /lib/x86_64-linux-gnu/libbrotlicommon.so.1<br>
> (0x000075aad616a000)<br>
>      libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x000075aad6154000)<br>
>      libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x000075aad6145000)<br>
><br>
</blockquote></div>