unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Aleix Conchillo Flaqué" <aconchillo@gmail.com>
To: guile-devel@gnu.org
Cc: "Aleix Conchillo Flaqué" <aconchillo@gmail.com>
Subject: [PATCH] foreign-library: fix RTLD_LAZY | RTLD_LOCAL crash on macOS
Date: Sat, 11 Sep 2021 22:10:24 -0700	[thread overview]
Message-ID: <20210912051024.40841-1-aconchillo@gmail.com> (raw)

* module/system/foreign-library.scm (load-foreign-library): On macOS
calling `dlopen` with RTLD_LAZY | RTLD_LOCAL causes a crash when calling
`dlsym`. There are a three working combinations:

- Using RTLD_NOW | RTLD_LOCAL
- Using RTLD_NOW | RTLD_GLOBAL
- Using RTLD_LAZY | RTLD_GLOBAL

For efficiency purposes we choose RTLD_LAZY | RTLD_GLOBAL.

See https://lists.gnu.org/archive/html/guile-devel/2021-09/msg00008.html
---
 module/system/foreign-library.scm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/module/system/foreign-library.scm b/module/system/foreign-library.scm
index dc426385f..63889277c 100644
--- a/module/system/foreign-library.scm
+++ b/module/system/foreign-library.scm
@@ -172,6 +172,11 @@ name."
          (else
           name)))))
 
+;; In macOS using dlopen with RTLD_LAZY | RTLD_LOCAL produces a crash.
+;; https://lists.gnu.org/archive/html/guile-devel/2021-09/msg00008.html
+(define system-needs-global?
+  (string-contains %host-type "-darwin"))
+
 (define* (load-foreign-library #:optional filename #:key
                                (extensions system-library-extensions)
                                (search-ltdl-library-path? #t)
@@ -186,7 +191,7 @@ name."
                #f))
   (define flags
     (logior (if lazy? RTLD_LAZY RTLD_NOW)
-            (if global? RTLD_GLOBAL RTLD_LOCAL)))
+            (if (or global? system-needs-global?) RTLD_GLOBAL RTLD_LOCAL)))
   (define (dlopen* name) (dlopen name flags))
   (if (and rename-on-cygwin? (string-contains %host-type "cygwin"))
       (set! filename (lib->cyg filename)))
-- 
2.33.0




             reply	other threads:[~2021-09-12  5:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-12  5:10 Aleix Conchillo Flaqué [this message]
2021-09-27  4:45 ` [PATCH] foreign-library: fix RTLD_LAZY | RTLD_LOCAL crash on macOS Aleix Conchillo Flaqué

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://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=20210912051024.40841-1-aconchillo@gmail.com \
    --to=aconchillo@gmail.com \
    --cc=guile-devel@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).