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é
  2021-09-27  4:45 ` Aleix Conchillo Flaqué
  0 siblings, 1 reply; 2+ messages 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 related	[flat|nested] 2+ messages in thread

* Re: [PATCH] foreign-library: fix RTLD_LAZY | RTLD_LOCAL crash on macOS
  2021-09-12  5:10 [PATCH] foreign-library: fix RTLD_LAZY | RTLD_LOCAL crash on macOS Aleix Conchillo Flaqué
@ 2021-09-27  4:45 ` Aleix Conchillo Flaqué
  0 siblings, 0 replies; 2+ messages in thread
From: Aleix Conchillo Flaqué @ 2021-09-27  4:45 UTC (permalink / raw)
  To: guile-devel

Ignore. The issue was the way libgcrypt was linked in macOS.

See: https://dev.gnupg.org/T5610

A libgcrypt's libtool.m4 patch has been applied upstream.

On Sat, Sep 11, 2021 at 10:10 PM Aleix Conchillo Flaqué
<aconchillo@gmail.com> wrote:
>
> * 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] 2+ messages in thread

end of thread, other threads:[~2021-09-27  4:45 UTC | newest]

Thread overview: 2+ messages (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é
2021-09-27  4:45 ` 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 read-only IMAP folder(s) and NNTP newsgroup(s).