guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] foreign-library: fix RTLD_LAZY | RTLD_LOCAL crash on macOS


From: Aleix Conchillo Flaqué
Subject: [PATCH] foreign-library: fix RTLD_LAZY | RTLD_LOCAL crash on macOS
Date: Sat, 11 Sep 2021 22:10:24 -0700

* 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 via email to

[Prev in Thread] Current Thread [Next in Thread]