<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    Hi Jiangli,<br>
    <br>
    <p>We were trying to run the JVM on a "scratch" container image (
      <a class="moz-txt-link-freetext" href="https://hub.docker.com/_/scratch">https://hub.docker.com/_/scratch</a> )  but were running into problems
      with missing shared libraries.</p>
    <p>At first we tried to build the JVM into a static executable, but
      that turns out to be more complicated that we thought.</p>
    <p>We ended up simply copying the shared libraries from the build
      host into the docker image and that seemed to work for our use
      case.</p>
    <p>
      <blockquote type="cite">
        <pre style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">If I understand the question correctly, -static-libgcc is the default
when building JDK on Linux. </pre>
      </blockquote>
      <br>
      <br>
      -static-libgcc affects only libgcc.a. To link all the other
      libraries (such as libc) statically, "g++ -static" need to be
      used.</p>
    <p><br>
    </p>
    <p>Thanks</p>
    <p>- Ioi</p>
    <p><br>
    </p>
    <br>
    <blockquote type="cite">
      <pre style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">CC'ing <a href="https://mail.openjdk.org/mailman/listinfo/leyden-dev">leyden-dev at openjdk.org</a>
Hi Ioi,
For the current state of  JDK static linking support, the
<a href="https://github.com/openjdk/leyden/tree/hermetic-java-runtime" class="moz-txt-link-freetext">https://github.com/openjdk/leyden/tree/hermetic-java-runtime</a> is about
the same as the JDK mainline. Most of the JDK libraries and libjvm are
statically linked with the launcher. Please see additional comments
below.
On Tue, Oct 14, 2025 at 10:04 AM <<a href="https://mail.openjdk.org/mailman/listinfo/leyden-dev">ioi.lam at oracle.com</a>> wrote:
><i>
</i>><i> Hi Jiangli,
</i>><i>
</i>><i> I tried building with
</i>><i> <a href="https://github.com/openjdk/leyden/tree/hermetic-java-runtime" class="moz-txt-link-freetext">https://github.com/openjdk/leyden/tree/hermetic-java-runtime</a> to see if I
</i>><i> can get a completely statically linked JVM, but the JVM is still
</i>><i> dynamically linked to a few shared libraries.
</i>
Could you please elaborate on the specific libraries that you are
looking into static linking as well? Such as libm, libasound, X11, ,
etc? What are the specific benefits for statically linking with those?
Do you have some context or details on what you are looking for?
><i>
</i>><i> Is it possible to do a static link (with "gcc-static ...")?
</i>
If I understand the question correctly, -static-libgcc is the default
when building JDK on Linux. See
<a href="https://github.com/openjdk/jdk/blob/3d95c83b14cf9a6f683776053e57c07b1847cc17/make/autoconf/lib-std.m4#L50." class="moz-txt-link-freetext">https://github.com/openjdk/jdk/blob/3d95c83b14cf9a6f683776053e57c07b1847cc17/make/autoconf/lib-std.m4#L50.</a>
It's the case with linking the libjvm.so as well. E.g.:
  g++ ... -static-libgcc -shared ... -Wl,-soname=libjvm.so -o
support/modules_libs/java.base/server/libjvm.so ... -lm -ldl -lpthread
-lrt -static-libstdc++
Thanks,
Jiangli
><i>
</i>><i> Thanks
</i>><i>
</i>><i> - Ioi
</i>><i>
</i>><i> $ bash configure
</i>><i> $ cd build/linux-x64
</i>><i> $ make static-jdk-bundles
</i>><i> $ ls -l build/linux-x64/images/static-jdk/bin/java
</i>><i> -rwxr-xr-x. 1 opc opc 34915696 Oct 14 08:55
</i>><i> build/linux-x64/images/static-jdk/bin/java
</i>><i> $ ldd images/static-jdk/bin/java
</i>><i>      linux-vdso.so.1 (0x000075aad82ca000)
</i>><i>      libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x000075aad64c3000)
</i>><i>      libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x000075aad829e000)
</i>><i>      libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x000075aad828b000)
</i>><i>      libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1
</i>><i> (0x000075aad827f000)
</i>><i>      libXtst.so.6 => /lib/x86_64-linux-gnu/libXtst.so.6 (0x000075aad8277000)
</i>><i>      libasound.so.2 => /lib/x86_64-linux-gnu/libasound.so.2
</i>><i> (0x000075aad63b9000)
</i>><i>      libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x000075aad8270000)
</i>><i>      libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6
</i>><i> (0x000075aad62ed000)
</i>><i>      libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
</i>><i> (0x000075aad826b000)
</i>><i>      librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x000075aad8266000)
</i>><i>      libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x000075aad824a000)
</i>><i>      libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x000075aad6204000)
</i>><i>      libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000075aad5e00000)
</i>><i>      /lib64/ld-linux-x86-64.so.2 (0x000075aad82cc000)
</i>><i>      libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x000075aad61db000)
</i>><i>      libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0
</i>><i> (0x000075aad8234000)
</i>><i>      libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16
</i>><i> (0x000075aad61a3000)
</i>><i>      libbrotlidec.so.1 => /lib/x86_64-linux-gnu/libbrotlidec.so.1
</i>><i> (0x000075aad6195000)
</i>><i>      libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x000075aad822c000)
</i>><i>      libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6
</i>><i> (0x000075aad618d000)
</i>><i>      libbrotlicommon.so.1 => /lib/x86_64-linux-gnu/libbrotlicommon.so.1
</i>><i> (0x000075aad616a000)
</i>><i>      libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x000075aad6154000)
</i>><i>      libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x000075aad6145000)
</i>></pre>
    </blockquote>
    <br>
  </body>
</html>