graal icon indicating copy to clipboard operation
graal copied to clipboard

Issue Building Statically Linked Executable with Docker Community Image

Open aahx opened this issue 2 years ago • 1 comments

Describe the issue I am unable to build a statically linked executable using native-image with the musl libc on GraalVM. The build process fails with a segmentation fault.

I am howver, able to produce dynamically linked executables without issues.


Steps to reproduce the issue

  1. Clone repo [email protected]:aahx/graalvm-docker.git branch attempt/michael/muslib

  2. Build the project and create native image using Docker. The Dockerfile:

FROM ghcr.io/graalvm/native-image-community:22.0.1-muslib-ol9-20240416

RUN microdnf install -y gzip tar && microdnf clean all

WORKDIR /app
COPY . .
RUN ./mvnw clean package
RUN native-image --no-fallback --static --libc=musl -jar /app/target/demo-0.0.1-SNAPSHOT.jar /app/target/demo

Building with $ docker build -t test1 .


Describe GraalVM and your environment:

  • GraalVM 22
  • java 21.0.1 2023-10-17 LTS Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29) Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)
  • Sonoma 14.5
  • Apple Silicon Apple M2

More details The build fails with the following error message

    ========================================================================================================================
GraalVM Native Image: Generating 'demo' (static executable)...
========================================================================================================================
Warning: The host machine does not support all features of 'x86-64-v3'. Falling back to '-march=compatibility' for best compatibility.
[1/8] Initializing...                                                                                    (8.9s @ 0.06GB)
 Java version: 22.0.1+8, vendor version: GraalVM CE 22.0.1+8.1
 Graal compiler: optimization level: 2, target machine: compatibility
 C compiler: x86_64-linux-musl-gcc (linux, x86_64, 10.2.1)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 1 user-specific feature(s):
 - com.oracle.svm.thirdparty.gson.GsonFeature
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 5.79GB of memory (75.6% of 7.66GB system memory, determined at start)
 - 8 thread(s) (100.0% of 8 available processor(s), determined at start)
[2/8] Performing analysis...  [#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007ffffee2ecd4, pid=31, tid=53
#
# JRE version: OpenJDK Runtime Environment GraalVM CE 22.0.1+8.1 (22.0.1+8) (build 22.0.1+8-jvmci-b01)
# Java VM: OpenJDK 64-Bit Server VM GraalVM CE 22.0.1+8.1 (22.0.1+8-jvmci-b01, mixed mode, tiered, jvmci, jvmci compiler, compressed oops, compressed class ptrs, parallel gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0xd5ccd4]  oopDesc* PSPromotionManager::copy_unmarked_to_survivor_space<false>(oopDesc*, markWord)+0x44
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /app/hs_err_pid31.log
#
# If you would like to submit a bug report, please visit:
#   https://github.com/oracle/graal/issues
#
Error: Image build request for 'demo' (pid: 31, path: /app/target) failed with exit status 134


Additional Info I am able to use FROM ghcr.io/graalvm/native-image-community:22 and run:

RUN native-image --no-fallback -jar /app/target/demo-0.0.1-SNAPSHOT.jar /app/target/demo

to produce a dynamically linked executable without any issues. The problem only occurs when using musl libc and attempting to create a statically linked executable.

Have also tried variations of

ghcr.io/graalvm/native-image-community:22-muslib-ol8
ghcr.io/graalvm/native-image-community:21-muslib
ghcr.io/graalvm/native-image-community:17-muslib 

aahx avatar Jun 19 '24 03:06 aahx

Issue resolved by using ghcr.io/graalvm/native-image-community:21.0.2-ol9-20240116 even though it does not have the [-muslib] it contains the glibc library to build static images correctly

aahx avatar Jun 20 '24 17:06 aahx