[PATCH] syscalls: Add support for musl libc

  • Done
  • quality assurance status badge
Details
4 participants
  • Ludovic Courtès
  • Christopher Baines
  • soeren
  • Sören Tempel
Owner
unassigned
Submitted by
soeren
Severity
normal
S
S
soeren wrote on 24 Aug 2023 08:33
(address . guix-patches@gnu.org)
20230824063303.7928-3-soeren@soeren-tempel.net
From: Sören Tempel <soeren@soeren-tempel.net>

This commit allows using Guix on a foreign distro which uses musl libc,
for example, Alpine Linux. Such a distro is detected via the new
linux-musl? variable based on the %host-type.

Using the new linux-musl? variable, we can now implement musl-specific
quirks. The only problem I encountered in this regard so far is that
musl does not export a readdir64 symbol. On musl, readdir64 is a CPP
macro that expands to readdir. For this reason, readdir-procedure now
uses readdir over readdir64 if the host-system uses musl libc.

The existing linux? variable is now set to a truth value if the
host-system is either a linux-gnu or a linux-musl. A new linux-gnu?
variable can be used to detect linux-gnu systems.

The patch has been tested on Alpine Linux and is already used for the
downstream Guix package shipped in Alpine Linux's package repository.

* guix/build/syscalls.scm (linux-gnu?): New variable.
* guix/build/syscalls.scm (linux-musl?): New variable.
* guix/build/syscalls.scm (linux?): Truth value on musl or GNU Linux.
* guix/build/syscalls.scm (readdir-procedure): Support musl libc.

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
---
guix/build/syscalls.scm | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

Toggle diff (29 lines)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index d947b010d3..a690e8da0b 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -836,7 +836,9 @@ (define-record-type <file-system>
(define-syntax fsword ;fsword_t
(identifier-syntax long))
-(define linux? (string-contains %host-type "linux-gnu"))
+(define linux-gnu? (string-contains %host-type "linux-gnu"))
+(define linux-musl? (string-contains %host-type "linux-musl"))
+(define linux? (or linux-gnu? linux-musl?))
(define-syntax define-statfs-flags
(syntax-rules (linux hurd)
@@ -1232,7 +1234,12 @@ (define closedir*
(define (readdir-procedure name-field-offset sizeof-dirent-header
read-dirent-header)
- (let ((proc (syscall->procedure '* "readdir64" '(*))))
+ (let ((proc (syscall->procedure '*
+ (cond
+ (linux-gnu? "readdir64")
+ (linux-musl? "readdir")
+ (else (error "unknown linux variant")))
+ '(*))))
(lambda* (directory #:optional (pointer->string pointer->string/utf-8))
(let ((ptr (proc directory)))
(and (not (null-pointer? ptr))
S
S
soeren wrote on 9 Sep 2023 15:04
[PATCH v2] syscalls: Add support for musl libc
(address . guix-patches@gnu.org)(address . 65486@debbugs.gnu.org)
20230909130548.31083-2-soeren@soeren-tempel.net
From: Sören Tempel <soeren@soeren-tempel.net>

This commit allows using Guix on a foreign distro which uses musl libc,
for example, Alpine Linux. Such a distro is detected via the new
linux-musl? variable based on the %host-type.

Using the new linux-musl? variable, we can now implement musl-specific
quirks. The two compatibility problems I encountered in this regard are
that musl dose not export a readdir64 and statfs64 symbol. On musl,
these two functions are implemented as CPP macros that expand to
readdir/statfs. For this reason, a case-distinction was added.

The existing linux? variable is now set to a truth value if the
host-system is either a linux-gnu or a linux-musl. A new linux-gnu?
variable can be used to detect linux-gnu systems.

The patch has been tested on Alpine Linux and is already used for the
downstream Guix package shipped in Alpine Linux's package repository.

* guix/build/syscalls.scm (linux-gnu?): New variable.
* guix/build/syscalls.scm (linux-musl?): New variable.
* guix/build/syscalls.scm (linux?): Truth value on musl or GNU Linux.
* guix/build/syscalls.scm (readdir-procedure): Support musl libc.
* guix/build/syscalls.scm (statfs): Support musl libc.

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
---
Changes since v1: Also add special handling for musl libc to the statfs
procedure. Instead of checking the %host-type, it may also be possible to
the lack of statfs64/readdir64 symbols during ./configure time.

guix/build/syscalls.scm | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

Toggle diff (42 lines)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index d947b010d3..416fdc768c 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -836,7 +836,9 @@ (define-record-type <file-system>
(define-syntax fsword ;fsword_t
(identifier-syntax long))
-(define linux? (string-contains %host-type "linux-gnu"))
+(define linux-gnu? (string-contains %host-type "linux-gnu"))
+(define linux-musl? (string-contains %host-type "linux-musl"))
+(define linux? (or linux-gnu? linux-musl?))
(define-syntax define-statfs-flags
(syntax-rules (linux hurd)
@@ -905,7 +907,11 @@ (define-c-struct %statfs ;<bits/statfs.h>
(spare (array fsword 4)))
(define statfs
- (let ((proc (syscall->procedure int "statfs64" '(* *))))
+ (let ((proc (syscall->procedure int (cond
+ (linux-gnu? "statfs64")
+ (linux-musl? "statfs")
+ (else (error "unknown linux variant")))
+ '(* *))))
(lambda (file)
"Return a <file-system> data structure describing the file system
mounted at FILE."
@@ -1232,7 +1238,12 @@ (define closedir*
(define (readdir-procedure name-field-offset sizeof-dirent-header
read-dirent-header)
- (let ((proc (syscall->procedure '* "readdir64" '(*))))
+ (let ((proc (syscall->procedure '*
+ (cond
+ (linux-gnu? "readdir64")
+ (linux-musl? "readdir")
+ (else (error "unknown linux variant")))
+ '(*))))
(lambda* (directory #:optional (pointer->string pointer->string/utf-8))
(let ((ptr (proc directory)))
(and (not (null-pointer? ptr))
L
L
Ludovic Courtès wrote on 11 Sep 2023 23:09
Re: bug#65486: [PATCH] syscalls: Add support for musl libc
(address . soeren@soeren-tempel.net)(address . 65486@debbugs.gnu.org)
87fs3kquwl.fsf_-_@gnu.org
Hi,

soeren@soeren-tempel.net skribis:

Toggle quote (19 lines)
> From: Sören Tempel <soeren@soeren-tempel.net>
>
> This commit allows using Guix on a foreign distro which uses musl libc,
> for example, Alpine Linux. Such a distro is detected via the new
> linux-musl? variable based on the %host-type.
>
> Using the new linux-musl? variable, we can now implement musl-specific
> quirks. The two compatibility problems I encountered in this regard are
> that musl dose not export a readdir64 and statfs64 symbol. On musl,
> these two functions are implemented as CPP macros that expand to
> readdir/statfs. For this reason, a case-distinction was added.
>
> The existing linux? variable is now set to a truth value if the
> host-system is either a linux-gnu or a linux-musl. A new linux-gnu?
> variable can be used to detect linux-gnu systems.
>
> The patch has been tested on Alpine Linux and is already used for the
> downstream Guix package shipped in Alpine Linux's package repository.

[...]

Toggle quote (17 lines)
> -(define linux? (string-contains %host-type "linux-gnu"))
> +(define linux-gnu? (string-contains %host-type "linux-gnu"))
> +(define linux-musl? (string-contains %host-type "linux-musl"))
> +(define linux? (or linux-gnu? linux-musl?))
>
> (define-syntax define-statfs-flags
> (syntax-rules (linux hurd)
> @@ -905,7 +907,11 @@ (define-c-struct %statfs ;<bits/statfs.h>
> (spare (array fsword 4)))
>
> (define statfs
> - (let ((proc (syscall->procedure int "statfs64" '(* *))))
> + (let ((proc (syscall->procedure int (cond
> + (linux-gnu? "statfs64")
> + (linux-musl? "statfs")
> + (else (error "unknown linux variant")))

I think this is misleading because this has to do with the C library,
not with the kernel (“linux variant”).

For example, GNU/Hurd uses the same C library as GNU/Linux, and both
should use “statfs64”, “readdir64”, etc. So what we want to check is
whether we’re using the GNU libc or Musl, regardless of the kernel.

Now, instead of checking the libc’s identity, we could check whether
“statfs64” is available, and if not, fall back to “statfs”.

WDYT?

Thanks,
Ludo’.
S
S
Sören Tempel wrote on 13 Sep 2023 12:23
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 65486@debbugs.gnu.org)
3DOVAMAK0VD13.2XDJ9MT35902D@8pit.net
Hi Ludovic,

Ludovic Courtès <ludo@gnu.org> wrote:
Toggle quote (6 lines)
> I think this is misleading because this has to do with the C library,
> not with the kernel (“linux variant”).
>
> For example, GNU/Hurd uses the same C library as GNU/Linux, and both
> should use “statfs64”, “readdir64”, etc.

Oh, right! I totally forgot about GNU/Hurd, thanks for pointing that out.

Toggle quote (3 lines)
> So what we want to check is whether we’re using the GNU libc or Musl,
> regardless of the kernel.

Keep in mind that—contrary to glibc—musl only supports Linux and not
GNU/Hurd. Therefore, it should be sufficient to simply check for a
linux-musl host and then use statfs/readdir over statfs64/readdir64:

(let ((proc (syscall->procedure (if linux-musl?
"readdir"
"readdir64"))))
........

Would that be acceptable?

Toggle quote (3 lines)
> Now, instead of checking the libc’s identity, we could check whether
> “statfs64” is available, and if not, fall back to “statfs”.

You mean using a GNU ./configure check? That would be possible. However,
I think we also need to check somehow that readdir/statfs return values
are struct-layout compatible with the readdir64/statfs64 versions used
by glibc.

Unfortunately, I am not deeply familiar with GNU autotools. Is there a
similar feature-check in the Guile code base already that I could use as
a source of inspiration? Maybe the if expression outlined above would
be sufficient for now and we can improve upon that later?

Greetings,
Sören
L
L
Ludovic Courtès wrote on 13 Sep 2023 22:39
(name . Sören Tempel)(address . tempel@uni-bremen.de)(address . 65486@debbugs.gnu.org)
87cyylkdt5.fsf@gnu.org
Hi,

Sören Tempel <tempel@uni-bremen.de> skribis:

Toggle quote (2 lines)
> Ludovic Courtès <ludo@gnu.org> wrote:

[...]

Toggle quote (14 lines)
>> So what we want to check is whether we’re using the GNU libc or Musl,
>> regardless of the kernel.
>
> Keep in mind that—contrary to glibc—musl only supports Linux and not
> GNU/Hurd. Therefore, it should be sufficient to simply check for a
> linux-musl host and then use statfs/readdir over statfs64/readdir64:
>
> (let ((proc (syscall->procedure (if linux-musl?
> "readdir"
> "readdir64"))))
> ........
>
> Would that be acceptable?

You could call it ‘musl?’ instead, to (hopefully) convey we’re
interested in the C library specifically.

Toggle quote (5 lines)
>> Now, instead of checking the libc’s identity, we could check whether
>> “statfs64” is available, and if not, fall back to “statfs”.
>
> You mean using a GNU ./configure check?

No no, I meant something like:

(or (false-if-exception (dynamic-func "readdir64" (dynamic-link)))
(dynamic-func "readdir" (dynamic-link)))

Of course, it’s not as simple as this because we’d rather have it
integrated with ‘syscall->procedure’ (maybe by adding an
#:alternative-name argument for the Musl name?), but you get the idea.

HTH!

Ludo’.
S
S
Sören Tempel wrote on 15 Sep 2023 12:57
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 65486@debbugs.gnu.org)
3V5VFSTNLLLHJ.3BBPH8V2N2EUI@8pit.net
Hi Ludovic,

Ludovic Courtès <ludo@gnu.org> wrote:
Toggle quote (3 lines)
> You could call it ‘musl?’ instead, to (hopefully) convey we’re
> interested in the C library specifically.

I used musl-libc? instead to make it more clear that we are interested
in the C library for this case-distinction. This is implemented in the
attached git-format-patch(1). Would that be suitable for inclusion in
Guix?

Toggle quote (9 lines)
> No no, I meant something like:
>
> (or (false-if-exception (dynamic-func "readdir64" (dynamic-link)))
> (dynamic-func "readdir" (dynamic-link)))
>
> Of course, it’s not as simple as this because we’d rather have it
> integrated with ‘syscall->procedure’ (maybe by adding an
> #:alternative-name argument for the Musl name?), but you get the idea.

Also this check doesn't ensure struct layout compatibility, e.g. if
readdir uses 32-bit types so not sure if this is necessarily better
than the musl libc check I proposed above.

Let me know what you think.

Greetings
Sören
From b1d478defc7f3e794974be2b9665cd4a58030569 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
Date: Thu, 14 Sep 2023 12:35:38 +0000
Subject: [PATCH] syscalls: Add support for musl libc

This commit allows using Guix on a foreign distro which uses musl libc,
for example, Alpine Linux. Usage of musl libc is detected via a new
musl-libc? variable using the Guile %host-type.

Using the new musl-libc? variable, we can now implement musl-specific
quirks. The two compatibility problems I encountered in this regard are
that musl dose not export a readdir64 and statfs64 symbol. On musl,
these two functions are implemented as CPP macros that expand to
readdir/statfs. To workaround that, a case-distinction was added.

The existing linux? variable has been modified to return true if the
%host-system contains "linux-" in order to ensure it is true for both
linux-gnu as well as linux-musl host systems.

The patch has been tested on Alpine Linux and is already used for the
downstream Guix package shipped in Alpine Linux's package repository.

* guix/build/syscalls.scm (musl-libc?): New variable.
* guix/build/syscalls.scm (linux?): Truth value on any linux system.
* guix/build/syscalls.scm (readdir-procedure): Support musl libc.
* guix/build/syscalls.scm (statfs): Support musl libc.
---
guix/build/syscalls.scm | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

Toggle diff (32 lines)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index c9c0bf594d..b845b8aab9 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -836,7 +836,8 @@ (define-record-type <file-system>
(define-syntax fsword ;fsword_t
(identifier-syntax long))
-(define linux? (string-contains %host-type "linux-gnu"))
+(define musl-libc? (string-contains %host-type "linux-musl"))
+(define linux? (string-contains %host-type "linux-"))
(define-syntax define-statfs-flags
(syntax-rules (linux hurd)
@@ -905,7 +906,7 @@ (define-c-struct %statfs ;<bits/statfs.h>
(spare (array fsword 4)))
(define statfs
- (let ((proc (syscall->procedure int "statfs64" '(* *))))
+ (let ((proc (syscall->procedure int (if musl-libc? "statfs" "statfs64") '(* *))))
(lambda (file)
"Return a <file-system> data structure describing the file system
mounted at FILE."
@@ -1232,7 +1233,7 @@ (define closedir*
(define (readdir-procedure name-field-offset sizeof-dirent-header
read-dirent-header)
- (let ((proc (syscall->procedure '* "readdir64" '(*))))
+ (let ((proc (syscall->procedure '* (if musl-libc? "readdir" "readdir64") '(*))))
(lambda* (directory #:optional (pointer->string pointer->string/utf-8))
(let ((ptr (proc directory)))
(and (not (null-pointer? ptr))
L
L
Ludovic Courtès wrote on 17 Sep 2023 12:14
(name . Sören Tempel)(address . soeren@soeren-tempel.net)(address . 65486-done@debbugs.gnu.org)
87o7i1yumq.fsf@gnu.org
Hi,

Sören Tempel <soeren@soeren-tempel.net> skribis:

Toggle quote (27 lines)
> From b1d478defc7f3e794974be2b9665cd4a58030569 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
> Date: Thu, 14 Sep 2023 12:35:38 +0000
> Subject: [PATCH] syscalls: Add support for musl libc
>
> This commit allows using Guix on a foreign distro which uses musl libc,
> for example, Alpine Linux. Usage of musl libc is detected via a new
> musl-libc? variable using the Guile %host-type.
>
> Using the new musl-libc? variable, we can now implement musl-specific
> quirks. The two compatibility problems I encountered in this regard are
> that musl dose not export a readdir64 and statfs64 symbol. On musl,
> these two functions are implemented as CPP macros that expand to
> readdir/statfs. To workaround that, a case-distinction was added.
>
> The existing linux? variable has been modified to return true if the
> %host-system contains "linux-" in order to ensure it is true for both
> linux-gnu as well as linux-musl host systems.
>
> The patch has been tested on Alpine Linux and is already used for the
> downstream Guix package shipped in Alpine Linux's package repository.
>
> * guix/build/syscalls.scm (musl-libc?): New variable.
> * guix/build/syscalls.scm (linux?): Truth value on any linux system.
> * guix/build/syscalls.scm (readdir-procedure): Support musl libc.
> * guix/build/syscalls.scm (statfs): Support musl libc.

This version LGTM. Applied, thanks!

Ludo’.
Closed
L
L
Ludovic Courtès wrote on 17 Sep 2023 12:17
(name . Sören Tempel)(address . soeren@soeren-tempel.net)
87il89yugy.fsf@gnu.org
Oooh, now I remember why I ended up not applying the previous
syscalls.scm patch: OpenJDK and a bunch of other things depend on it, so
changing syscalls.scm entails lots of rebuilds. (Really, they shouldn’t
depend on it in the first place, IMO.)

So we need bordeaux.guix to build everything ahead of time.

To do that, can you resend both syscalls.scm patch (with ‘git
send-email’) here? Then we’ll check qa.guix to ensure it builds things.

Chris, how does that sound?

Ludo’.
L
L
Ludovic Courtès wrote on 17 Sep 2023 12:17
control message for bug #65486
(address . control@debbugs.gnu.org)
87jzspyuhs.fsf@gnu.org
reopen 65486
tags 65486 - fixed patch
quit
C
C
Christopher Baines wrote on 17 Sep 2023 13:38
Re: bug#65486: [PATCH] syscalls: Add support for musl libc
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 65486@debbugs.gnu.org)
87v8c9owny.fsf@cbaines.net
Ludovic Courtès <ludo@gnu.org> writes:

Toggle quote (7 lines)
> So we need bordeaux.guix to build everything ahead of time.
>
> To do that, can you resend both syscalls.scm patch (with ‘git
> send-email’) here? Then we’ll check qa.guix to ensure it builds things.
>
> Chris, how does that sound?

This probably falls under the core team (although ./etc/teams.scm says
it doesn't fall under any team), so I'd suggest putting it on a branch.

That way, we can collect some other similar changes together before
merging.
-----BEGIN PGP SIGNATURE-----

iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmUG5aFfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh
aW5lcy5uZXQACgkQXiijOwuE9XdmWA//SWzVcCUO2Rku5GSVYDBynEfFM/X0q4uv
59eu8/urJBIlGFFC/OjzNq5Bst5VIyn7R1PvbH16XDIEee9DNJWPZu9vxKCgisoN
F2+fOFnHnRMkWgBOn+/MHHq8It3reyzAVw4euXx9qiORsH5821/tN6YhO+IHifIs
ZRTjXfpslDdCOXW/9yDqJHBhIp2ONign0dW/GLA9nT55nD9kv7TVQHofjVebqmFq
2wvdtVL0LJ0mNMr5BnxFQaoE5EhPYutepP1ESjl5wF31HzBqdhiSSmF5AUfE0Op0
6BqS2Pa6tZe+L1ueFmw/QIWAgdqDgtXLHQ6n7pvyJaWQPD/DgAmPxeFScXHrHlbd
SvoD/E9yVkATPBUU9423fN7UgF/yC6hmmfHX+jVhmsvCcDEzt0+ObsHM8nGr6U6e
ENukix0901sT78Ni/pSuM37ebR0rdpY6c9JDC4Wfo+aQ99dVq2kOzdkNmhcOOkBs
LTsgE1CXLhGJ6uSLxc/NdoKsHEETB0WpdOKQehHfmlyWtljrQ8Q9hBCvLMNVKYD6
4zxssA1PNH1CKC7oKfB3Dclziir2nXPM5K0hpYOZXMJEguNU4JvmdaAkdUZ0C9SH
B5ZGoFdsm9AU0VklMIVJJc5j12mSRMCxyvoEDuewLIl1eSay0GNZSgOLKfvgnbNW
LttvMMjXOOI=
=OFyc
-----END PGP SIGNATURE-----

S
S
soeren wrote on 17 Sep 2023 17:21
[PATCH v3] syscalls: Consistently use existing linux? definition
(address . guix-patches@gnu.org)
20230917152149.8587-1-soeren@soeren-tempel.net
From: Sören Tempel <soeren@soeren-tempel.net>

Instead of duplicating this existing logic across the source file. This
will make it easier to add additional linux targets (e.g. linux-musl) in
the future.

* guix/build/syscalls.scm (readdir*): Use linux? constant.
* guix/build/syscalls.scm (write-socket-address!): Use linux? constant.
* guix/build/syscalls.scm (read-socket-address): Use linux? constant.

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
---
guix/build/syscalls.scm | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

Toggle diff (30 lines)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index d947b010d3..c9c0bf594d 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -1244,7 +1244,7 @@ (define (readdir-procedure name-field-offset sizeof-dirent-header
(define readdir*
;; Decide at run time which one must be used.
- (if (string-contains %host-type "linux-gnu")
+ (if linux?
(readdir-procedure (c-struct-field-offset %struct-dirent-header/linux
name)
sizeof-dirent-header/linux
@@ -1664,7 +1664,7 @@ (define (write-socket-address!/hurd sockaddr bv index)
(error "unsupported socket address" sockaddr)))))
(define write-socket-address!
- (if (string-contains %host-type "linux-gnu")
+ (if linux?
write-socket-address!/linux
write-socket-address!/hurd))
@@ -1696,7 +1696,7 @@ (define* (read-socket-address/hurd bv #:optional (index 0))
(vector family)))))
(define read-socket-address
- (if (string-contains %host-type "linux-gnu")
+ (if linux?
read-socket-address/linux
read-socket-address/hurd))
S
S
soeren wrote on 17 Sep 2023 17:21
[PATCH v3] syscalls: Add support for musl libc
(address . guix-patches@gnu.org)
20230917152149.8587-2-soeren@soeren-tempel.net
From: Sören Tempel <soeren@soeren-tempel.net>

This commit allows using Guix on a foreign distro which uses musl libc,
for example, Alpine Linux. Usage of musl libc is detected via a new
musl-libc? variable using the Guile %host-type.

Using the new musl-libc? variable, we can now implement musl-specific
quirks. The two compatibility problems I encountered in this regard are
that musl dose not export a readdir64 and statfs64 symbol. On musl,
these two functions are implemented as CPP macros that expand to
readdir/statfs. To workaround that, a case-distinction was added.

The existing linux? variable has been modified to return true if the
%host-system contains "linux-" in order to ensure it is true for both
linux-gnu as well as linux-musl host systems.

The patch has been tested on Alpine Linux and is already used for the
downstream Guix package shipped in Alpine Linux's package repository.

* guix/build/syscalls.scm (musl-libc?): New variable.
* guix/build/syscalls.scm (linux?): Truth value on any linux system.
* guix/build/syscalls.scm (readdir-procedure): Support musl libc.
* guix/build/syscalls.scm (statfs): Support musl libc.

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
---
guix/build/syscalls.scm | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

Toggle diff (32 lines)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index c9c0bf594d..b845b8aab9 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -836,7 +836,8 @@ (define-record-type <file-system>
(define-syntax fsword ;fsword_t
(identifier-syntax long))
-(define linux? (string-contains %host-type "linux-gnu"))
+(define musl-libc? (string-contains %host-type "linux-musl"))
+(define linux? (string-contains %host-type "linux-"))
(define-syntax define-statfs-flags
(syntax-rules (linux hurd)
@@ -905,7 +906,7 @@ (define-c-struct %statfs ;<bits/statfs.h>
(spare (array fsword 4)))
(define statfs
- (let ((proc (syscall->procedure int "statfs64" '(* *))))
+ (let ((proc (syscall->procedure int (if musl-libc? "statfs" "statfs64") '(* *))))
(lambda (file)
"Return a <file-system> data structure describing the file system
mounted at FILE."
@@ -1232,7 +1233,7 @@ (define closedir*
(define (readdir-procedure name-field-offset sizeof-dirent-header
read-dirent-header)
- (let ((proc (syscall->procedure '* "readdir64" '(*))))
+ (let ((proc (syscall->procedure '* (if musl-libc? "readdir" "readdir64") '(*))))
(lambda* (directory #:optional (pointer->string pointer->string/utf-8))
(let ((ptr (proc directory)))
(and (not (null-pointer? ptr))
S
S
Sören Tempel wrote on 30 Sep 2023 12:16
Re: bug#65486: [PATCH] syscalls: Add support for musl libc
(name . Ludovic Courtès)(address . ludo@gnu.org)
2Q84POXRPGUHK.2VMS1AUMSNS7X@8pit.net
Hi,

Ludovic Courtès <ludo@gnu.org> wrote:
Toggle quote (3 lines)
> To do that, can you resend both syscalls.scm patch (with ‘git
> send-email’) here? Then we’ll check qa.guix to ensure it builds things.

Did I resend the patches correctly? I noticed that the QA status is
still unknown on issues.guix.gnu.org. Is it required to open a new
thread instead of replying to the existing one?

Greetings,
Sören
C
C
Christopher Baines wrote on 10 Oct 2023 19:15
(name . Sören Tempel)(address . soeren@soeren-tempel.net)(address . 65486@debbugs.gnu.org)
87a5sqflcy.fsf@cbaines.net
Sören Tempel <soeren@soeren-tempel.net> writes:

Toggle quote (10 lines)
> Hi,
>
> Ludovic Courtès <ludo@gnu.org> wrote:
>> To do that, can you resend both syscalls.scm patch (with ‘git
>> send-email’) here? Then we’ll check qa.guix to ensure it builds things.
>
> Did I resend the patches correctly? I noticed that the QA status is
> still unknown on issues.guix.gnu.org. Is it required to open a new
> thread instead of replying to the existing one?

The unknown status is because QA doesn't have any information on the
builds. Currently there's a limit of 300 builds per system for patches
which these changes exceed.
-----BEGIN PGP SIGNATURE-----

iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmUlhx5fFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh
aW5lcy5uZXQACgkQXiijOwuE9XffRg//X2B3GBBIWQkIl0igrIhU5rUInFGb+pLU
4l34VOs+VE45pDCL9GkwYY0lv9KGLpLkn8i1Vw5m1rScQEUhQF7sqxqhQsDVxT/n
b73+9sVuGkK5Meba0RnjYRZJtpu+ZwUmYEZtpiweYBS6rfdY2j9V834AOosyyO4u
pF3fntbRCRCYWfw7OdRjrKqcxPNR+h4J/CV2prE1psSXaifE39dU62aK+DZgzpoE
FF8vq08aZ91w9K0ZPVFLM/n2n6C7UHisBU57bxI42slE62FFp5XJ/MdJknBN9kbS
u2vs71RrLv8m0LJ+0OtWqvwu4vaEoC1t4IxsSsNjX6L1q6Jy7wF/STi17SCKY+MC
OwEbVPaAhhRxlcQMp939Uyn6/+MblAqQkyzLLXzQbVpaWVSNLUuk/ncRiOGlz1jh
FW9csM8zlpbkwcFEuwAbRizOlfTgQqz33OYe9GnsxV096FkTMGo5ZdvyjmwUCf6n
BVPZxxGhyjj2tmSzktIrmsWj9IqAGdJLzenqbiuaZe1E7DXj/GMrhC//kOKwvC0W
N8lY32ybfMGuSlxO2A/6YzcfyG78TYzPvchXkRSWC3bJ221BSgNou/WlGoMAevns
DPRsJV6maHriLGbhkbjlzICLqliplZvQKM9vrN87t8tJyRXrg0zxwJTF0D2qBiXM
x+DH35yQicQ=
=ESKl
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 23 Oct 2023 12:12
control message for bug #65486
(address . control@debbugs.gnu.org)
87bkcphclq.fsf@gnu.org
close 65486
quit
L
L
Ludovic Courtès wrote on 23 Oct 2023 12:11
Re: [bug#65486] [PATCH] syscalls: Add support for musl libc
(name . Sören Tempel)(address . soeren@soeren-tempel.net)
87fs21hcmc.fsf@gnu.org
Hello,

Ludovic Courtès <ludo@gnu.org> skribis:

Toggle quote (5 lines)
> Oooh, now I remember why I ended up not applying the previous
> syscalls.scm patch: OpenJDK and a bunch of other things depend on it, so
> changing syscalls.scm entails lots of rebuilds. (Really, they shouldn’t
> depend on it in the first place, IMO.)

This is now fixed (see https://issues.guix.gnu.org/66525), and I’m
happy to report that your patches have finally been pushed!

Thanks,
Ludo’.
Closed
?