Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraalVM: native image from skiko application throws error: cannot open (null)/lib/libjawt.so #580

Closed
AlexanderScherbatiy opened this issue Aug 26, 2022 · 1 comment

Comments

@AlexanderScherbatiy
Copy link

AlexanderScherbatiy commented Aug 26, 2022

The original issue has been reported at bell-sw/LibericaNIK#14

Native image, built by GraalVM, does not define java.home java property so dynamic jawt lib loading fails on Linux and MacOS in code

void *lib = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);

The proposed solution could be to link skiko lib with jawt lib statically only for native image generation.

Steps to reproduce:

  • Update SkiaAwtSample build.gradle.kts to create uber jar:
plugins {
    kotlin("jvm") version "1.6.10"
    application
    id("com.github.johnrengelman.shadow") version "7.1.2"
}
  • Create an uber jar gradle build
  • Run SkiaAwtSample with GraalVM native image agent to generate configuration files with JNI, reflections, and resources:
<graalvm>/bin/java -agentlib:native-image-agent=config-output-dir=conf-dir -jar build/libs/SkiaAwtSample-all.jar
  • Build a native image with GraalVM
<graalvm>/bin/native-image -Djava.awt.headless=false -H:ReflectionConfigurationFiles=conf-dir/reflect-config.json -H:JNIConfigurationFiles=conf-dir/jni-config.json -H:ResourceConfigurationFiles=conf-dir/resource-config.json -jar build/libs/SkiaAwtSample-all.jar
  • Run the generated native image:
./SkiaAwtSample-all 
Cannot open (null)/lib/libjawt.so: (null)/lib/libjawt.so: cannot open shared object file: No such file or directory
Aborted (core dumped)

The fix could consist of two steps.
First, change the dynamic jawt lib loading to link skiko lib with jawt. As an example, the draft solution tested on Linux only: AlexanderScherbatiy@94b7097
Second, if the first step is accepted, add an option which links with jawt lib statically to make it possible to generate a native image by GraalVM. It would need to use static jawt library from GraalVM and its dependencies, like:

           OS.Linux -> {
                osFlags = arrayOf(
                   ...
                    "-l:libjawt.a",
                    "-l:libawt_xawt.a",
                    "-l:libawt.a",
                    "-l:libjava.a",
                    "-L$jdkHome/lib",

where jdkHome is path to GraalVM.

@okushnikov
Copy link

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants