Skip to content

Linux shared libraries can't be loaded in Java #22528

Closed
@drrb

Description

@drrb

It seems that there is something peculiar about the shared libraries that come with Rust for Linux that stops them from being able to be loaded from Java. Loading libraries this way is important for embedding Rust code in Java, and works as expected with the OSX shared libraries.

Script that reproduces the problem on post-alpha nightlies (tested with Ubuntu 12.04/14.10 64 bit, OpenJDK 7, Oracle JDK 7, 8):

#!/bin/bash -e

trap 'rm *.java *.class' EXIT

cat > LoadNativeLibrary.java <<EOF
class LoadNativeLibrary {
    public static void main(String[] args) {
        String library = args[0];
        System.load(library);
    }
}
EOF
javac LoadNativeLibrary.java

echo "Attempting to load libsyntax in Java..."
java LoadNativeLibrary /usr/local/lib/libsyntax-*.so
echo "Loaded"

Example output:

$ ./load-rust-library 
Attempting to load libsyntax in Java...
./load-rust-library: line 16:  8388 Segmentation fault      (core dumped) java LoadNativeLibrary /usr/local/lib/libsyntax-*.so

Core dump backtrace:

Core was generated by `java LoadNativeLibrary /usr/local/lib/libsyntax-4e7c5e5c.so'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  open_verify (name=0x7f9f7c0e1770 "/usr/local/lib/libsyntax-4e7c5e5c.so", fbp=0x7f9f84a353d8, loader=<optimized out>, whatcode=<optimized out>, found_other_class=<optimized out>, 
    free_name=<optimized out>) at dl-load.c:2098
2098    dl-load.c: No such file or directory.
(gdb) bt full
#0  open_verify (name=0x7f9f7c0e1770 "/usr/local/lib/libsyntax-4e7c5e5c.so", fbp=0x7f9f84a353d8, loader=<optimized out>, whatcode=<optimized out>, found_other_class=<optimized out>, 
    free_name=<optimized out>) at dl-load.c:2098
        size = 3836402
        phdr = 0x7f9f84a35420
        ph = 0x7f9f84a354c8
        ehdr = 0x7f9f84a353e0
        abi_note = <optimized out>
        osversion = <optimized out>
        maplength = <optimized out>
        errstring = 0x0
        errval = 0
        fd = 11
#1  0x00007f9f8482ed9f in _dl_map_object (loader=loader@entry=0xd227e0, name=name@entry=0x7f9f7c0e0c90 "/usr/local/lib/libsyntax-4e7c5e5c.so", type=type@entry=2, trace_mode=trace_mode@entry=0, 
    mode=mode@entry=-1879048191, nsid=0) at dl-load.c:2543
        fd = <optimized out>
        realname = 0x7f9f7c0e1770 "/usr/local/lib/libsyntax-4e7c5e5c.so"
        l = <optimized out>
        fb = {len = 832, 
          buf = "\177ELF\002\001\001\000\000\000\000\000\000\000\000\000\003\000>\000\001\000\000\000\220\377\004\000\000\000\000\000@\000\000\000\000\000\000\000\030|{\000\000\000\000\000\000\000\000\000@\000\070\000\a\000@\000\037\000\034\000\001\000\000\000\005", '\000' <repeats 28 times>, "\365?\000\000\000\000\000\000\365?\000\000\000\000\000\000\000 \000\000\000\000\000\001\000\000\000\006\000\000\000\000\365?\000\000\000\000\000\000\365_\000\000\000\000\000\000\365_\000\000\000\000\000\222\205;\000\000\000\000\000\250\205;\000\000\000\000\000\000\000 \000\000\000\000\000\002\000\000\000\006\000\000\000P\320@\000\000\000\000\000P\320`\000\000\000\000\000"...}
        __PRETTY_FUNCTION__ = "_dl_map_object"
        found_other_class = false
        stack_end = 0x7f9f00000000
#2  0x00007f9f8483aa54 in dl_open_worker (a=a@entry=0x7f9f84a35958) at dl-open.c:235
        args = 0x7f9f84a35958
        file = 0x7f9f7c0e0c90 "/usr/local/lib/libsyntax-4e7c5e5c.so"
        mode = -2147483647
        call_map = 0xd227e0
        dst = <optimized out>
        __PRETTY_FUNCTION__ = "dl_open_worker"
        new = <optimized out>
        r = <optimized out>
        reloc_mode = <optimized out>
        nmaps = <optimized out>
        l = <optimized out>
        maps = <optimized out>
        any_tls = <optimized out>
        first_static_tls = <optimized out>
#3  0x00007f9f84835ff4 in _dl_catch_error (objname=objname@entry=0x7f9f84a35948, errstring=errstring@entry=0x7f9f84a35950, mallocedp=mallocedp@entry=0x7f9f84a35940, 
    operate=operate@entry=0x7f9f8483a9a0 <dl_open_worker>, args=args@entry=0x7f9f84a35958) at dl-error.c:187
        errcode = 32671
        c = {objname = 0x7f9f84a35948, errstring = 0x7f9f84a35950, malloced = 0x7f9f84a35940, errcode = 0x7f9f84a35834, env = {{__jmpbuf = {140323101825624, 9168241663064937987, 2147483649, 140322957823120, 
                140736273650424, 3, 9168241662859417091, 9168241938003793411}, __mask_was_saved = 2080374816, __saved_mask = {__val = {50752, 0, 8092888, 50736, 1792, 140323094083624, 3598896384, 391126, 
                  4095, 391168, 4096, 1, 140323101825376, 763, 3669971740273, 95}}}}}
        catchp = 0x7f9f84a376f8

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions