GNU bug report logs - #66055
[PATCH v3] syscalls: Add support for musl libc

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: soeren@HIDDEN; Keywords: patch; dated Sun, 17 Sep 2023 15:23:02 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.

Message received at submit <at>

Received: (at submit) by; 17 Sep 2023 15:22:24 +0000
From debbugs-submit-bounces <at> Sun Sep 17 11:22:24 2023
Received: from localhost ([]:51179
	by with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at>>)
	id 1qhtbL-0000fO-SW
	for submit <at>; Sun, 17 Sep 2023 11:22:24 -0400
Received: from ([2001:470:142::17]:38074)
 by with esmtp (Exim 4.84_2)
 (envelope-from <soeren@HIDDEN>) id 1qhtbJ-0000eR-6z
 for submit <at>; Sun, 17 Sep 2023 11:22:21 -0400
Received: from ([2001:470:142:3::10])
 by with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <soeren@HIDDEN>)
 id 1qhtb5-00061R-11
 for guix-patches@HIDDEN; Sun, 17 Sep 2023 11:22:07 -0400
Received: from ([2001:19f0:6c01:4ae:5400:ff:fe66:af9d])
 by with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <soeren@HIDDEN>)
 id 1qhtb2-0003ea-Oc; Sun, 17 Sep 2023 11:22:06 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=fp6dfzRq/g
 subject:cc:to:from;; b=eRt7HdBoTKhChsmVgUrkYG2FLCx
Received: from localhost (
 by (OpenSMTPD) with ESMTPSA id 64276c78
 Sun, 17 Sep 2023 17:21:56 +0200 (CEST)
From: soeren@HIDDEN
To: guix-patches@HIDDEN
Subject: [PATCH v3] syscalls: Add support for musl libc
Date: Sun, 17 Sep 2023 17:21:49 +0200
Message-ID: <20230917152149.8587-2-soeren@HIDDEN>
X-Mailer: git-send-email 2.42.0
In-Reply-To: <20230917152149.8587-1-soeren@HIDDEN>
References: <87il89yugy.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=2001:19f0:6c01:4ae:5400:ff:fe66:af9d;
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
Cc: 65486 <at>, ludo@HIDDEN
X-BeenThere: debbugs-submit <at>
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <>
List-Unsubscribe: <>, 
 <mailto:debbugs-submit-request <at>>
List-Archive: <>
List-Post: <mailto:debbugs-submit <at>>
List-Help: <mailto:debbugs-submit-request <at>>
List-Subscribe: <>, 
 <mailto:debbugs-submit-request <at>>
Errors-To: debbugs-submit-bounces <at>
Sender: "Debbugs-submit" <debbugs-submit-bounces <at>>
X-Spam-Score: -0.1 (/)

From: Sören Tempel <soeren@HIDDEN>

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

Acknowledgement sent to soeren@HIDDEN:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#66055; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 17 Sep 2023 15:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.