From b14ebdfda1c11eb580331c827c21fcd7ca140411 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Fri, 1 Mar 2024 15:03:44 +0100 Subject: [PATCH] Introduce `--static-nolibc` API option. --- docs/reference-manual/native-image/BuildOptions.md | 1 + .../guides/build-static-and-mostly-static-executable.md | 4 ++-- substratevm/CHANGELOG.md | 1 + .../src/com/oracle/svm/core/SubstrateOptions.java | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/reference-manual/native-image/BuildOptions.md b/docs/reference-manual/native-image/BuildOptions.md index 85e4c9fbd1c0..a56c1cc2b612 100644 --- a/docs/reference-manual/native-image/BuildOptions.md +++ b/docs/reference-manual/native-image/BuildOptions.md @@ -73,6 +73,7 @@ Run `native-image --help` for help on build options. * `--shared`: build a shared library * `--silent`: silence build output * `--static`: build a statically-linked executable (requires `libc` and `zlib` static libraries) +* `--static-nolibc`: build statically linked executable with libc dynamically linked * `--target`: select the compilation target for `native-image` (in the `-` format). It defaults to host's OS-architecture pair. * `--trace-class-initialization`: provide a comma-separated list of fully-qualified class names that a class initialization is traced for * `--trace-object-instantiation`: provide a comma-separated list of fully-qualified class names that an object instantiation is traced for diff --git a/docs/reference-manual/native-image/guides/build-static-and-mostly-static-executable.md b/docs/reference-manual/native-image/guides/build-static-and-mostly-static-executable.md index 805baee2020e..68079967aff2 100644 --- a/docs/reference-manual/native-image/guides/build-static-and-mostly-static-executable.md +++ b/docs/reference-manual/native-image/guides/build-static-and-mostly-static-executable.md @@ -114,13 +114,13 @@ With GraalVM Native Image you can build a mostly-static native executable that s To build a mostly-static native executable, use this command: ```shell -native-image -H:+StaticExecutableWithDynamicLibC [other arguments] +native-image --static-nolibc [other arguments] ``` To build a a mostly-static native executable for the above `EnvMap` demo, run: ```shell -native-image -H:+StaticExecutableWithDynamicLibC EnvMap +native-image --static-nolibc EnvMap ``` This produces a native executable that statically links all involved libraries (including JDK shared libraries) except for `libc`. This includes `zlib`. Also, depending on the user's code, it may link `libstdc+` and `libgcc`. diff --git a/substratevm/CHANGELOG.md b/substratevm/CHANGELOG.md index fb6f07275217..8b3c5b39c908 100644 --- a/substratevm/CHANGELOG.md +++ b/substratevm/CHANGELOG.md @@ -15,6 +15,7 @@ This changelog summarizes major changes to GraalVM Native Image. * (GR-51053) Use [`vswhere`](https://github.com/microsoft/vswhere) to find Visual Studio installations more reliably and in non-standard installation locations. * (GR-47832) Experimental support for upcalls from foreign code and other improvements to our implementation of the [Foreign Function & Memory API](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/ForeignInterface.md) (part of "Project Panama", [JEP 454](https://openjdk.org/jeps/454)) on AMD64. Must be enabled with `-H:+ForeignAPISupport` (requiring `-H:+UnlockExperimentalVMOptions`). * (GR-52314) `-XX:MissingRegistrationReportingMode` can now be used on program invocation instead of as a build option, to avoid a rebuild when debugging missing registration errors. +* (GR-51086) Introduce a new `--static-nolibc` API option as a replacement for the experimental `-H:±StaticExecutableWithDynamicLibC` option. ## GraalVM for JDK 22 (Internal Version 24.0.0) * (GR-48304) Red Hat added support for the JFR event ThreadAllocationStatistics. diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index 10ec72f2380c..d09453167ded 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -150,7 +150,8 @@ protected void onValueUpdate(EconomicMap, Object> values, String ol } }; - @Option(help = "Builds a statically linked executable with libc dynamically linked", type = Expert, stability = OptionStability.EXPERIMENTAL)// + @APIOption(name = "static-nolibc")// + @Option(help = "Build statically linked executable with libc dynamically linked", type = Expert, stability = OptionStability.EXPERIMENTAL)// public static final HostedOptionKey StaticExecutableWithDynamicLibC = new HostedOptionKey<>(false); @Option(help = "Builds image with libstdc++ statically linked into the image (if needed)", type = Expert, stability = OptionStability.EXPERIMENTAL)//