Open marcust opened 1 year ago
Hi, Thank you for raising this issue, we will take a look into it shortly
Hi, I tried using GraalVM 22.3.1 and libc 2.36 (Ubuntu 22.10 on wsl) and was able to build a hello world example statically without issues.
Can you please verify the latest release of 22.3.1?
Same with 22.3.1:
/usr/bin/ld: /home/marcus/.sdkman/candidates/java/22.3.1.r19-grl/lib/static/linux-amd64/glibc/libnio.a(UnixNativeDispatcher.o): in function `Java_sun_nio_fs_UnixNativeDispatcher_mknod0':
UnixNativeDispatcher.c:(.text.Java_sun_nio_fs_UnixNativeDispatcher_mknod0+0x44): undefined reference to `__xmknod'
collect2: error: ld returned 1 exit status
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.handleLinkerFailure(NativeImageViaCC.java:204)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.runLinkerCommand(NativeImageViaCC.java:151)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.write(NativeImageViaCC.java:117)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:718)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
That is the Version: GraalVM CE 22.3.1 (build 19.0.2+7-jvmci-22.3-b12) on Ubuntu 22.10.
Not sure what you need to do in order for Graal to try to link libnio.a
, maybe the "Hello World" should write to stdout via NIO then? I am not sure how to make a minimal test case here...
This is a minimum test case for me:
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class FileSystemTest {
public static void main(String[] args) {
try {
final FileSystem fileSystem = FileSystems.getFileSystem(URI.create("file:///"));
fileSystem.provider().move(new File("/dev/null").toPath(), new File("/tmp/foo").toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
When compiling and linking static with
javac FileSystemTest.java && native-image --static FileSystemTest
I get my error:
/usr/bin/ld: /home/marcus/.sdkman/candidates/java/22.3.1.r19-grl/lib/static/linux-amd64/glibc/libnio.a(UnixNativeDispatcher.o): in function `Java_sun_nio_fs_UnixNativeDispatcher_mknod0':
UnixNativeDispatcher.c:(.text.Java_sun_nio_fs_UnixNativeDispatcher_mknod0+0x44): undefined reference to `__xmknod'
collect2: error: ld returned 1 exit status
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.handleLinkerFailure(NativeImageViaCC.java:204)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.runLinkerCommand(NativeImageViaCC.java:151)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.write(NativeImageViaCC.java:117)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:718)
I can build the example you shared statically on muslib
Can you please try with native-image --static --libc=musl FileSystemTest
as mentioned here: https://www.graalvm.org/22.0/reference-manual/native-image/StaticImages/
Make sure also the prerequisites are satisfied (mentioned in the previous link as well)
So I have a workaround, which is basically just building on an older Ubuntu, e.g. 20.04.
Building a mostly static image also works, at least it links, I am not sure if this would not break at runtime.
The musl
toolchain fails for me with a different error, not sure if I did something wrong in the setup:
Linker command executed:
/home/marcus/test/x86_64-linux-musl-native/bin/x86_64-linux-musl-gcc -z noexecstack -Wl,--gc-sections -Wl,-x -o /home/marcus/test/filesystemtest filesystemtest.o /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/svm/clibraries/linux-amd64/liblibchelper.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libnet.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libnio.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libjava.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libfdlibm.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libzip.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/svm/clibraries/linux-amd64/libjvm.a -static -v -L/tmp/SVM-1253074152190741275 -L/home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl -L/home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/svm/clibraries/linux-amd64 -lz -lpthread -ldl -lrt
Linker command output:
Using built-in specs.
COLLECT_GCC=/home/marcus/test/x86_64-linux-musl-native/bin/x86_64-linux-musl-gcc
COLLECT_LTO_WRAPPER=/home/marcus/test/x86_64-linux-musl-native/bin/../libexec/gcc/x86_64-linux-musl/11.2.1/lto-wrapper
Target: x86_64-linux-musl
Configured with: ../src_gcc/configure --enable-languages=c,c++,fortran CC='x86_64-linux-musl-gcc -static --static' CXX='x86_64-linux-musl-g++ -static --static' FC='x86_64-linux-musl-gfortran -static --static' CFLAGS='-g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels -Wno-error' CXXFLAGS='-g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels -Wno-error' FFLAGS='-g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels -Wno-error' LDFLAGS='-s -static --static' --enable-default-pie --enable-static-pie --disable-cet --disable-bootstrap --disable-assembly --disable-werror --target=x86_64-linux-musl --prefix= --libdir=/lib --disable-multilib --with-sysroot=/ --enable-tls --disable-libmudflap --disable-libsanitizer --disable-gnu-indirect-function --disable-libmpx --enable-initfini-array --enable-libstdcxx-time=rt --enable-deterministic-archives --enable-libstdcxx-time --enable-libquadmath --enable-libquadmath-support --disable-decimal-float --build=x86_64-pc-linux-muslxx --host=x86_64-linux-musl
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.1 20211120 (GCC)
COMPILER_PATH=/home/marcus/test/x86_64-linux-musl-native/bin/../libexec/gcc/x86_64-linux-musl/11.2.1/:/home/marcus/test/x86_64-linux-musl-native/bin/../libexec/gcc/:/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/bin/
LIBRARY_PATH=/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/:/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/:/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/lib/:/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../:/home/marcus/test/x86_64-linux-musl-native/bin/../lib/:/home/marcus/test/x86_64-linux-musl-native/bin/../usr/lib/
COLLECT_GCC_OPTIONS='-z' 'noexecstack' '-o' '/home/marcus/test/filesystemtest' '-static' '-v' '-L/tmp/SVM-1253074152190741275' '-L/home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl' '-L/home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/svm/clibraries/linux-amd64' '-mtune=generic' '-march=x86-64' '-dumpdir' '/home/marcus/test/filesystemtest.'
/home/marcus/test/x86_64-linux-musl-native/bin/../libexec/gcc/x86_64-linux-musl/11.2.1/collect2 --sysroot=/home/marcus/test/x86_64-linux-musl-native/bin/../ --eh-frame-hdr -m elf_x86_64 -static -pie --no-dynamic-linker -z text -Bsymbolic -o /home/marcus/test/filesystemtest -z noexecstack /home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../rcrt1.o /home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../crti.o /home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/crtbeginS.o -L/tmp/SVM-1253074152190741275 -L/home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl -L/home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/svm/clibraries/linux-amd64 -L/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1 -L/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc -L/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/lib -L/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../.. -L/home/marcus/test/x86_64-linux-musl-native/bin/../lib -L/home/marcus/test/x86_64-linux-musl-native/bin/../usr/lib --gc-sections -x filesystemtest.o /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/svm/clibraries/linux-amd64/liblibchelper.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libnet.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libnio.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libjava.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libfdlibm.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/static/linux-amd64/musl/libzip.a /home/marcus/.sdkman/candidates/java/22.3.r19-grl/lib/svm/clibraries/linux-amd64/libjvm.a -lz -lpthread -ldl -lrt --start-group -lgcc -lgcc_eh -lc --end-group /home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/crtendS.o /home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../crtn.o
/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/bin/ld: filesystemtest.o: warning: relocation in read-only section `.svm_heap'
/home/marcus/test/x86_64-linux-musl-native/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/bin/ld: read-only segment has dynamic relocations
collect2: error: ld returned 1 exit status
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.handleLinkerFailure(NativeImageViaCC.java:204)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.runLinkerCommand(NativeImageViaCC.java:151)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.write(NativeImageViaCC.java:117)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:718)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
Recent versions of musl
don't work well with native-image, please check this comment for the exact version to use.
Yes, with this version linking against musl
works.
Nontheless, the issue that it does not work on newer standard GLIBC will be adressed, or is this just not supported anymore?
The newer prebuilt toolchains from musl.cc have a check that no relocations should be emitted in the read only section of our generated executable, if they are - the build fails. Solving the relocations problem is a bit harder, but, to be honest, we didn't give much time to this to see if we can workaround it somehow.
I will check with the NI team to see if we can solve this. in the meantime, please keep using that version for building static images.
Bump. Is it possible not to use this symbol?
I encountered today the same problem, any progress regarding libC?
same there (libc, no musl)
Tracked internally in GR 44421
Describe the issue Trying to link a static (
--static
) native image on Ubuntu 22.10 shows the following:The internet claims that
(Source: https://gitlab.com/Mr_Goldberg/goldberg_emulator/-/issues/164)
Describe GraalVM and your environment: