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.27k stars 1.63k forks source link

[native-image] Using both AWT and OperatingSystemMXBean doesn't work with lld #4900

Open kb-1000 opened 2 years ago

kb-1000 commented 2 years ago

Describe the issue Using lld as the linker makes using headless AWT together with OperatingSystemMXBean fail. (I'm using lld because if I use gold, debug info gets corrupted in my project, making gdb crash, while lld doesn't do that)

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

  1. Download AWTJMXTest.java
  2. javac AWTJMXTest.java
  3. native-image -Djava.awt.headless=true --native-compiler-options=-fuse-ld=lld AWTJMXTest

build fails, thus no run steps

Describe GraalVM and your environment:

More details Consider adding the --native-image-info and --verbose flags when building your native image and paste output below.

Add any other information about the problem here. Especially important are stack traces or log output. Feel free to link to gists or to screenshots if necessary.

WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports
WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports
WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports
========================================================================================================================
GraalVM Native Image: Generating 'awtjmxtest' (executable)...
========================================================================================================================
[1/7] Initializing...                                                                                    (5.0s @ 0.11GB)
 Version info: 'GraalVM 22.2.0 Java 17 CE'
 Java version info: '17.0.4+8-jvmci-22.2-b06'
 C compiler: gcc (redhat, x86_64, 12.2.1)
 Garbage collector: Serial GC
[2/7] Performing analysis...  [*****]                                                                   (13.9s @ 0.76GB)
   2,897 (71.30%) of  4,063 classes reachable
   3,476 (51.44%) of  6,757 fields reachable
  12,870 (42.63%) of 30,189 methods reachable
      28 classes,     0 fields, and   323 methods registered for reflection
      59 classes,    58 fields, and    55 methods registered for JNI access
       6 native libraries: dl, m, pthread, rt, stdc++, z
[3/7] Building universe...                                                                               (1.7s @ 1.28GB)
[4/7] Parsing methods...      [*]                                                                        (1.8s @ 0.58GB)
[5/7] Inlining methods...     [***]                                                                      (1.1s @ 1.09GB)
[6/7] Compiling methods...    [***]                                                                     (10.6s @ 1.39GB)
[7/7] Creating image...
                                                                                  (0.0s @ 1.82GB)
Fatal error: java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1

Linker command executed:
/usr/lib64/ccache/gcc -fuse-ld=lld -z noexecstack -Wl,--gc-sections -Wl,--dynamic-list -Wl,/tmp/SVM-3299150018469051287/exported_symbols.list -Wl,--exclude-libs,ALL -Wl,-x -o /home/user/awt-jmx-test/awtjmxtest awtjmxtest.o /home/user/graalvm-ce-java17-22.2.0/lib/svm/clibraries/linux-amd64/liblibchelper.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libnet.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libnio.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libmanagement_ext.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libjava.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libfdlibm.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libawt_headless.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libawt.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libzip.a /home/user/graalvm-ce-java17-22.2.0/lib/svm/clibraries/linux-amd64/libjvm.a -v -L/tmp/SVM-3299150018469051287 -L/home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc -L/home/user/graalvm-ce-java17-22.2.0/lib/svm/clibraries/linux-amd64 -lstdc++ -lm -lz -ldl -lpthread -lrt

Linker command output:
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-12.2.1-20220819/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.1 20220819 (Red Hat 12.2.1-1) (GCC) 
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/12/:/usr/libexec/gcc/x86_64-redhat-linux/12/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/12/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/12/:/usr/lib/gcc/x86_64-redhat-linux/12/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/12/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-fuse-ld=lld' '-z' 'noexecstack' '-o' '/home/user/awt-jmx-test/awtjmxtest' '-v' '-L/tmp/SVM-3299150018469051287' '-L/home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc' '-L/home/user/graalvm-ce-java17-22.2.0/lib/svm/clibraries/linux-amd64' '-mtune=generic' '-march=x86-64' '-dumpdir' '/home/user/awt-jmx-test/awtjmxtest.'
 /usr/libexec/gcc/x86_64-redhat-linux/12/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/12/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/12/lto-wrapper -plugin-opt=-fresolution=/tmp/ccBmlrO9.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -fuse-ld=lld -o /home/user/awt-jmx-test/awtjmxtest -z noexecstack /usr/lib/gcc/x86_64-redhat-linux/12/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/12/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/12/crtbegin.o -L/tmp/SVM-3299150018469051287 -L/home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc -L/home/user/graalvm-ce-java17-22.2.0/lib/svm/clibraries/linux-amd64 -L/usr/lib/gcc/x86_64-redhat-linux/12 -L/usr/lib/gcc/x86_64-redhat-linux/12/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/12/../../.. --gc-sections --dynamic-list /tmp/SVM-3299150018469051287/exported_symbols.list --exclude-libs ALL -x awtjmxtest.o /home/user/graalvm-ce-java17-22.2.0/lib/svm/clibraries/linux-amd64/liblibchelper.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libnet.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libnio.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libmanagement_ext.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libjava.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libfdlibm.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libawt_headless.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libawt.a /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libzip.a /home/user/graalvm-ce-java17-22.2.0/lib/svm/clibraries/linux-amd64/libjvm.a -lstdc++ -lm -lz -ldl -lpthread -lrt -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-redhat-linux/12/crtend.o /usr/lib/gcc/x86_64-redhat-linux/12/../../../../lib64/crtn.o
ld.lld: error: duplicate symbol: throw_internal_error
>>> defined at awtjmxtest.o:(IsolateEnterStub_LibManagementExtSupport_throwInternalError_8dcbf61ef7519f805415daa5101b4f16c1d6aada_ef63b5f4efb298f9ead1a6fd18512f88eec73184)
>>> defined at management_ext.c
>>>            management_ext.o:(.text.throw_internal_error+0x0) in archive /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libmanagement_ext.a

ld.lld: error: duplicate symbol: jvm
>>> defined at management_ext.c
>>>            management_ext.o:(jvm) in archive /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libmanagement_ext.a
>>> defined at awt_LoadLibrary.c
>>>            awt_LoadLibrary.o:(.bss.jvm+0x0) in archive /home/user/graalvm-ce-java17-22.2.0/lib/static/linux-amd64/glibc/libawt.a
collect2: error: ld returned 1 exit status
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.handleLinkerFailure(NativeImageViaCC.java:191)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageViaCC.write(NativeImageViaCC.java:135)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:704)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:521)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
------------------------------------------------------------------------------------------------------------------------
                        0.8s (1.9% of total time) in 18 GCs | Peak RSS: 2.23GB | CPU load: 5.12
========================================================================================================================
Failed generating 'awtjmxtest' after 38.6s.
Error: Image build request failed with exit status 1
fniephaus commented 2 years ago

AWT, especially on JDK17+, is not designed to be statically linked. That's why you get the duplicate symbol: jvm error. We are working on switching to dynamically linking AWT on Linux and macOS, similar to how it's already done for Windows. While this won't make it into the 22.3, we hope to have this ready for the 23.0 release.