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: crash on macOS with dlsym RTLD_LOCAL Date: Sat, 4 Sep 2021 22:48:05 -0700 Message-ID: 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="2765"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sun Sep 05 07:48:52 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 1mMl1P-0000VT-Rh for guile-devel@m.gmane-mx.org; Sun, 05 Sep 2021 07:48:51 +0200 Original-Received: from localhost ([::1]:59820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMl1O-0005wK-Ni for guile-devel@m.gmane-mx.org; Sun, 05 Sep 2021 01:48:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMl0u-0005vx-Hm for guile-devel@gnu.org; Sun, 05 Sep 2021 01:48:20 -0400 Original-Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:52099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mMl0s-0000k1-WD for guile-devel@gnu.org; Sun, 05 Sep 2021 01:48:20 -0400 Original-Received: by mail-pj1-x102f.google.com with SMTP id c6so2288662pjv.1 for ; Sat, 04 Sep 2021 22:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=UuAFck3N4IsOg8qiOBYWzG1jRihYfCw5kiUIPv5BQyU=; b=CxDT7IXtcTo6ANg8UeucdLj26qtKp/nlatiw94+3bqov8iwoJCuvFfrlu4v6Yj4pKe 09iXOiBnLwf0ROFKjWpHWK2wz5uPKWWNJA4DdxNATj8iirr/arxsj3wUaE7Ew3a2wk7U lN6b28UKXIRseUGRsxZmfqGpKUVkVEa4DMaqWfVnoWNrU1GylvknVeq9iSlGBT0Gg2fX Z2B7+wNjIVZGdvbETDygUsGx11HzwlUj9M2OvuPdcPnwGF2+cfRJf6/pa5kE34CGVeXu umsY0oFX2PglyBU8glMY6Xn+U3wdOI+wQOpbQqSEfJHvj5Xbfga1M6tRxx/T8GxbMYP+ 4GjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=UuAFck3N4IsOg8qiOBYWzG1jRihYfCw5kiUIPv5BQyU=; b=tJrQOlHHybK9/pQWdnRlx6aCrrfmrBOUfM6UVgcbYOkUZArM7/qS8W/VdTpk9DvDw4 1hHsQT5FlaFyEjMSgsXhymIo1eDZ6vHi9GDwSYhtZCGqnBQ6sX3CL4kCryuXGAbEntbA c1ZMhV8kDGu3XJAHgUEtiIXTR8OW3Y1eSxp0vzWCLlOV6kc6zozpC14oLucDNxk840jJ umtaxUpUSclEbFar71hXHnAuvdbWNshC72H1XbIRqTC8lOgjoLD8Q4ppVyN/dOSUEjVU ctdWZKspgyAt9xHZDEjK5rdyeJ1Nrd5jdh6G376pz1xMh3pf9jGSAB5+jOG+MSWvvJIW LB2Q== X-Gm-Message-State: AOAM532dwuAVXi73ulNkXCfkZhpo0Nsbbt76G4Wi3iBtN29mMSwmRQUr YjfxsTFKIS5/Kx0PRapzrLP3wCYdpRVw/iUcNcV+00mffU8= X-Google-Smtp-Source: ABdhPJy2BEr77VyHkZfXwFM6e8nDR76hdqYDSq5qeUmSWTRJmKOxE4bpwsAvRQvUIsw+HH+qbXaNmr7nglOG0HUE4EY= X-Received: by 2002:a17:90a:4549:: with SMTP id r9mr7397565pjm.147.1630820896528; Sat, 04 Sep 2021 22:48:16 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=aconchillo@gmail.com; helo=mail-pj1-x102f.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:20840 Archived-At: 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=3D1f100a4f20c3a= 6e57922fb26fce212997e2a03cb) guile-gcrypt still does not load properly. TLDR; Using RTLD_LOCAL instead of RTLD_GLOBAL (default) causes issues on ma= cOS. https://git.savannah.gnu.org/cgit/guile.git/tree/module/system/foreign-libr= ary.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_version 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_version 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 handle. 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