all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Sören Tempel" <soeren@soeren-tempel.net>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 65486@debbugs.gnu.org
Subject: [bug#65486] [PATCH] syscalls: Add support for musl libc
Date: Fri, 15 Sep 2023 12:57:29 +0200	[thread overview]
Message-ID: <3V5VFSTNLLLHJ.3BBPH8V2N2EUI@8pit.net> (raw)
In-Reply-To: <87cyylkdt5.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1011 bytes --]

Hi Ludovic,

Ludovic Courtès <ludo@gnu.org> wrote:
> 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?

> 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


[-- Attachment #2: 0002-syscalls-Add-support-for-musl-libc.patch --]
[-- Type: text/plain, Size: 2891 bytes --]

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(-)

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))

  reply	other threads:[~2023-09-15 10:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24  6:33 [bug#65486] [PATCH] syscalls: Add support for musl libc soeren
2023-09-09 13:04 ` [bug#65486] [PATCH v2] " soeren
2023-09-11 21:09   ` [bug#65486] [PATCH] " Ludovic Courtès
2023-09-13 10:23     ` Sören Tempel
2023-09-13 20:39       ` Ludovic Courtès
2023-09-15 10:57         ` Sören Tempel [this message]
2023-09-17 10:14           ` bug#65486: " Ludovic Courtès
2023-09-17 10:17           ` [bug#65486] " Ludovic Courtès
2023-09-17 11:38             ` Christopher Baines
2023-09-17 15:21             ` [bug#65486] [PATCH v3] syscalls: Consistently use existing linux? definition soeren
2023-09-17 15:21               ` [bug#65486] [PATCH v3] syscalls: Add support for musl libc soeren
2023-09-30 10:16             ` [bug#65486] [PATCH] " Sören Tempel
2023-10-10 17:15               ` Christopher Baines
2023-10-23 10:11             ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3V5VFSTNLLLHJ.3BBPH8V2N2EUI@8pit.net \
    --to=soeren@soeren-tempel.net \
    --cc=65486@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.