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

[GR-39191] error linking the native image - multiple definition of `jvm' #4594

Closed
Holger2019 opened this issue May 24, 2022 · 31 comments
Closed
Assignees

Comments

@Holger2019
Copy link

Holger2019 commented May 24, 2022

Hello,

unfortunately I have a problem and have unfortunately found nothing that helps me.

Describe the issue
I am trying to convert a JAR file that uses swing / awt components into a native image. Since this does not work on Windows, I set up a ubuntu subsystem. This worked fine so far. However, I get a "linking" error during the "Creating image" step. According to my understanding this error is caused by multiple definitions of jvm ( /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libawt.a(awt_LoadLibrary.o):(.bss.jvm+0x0): multiple definition of `jvm'; /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libawt_xawt.a(XlibWrapper.o):(.bss.jvm+0x0): first defined here)
--> does anyone know how to solve this problem? If yes, many thanks in advance.

Steps to reproduce the issue

  1. Jar-file (via eclipse):

import javax.swing.JFrame;
public class Testgraal {
public static void main(String[] args) {
JFrame meinFrame = new JFrame("TEST JFrame");
meinFrame.setSize(200,200);
meinFrame.setVisible(true);
}
}

  1. use Traceagent:
    java -agentlib:native-image-agent=config-merge-dir=config/META-INF/native-image -jar /home/info/JAR-TEST/TEST.jar

  2. build native-image:
    native-image -cp config:. -Djava.awt.headless=false -jar /home/info/JAR-TEST/TEST.jar
    I have tried many flags. But they didn't worked.

Describe GraalVM and your environment:

  • java version "17.0.3" 2022-04-19 LTS
  • Java(TM) SE Runtime Environment GraalVM EE 22.1.0 (build 17.0.3+8-LTS-jvmci-22.1-b05)
  • Java HotSpot(TM) 64-Bit Server VM GraalVM EE 22.1.0 (build 17.0.3+8-LTS-jvmci-22.1-b05, mixed mode, sharing)
  • JDK major version: 17
  • OS: Ubuntu 9.4.0-1ubuntu1~20.04.1 (Windows-Subsystem for Linux (Windows 11))
  • Architecture: x86_64 AMD64

More details
output:

> > GraalVM Native Image: Generating 'TEST' (executable)...
> > ========================================================================================================================
> > [1/7] Initializing...                                                                                    (2.7s @ 0.12GB)
> >  Version info: 'GraalVM 22.1.0 Java 17 EE'
> >  C compiler: gcc (linux, x86_64, 9.4.0)
> >  Garbage collector: Serial GC
> > [2/7] Performing analysis...  [*********]                                                               (14.0s @ 1.18GB)
> >    7,450 (85.07%) of  8,758 classes reachable
> >   14,482 (62.95%) of 23,004 fields reachable
> >   43,688 (60.93%) of 71,706 methods reachable
> >      177 classes,    95 fields, and   866 methods registered for reflection
> >      120 classes,   178 fields, and    93 methods registered for JNI access
> > [3/7] Building universe...                                                                               (1.4s @ 1.78GB)
> > [4/7] Parsing methods...      [*]                                                                        (1.0s @ 1.80GB)
> > [5/7] Inlining methods...     [****]                                                                     (1.1s @ 2.30GB)
> > [6/7] Compiling methods...    [*****]                                                                   (25.1s @ 1.33GB)
> > [7/7] Creating image...
> >                                                                                   (0.0s @ 2.53GB)
> > Fatal error: java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1
> > 
> > Linker command executed:
> > /usr/bin/gcc -z noexecstack -Wl,--gc-sections -Wl,--dynamic-list -Wl,/tmp/SVM-10078692684294649371/exported_symbols.list 
> 
> > -Wl,--exclude-libs,ALL -Wl,-x -o /home/info/TEST TEST.o /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libnet.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libjavajpeg.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libnio.a /home/info/graalvm-ee-java17-22.1.0/lib/svm/clibraries/linux-amd64/liblibchelper.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libjava.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/liblcms.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libprefs.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libfontmanager.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libawt_xawt.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libawt.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libfdlibm.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libzip.a /home/info/graalvm-ee-java17-22.1.0/lib/svm/clibraries/linux-amd64/libjvm.a -v -L/tmp/SVM-10078692684294649371 -L/home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc -L/home/info/graalvm-ee-java17-22.1.0/lib/svm/clibraries/linux-amd64 -lX11 -lXrender -lXext -lXi -lstdc++ -lm -lfreetype -lpthread -ldl -lz -lrt
> 
> > 
> > Linker command output:
> > Using built-in specs.
> > COLLECT_GCC=/usr/bin/gcc
> > COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
> > OFFLOAD_TARGET_NAMES=nvptx-none:hsa
> > OFFLOAD_TARGET_DEFAULT=1
> > Target: x86_64-linux-gnu
> > Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-Av3uEd/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
> > Thread model: posix
> > gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
> > COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/
> > LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/
> > COLLECT_GCC_OPTIONS='-z' 'noexecstack' '-o' '/home/info/TEST' '-v' '-L/tmp/SVM-10078692684294649371' '-L/home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc' '-L/home/info/graalvm-ee-java17-22.1.0/lib/svm/clibraries/linux-amd64' '-mtune=generic' '-march=x86-64'
> >  /usr/lib/gcc/x86_64-linux-gnu/9/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccvO0fNh.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 --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o /home/info/TEST -z noexecstack /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/tmp/SVM-10078692684294649371 -L/home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc -L/home/info/graalvm-ee-java17-22.1.0/lib/svm/clibraries/linux-amd64 -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. --gc-sections --dynamic-list /tmp/SVM-10078692684294649371/exported_symbols.list --exclude-libs ALL -x TEST.o /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libnet.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libjavajpeg.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libnio.a /home/info/graalvm-ee-java17-22.1.0/lib/svm/clibraries/linux-amd64/liblibchelper.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libjava.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/liblcms.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libprefs.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libfontmanager.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libawt_xawt.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libawt.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libfdlibm.a /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libzip.a /home/info/graalvm-ee-java17-22.1.0/lib/svm/clibraries/linux-amd64/libjvm.a -lX11 -lXrender -lXext -lXi -lstdc++ -lm -lfreetype -lpthread -ldl -lz -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-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o
> > /usr/bin/ld: /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libawt.a(awt_LoadLibrary.o):(.bss.jvm+0x0): multiple definition of `jvm'; /home/info/graalvm-ee-java17-22.1.0/lib/static/linux-amd64/glibc/libawt_xawt.a(XlibWrapper.o):(.bss.jvm+0x0): first defined here
> > collect2: error: ld returned 1 exit status
> >         at com.oracle.svm.hosted.image.NativeImageViaCC.handleLinkerFailure(NativeImageViaCC.java:505)
> >         at com.oracle.svm.hosted.image.NativeImageViaCC.write(NativeImageViaCC.java:452)
> >         at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:695)
> >         at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:515)
> >         at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
> >         at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
> >         at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
> >         at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:615)
> > ------------------------------------------------------------------------------------------------------------------------
> >                         4.7s (9.2% of total time) in 71 GCs | Peak RSS: 5.91GB | CPU load: 12.08
> > ========================================================================================================================
> > Failed generating 'TEST' after 50.2s.
> > Error: Image build request failed with exit status 1
@Holger2019
Copy link
Author

Holger2019 commented May 24, 2022

I am actually one step further in my research. But unfortunately the big problem still seems to be swing and awt.
I've been at this problem for days and can't find a proper solution. Is there a good and easy to understand step by step guide on how to convert swing awt applications (+.jars) into a native image?
I read that this is possible in theory, but I haven't read from anyone that they actually did it. Especially for more complex applications it seems to be almost impossible.
I would be very happy if I am wrong and it is actually quite simple to create. Thank you very much.

@chirontt
Copy link

@Holger2019 try using the JDK11 version of GraalVM, rather than the JDK17 version which has this problem with Swing/AWT in Linux as you've reported.

The issue is being worked on, as mentioned in a similar issue: #3938

@Holger2019
Copy link
Author

Holger2019 commented May 28, 2022

Thank you very much for your comment. I am working on a bigger project that is written in Java 17. I tried it with this project under JDK 11 but as expected I get an error (Fatal error: java.lang.UnsupportedClassVersionError:) because the versions do not match. ;)

in the meantime i managed to create a native image(corresponding to kkriske Ticket: #4165) under OS: Windows11 with jdk17. but this still needs the fontconfig.bfc for the .awt fonts. is there a way to integrate this fontconfig.bfc into the native image? That would be great.

kkriske Ticket: #4165 :

REM collect config for the app
java -agentlib:native-image-agent=config-merge-dir=. CssExample
REM compile native-image
native-image --no-fallback --no-server --verbose -H:JNIConfigurationFiles=./jni-config.json -H:ReflectionConfigurationFiles=./reflect-config.json -H:ResourceConfigurationFiles=./resource-config.json CssExample
REM copy required resources
mkdir conf\fonts
copy "%JAVA_HOME%\lib\fontconfig.bfc" conf\fonts\fontconfig.bfc
REM run native binary
cssexample.exe -Djava.home=.

@chirontt
Copy link

but this still needs the fontconfig.bfc for the .awt fonts. is there a way to integrate this fontconfig.bfc into the native image?

I don't think so, as this is a weird requirement of the Swing/AWT implementation in Windows JDK/JRE. This fontconfig.bfc file must be present in the physical file system at particular locations, either at %JAVA_HOME%\lib or at %JAVA_HOME%\conf\fonts, to be read at the start of the runtime Swing/AWT initialization in Windows. The relevant code in the JDK is here.

To change it requires a re-implementation of Swing/AWT in Windows, I guess.

@Holger2019
Copy link
Author

Holger2019 commented May 31, 2022

First of all, thank you for the support. :)

That is unfortunately not nice to hear. If I understand correctly, this is a Windows problem. Accordingly, I'm currently trying to manage this in Ubuntu via WSL (OS: Ubuntu 9.4.0-1ubuntu1~20.04.1 (Windows Subsystem for Linux (Windows 11)). You said that the problems do not exist in Java 11. Now I changed my project to Java 11 and tried it with GRAAL version 22.1.0 of Java 11.
unfortunately I get a new error. This problem seems to occur only together with the jni-config.json (-->.awt)


> > Fatal error: java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1
> > [...]

> 
> d -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o
> /usr/bin/ld: /home/info/graalvm-ee-java11-22.1.0/lib/static/linux-amd64/glibc/libawt_xawt.a(awt_Robot.o): in function `Java_sun_awt_X11_XRobotPeer_setup':
> awt_Robot.c:(.text.Java_sun_awt_X11_XRobotPeer_setup+0x1fd): undefined reference to `XTestQueryExtension'
> /usr/bin/ld: awt_Robot.c:(.text.Java_sun_awt_X11_XRobotPeer_setup+0x222): undefined reference to `XTestGrabControl'
> /usr/bin/ld: /home/info/graalvm-ee-java11-22.1.0/lib/static/linux-amd64/glibc/libawt_xawt.a(awt_Robot.o): in function `mouseAction':n':
> 

> > awt_Robot.c:(.text.mouseAction+0x133): undefined reference to `XTestFakeButtonEvent'
> > /usr/bin/ld: awt_Robot.c:(.text.mouseAction+0x18c): undefined reference to `XTestFakeButtonEvent'
> > /usr/bin/ld: awt_Robot.c:(.text.mouseAction+0x1ab): undefined reference to `XTestFakeButtonEvent'
> > /usr/bin/ld: awt_Robot.c:(.text.mouseAction+0x1d3): undefined reference to `XTestFakeButtonEvent'
> > collect2: error: ld returned 1 exit status
> >         at com.oracle.svm.hosted.image.NativeImageViaCC.handleLinkerFailure(NativeImageViaCC.java:505)
> >         at com.oracle.svm.hosted.image.NativeImageViaCC.write(NativeImageViaCC.java:452)
> >         at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:695)
> >         at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:515)
> >         at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
> >         at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
> >         at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
> >         at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:615)
> 
> ------------------------------------------------------------------------------------------------------------------------
>                       10.3s (12.6% of total time) in 127 GCs | Peak RSS: 5.26GB | CPU load: 12.47
> ========================================================================================================================
> Failed generating 'TEST_Project' after 1m 20s.
> Error: Image build request failed with exit status 1
> com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
>         at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1678)
>         at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1389)
>         at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1350)
>         at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1337)
> 
> 

Can anyone help me with this? I'm starting to get a little desperate. :)

i have tried many ways. But in general, that's what I did:

  1. java -agentlib:native-image-agent=config-merge-dir=. -jar TEST_Project.jar
  2. native-image --no-fallback --no-server --verbose -Djava.awt.headless=false -H:JNIConfigurationFiles=./jni-config.json -H:ReflectionConfigurationFiles=./reflect-config.json -H:ResourceConfigurationFiles=./resource-config.json -H:SerializationConfigurationResources=./serialization-config.json -H:PredefinedClassesConfigurationFiles=./predefined-classes-config.json -H:DynamicProxyConfigurationFiles=./proxy-config.json -jar TEST_Project.jar

@oubidar-Abderrahim oubidar-Abderrahim self-assigned this Jun 1, 2022
@oubidar-Abderrahim
Copy link
Member

Hi, Could you please share a minimal reproducer to this? Thank you

@Holger2019
Copy link
Author

Hi, that's a good idea. Thank you. :)
I hope that I will be able to do it tomorrow. it is quite an extensive project with a large number of classes.

@Holger2019
Copy link
Author

I have a new specification to the project. it must also run on Windows. Does the Native image (generated in Linux) also run on Windows?
If not, the question would be if the missing components of fontconfig.bfc will be integrated in the next versions?
I assume that it is not allowed to distribute the fontconfig.bfc together (bundled) with the .exe-file.

@oubidar-Abderrahim
Copy link
Member

Does the Native image (generated in Linux) also run on Windows?
No, native images are platform-specific, so you will have to build a new image for Windows

the missing components of fontconfig.bfc will be integrated in the next versions?
That's not something we can provide, either the Swing code should change to allow adding the file as a resource, or a more direct approach is to set JAVA_HOME to point Swing to this file (you do not need to have the entire JDK installed, just the required file in the required path, for example %JAVA_HOME%\conf\fonts\fontconfig.bfc)

@chirontt
Copy link

chirontt commented Jun 2, 2022

the missing components of fontconfig.bfc will be integrated in the next versions?

I doubt it, for reason that @oubidar-Abderrahim gave above. But the fontconfig.bfc file would be the least of your worry, as the native image program in Windows also generates a few .dll files for Swing/AWT usage, in addition to your .exe file. I've mentioned the resulting structure of Windows files in my project here.

If you want to avoid the multiple files needed for a Windows native executable, the best option is to abandon Swing/AWT and use JavaFX instead in your project. JavaFX would solve both of your problems in Linux and Windows.

@Holger2019
Copy link
Author

Holger2019 commented Jun 3, 2022

Thank you both for the quick and well explained answers. I think I have understood it (better) now. Unfortunately it's not an option to replace Swing at the moment, since the final phase is coming up. But I will keep it in mind for the future . ;)
The file structure itself would not be a problem. I wonder what the legal situation is. Is it allowed to share these files (.dll and fontconfig.bcf) to a customer?

@fniephaus fniephaus changed the title error linking the native image - multiple definition of `jvm' [GR-39191] error linking the native image - multiple definition of `jvm' Jun 16, 2022
@fniephaus
Copy link
Member

It seems this may be related to https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8264047, and a fix by @jerboaa that landed via openjdk/jdk11u@0e4fdcf.

I ran into a similar issue compiling my Truffle language that uses AWT:

git clone https://github.com/hpi-swa/trufflesqueak.git
cd trufflesqueak
git checkout a5bd690792b71c5893a1075fd9f2c35d3c1df9f8
mx --env trufflesqueak build

When I do this using a labsjdk-ce-11-jvmci-22.2-b03 everything work but using labsjdk-ce-17-jvmci-22.2-b03, I get this:

/usr/bin/ld: /home/fniephaus/dev/graalvm/graal/sdk/mxbuild/linux-amd64/GRAALVM_4936CB2EAE_JAVA17_STAGE1/graalvm-4936cb2eae-java17-22.2.0-dev/lib/static/linux-amd64/glibc/libawt.a(awt_LoadLibrary.o):(.bss.jvm+0x0): multiple definition of `jvm'; /home/fniephaus/dev/graalvm/graal/sdk/mxbuild/linux-amd64/GRAALVM_4936CB2EAE_JAVA17_STAGE1/graalvm-4936cb2eae-java17-22.2.0-dev/lib/static/linux-amd64/glibc/libawt_xawt.a(XlibWrapper.o):(.bss.jvm+0x0): first defined here
collect2: error: ld returned 1 exit status
	at com.oracle.svm.hosted.image.NativeImageViaCC.handleLinkerFailure(NativeImageViaCC.java:188)
	at com.oracle.svm.hosted.image.NativeImageViaCC.write(NativeImageViaCC.java:135)
	at com.oracle.svm.hosted.image.SharedLibraryImageViaCC.write(SharedLibraryImageViaCC.java:56)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:702)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:519)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:615)

Could you look into this please, @jerboaa?

@jerboaa
Copy link
Collaborator

jerboaa commented Jun 20, 2022

@fniephaus Is there a smaller reproducer than this trufflesqueak thingy?

@fniephaus fniephaus assigned pejovica and unassigned fniephaus Jun 20, 2022
@fniephaus
Copy link
Member

@fniephaus Is there a smaller reproducer than this trufflesqueak thingy?

Not really, sorry.

I had a chat with @pejovica about this today and it seems that the best fix for this is to dynamically link AWT libraries as we already do on Windows, which will hopefully happen sooner than later. So I don't think we need to investigate this on the JDK level at this point.

@jerboaa
Copy link
Collaborator

jerboaa commented Jun 20, 2022

OK.

@Holger2019
Copy link
Author

Holger2019 commented Jun 20, 2022

Hello,

as explained above, I managed to create a native image on windows. this (.exe) runs fine as long as the necessary libraries (dll's and fontconfig.bfc) are available. The current question was, if these files (dll's and fontconfig) may be given to the customers together with the exe?

the dlls were created automatically. As described here: https://github.com/chirontt/swingset3/tree/master/trunk/SwingSet3#caveats-on-native-image

@fniephaus
Copy link
Member

The current question was, if these files (dll's and fontconfig) may be given to the customers together with the exe?

You have to because otherwise your Native Image executable does not work, right? I can't answer any licensing questions though.

@Holger2019
Copy link
Author

that is absolutely correct. Then I will contact Oracle support. Thank you very much for your help.

@bflorat
Copy link

bflorat commented Jul 17, 2022

I'm stuck with a very similar error (without the reference to 'jvm' ) when creating native image of a large Swing app (under Ubuntu 22.04 and after having exercised the app using the native-image agent):

native-image --version
GraalVM 22.1.0 Java 11 CE (Java Version 11.0.15+10-jvmci-22.1-b06)

native-image  --initialize-at-build-time=sun.instrument.InstrumentationImpl --trace-class-initialization=sun.instrument.InstrumentationImpl -Djava.awt.headless=false --no-fallback -H:+ReportExceptionStackTraces  --verbose -cp "jajuk.jar.jar:lib/*"  org.jajuk.Main

[...]
/usr/bin/ld: org.jajuk.main.o: warning: relocation in read-only section `.svm_heap'
/usr/bin/ld: /home/bflorat/prog/graalvm-ce-java11-22.1.0/lib/static/linux-amd64/glibc/libawt_xawt.a(awt_Robot.o): in function `Java_sun_awt_X11_XRobotPeer_setup':
awt_Robot.c:(.text.Java_sun_awt_X11_XRobotPeer_setup+0x1fd): undefined reference to `XTestQueryExtension'
/usr/bin/ld: awt_Robot.c:(.text.Java_sun_awt_X11_XRobotPeer_setup+0x222): undefined reference to `XTestGrabControl'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
        at com.oracle.svm.hosted.image.NativeImageViaCC.handleLinkerFailure(NativeImageViaCC.java:505)
        at com.oracle.svm.hosted.image.NativeImageViaCC.write(NativeImageViaCC.java:452)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:695)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:515)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:615)

Any idea ?

Complete log attached.
native-image.log

@fniephaus
Copy link
Member

This problem should go away when we support dynamic linking of AWT libraries on Linux. We've made some progress on that recently, so stay tuned for more updates on this soon!

@bflorat
Copy link

bflorat commented Aug 25, 2022

Fine ! I'll keep in touch. Thx.

@AlexanderScherbatiy
Copy link
Contributor

AlexanderScherbatiy commented Nov 15, 2022

I downloaded GraalVM Community Edition 22.3.0 Java 19 from https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-22.3.0 page.

objdump shows that symbol jvm is defined as global:

objdump -t graalvm-ce-java19-22.3.0/lib/static/linux-amd64/glibc/libawt.a | grep jvm
0000000000000000 g     O .bss.jvm	0000000000000008 jvm
0000000000000000         *UND*	0000000000000000 jvm

I build jdk 19 from jdk19u and labs-openjdk-19 repositories:
https://github.com/openjdk/jdk19u.git
https://github.com/graalvm/labs-openjdk-19.git

./configure --with-boot-jdk=<jdk19u>
make images

make static-libs-bundles generates libawt.a with non global jvm symbol:

make static-libs-bundles
objdump -t images/static-libs/lib/libawt.a | grep jvm
0000000000000008       O *COM*	0000000000000008 jvm
0000000000000000         *UND*	0000000000000000 jvm

make graal-builder-image generates libawt.a with non global jvm symbol as well:

objdump -t ./images/graal-builder-jdk/lib/libawt.a | grep jvm
0000000000000008       O *COM*	0000000000000008 jvm
0000000000000000         *UND*	0000000000000000 jvm

Could you provide more details how to build jdk19 for GraalVM so the jvm symbol is defined as global in libawt.a static library?

@melix
Copy link
Member

melix commented Nov 29, 2022

I am facing the same issue with GraalVM 22.3 (17.0.5+8-jvmci-22.3-b08): https://scans.gradle.com/s/pp4d2ulbe7gdi/console-log?page=1#L73

@fniephaus
Copy link
Member

#4921 is the roadmap item for better AWT support. Hopefully, we'll be able to ship improvements in the next release.

@melix
Copy link
Member

melix commented Nov 29, 2022

I guess there's no workaround?

@fniephaus
Copy link
Member

Avoid AWT or build on Windows, but I wouldn't call these options workarounds. Is AWT used by the application or is it unclear why it's being pulled in? Maybe it's pulled in by accident (see #5224)?

@melix
Copy link
Member

melix commented Nov 29, 2022

It is using awt, I was building this demo project.

@fniephaus
Copy link
Member

Ah ok, I haven't tried that demo myself but in that case, I'd try to use JDK11 (even though the readme mentions 17+). AWT on 11 can be statically linked.

melix added a commit to melix/doom-graalvm that referenced this issue Nov 29, 2022
This commit switches from Maven to Gradle for building the project.
It makes the instructions simpler, by using Gradle plugins:

- the `application` plugin exposes the `run` method directly for the
JVM version, without having to explain to grow the stack size
- the official GraalVM native plugin exposes the `nativeCompile`
and `nativeRun` tasks, respectively for building the native image
and executing it

In addition, this commit switches from using Java 19 to Java 11.
The underlying reason is a [bug](oracle/graal#4594 (comment))
which prevents building the native image under Linux with AWT,
with more recent versions of Java.

Native configuration has been moved to the conventional
`src/main/resources/META-INF/native-image` location. Although
this isn't required for the JVM version, it simplifies the setup
of the build.
@AlexanderScherbatiy
Copy link
Contributor

I built graal with jdk 19 from jdk19u and labs-openjdk-19 repositories.
make static-libs-bundles generates libawt.a static library with non global jvm symbol and I am able to generate a native image for a Swing application without multiple definition of 'jvm' error with my local graal build.

Which way jdk static libraries are generated for graal that libawt.a static library defines jvm symbol as global?

@chirontt
Copy link

@melix

I guess there's no workaround?

Yes, there is a workaround: use the Liberica NIK, its version for the JDK17 can successfully produce a Linux native image without this multiple definition of 'jvm' problem of the stock GraalVM.

@pejovica
Copy link
Member

pejovica commented Mar 8, 2023

Fixed by #6088.

@pejovica pejovica closed this as completed Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants