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

From: Marius Bakke <[email-masked]>
Date: Thu, 15 Sep 2022 17:26:19 +0200

Ludovic Courtès <[email-masked]> 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!