From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?S=C3=B6ren?= Tempel Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.bugs Subject: Re: [PATCH] load-foreign-library: perform substring match on library files Date: Sat, 20 Aug 2022 15:52:21 +0200 Message-ID: <27GGIELIPN05K.2DRSYZVI36WYY@8pit.net> References: <23TGNISPS9PPL.2YOENNQD9V56X@8pit.net> <20220723110919.30107-1-soeren@soeren-tempel.net> <936e98a7-a9d2-2607-ef6a-8c0edff19c4a@telenet.be> <2EA1MELO27342.28JGAL8QO05T4@8pit.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29925"; mail-complaints-to="usenet@ciao.gmane.io" Cc: bug-guile@gnu.org, guile-devel@gnu.org To: Maxime Devos Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Aug 20 15:53:03 2022 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oPOuM-0007am-TQ for guile-devel@m.gmane-mx.org; Sat, 20 Aug 2022 15:53:03 +0200 Original-Received: from localhost ([::1]:46602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oPOuL-0004fK-Tk for guile-devel@m.gmane-mx.org; Sat, 20 Aug 2022 09:53:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oPOtv-0004f9-3t; Sat, 20 Aug 2022 09:52:35 -0400 Original-Received: from magnesium.8pit.net ([45.76.88.171]:11975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oPOts-0000gL-Nr; Sat, 20 Aug 2022 09:52:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=ehwSRmQn4l FQch+fdYUA2OVsCkvh7NAsTGC4cwSfwaw=; h=in-reply-to:references:from: subject:cc:to:date; d=soeren-tempel.net; b=nj7o8GVCuQPv+/vHhZtSy2zuOhm MNhS1ezo5s9v5yA5xoXEFY2ZnVSVYYKZhipGK9/tioCdDxM5KYPgCP/xVlszs1cVOxj0q4 wV5NDkLmE2pW/yCLlz/NWs6A5DNtLa7Hz5Wceam9j7KF64NkZfnIpSWH7Sm0I5zHh3sDZa kze4= Original-Received: from localhost (p200300f5ff05aa009d746ddc22c1eda1.dip0.t-ipconnect.de [2003:f5:ff05:aa00:9d74:6ddc:22c1:eda1]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 6cc17e7f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Sat, 20 Aug 2022 15:52:24 +0200 (CEST) In-Reply-To: <2EA1MELO27342.28JGAL8QO05T4@8pit.net> Received-SPF: pass client-ip=45.76.88.171; envelope-from=soeren@soeren-tempel.net; helo=magnesium.8pit.net 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:21316 gmane.lisp.guile.bugs:10319 Archived-At: Hi, How do we proceed with this? I would especially be interested in the "patching" that you do in Guix. Maybe that would also be a suitable workaround for us on the Alpine side until this is sorted out properly. Greetings, S=C3=B6ren S=C3=B6ren Tempel wrote: > Hi, >=20 > Thanks for your feedback, comments below. >=20 > Maxime Devos wrote: > > Long term, I think it would be ideal for Guile to decide upon a major=20= > > version (and maybe even location, depending on the choices of the=20 > > distro) at _compile_ time instead of runtime, not unlike how other=20 > > compilers work. >=20 > Sure, that could work too. >=20 > > If the Guile module is being compiled with --rpath, it searches > > $CROSS_LIBRARY_PATH or $LIBRARY_PATH and encodes the full file name > > (/usr/lib/.../libguile-... or /gnu/store/.../lib/...) in the .go, > > which avoids some manual patching we have to do in Guix. >=20 > What kind of manual patching do you do on Guix? Could you refer me to > the code for that? Maybe that's something we could also do on Alpine in > the meantime. >=20 > > IIUC, the string-prefix? search is non-deterministic, which can make=20= > > debugging complicated when multiple versions are installed.=20 >=20 > Well, on Linux readdir(3) file name order depends on the file system > implementation. Since the algorithm returns the first file with a > substring match, it depends on the readdir order. As long as the same > filesystem is used, it should be deterministic. >=20 > > I think it would be better to bail out if there are multiple matches > > instead of a risk of guessing incorrectly. >=20 > Many packages provide multiple .so files with different version > granularity so bailing out if there are multiple substring matches > doesn't really work. For example, for libgit2 I have the following files > installed on my system: >=20 > $ ls /usr/lib/libgit2* > /usr/lib/libgit2.so.1.4 > /usr/lib/libgit2.so.1.4.4 >=20 > Where the former is a symlink to the latter. However, it would be > possible to collect all substring matches and prioritize them according > to some algorithm (e.g. alphabetical order). This would also make the > algorithm independent of the readdir(3) order. >=20 > > The prefixing behaviour is also not documented, so some documentation i= s=20 > > needed in the manual. >=20 > I can add some documentation if there is interest in merging this. >=20 > > * Does it go scanning the dir even if libfoo.so could be found? > > Otherwise, there are some possible performance gains by checking fo= r > > libfoo.so first -- consider the case where /usr/lib is huge. >=20 > Yes, a fast path could be added though you probably really need to have > a lot of files installed in /usr/lib for this to be worth it. >=20 > > * When doing (load-foreign-library "/gnu/store/.../libfoo.so") > > (absolute file name!), would it search for > > /gnu/store/.../libfoo.so.N?=C2=A0 If so, that would be surprising, > > especially if libfoo.so.N exists. >=20 > Yep, it does. I originally didn't want to modify the handling of > absolute paths but unfortunately during testing I noticed that Guile > extensions seem to be loaded with an absolute path and hence don't > work without the libfoo.so symlink [1]. >=20 > > * If doing libfoo.so.N, will it search for libfoo.so.N.M? >=20 > Yes, since libfoo.so.N is a prefix of libfoo.so.N.M. >=20 > > * Does it only apply to the system paths, or also to > > GUILE_SYSTEM_EXTENSION_PATH, LTDL_LIBRARY_PATH and > > GUILE_EXTENSION_PATH? The latter would be surprising to me, as > > versioning is more of a system thing. >=20 > If those paths are also searched using the load-foreign-library > procedure then they are affected by this change. Also, I am not a Guile > expert but on Alpine, Guile extensions such as guile-reader also ship > versioned sonames [1]. >=20 > > * To test it, and avoid breaking things later with future changes to > > load-foreign-library, could some tests be added? >=20 > Probably, though I am not familiar with the Guile test setup and there > don't seem to be any existing tests for foreign-library. >=20 > > * Is this change desirable?=C2=A0 I mean, this is an FFI API, so the A= BI of > > the library is rather important. If a Guile module links to > > libfoo.so, and they had version N in mind, then it's important it > > doesn't link to N-1 or N+1 instead, because of ABI > > incompatibilities. As such, to me it seems _good_ that you got some > > errors, as now you get a reminder to explicitly state which ABI > > version is needed. (YMMV, and the mileage of the Guile maintainers > > might vary, etc.) >=20 > In my experience, most languages which don't link against shared > libraries directly but instead load them at run-time don't hardcode ABI > versions (for example, refer to Python's ctypes.util.find_library). > Also, the current implementation of load-foreign-library does not force > you to specify an ABI version but instead loads whatever the libfoo.so > symlink refers to. >=20 > > Also, this seems like a non-trivial change to me, so a copyright line=20= > > might be in order, unless you did the copyright assignment. >=20 > I didn't do any copyright assignment yet but if there is actually any > interest in merging this then I can do it once we agreed on changes to > the algorithm. >=20 > Greetings, > S=C3=B6ren >=20 > [1]: https://gitlab.alpinelinux.org/alpine/aports/-/issues/12783