unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: Ekaitz Zarraga <ekaitz@elenq.tech>
To: Ekaitz Zarraga <ekaitz@elenq.tech>
Cc: "guix-devel\\@gnu.org" <guix-devel@gnu.org>,
	"help-guix\\\\@gnu.org" <help-guix@gnu.org>
Subject: Re: LuaJIT ffi issue with dynamic libraries
Date: Wed, 05 Jan 2022 22:32:16 +0000	[thread overview]
Message-ID: <57DXvwAXKKzuEb-7AisJvegztAagoAAQ9KfKvrz0lAWsRUryrZG-v4yk-R3NBqpO-FK4KcXpqn-VA5rZyvcigVkOn3GYZA8LzOU4SnwMdX8=@elenq.tech> (raw)
In-Reply-To: <OsAPl4D9SKjtLq7uOUFVmddZOdaC2V1Wm7nurteXYFyEM4r_f5qMnurUxNQv8tCOoIM-KH-5h7CsZe-kouNXNpVThRrXKOOGYUre4OYjsQY=@elenq.tech>

Hi,

I'm pushing this again just in case anyone has an answer.

Thanks!

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Thursday, November 25th, 2021 at 5:46 PM, Ekaitz Zarraga <ekaitz@elenq.tech> wrote:

> Hi all,
>
> I've been having some issues with LuaJIT's FFI. More specifically with the
> `load` function, that loads a library in the "search path for dynamic
> libraries".
>
> The LuaJIT documentation says the following:
>
> > On POSIX systems, if the name contains no dot, the extension .so is appended.
> > Also, the lib prefix is prepended if necessary. So ffi.load("z") looks for
> > "libz.so" in the default shared library search path.
>
>
> In my case I'm unable to load a library, in this case `librec.so` simply by
> calling `ffi.load` even if both are part of the same environment. I read a
> little bit of the LuaJIT code and I found that it is doing a `dlopen` inside so
> I made a test:
>
> First I made a simple C file with a call to `dlopen` and straced its result. It
> simply finds the library after proving some folders. I also noted that the
> environment automatically set the `LIBRARY_PATH` variable for me (even if the
> value of the variable does not match the patch where librec.so is being
> searched):
>
> --8<---------------cut here---------------start------------->8---
> $ guix shell gcc-toolchain strace recutils
> $ cat <<EOF > dl.c
> > #include<dlfcn.h>
> >
> > int main(int argc, char *argv[]){
> >     void * i = dlopen("librec.so", RTLD_LAZY);
> >     return (int)i;
> > }
> EOF
> $ gcc dl.c -ldl
> $ strace ./a.out 2>&1 | grep librec.so
> openat(AT_FDCWD, "/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/28bcmy08ki5krvr2g9hbm3bhys822fvn-gcc-11.2.0-lib/lib/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib/tls/haswell/x86_64/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib/tls/haswell/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib/tls/x86_64/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib/tls/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib/haswell/x86_64/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib/haswell/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib/x86_64/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib/librec.so", O_RDONLY|O_CLOEXEC) = 3
> $ echo $LIBRARY_PATH
> /gnu/store/hiiyy2b8pw2cq9mw8iik9xi9lpclcv7b-profile/lib
> --8<---------------cut here---------------end--------------->8---
>
> When I do a similar approach with LuaJIT I get the following:
>
> - The paths the `dlopen` call is proving are different to the previous case and
>   they are pretty weird too.
> - There's no `LIBRARY_PATH` set.
> - Even if I set `LIBRARY_PATH` myself it's ignored.
> - It works correctly when I set `LD_LIBRARY_PATH`, but should I?
>
>
> --8<---------------cut here---------------start------------->8---
> $ guix shell luajit strace recutils
> $ cat <<EOF > dl.lua
> > ffi = require "ffi"
> > ffi.load "rec"
> > EOF
> $ strace luajit dl.lua 2>&1  | grep librec.so
> openat(AT_FDCWD, "/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../tls/haswell/x86_64/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../tls/haswell/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../tls/x86_64/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../tls/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../haswell/x86_64/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../haswell/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../x86_64/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/librec.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> $ echo $LIBRARY_PATH
>
> $ export LIBRARY_PATH=$GUIX_ENVIRONMENT/lib
> $ strace luajit dl.lua 2>&1  | grep librec.so
> #### SAME AS BEFORE ####
> $ export LD_LIBRARY_PATH=$GUIX_ENVIRONMENT/lib
> $ echo $LD_LIBRARY_PATH
> /gnu/store/5v09kbdda7966x263cgnva2z15yrdbfb-profile/lib
> $ strace luajit dl.lua 2>&1  | grep librec.so
> openat(AT_FDCWD, "/gnu/store/5v09kbdda7966x263cgnva2z15yrdbfb-profile/lib/librec.so", O_RDONLY|O_CLOEXEC) = 3
> --8<---------------cut here---------------end--------------->8---
>
> Does any of this make sense?
>
> The easiest conclusion is that LuaJIT is not working out the box and we should
> fix it, but I'm not sure where to start because I'm assuming both examples here
> come from the same concept: making a similar call to `dlopen`. There must be
> some context I'm missing here to solve this.
>
> Any ideas?
>
>
> ElenQ Technology
> Ethical Innovation



  reply	other threads:[~2022-01-05 22:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-25 16:46 LuaJIT ffi issue with dynamic libraries Ekaitz Zarraga
2022-01-05 22:32 ` Ekaitz Zarraga [this message]
2022-01-05 23:33   ` zimoun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='57DXvwAXKKzuEb-7AisJvegztAagoAAQ9KfKvrz0lAWsRUryrZG-v4yk-R3NBqpO-FK4KcXpqn-VA5rZyvcigVkOn3GYZA8LzOU4SnwMdX8=@elenq.tech' \
    --to=ekaitz@elenq.tech \
    --cc=guix-devel@gnu.org \
    --cc=help-guix@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).