janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.38k stars 217 forks source link

janet fails to run with 'error while loading shared libraries' #1356

Closed meinside closed 6 months ago

meinside commented 6 months ago

Hi, I use asdf-vm for installing and managing various kinds & versions of programming languages,

but since version 1.32.0, janet fails to run with the following error:

/home/ubuntu/.asdf/installs/janet/1.33.0/bin/janet: error while loading shared libraries: libjanet.so.1.33: cannot open shared object file: No such file or directory

.so files are in place correctly:

$ pwd
/home/ubuntu/.asdf/installs/janet/1.33.0/lib

$ ll
total 1928
drwxr-xr-x 4 ubuntu ubuntu    4096 Jan 10 10:44 ./
drwxrwxr-x 6 ubuntu ubuntu    4096 Jan 10 10:44 ../
drwxr-xr-x 2 ubuntu ubuntu    4096 Jan 10 10:44 janet/
-rw-r--r-- 1 ubuntu ubuntu 1108746 Jan 10 10:44 libjanet.a
lrwxrwxrwx 1 ubuntu ubuntu      16 Jan 10 10:44 libjanet.so -> libjanet.so.1.33*
lrwxrwxrwx 1 ubuntu ubuntu      18 Jan 10 10:44 libjanet.so.1.33 -> libjanet.so.1.33.0*
-rwxr-xr-x 1 ubuntu ubuntu  846528 Jan 10 10:44 libjanet.so.1.33.0*
drwxr-xr-x 2 ubuntu ubuntu    4096 Jan 10 10:44 pkgconfig/

and I can run it successfully with LD_LIBRARY_PATH, like:

$ LD_LIBRARY_PATH=~/.asdf/installs/janet/1.33.0/lib janet
Janet 1.33.0-meson linux/aarch64/gcc - '(doc)' for help
repl:1:

The last working version without LD_LIBRARY_PATH is 1.31.0 for me.

Was there any change that could make this happen?

Or, can there be anything going bad in asdf-vm?

sogaiu commented 6 months ago

Not sure when things changed, but my guess is that your setup uses meson to build.

For v1.31.0, when examined using ldd, the resulting meson-built janet shows:

$ ldd build/janet
    linux-vdso.so.1 (0x00007ffc755df000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007f2295836000)
    libc.so.6 => /usr/lib/libc.so.6 (0x00007f2295400000)
    /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f22959f2000)

while for v1.33.0 I get:

$ ldd build/janet
    linux-vdso.so.1 (0x00007ffcd6f53000)
    libjanet.so.1.33 => /home/user/src/janet.1356/build/libjanet.so.1.33 (0x00007ff85ae11000)
    libc.so.6 => /usr/lib/libc.so.6 (0x00007ff85aa00000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007ff85ad22000)
    /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007ff85aedf000)

FWIW, a Makefile-based janet v1.33.0 doesn't seem to be linked to the janet shared object:

$ ldd build/janet
    linux-vdso.so.1 (0x00007ffd2c1e4000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007f1ca0239000)
    libc.so.6 => /usr/lib/libc.so.6 (0x00007f1c9fe00000)
    /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f1ca03ec000)
sogaiu commented 6 months ago

I think the change may have been in this commit.

Perhaps this bit is related.

meinside commented 6 months ago

I see. janet installed with asdf-vm is built with meson, so that must be the reason.

I don't want to build things manually, so I'll stick with LD_LIBRARY_PATH then.

sogaiu commented 6 months ago

In some of the output from ldd above it looks like the path to the janet shared object is within the source repository:

libjanet.so.1.33 => /home/user/src/janet.1356/build/libjanet.so.1.33 (0x00007ff85ae11000)

Looking at readelf -a output I see:

Dynamic section at offset 0x5dc0 contains 28 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libjanet.so.1.33]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/]
sogaiu commented 6 months ago

I don't know what other effects it might have, but FWIW, -Dshared=false when invoking meson setup seems to arrange for things such that once building completes, the janet shared object is not used:

$ meson setup build --prefix $HOME/.local --optimization 2 --libdir $HOME/.local/lib -Dshared=false -Dgit_hash=$(git log --pretty=format:'%h' -n 1)
The Meson build system
Version: 1.3.0
Source dir: /home/user/src/janet.1356
Build dir: /home/user/src/janet.1356/build
Build type: native build
Project name: janet
Project version: 1.33.0
C compiler for the host machine: cc (gcc 12.2.0 "cc (GCC) 12.2.0")
C linker for the host machine: cc ld.bfd 2.39
Host machine cpu family: x86_64
Host machine cpu: x86_64
Library m found: YES
Library dl found: YES
Library android-spawn found: NO
Run-time dependency threads found: YES
Configuring janetconf.h using configuration
Compiler for C supports arguments -fvisibility=hidden: YES 
Build targets in project: 6

janet 1.33.0

  User defined options
    libdir      : /home/user/.local/lib
    optimization: 2
    prefix      : /home/user/.local
    git_hash    : f91e5994
    shared      : false

Found ninja-1.11.1 at /usr/bin/ninja

Building:

$ ninja -C build
ninja: Entering directory `build'
[51/51] Generating patched-janeth with a custom command

Checking with ldd:

$ ldd ./build/janet
    linux-vdso.so.1 (0x00007ffd4d9fa000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007fc0654fa000)
    libc.so.6 => /usr/lib/libc.so.6 (0x00007fc065200000)
    /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007fc0656b8000)
meinside commented 6 months ago

I'll contact the author of the asdf-vm janet plugin and let him/her know about this issue.

Fixing the meson build script can be another solution for this.

sogaiu commented 6 months ago

Fixing the meson build script can be another solution for this.

I'm not sure if the current behavior of the meson build script is intentional or not. That's something may be the author would have better insight about.