unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] foreign-library: fix RTLD_LAZY | RTLD_LOCAL crash on macOS
@ 2021-09-12  5:10 Aleix Conchillo Flaqué
  0 siblings, 0 replies; only message in thread
From: Aleix Conchillo Flaqué @ 2021-09-12  5:10 UTC (permalink / raw)
  To: guile-devel; +Cc: Aleix Conchillo Flaqué

* 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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-12  5:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-12  5:10 [PATCH] foreign-library: fix RTLD_LAZY | RTLD_LOCAL crash on macOS Aleix Conchillo Flaqué

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 NNTP newsgroup(s).