From patchwork Sat Sep 9 13:04:28 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: 53686 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 655EC27BBE9; Sat, 9 Sep 2023 14:09: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=ham 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 9288427BBE2 for ; Sat, 9 Sep 2023 14:09:28 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qexfz-0007wH-Cy; Sat, 09 Sep 2023 09:07:03 -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 1qexfw-0007on-UB for guix-patches@gnu.org; Sat, 09 Sep 2023 09:07:00 -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 1qexfv-0003iS-Bu for guix-patches@gnu.org; Sat, 09 Sep 2023 09:07:00 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qexfy-0001Kq-5m for guix-patches@gnu.org; Sat, 09 Sep 2023 09:07:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65486] [PATCH v2] syscalls: Add support for musl libc Resent-From: soeren@soeren-tempel.net Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 09 Sep 2023 13:07: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: 65486@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Cc: 65486@debbugs.gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16942647995101 (code B ref -1); Sat, 09 Sep 2023 13:07:02 +0000 Received: (at submit) by debbugs.gnu.org; 9 Sep 2023 13:06:39 +0000 Received: from localhost ([127.0.0.1]:46396 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qexfb-0001KD-Bs for submit@debbugs.gnu.org; Sat, 09 Sep 2023 09:06:39 -0400 Received: from lists.gnu.org ([2001:470:142::17]:43740) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qexfY-0001K0-Vn for submit@debbugs.gnu.org; Sat, 09 Sep 2023 09:06:38 -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 1qexfQ-0006pj-AM for guix-patches@gnu.org; Sat, 09 Sep 2023 09:06:28 -0400 Received: from magnesium.8pit.net ([45.76.88.171]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qexfN-0003eZ-GE; Sat, 09 Sep 2023 09:06:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=d2mUpqragy YMXxnQCP3XHrMMgnVvknHJQhys+K4welY=; h=references:in-reply-to:date: subject:cc:to:from; d=soeren-tempel.net; b=fWPryGHmjCSihhCG9Tut5+S/Y4y XvsdbU7ryO8zmkf1oEwRQnwP4hDC0OYKgCJZms07jahgcnQ36+yVr8pVeRT0NperkVH+eh JPaJEweSDaK2deX5u/yaga73ArqDHFh4rCBWjip6oLrz+6SMoCwa7qbUGOwHKBacMZHCcd iwwQ= Received: from localhost (dynamic-2a02-3102-49da-001b-a1f5-aaf2-6701-ddb5.310.pool.telefonica.de [2a02:3102:49da:1b:a1f5:aaf2:6701:ddb5]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 6d6ccb73 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Sat, 9 Sep 2023 15:06:20 +0200 (CEST) From: soeren@soeren-tempel.net Date: Sat, 9 Sep 2023 15:04:28 +0200 Message-ID: <20230909130548.31083-2-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230824063303.7928-3-soeren@soeren-tempel.net> References: <20230824063303.7928-3-soeren@soeren-tempel.net> MIME-Version: 1.0 Received-SPF: pass client-ip=45.76.88.171; envelope-from=soeren@soeren-tempel.net; helo=magnesium.8pit.net 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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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 From: Sören Tempel 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 --- 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(-) 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 (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 ; (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 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))