From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id cJtgFrYc1mHUIgEAgWs5BA (envelope-from ) for ; Wed, 05 Jan 2022 23:33:26 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 2IkbD7Yc1mH2IwEAG6o9tA (envelope-from ) for ; Wed, 05 Jan 2022 23:33:26 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A54E140DBC for ; Wed, 5 Jan 2022 23:33:25 +0100 (CET) Received: from localhost ([::1]:36882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5EqS-0007RS-PG for larch@yhetil.org; Wed, 05 Jan 2022 17:33:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5Epm-0007QN-Au for help-guix@gnu.org; Wed, 05 Jan 2022 17:32:42 -0500 Received: from mail-4317.proton.ch ([185.70.43.17]:20911) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5EpY-0007ZF-MX for help-guix@gnu.org; Wed, 05 Jan 2022 17:32:32 -0500 Date: Wed, 05 Jan 2022 22:32:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=elenq.tech; s=protonmail; t=1641421937; bh=HBn1XtgxjkbD1YqP5W79qCm3bXirdRbcDhhegrzfgBo=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc; b=Ykffc0YS/upA+ig90JkS72VblVi4b84Ofz5d7H2likbODstq8G8+fkJrf0IeAsjFk MoSQYgCSxL4CSFlt5mTey2lVEBcRh4HcpX3e8qfy6TQylMFtRo/ULX+Ees6NS5EBfN Ws2O8lAQavVYca+N7r6qVu4QxICzAhtpY4sbquFOmkle1HifHOnZwwkepCE2854iH+ XgPMyzFo3SieqpruH0yLYdO6NjPXo0JsfHoOwb7PqBGTF4aL+3obKwt5kK2cHagEuy ySjrDbLZwa2RubrvsPOaGvZxTytbAJNNJ7acOqf0rVS8YFLdEe/B4LaIj+8YLddowY Ke/rxm5CsLXOQ== To: Ekaitz Zarraga From: Ekaitz Zarraga Subject: Re: LuaJIT ffi issue with dynamic libraries Message-ID: <57DXvwAXKKzuEb-7AisJvegztAagoAAQ9KfKvrz0lAWsRUryrZG-v4yk-R3NBqpO-FK4KcXpqn-VA5rZyvcigVkOn3GYZA8LzOU4SnwMdX8=@elenq.tech> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.70.43.17; envelope-from=ekaitz@elenq.tech; helo=mail-4317.proton.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TO_EQ_FM_DIRECT_MX=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-guix@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Ekaitz Zarraga Cc: "guix-devel\\@gnu.org" , "help-guix\\\\@gnu.org" Errors-To: help-guix-bounces+larch=yhetil.org@gnu.org Sender: "Help-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641422005; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=HBn1XtgxjkbD1YqP5W79qCm3bXirdRbcDhhegrzfgBo=; b=kSeEGGmmnSntqE2FbrjtDf1MpnU2ir5qnw4wGRmXpA8KTcODKc0mPceKm+wrQT+zzB7vy4 HKGTIS7biFxW7NK/lH4EV6Ay8ZNTBd8L9gwjBpCE3Z5MtMlkS1mSMl1nCA5J3bOAlSrWc8 Fg59JJoO6wjkNfkgi0BP2yVXZMBdeI1hOlqIgOwJRBbrKhpwzMvKgRAnx7mZcpLlpIXCPA 87mUNw/njBAgKE/HDqTPvnQcZFbJG6fUSZuWcmrX9zNJOR9v0J9X2MO1nnkYgFaNzN39/L 0mNrIYVGrAWgy4hlmA0hZwLVlCRovMGnqBjJZMbcvjzCA+ZAXNqK80QGm4uE5g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641422005; a=rsa-sha256; cv=none; b=U/BGPMBP+zHe6dsVeZOMJjgp3Dzf/Iyx16Llw5YR9VgVbpVtV6gxaeKcUkfvQHDogVi3mm tRo1+uOf5/687gLDqRIFJO22xIumBvqRaMMkzpn8d7AWjUbhKvhq781vyEfYe7LCz0Egg6 hDzgeBYvzTfERJEBOZb5BjwycUW234CUFf/QF4CbN9sKOZXtgwxRwf8s/v6xGofUl8taoz FMNJVfKm/ERsnb2Lx9O/SWIka+XzrlTTIslmTpKlRRO//ycIqd72JeKo4pKPvS3Dq7z15D GyfSbzIt3lvMm0JtnjZiOKQ9IA90YUyDxmYV++qn8Te7nACwaBRdMDSD0NM/rg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=elenq.tech header.s=protonmail header.b=Ykffc0YS; dmarc=fail reason="SPF not aligned (relaxed)" header.from=elenq.tech (policy=none); spf=pass (aspmx1.migadu.com: domain of "help-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="help-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.00 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=elenq.tech header.s=protonmail header.b=Ykffc0YS; dmarc=fail reason="SPF not aligned (relaxed)" header.from=elenq.tech (policy=none); spf=pass (aspmx1.migadu.com: domain of "help-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="help-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: A54E140DBC X-Spam-Score: -2.00 X-Migadu-Scanner: scn1.migadu.com X-TUID: iSeJozuCYMjM Hi, I'm pushing this again just in case anyone has an answer. Thanks! =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original Me= ssage =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 On Thursday, November 25th, 2021 at 5:46 PM, Ekaitz Zarraga wrote: > Hi all, > > I've been having some issues with LuaJIT's FFI. More specifically with th= e > `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 app= ended. > > 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` ins= ide so > I made a test: > > First I made a simple C file with a call to `dlopen` and straced its resu= lt. It > simply finds the library after proving some folders. I also noted that th= e > 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 < dl.c > > #include > > > > int main(int argc, char *argv[]){ > > void * i =3D 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) =3D -1 ENOENT (No such file or director= y) > openat(AT_FDCWD, "/gnu/store/28bcmy08ki5krvr2g9hbm3bhys822fvn-gcc-11.2.0-= lib/lib/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or dire= ctory) > openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib= /tls/haswell/x86_64/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such = file or directory) > openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib= /tls/haswell/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or= directory) > openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib= /tls/x86_64/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or = directory) > openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib= /tls/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directo= ry) > openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib= /haswell/x86_64/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file= or directory) > openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib= /haswell/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or dir= ectory) > openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib= /x86_64/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or dire= ctory) > openat(AT_FDCWD, "/gnu/store/fz52krs37spvca6q0g0zmx6jmc1n388g-profile/lib= /librec.so", O_RDONLY|O_CLOEXEC) =3D 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 ca= se 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 < dl.lua > > ffi =3D 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) =3D -1 ENOENT (No such file or director= y) > openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-l= ib/lib/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or direc= tory) > openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-l= ib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../tls/haswell/x86_64/libre= c.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) > openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-l= ib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../tls/haswell/librec.so", = O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) > openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-l= ib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../tls/x86_64/librec.so", O= _RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) > openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-l= ib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../tls/librec.so", O_RDONLY= |O_CLOEXEC) =3D -1 ENOENT (No such file or directory) > openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-l= ib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../haswell/x86_64/librec.so= ", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) > openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-l= ib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../haswell/librec.so", O_RD= ONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) > openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-l= ib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../x86_64/librec.so", O_RDO= NLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) > openat(AT_FDCWD, "/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-l= ib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../../librec.so", O_RDONLY|O_C= LOEXEC) =3D -1 ENOENT (No such file or directory) > openat(AT_FDCWD, "/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/= lib/librec.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or director= y) > $ echo $LIBRARY_PATH > > $ export LIBRARY_PATH=3D$GUIX_ENVIRONMENT/lib > $ strace luajit dl.lua 2>&1 | grep librec.so > #### SAME AS BEFORE #### > $ export LD_LIBRARY_PATH=3D$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) =3D 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 s= hould > fix it, but I'm not sure where to start because I'm assuming both example= s 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