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?Aleix_Conchillo_Flaqu=C3=A9?= Newsgroups: gmane.lisp.guile.devel Subject: Re: crash on macOS with dlsym RTLD_LOCAL Date: Tue, 14 Sep 2021 10:06:59 -0700 Message-ID: References: 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="24440"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Tue Sep 14 19:07:57 2021 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 1mQBuV-00063G-Ot for guile-devel@m.gmane-mx.org; Tue, 14 Sep 2021 19:07:55 +0200 Original-Received: from localhost ([::1]:35118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQBuS-0001dG-NL for guile-devel@m.gmane-mx.org; Tue, 14 Sep 2021 13:07:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQBtr-0001cx-8O for guile-devel@gnu.org; Tue, 14 Sep 2021 13:07:15 -0400 Original-Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:44802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mQBtp-0001m1-Hm for guile-devel@gnu.org; Tue, 14 Sep 2021 13:07:15 -0400 Original-Received: by mail-pg1-x52a.google.com with SMTP id s11so13337845pgr.11 for ; Tue, 14 Sep 2021 10:07:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=RZZiCZL6Imb0mtOMX9eADWZ+0v9a5d9JfPYQGXv91nk=; b=DfpRnRsXGyP4CVCnmKL/vaMa6XI4Gp/EbDWEWu1fbMfQYbDnf3Jyiip250sn+AdQ41 l7PezH0LIrWlEBqqmy0fXrtcLJBnI6jaqix2Kn9e5aIH6a3al3cDkr08tnwa0VTWeM0V xjmvLgG1eV2RahnRGo72whVnoj8C2rnCHLx6MxH/0VzdoLsYju9QRd7djT3nNLw9bheE eIjwarZ/JvWdsivR1m7nU4ewBZu9bkvw6Bh6GlD66oZgCFe0FjOL04EJqx9tmUcfX/Aq R04s4GHEq/jtRaEHewNfNexaaNb32WU/87anw0iorbofPdnS79Veden5zGgRZv3QNAAQ ORiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=RZZiCZL6Imb0mtOMX9eADWZ+0v9a5d9JfPYQGXv91nk=; b=qW3mFksrt460qZCbXOLmy7uYHP5KPJ/9nqtb5ab3qqbTEQN2vQ9FEgxAqVYhKL2Bp0 kK6ntBy8aNa17LBBbq3JC1MTSINqwCvTp17T2+edZ85pvhitN9FdMmmqqe+/jZ+JtBzi xwDPOu+mJBleAllRy5KwmNqA3iKL/c4H5d878AhESbfkjuqBxxWnqFaMlPd5kk7wqiSg WCLcu2xgpZA/nSI+v5g2IxrZjsbqdOVOoewKh2C4xPqF/P5rgUEgjFWH3dI3fAQv70cc K8N3AFFCuUNGfYaLPGkl/hDmPdUMa/sCA0D/8HDGNPk17o8pBcO5m1FW4uMK87lRUytC f+xw== X-Gm-Message-State: AOAM532YzXFXFScDoMOr1rTvhsUjsU79ZA5AdX6JKZAUj7xChs0raA88 LfffUNLlcy5ZbB6wDz0uxxHdDOWQK2N6lpC/HzHMc1kqU60= X-Google-Smtp-Source: ABdhPJwn7OUDsrh0yt+n0ZWfUe0eHA5Wyecr7Qy+mKgszQ7EBA9MCmQ4XuLelbTWjqtC1Emf2pIppbqeoKueKINVYB0= X-Received: by 2002:a63:fe41:: with SMTP id x1mr16472380pgj.272.1631639230282; Tue, 14 Sep 2021 10:07:10 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=aconchillo@gmail.com; helo=mail-pg1-x52a.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 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:20860 Archived-At: I have posted a message to Apple's forums to see if there's any luck: https://developer.apple.com/forums/thread/689991 Aleix On Sat, Sep 11, 2021 at 10:14 PM Aleix Conchillo Flaqu=C3=A9 wrote: > > I did a little bit more research. The combination that actually fails > is RTLD_LAZY | RTLD_GLOBAL (what guile uses). So, you can actually > use: > > - RTLD_LAZY | RTLD_GLOBAL > - RTLD_NOW | RTLD_GLOBAL > - RTLD_NOW | RTLD_LOCAL > > I found the source code of dyld > > https://opensource.apple.com/source/dyld/dyld-852.2/ > > But I have no clue how to build this, I tried it but failed with > missing dependencies. In any case, I provided a patch so at least we > can use Guile on macOS. > > Best, > > Aleix > > On Sat, Sep 4, 2021 at 10:48 PM Aleix Conchillo Flaqu=C3=A9 > wrote: > > > > Hi, > > > > I'm trying to load guile-grcypt with guile 3.0.7 and after my previous > > fix (https://git.savannah.gnu.org/cgit/guile.git/commit/?id=3D1f100a4f2= 0c3a6e57922fb26fce212997e2a03cb) > > guile-gcrypt still does not load properly. > > > > TLDR; Using RTLD_LOCAL instead of RTLD_GLOBAL (default) causes issues o= n macOS. > > > > https://git.savannah.gnu.org/cgit/guile.git/tree/module/system/foreign-= library.scm#n181 > > > > In the case of guile-gcrypt this is what I'm getting: > > > > ------------------------- > > scheme@(guile-user)> (use-modules (gcrypt hmac)) > > dyld: lazy symbol binding failed: Symbol not found: __gcry_check_versio= n > > Referenced from: /usr/local/lib/libgcrypt.dylib > > Expected in: flat namespace > > > > dyld: Symbol not found: __gcry_check_version > > Referenced from: /usr/local/lib/libgcrypt.dylib > > Expected in: flat namespace > > ------------------------- > > > > Looking at gcrypt symbols I can see: > > > > =E2=9D=AF nm -gU /usr/local/lib/libgcrypt.dylib | grep gcry_check_versi= on > > 0000000000005954 T __gcry_check_version > > 0000000000002aa7 T _gcry_check_version > > > > Actually in libgcrypt the public functions are: gcry_check_version and > > _gcry_check_version (no extra underscore). I think extra underscores > > are automatically added when building the library but I'm not sure why > > and when and what systems. And when you call dlsym() you don't need to > > add those extra underscores. > > > > The following code (which uses RTLD_GLOBAL) works fine: > > > > ./a.out gcry_check_version > > > > ------------------------- > > #include > > #include > > > > int > > main(int argc, char *argv[]) > > { > > char* (*fptr)(char *); > > void *handle =3D dlopen("/usr/local/lib/libgcrypt.dylib", RTLD_LAZY | > > RTLD_GLOBAL); > > if (handle =3D=3D NULL) { > > printf("OOOPS: %s\n", dlerror()); > > } else { > > *(void **)(&fptr) =3D dlsym(handle, argv[1]); > > if (fptr =3D=3D NULL) { > > printf("NOT FOUND: %s : %s\n", argv[1], dlerror()); > > } else { > > printf("FOUND: %s %s\n", argv[1], (*fptr)(NULL)); > > } > > } > > return 0; > > } > > ------------------------- > > > > But if we change to RTLD_LOCAL we get a crash like in guile's case. > > > > Sorry for being too vague but I'm not familiar with how all this > > works. All I know is that using RTLD_GLOBAL fixes the issue. > > > > Also, from dlopen man page I read: > > > > ------------------------- > > RTLD_GLOBAL Symbols exported from this image (dynamic library or > > bundle) will be available to any images build with -flat_namespace > > option to > > ld(1) or to calls to dlsym() when using a special han= dle. > > > > RTLD_LOCAL Symbols exported from this image (dynamic library or > > bundle) are generally hidden and only availble to dlsym() when > > directly using > > the handle returned by this call to dlopen(). > > ------------------------- > > > > But I don't fully get what this means. > > > > Any help would be really appreciated. > > > > Thank you, > > > > Aleix