substrate icon indicating copy to clipboard operation
substrate copied to clipboard

linux linker error: multiple definition of 'javaVM'

Open kristofdho opened this issue 3 years ago • 5 comments

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 version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>lcms-poc</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.release>17</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <!-- inclusion of javafx dependency forces javafx natives to be included -->
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>17.0.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
            </plugin>
            <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>gluonfx-maven-plugin</artifactId>
                <version>1.0.16</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>org.example.Main</mainClass>
                    <nativeImageArgs>
                        <arg>--verbose</arg>
                        <arg>--no-fallback</arg>
                        <arg>--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED</arg>
                    </nativeImageArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
org.example.Main
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

  • Ubuntu 20.04 (WSL2 but that shouldn't matter)
  • GraalVM 22.3.0 JDK 17

kristofdho avatar Jan 06 '23 09:01 kristofdho

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)

johanvos avatar Feb 22 '23 16:02 johanvos

@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.

kristofdho avatar Feb 28 '23 15:02 kristofdho

@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 avatar Feb 03 '24 00:02 credmond

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 avatar Feb 03 '24 17:02 credmond

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.

credmond avatar Feb 03 '24 19:02 credmond