gluonhq / substrate

Create native Java(FX) apps for desktop, mobile and embedded
GNU General Public License v2.0
390 stars 52 forks source link

linux linker error: multiple definition of 'javaVM' #1193

Open kristofdho opened 1 year ago

kristofdho commented 1 year ago

There seems to be a symbol conflict between libglassgtk3.a and liblcms.a. Happens both with <javafxStaticSdkVersion>17.0.2</...> and without specifying it, which defaults to 20-ea+7.

Expected Behavior

linking succeeds

Current Behavior

linker error multiple definition of 'javaVM':

Process
=======
link

Command Line
============
gcc /home/kristof/projects/redacted/build/native-image/target/gluonfx/x86_64-linux/gvm/native-image/launcher.o /home/kristof/projects/redacted/build/native-image/target/gluonfx/x86_64-linux/gvm/tmp/SVM-1672948646458/redacted.o /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libjava.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libnio.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libzip.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libnet.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libprefs.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libj2pkcs11.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libextnet.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libfdlibm.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libfontmanager.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libjavajpeg.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/liblcms.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libawt_headless.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libawt.a -l:libjvm.a -l:liblibchelper.a -lz -ldl -lstdc++ -lpthread -Wl,--wrap=pow -rdynamic -lprism_es2 -lglass -lglassgtk3 -ljavafx_font -ljavafx_font_freetype -ljavafx_font_pango -ljavafx_iio -lgstreamer-lite -L/usr/lib/x86_64-linux-gnu -lavcodec -L/usr/lib/x86_64-linux-gnu -lavformat -L/usr/lib/x86_64-linux-gnu -lavutil -L/usr/lib/x86_64-linux-gnu -lasound -Wl,--no-whole-archive -L/usr/lib/x86_64-linux-gnu -lGL -L/usr/lib/x86_64-linux-gnu -lX11 -L/usr/lib/x86_64-linux-gnu -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -L/usr/lib/x86_64-linux-gnu -lfreetype -L/usr/lib/x86_64-linux-gnu -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lharfbuzz -lfontconfig -lfreetype -L/usr/lib/x86_64-linux-gnu -lgthread-2.0 -pthread -lglib-2.0 -lstdc++ -L/usr/lib/x86_64-linux-gnu -lz -L/usr/lib/x86_64-linux-gnu -lXtst -lm -L/usr/lib/x86_64-linux-gnu -lgmodule-2.0 -pthread -lglib-2.0 -lm -ldl -o /home/kristof/projects/redacted/build/native-image/target/gluonfx/x86_64-linux/native-image -L/home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/svm/clibraries/linux-amd64 -L/home/kristof/.gluon/substrate/javafxStaticSdk/17.0.2/linux-x86_64/sdk/lib /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libmlib_image.a /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/libmanagement_ext.a

Output
======
/usr/bin/ld: /home/kristof/.gluon/substrate/javafxStaticSdk/17.0.2/linux-x86_64/sdk/lib/libglassgtk3.a(glass_general.obj):(.bss.javaVM+0x0): multiple definition of `javaVM'; /home/kristof/.sdkman/candidates/java/22.3.r17-grl/lib/static/linux-amd64/glibc/liblcms.a(LCMS.o):(.bss.javaVM+0x0): first defined here
collect2: error: ld returned 1 exit status

Result
======
result: 1

Steps to Reproduce

run mvn package in the project defined by these pom and java files:

pom.xml ```xml 4.0.0 org.example lcms-poc 1.0-SNAPSHOT 17 UTF-8 org.openjfx javafx-controls 17.0.2 org.apache.maven.plugins maven-compiler-plugin 3.10.1 com.gluonhq gluonfx-maven-plugin 1.0.16 build package org.example.Main --verbose --no-fallback --add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED ```
org.example.Main ```java package org.example; import java.awt.*; import java.awt.color.ColorSpace; public class Main { public static void main(String[] args) { Color color = new Color( ColorSpace.getInstance(ColorSpace.CS_sRGB), new float[]{1.0f, 1.0f, 1.0f}, 1.0f ); System.out.println(color); } } ```

Your Environment

johanvos commented 1 year ago

good remark. Our static libs should not expose javaVM (or any other symbol that is not strictly needed by other code not in that library)

kristofdho commented 1 year ago

@johanvos do you have any idea for a potential timeline for a fix? I'm assuming this would then also be included in a future 17.x.x version? It's not that urgent for us yet, but this is currenty blocking our linux deployments.

credmond commented 7 months ago

@johanvos Any update on this?

[Sat Feb 03 00:29:55 UTC 2024][INFO] [SUB] /usr/bin/ld: /home/runner/.gluon/substrate/javafxStaticSdk/21-ea+11.1/linux-x86_64/sdk/lib/libglassgtk3.a(glass_general.obj):(.bss.javaVM+0x0): multiple definition of `javaVM'; /opt/hostedtoolcache/graalvm-ce-java17-linux/22.1.0/x64/graalvm-ce-java17-22.1.0/lib/static/linux-amd64/glibc/liblcms.a(LCMS.o):(.bss.javaVM+0x0): first defined here

Still an issue with latest substrate (using JFX "21-ea+11.1"). I notice this when using linkerArg:

${env.GRAALVM_HOME}/lib/static/linux-amd64/glibc/libjaas.a

which, was a solution @jperedadnr recommended here (and somewhere else):

https://stackoverflow.com/questions/73606094/graalvm-library-is-not-linking-in-linux-mint

Firstly, this should be included by default (and working obviously), IMO.

It's listed here ("'jaas"):

https://github.com/gluonhq/substrate/blob/master/src/main/java/com/gluonhq/substrate/target/AbstractTargetConfiguration.java#L104

... but that's completely ignored by the superclass, which uses its own list (curiously omitting jaas):

https://github.com/gluonhq/substrate/blob/master/src/main/java/com/gluonhq/substrate/target/LinuxTargetConfiguration.java#L63

... can someone elaborate on why this isn't fixed or if it can be easily?

credmond commented 7 months ago

I noticed this error was only happening for me on Github runners, and I investigated why. I was using an official GraalVM 21.1.0, not Gluon's 21.1.0.1-Final (which is what I was using locally where the problem did not occur). I didn't even know you guys had a Github action to download your GraalVM builds -- some documentation/sampless refer to the official GraalVM builds when it comes to Github workflows, if I recall.

Anyway, the next question is...what's the difference...? I would have expected this problem to exist in both.

credmond commented 7 months ago

Problematic build, you can see "B" meaning global/static:

credmond@UM790:~/.jdks$ nm /home/credmond/.jdks/graalvm-ce-java17-22.1.0/lib/static/linux-amd64/glibc/liblcms.a | grep javaVM
0000000000000000 B javaVM

Gluon's build:

credmond@UM790:~/.jdks$ nm /home/credmond/.jdks/graalvm-svm-java17-linux-gluon-22.1.0.1-Final/lib/static/linux-amd64/glibc/liblcms.a | grep javaVM
0000000000000008 C javaVM

I don't really know where this came from exactly, or why that might be the case.