kohlschutter / junixsocket

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

"failed to map segment from shared object" — Could not load native library junixsocket-native for architecture amd64-Linux #99

Closed MattiL closed 2 years ago

MattiL commented 2 years ago

Describe the bug Could not load native library junixsocket-native for architecture amd64-Linux

To Reproduce Steps to reproduce the behavior:

  1. java -jar /tmp/junixsocket-selftest-2.4.0-jar-with-dependencies.jar

Expected behavior Tests pass and connection achieved.

Output/Screenshots

junixsocket selftest version 2.4.0

System properties:

awt.toolkit: sun.awt.X11.XToolkit file.encoding: UTF-8 file.encoding.pkg: sun.io file.separator: / java.awt.graphicsenv: sun.awt.X11GraphicsEnvironment java.awt.printerjob: sun.print.PSPrinterJob java.class.path: /tmp/junixsocket-selftest-2.4.0-jar-with-dependencies.jar java.class.version: 52.0 java.endorsed.dirs: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/endorsed java.ext.dirs: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/ext:/usr/java/packages/lib/ext java.home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre java.io.tmpdir: /tmp java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib java.runtime.name: OpenJDK Runtime Environment java.runtime.version: 1.8.0_322-b06 java.specification.name: Java Platform API Specification java.specification.vendor: Oracle Corporation java.specification.version: 1.8 java.vendor: Red Hat, Inc. java.vendor.url: https://www.redhat.com/ java.vendor.url.bug: https://bugzilla.redhat.com/enter_bug.cgi?product=Red%20Hat%20Enterprise%20Linux%208&component=java-1.8.0-openjdk java.version: 1.8.0_322 java.vm.info: mixed mode java.vm.name: OpenJDK 64-Bit Server VM java.vm.specification.name: Java Virtual Machine Specification java.vm.specification.vendor: Oracle Corporation java.vm.specification.version: 1.8 java.vm.vendor: Red Hat, Inc. java.vm.version: 25.322-b06 line.separator: \n os.arch: amd64 os.name: Linux os.version: 4.18.0-240.15.1.el8_3.x86_64 path.separator: : sun.arch.data.model: 64 sun.boot.class.path: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/jfr.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/classes sun.boot.library.path: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/amd64 sun.cpu.endian: little sun.cpu.isalist: sun.io.unicode.encoding: UnicodeLittle sun.java.command: /tmp/junixsocket-selftest-2.4.0-jar-with-dependencies.jar sun.java.launcher: SUN_STANDARD sun.jnu.encoding: UTF-8 sun.management.compiler: HotSpot 64-Bit Tiered Compilers sun.os.patch.level: unknown user.country: US user.dir: /home/matti/support user.home: /root user.language: en user.name: root user.timezone:

BEGIN contents of file: /etc/os-release NAME="Red Hat Enterprise Linux" VERSION="8.5 (Ootpa)" ID="rhel" ID_LIKE="fedora" VERSION_ID="8.5" PLATFORM_ID="platform:el8" PRETTY_NAME="Red Hat Enterprise Linux 8.5 (Ootpa)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:redhat:enterprise_linux:8::baseos" HOME_URL="https://www.redhat.com/" DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/8/" BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8" REDHAT_BUGZILLA_PRODUCT_VERSION=8.5 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION="8.5" =END= contents of file: /etc/os-release

BEGIN contents of file: /etc/system-release Red Hat Enterprise Linux release 8.5 (Ootpa) =END= contents of file: /etc/system-release

BEGIN contents of file: /etc/system-release-cpe cpe:/o:redhat:enterprise_linux:8::baseos =END= contents of file: /etc/system-release-cpe

AFUNIXSocket.isSupported: Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load native library junixsocket-native for architecture amd64-Linux at org.newsclub.net.unix.NativeLibraryLoader.initCantLoadLibraryError(NativeLibraryLoader.java:282) at org.newsclub.net.unix.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:264) at org.newsclub.net.unix.NativeUnixSocket.(NativeUnixSocket.java:61) at org.newsclub.net.unix.AFUNIXSocket.isSupported(AFUNIXSocket.java:241) at org.newsclub.net.unix.selftest.Selftest.checkSupported(Selftest.java:166) at org.newsclub.net.unix.selftest.Selftest.main(Selftest.java:106) Suppressed: java.lang.Exception: No library specified with -Dorg.newsclub.net.unix.library.override= at org.newsclub.net.unix.NativeLibraryLoader.loadLibraryOverride(NativeLibraryLoader.java:217) at org.newsclub.net.unix.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:240) ... 4 more Suppressed: java.lang.UnsatisfiedLinkError: no junixsocket-native-2.4.0 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:871) at java.lang.System.loadLibrary(System.java:1124) at org.newsclub.net.unix.NativeLibraryLoader$StandardLibraryCandidate.load(NativeLibraryLoader.java:117) at org.newsclub.net.unix.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:251) ... 4 more Suppressed: java.lang.UnsatisfiedLinkError: /tmp/libtmp4089354928993834369libjunixsocket-native-2.4.0.so: /tmp/libtmp4089354928993834369libjunixsocket-native-2.4.0.so: failed to map segment from shared object at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817) at java.lang.Runtime.load0(Runtime.java:810) at java.lang.System.load(System.java:1088) at org.newsclub.net.unix.NativeLibraryLoader$ClasspathLibraryCandidate.load(NativeLibraryLoader.java:167) at org.newsclub.net.unix.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:251) ... 4 more Suppressed: java.lang.UnsatisfiedLinkError: /tmp/libtmp1592733482443988882libjunixsocket-native-2.4.0.so: /tmp/libtmp1592733482443988882libjunixsocket-native-2.4.0.so: failed to map segment from shared object at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817) at java.lang.Runtime.load0(Runtime.java:810) at java.lang.System.load(System.java:1088) at org.newsclub.net.unix.NativeLibraryLoader$ClasspathLibraryCandidate.load(NativeLibraryLoader.java:167) at org.newsclub.net.unix.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:251) ... 4 more Suppressed: java.lang.UnsatisfiedLinkError: /tmp/libtmp4275623568784751316libjunixsocket-native-2.4.0.so: /tmp/libtmp4275623568784751316libjunixsocket-native-2.4.0.so: failed to map segment from shared object at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817) at java.lang.Runtime.load0(Runtime.java:810) at java.lang.System.load(System.java:1088) at org.newsclub.net.unix.NativeLibraryLoader$ClasspathLibraryCandidate.load(NativeLibraryLoader.java:167) at org.newsclub.net.unix.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:251) ... 4 more Suppressed: java.lang.UnsatisfiedLinkError: /tmp/libtmp4109876805529846049libjunixsocket-native-2.4.0.so: /tmp/libtmp4109876805529846049libjunixsocket-native-2.4.0.so: failed to map segment from shared object at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817) at java.lang.Runtime.load0(Runtime.java:810) at java.lang.System.load(System.java:1088) at org.newsclub.net.unix.NativeLibraryLoader$ClasspathLibraryCandidate.load(NativeLibraryLoader.java:167) at org.newsclub.net.unix.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:251) ... 4 more

Environment (please complete the following information):

kohlschuetter commented 2 years ago

Your temporary directory (/tmp) is configured to prevent executing binary code (which we need for the native library).

You could specify a different temporary directory for junixsocket (recommended), via the system property org.newsclub.net.unix.library.tmpdir.

Alternatively, you could also remount /tmp to alllow binary code. However, that may be undesirable since it affects more than junixsocket.

sudo mount /tmp -o remount,exec

If neither option is viable for you, consider providing the junixsocket library file directly, either by placing it in your JRE's library path, or by specifying a direct path to the library via the org.newsclub.net.unix.library.override system property.