kohlschutter / junixsocket

Unix Domain Sockets in Java 7 and newer (AF_UNIX), AF_TIPC, AF_VSOCK, and more
Apache License 2.0
438 stars 114 forks source link

Allow building for loongarch64 #161

Closed cheungxi closed 1 month ago

cheungxi commented 2 months ago

Describe the bug I porting junixsocket to a new cpu architecture (loongarch)

ld cant find *.deps.so

To Reproduce Steps to reproduce the behavior:

  1. ./junixsocket-native/src/main/nar/aol.properties add these code:
+loongarch64.Linux.clang.linker.name=clang
+loongarch64.Linux.clang.linker.options=${junixsocket.native.default.linker.options} -Xcrossclang-with-and-without-lc -target ${junixsocket.native.llvm.target} -Xcrossclang-llvm-name llvm
+loongarch64.Linux.clang.c.compiler=clang
+loongarch64.Linux.clang.c.defines=_GNU_SOURCE
+loongarch64.Linux.clang.c.options=-march=loongarch64 -mabi=lp64d ${junixsocket.native.clang.c.options} -Xcrossclang-with-and-without-lc -I${project.basedir}/src/main/c/jni -target ${junixsocket.native.llvm.target}
+loongarch64.Linux.clang.c.includes=${junixsocket.native.default.c.includes}
+loongarch64.Linux.clang.c.excludes=
+loongarch64.Linux.clang.java.include=
+loongarch64.Linux.clang.java.runtimeDirectory=IGNORED
+loongarch64.Linux.clang.lib.prefix=lib
+loongarch64.Linux.clang.shared.prefix=lib
+loongarch64.Linux.clang.static.extension=a
+loongarch64.Linux.clang.shared.extension=so
+loongarch64.Linux.clang.plugin.extension=so
+loongarch64.Linux.clang.jni.extension=so
+loongarch64.Linux.clang.executable.extension=
+loongarch64.Linux.clang.cpp.compiler=clang++
+loongarch64.Linux.clang.cpp.defines=_GNU_SOURCE
+loongarch64.Linux.clang.cpp.options=${junixsocket.native.clang.cpp.options} -target ${junixsocket.native.llvm.target}
+loongarch64.Linux.clang.cpp.includes=${junixsocket.native.default.cpp.includes}
+loongarch64.Linux.clang.cpp.excludes=
  1. mvn -e -X clean install >> a.txt

  2. error message

    [INFO] 25 files were compiled.
    [INFO] Linking...
    [DEBUG] Starting link {13.2.0 -shared -Xcrossclang-with-and-without-lc -target default -Xcrossclang-llvm-name llvm -shared}
    [DEBUG] /home/loongson/tools/junixsocket/junixsocket-native/crossclang/bin//gcc -shared -Xcrossclang-with-and-without-lc -target default -Xcrossclang-llvm-name llvm -shared -o libjunixsocket-native-2.10.1-SNAPSHOT.so /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/accept.e0e0fc43.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/address.ed9a7a63.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/afsystem.8ea7694f.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/ancillary.a6102324.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/bind.b3b48bb8.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/capabilities.a18056f1.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/config.3e3e23fd.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/connect.96f3f1d9.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/credentials.6123126b.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/dummy.3617ec9a.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/exceptions.ec71f3f.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/filedescriptors.6e103757.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/init.bfeae3cb.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/jniutil.413a8ed6.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/listen.b10f2142.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/pipe.cb9950e9.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/polling.b1749a72.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/receive.e32b5192.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/reflection.6908e3a6.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/send.d07e9043.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/socket.a9d077ee.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/socketoptions.890270fa.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/socketpair.4c8be7c8.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/tipc.d26cabe3.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/vsock.f5f884a9.o
    [DEBUG] Executing - /home/loongson/tools/junixsocket/junixsocket-native/crossclang/bin//gcc -shared -Xcrossclang-with-and-without-lc -target default -Xcrossclang-llvm-name llvm -shared -o libjunixsocket-native-2.10.1-SNAPSHOT.so /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/accept.e0e0fc43.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/address.ed9a7a63.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/afsystem.8ea7694f.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/ancillary.a6102324.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/bind.b3b48bb8.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/capabilities.a18056f1.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/config.3e3e23fd.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/connect.96f3f1d9.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/credentials.6123126b.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/dummy.3617ec9a.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/exceptions.ec71f3f.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/filedescriptors.6e103757.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/init.bfeae3cb.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/jniutil.413a8ed6.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/listen.b10f2142.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/pipe.cb9950e9.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/polling.b1749a72.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/receive.e32b5192.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/reflection.6908e3a6.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/send.d07e9043.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/socket.a9d077ee.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/socketoptions.890270fa.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/socketpair.4c8be7c8.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/tipc.d26cabe3.o /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/vsock.f5f884a9.o 
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/accept.e0e0fc43.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/address.ed9a7a63.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/afsystem.8ea7694f.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/ancillary.a6102324.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/bind.b3b48bb8.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/capabilities.a18056f1.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/config.3e3e23fd.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/connect.96f3f1d9.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/credentials.6123126b.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/dummy.3617ec9a.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/exceptions.ec71f3f.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/filedescriptors.6e103757.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/init.bfeae3cb.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/jniutil.413a8ed6.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/listen.b10f2142.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/pipe.cb9950e9.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/polling.b1749a72.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/receive.e32b5192.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/reflection.6908e3a6.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/send.d07e9043.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/socket.a9d077ee.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/socketoptions.890270fa.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/socketpair.4c8be7c8.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/tipc.d26cabe3.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>/usr/bin/ld: 找不到 /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/vsock.f5f884a9.nodeps.o: 没有那个文件或目录
    [INFO] OUTPUT>collect2: 错误:ld 返回 1
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary for junixsocket 2.10.1-SNAPSHOT:
    [INFO] 
    [INFO] junixsocket ........................................ SUCCESS [  6.309 s]
    [INFO] junixsocket-native ................................. FAILURE [ 13.278 s]
    [INFO] junixsocket-native-cross ........................... SKIPPED
    [INFO] junixsocket-native-common .......................... SKIPPED
    [INFO] junixsocket-native-custom .......................... SKIPPED
    [INFO] junixsocket-common ................................. SKIPPED
  3. then i ls /home/loongson/tools/junixsocket/junixsocket-native/target/nar/obj/loongarch64-Linux-clang/ the output is :

accept.e0e0fc43.o    ancillary.a6102324.o     config.3e3e23fd.o       dummy.3617ec9a.o            history.xml         listen.b10f2142.o   receive.e32b5192.o     socket.a9d077ee.o         tipc.d26cabe3.o
address.ed9a7a63.o   bind.b3b48bb8.o          connect.96f3f1d9.o      exceptions.ec71f3f.o        init.bfeae3cb.o     pipe.cb9950e9.o     reflection.6908e3a6.o  socketoptions.890270fa.o  vsock.f5f884a9.o
afsystem.8ea7694f.o  capabilities.a18056f1.o  credentials.6123126b.o  filedescriptors.6e103757.o  jniutil.413a8ed6.o  polling.b1749a72.o  send.d07e9043.o        socketpair.4c8be7c8.o

dont have *.nodeps.o

kohlschuetter commented 1 month ago

Thanks for reporting, @cheungxi!

You are using the built-in crossclang linker script to link binary objects that have been created by some other compiler. This will not work.

Mostly because of "-Xcrossclang-with-and-without-lc" (which tells our scripts to build both flavors of the dynamic library, one with, and one without dependencies, i.e., nodeps), but also because of "-target default".

See https://kohlschutter.github.io/junixsocket/crosscomp.html how to use crossclang.

kohlschuetter commented 1 month ago

Repurposing this ticket to keep track of out-of-the-box loongarch64 support.

@cheungxi Please see the above commit. Try the following snapshot selftest jar to see if junixsocket now works for you: https://oss.sonatype.org/content/repositories/snapshots/com/kohlschutter/junixsocket/junixsocket-selftest/2.10.1-SNAPSHOT/junixsocket-selftest-2.10.1-20240905.121638-4-jar-with-dependencies.jar

I've tried with openEuler-24.03-LTS, and that seems to work.

Please report back on this issue with your findings. Thanks for reporting!

cheungxi commented 1 month ago

Repurposing this ticket to keep track of out-of-the-box loongarch64 support.

@cheungxi Please see the above commit. Try the following snapshot selftest jar to see if junixsocket now works for you: https://oss.sonatype.org/content/repositories/snapshots/com/kohlschutter/junixsocket/junixsocket-selftest/2.10.1-SNAPSHOT/junixsocket-selftest-2.10.1-20240905.121638-4-jar-with-dependencies.jar

I've tried with openEuler-24.03-LTS, and that seems to work.

Please report back on this issue with your findings. Thanks for reporting!

Thank you very much ! I've tried with AOSC , and that also work (Selftest PASSED).

I will use this porting compile mill source code.

cheungxi commented 1 month ago

https://github.com/kohlschutter/junixsocket/blob/54576d6ea7c690bdc45feae93fd4b0bb9c639a2c/junixsocket-native-cross/pom.xml#L820

but this classifier is s390x ?

cheungxi commented 1 month ago

when i run mvn -e -X clean install -target current

have a error

[ERROR] Error executing Maven.
java.io.FileNotFoundException: The specified user toolchains file does not exist: /home/loongson/tools/junixsocket/arget
    at org.apache.maven.cli.MavenCli.toolchains (MavenCli.java:1121)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:277)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:203)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
[DEBUG] Shutting down adapter factory; available factories [file-lock, rwlock-local, semaphore-local, noop]; available name mappers [discriminating, file-gav, file-hgav, file-static, gav, static]

what is arget ? is target ?

kohlschuetter commented 1 month ago

mvn -e -X clean install -target current is not a valid command. Where did you get that from? You just specified a toolchain (-t) named arget...

You should be able to simply run "mvn clean install". (I will try that on loonarch64 later).

However, what I usually do is to crosscompile everything (all native platforms) from my Mac.

If you want to hack around the non-native code, you can simply skip the C part by running

mvn clean install -Duse-snapshots -rf :junixsocket-common

See https://kohlschutter.github.io/junixsocket/building.html for details

kohlschuetter commented 1 month ago

2.10.1 has just been released. Please test again, and re-open this ticket if necessary. Thanks again for reporting, @cheungxi !