diff mbox series

[bug#57730] syscalls: Adjust for glibc 2.34 and later.

Message ID 87illsb71w.fsf@gnu.org
State New
Headers show
Series [bug#57730] syscalls: Adjust for glibc 2.34 and later. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Ludovic Courtès Sept. 12, 2022, 9:45 p.m. UTC
Hi,

Marius Bakke <marius@gnu.org> skribis:

> This is a re-implementation of 3c8b6fd94ceb1e898216929e8768fb518dbf1de9 that
> works with new and old libc's.
>
> * guix/build/syscalls.scm (openpty, login-tty): Wrap in exception handlers and
> retry with libutil if the first call is unsuccessful.

[...]

>  (define openpty
> -  (let ((proc (syscall->procedure int "openpty" '(* * * * *)
> -                                  #:library "libutil")))
> -    (lambda ()
> -      "Return two file descriptors: one for the pseudo-terminal control side,
> +  (lambda* (#:optional library)
> +    "Return two file descriptors: one for the pseudo-terminal control side,
>  and one for the controlled side."
> +    (let ((proc (syscall->procedure int "openpty" '(* * * * *)
> +                                    #:library library)))

In general, we must ensure that ‘syscall->procedure’ is called only once
per procedure, because it’s expensive compared to the function we’re
wrapping (it’s doing dlopen, dlsym, and all that).

Anyway, I think this should work:
WDYT?

Thanks,
Ludo’.

Comments

Marius Bakke Sept. 15, 2022, 3:26 p.m. UTC | #1
Ludovic Courtès <ludo@gnu.org> skriver:

>>  (define openpty
>> -  (let ((proc (syscall->procedure int "openpty" '(* * * * *)
>> -                                  #:library "libutil")))
>> -    (lambda ()
>> -      "Return two file descriptors: one for the pseudo-terminal control side,
>> +  (lambda* (#:optional library)
>> +    "Return two file descriptors: one for the pseudo-terminal control side,
>>  and one for the controlled side."
>> +    (let ((proc (syscall->procedure int "openpty" '(* * * * *)
>> +                                    #:library library)))
>
> In general, we must ensure that ‘syscall->procedure’ is called only once
> per procedure, because it’s expensive compared to the function we’re
> wrapping (it’s doing dlopen, dlsym, and all that).

That makes sense.

> Anyway, I think this should work:
>
> diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
> index 7842b0a9fc..e081aaca44 100644
> --- a/guix/build/syscalls.scm
> +++ b/guix/build/syscalls.scm
> @@ -445,9 +445,14 @@ (define* (syscall->procedure return-type name argument-types
>  the returned procedure is called."
>    (catch #t
>      (lambda ()
> +      ;; Note: When #:library is set, try it first and fall back to libc
> +      ;; proper.  This is because libraries like libutil.so have been subsumed
> +      ;; by libc.so with glibc >= 2.34.
>        (let ((ptr (dynamic-func name
>                                 (if library
> -                                   (dynamic-link library)
> +                                   (or (false-if-exception
> +                                        (dynamic-link library))
> +                                       (dynamic-link))
>                                     (dynamic-link)))))
>          ;; The #:return-errno? facility was introduced in Guile 2.0.12.
>          (pointer->procedure return-type ptr argument-types
>
> WDYT?

I can confirm this works after reverting 3c8b6fd94ceb1e89821.

Can you commit it, or should I do it on your behalf?  I think we should
try to get it in 1.4.0 so Guix works when linked against system libc on
foreign distributions.

I'll revert 3c8b6fd94ce once this lands on 'core-updates'.

Thanks!
Mathieu Othacehe Nov. 1, 2022, 5:54 p.m. UTC | #2
Hey,

> Can you commit it, or should I do it on your behalf?  I think we should
> try to get it in 1.4.0 so Guix works when linked against system libc on
> foreign distributions.

This indeed seems like the right thing to do :) Marius or Ludo, I think
you can go ahead :)

Thanks,

Mathieu
Ludovic Courtès Nov. 7, 2022, 9:30 p.m. UTC | #3
Hi,

Mathieu Othacehe <othacehe@gnu.org> skribis:

> Hey,
>
>> Can you commit it, or should I do it on your behalf?  I think we should
>> try to get it in 1.4.0 so Guix works when linked against system libc on
>> foreign distributions.
>
> This indeed seems like the right thing to do :) Marius or Ludo, I think
> you can go ahead :)

Pushed on ‘core-updates’ as 3f6c32a88fc7a4d707ae1ed8ef3f7bd995461aff!

Ludo’.
diff mbox series

Patch

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 7842b0a9fc..e081aaca44 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -445,9 +445,14 @@  (define* (syscall->procedure return-type name argument-types
 the returned procedure is called."
   (catch #t
     (lambda ()
+      ;; Note: When #:library is set, try it first and fall back to libc
+      ;; proper.  This is because libraries like libutil.so have been subsumed
+      ;; by libc.so with glibc >= 2.34.
       (let ((ptr (dynamic-func name
                                (if library
-                                   (dynamic-link library)
+                                   (or (false-if-exception
+                                        (dynamic-link library))
+                                       (dynamic-link))
                                    (dynamic-link)))))
         ;; The #:return-errno? facility was introduced in Guile 2.0.12.
         (pointer->procedure return-type ptr argument-types