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.26k stars 1.62k forks source link

[GR-58059] Statically Linked native image does not produce/embed all the needed .so next to the executable #8911

Open mpalourdio opened 4 months ago

mpalourdio commented 4 months ago

Hello,

I have a working little app (Spring Boot 3, maven, latest graalvm CE, linux) here. I want to compile it with musl, so it's more portable regarding glibc.

At the moment, the executable is produced without any problem in github actions (and on my work station) : the executable and all the .so are well produced in target.

I have installed musl and zlib like stated here , and have changed my maven configuration :

        <plugins>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <configuration>
                    <buildArgs>
                        <buildArg>--static</buildArg>
                        <buildArg>--libc=musl</buildArg>
                    </buildArgs>
                </configuration>
            </plugin>

The compilation is succesful, but the .so are not next to the executable (expected, as I imagine they are "embedded" in the final executable), then the app fails with Caused by: java.lang.UnsatisfiedLinkError: No awt in java.library.path for example, and so on.

I can see in the log that the .so are not produced

Produced artifacts:
 /home/ben/IdeaProjects/flhacker/target/build-artifacts.json (build_info)
 /home/ben/IdeaProjects/flhacker/target/flhacker (executable)

Am I missing something ? Thanks !

 - GraalVM version : `OpenJDK 64-Bit Server VM GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30, mixed mode, sharing)`
 - JDK major version: 21
 - OS: ubuntu 20.04 (work station) and 22.04 (github actions OS)
 - Architecture: x86_64
oubidar-Abderrahim commented 4 months ago

Thank you for reaching out, we'll take a look into this shortly

mpalourdio commented 4 months ago

FWIW, -H:+StaticExecutableWithDynamicLibC leads to the same error

oubidar-Abderrahim commented 2 months ago

Sorry, I couldn't reproduce this issue locally. Could you please share a reproducer that I can use to verify? Thank you

mpalourdio commented 2 months ago

@oubidar-Abderrahim Sure, clone this repo, and checkout the musl branch. I use GraalVM CE 21

Once compiled, the native executable does not 'embed'/link the .so, and it fails at runtime with java.lang.UnsatisfiedLinkError: No awt in java.library.path for example, which tends to prove that the static linking has failed

Checkout main, the app compiles and run successfully

mpalourdio commented 2 months ago

A bit more of context, after installing Liberica-NIK-23.1.3-1 (build 21.0.3+10-LTS) from sdkman

oubidar-Abderrahim commented 1 month ago

I was able to statically build the repo you shared, I believe this is an issue of the version of musl toolchain used. Static image are currently working with v10.2.1

> x86_64-linux-musl-gcc --version
x86_64-linux-musl-gcc (GCC) 10.2.1 20210227
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Also make sure to follow the instruction at: https://www.graalvm.org/22.1/reference-manual/native-image/StaticImages/

mpalourdio commented 1 month ago

I can build too! But can you run it without any error with missing awt for example?

oubidar-Abderrahim commented 1 month ago

Sorry, I wasn't clear enough, I was able to both build and run the application statically, without any AWT errors

mpalourdio commented 1 month ago

Here is my version

$ x86_64-linux-musl-gcc --version
x86_64-linux-musl-gcc (GCC) 10.2.1 20210227
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Did you build with graalvm CE?

oubidar-Abderrahim commented 1 month ago

image

mpalourdio commented 1 month ago

01-Army of Me.mp3.zip Can you please download this zip, extract the .mp3 file and then run

flhacker -f /path/to/extracted.mp3

You should see the fail once the code reaches something that needs awt

Thanks again !