From patchwork Fri Sep 15 10:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?S=C3=B6ren_Tempel?= X-Patchwork-Id: 53915 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6068E27BBE2; Fri, 15 Sep 2023 11:58:29 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4311F27BBE9 for ; Fri, 15 Sep 2023 11:58:28 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qh6WO-0004PB-1S; Fri, 15 Sep 2023 06:58:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qh6WK-0004O3-F6 for guix-patches@gnu.org; Fri, 15 Sep 2023 06:57:56 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qh6WK-0001d0-6J for guix-patches@gnu.org; Fri, 15 Sep 2023 06:57:56 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qh6WQ-0004Vi-Gd for guix-patches@gnu.org; Fri, 15 Sep 2023 06:58:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65486] [PATCH] syscalls: Add support for musl libc Resent-From: =?utf-8?b?U8O2cmVu?= Tempel Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 15 Sep 2023 10:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65486 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Cc: 65486@debbugs.gnu.org Received: via spool by 65486-submit@debbugs.gnu.org id=B65486.169477546717318 (code B ref 65486); Fri, 15 Sep 2023 10:58:02 +0000 Received: (at 65486) by debbugs.gnu.org; 15 Sep 2023 10:57:47 +0000 Received: from localhost ([127.0.0.1]:42241 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qh6WB-0004VF-7b for submit@debbugs.gnu.org; Fri, 15 Sep 2023 06:57:47 -0400 Received: from magnesium.8pit.net ([45.76.88.171]:24337) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qh6W8-0004V3-E9 for 65486@debbugs.gnu.org; Fri, 15 Sep 2023 06:57:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=/k1F3e2979 uofnMFoW8fNmXr0Fq1YFLseHixwvDlunA=; h=in-reply-to:references:from: subject:cc:to:date; d=soeren-tempel.net; b=qBcox/3jN621/2zGgMeEvjmTZM5 EG7VaahJhHNC56KPfcRh10OHsKY/x9xrJyh2i0cyToLhQ+fnqG49xb30dB2AegpvlKjYEE TzOQ2HwcoLtRdq2M4gys/bWFokOO/2TstdEm+p2u/IdPjeCOgOi/aXv1sBGWUAq8wyPFT/ r3dU= Received: from localhost (dynamic-002-247-251-213.2.247.pool.telefonica.de [2.247.251.213]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 139f614c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Fri, 15 Sep 2023 12:57:35 +0200 (CEST) Date: Fri, 15 Sep 2023 12:57:29 +0200 From: =?utf-8?b?U8O2cmVu?= Tempel References: <20230824063303.7928-3-soeren@soeren-tempel.net> <20230909130548.31083-2-soeren@soeren-tempel.net> <87fs3kquwl.fsf_-_@gnu.org> <3DOVAMAK0VD13.2XDJ9MT35902D@8pit.net> <87cyylkdt5.fsf@gnu.org> In-Reply-To: <87cyylkdt5.fsf@gnu.org> Message-Id: <3V5VFSTNLLLHJ.3BBPH8V2N2EUI@8pit.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Hi Ludovic, Ludovic Courtès 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 From b1d478defc7f3e794974be2b9665cd4a58030569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= 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 (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 ; (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 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))