oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.4k stars 1.64k forks source link

Linux aarch64 static builds break going from GraalVM 21 to 23 #10018

Closed MikeTheSnowman closed 1 week ago

MikeTheSnowman commented 1 week ago

Describe the issue Below is the command that I use with GraalVM 21, on aarch64 Linux, to product static native binaries:

native-image --verbose -H:Log=registerResource:verbose \
-H:+PrintClassInitialization -H:+UnlockExperimentalVMOptions \
-Djansi.disable=true --initialize-at-build-time=com.fortify.cli.app.FortifyCLI \
--static -H:ExcludeResources="org/fusesource/jansi/internal/native/.*" \
-jar ./artifacts/release-assets/fcli.jar -o fcli

This command that works with GraalVM 21, will not work on GraalVM 23. When trying to use this command with GraalVM 23, I'm presented with the following error: Error: Invalid option '--static'. Building static executable images is only supported with musl libc. Remove the '--static' option or add the '--libc=musl' option.

I've tried adding the '--libc=musl' option, but Graal still produces the exact same error, even after providing the '--libc=musl' option.

Any idea as to why this was working in GraalVM 21 but not 23?

Steps to reproduce the issue Please include both build steps as well as run steps

  1. Try to build a static image on a aarch64 Linux host with the following two options. --static --libc=glibc

Describe GraalVM and your environment:

More details I've also noticed that native image builds with GraalVM 21 on x86_64 are about 10MB smaller than native image builds with GraamVM 23. Any ideas why.

Error: Invalid option '--static'. Building static executable images is only supported with musl libc. Remove the '--static' option or add the '--libc=musl' option..
------------------------------------------------------------------------------------------------------------------------
                        0.7s (4.4% of total time) in 66 GCs | Peak RSS: 0.54GB | CPU load: 1.85
========================================================================================================================
Failed generating 'fcli' after 14.2s.
com.oracle.svm.driver.NativeImage$NativeImageError
    at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.showError(NativeImage.java:2300)
    at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.build(NativeImage.java:1888)
    at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1847)
    at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.main(NativeImage.java:1829)
    at java.base@23.0.1/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
linghengqian commented 1 week ago

Linux aarch64 static builds break going from GraalVM 21 to 23

I've also noticed that native image builds with GraalVM 21 on x86_64 are about 10MB smaller than native image builds with GraamVM 23. Any ideas why.

MikeTheSnowman commented 1 week ago

Hey @linghengqian. Thanks for your reply.

One last question is, do you know if it's on the roadmap to add support for static images for aarch64 Linux?

linghengqian commented 1 week ago

It sounds like you never actually generated a fully statically linked graalvm native image on graalvm ce for jdk 21 before. The --libc=musl argument is always required, feel free to consult the graalvm documentation.

I don't encourage running x86_64 docker images on aarch64, doing so will incur performance penalties.

Is this on the graalvm roadmap? I'm not a graalvm committer, but it's not on the roadmap at the moment.

MikeTheSnowman commented 1 week ago

Hey @linghengqian . Thanks again for the speedy reply.

linghengqian commented 1 week ago

Sorry, but I think I worded my question poorly. My question was: If I compile/install musl from source, as you suggested, on aarch64 Linux, will this allow me to generate a native image with GraalVM 23?

This is not possible at the moment. The code that interacts with musl is in the current git, and that code is hard-coded with x86_64 specific stuff.

MikeTheSnowman commented 1 week ago

Understood. Thanks for the clarification.

oubidar-Abderrahim commented 1 week ago

This is expected behavior, using --static requires using --libc=musl, and both are only supported in x86_64 (amd64) architecture

MikeTheSnowman commented 1 week ago

Hey @oubidar-Abderrahim , but do you have any ideas as to why in GraalVM 21, using only --static was able to produce a static native binary on aarch64 Linux?

I'm just trying to understand what changed between GraalVM 21 and 23.