From nobody Fri Jun 19 20:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 863E0C433EF for ; Tue, 29 Mar 2022 10:17:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235046AbiC2KTh (ORCPT ); Tue, 29 Mar 2022 06:19:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235035AbiC2KTc (ORCPT ); Tue, 29 Mar 2022 06:19:32 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D92E23EC44 for ; Tue, 29 Mar 2022 03:17:50 -0700 (PDT) Received: from integral2.. (unknown [182.2.70.161]) by gnuweeb.org (Postfix) with ESMTPSA id 3DEE67E730; Tue, 29 Mar 2022 10:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648549070; bh=nXwybG2xj7FxsXwg0gN7BG4ukSnulUCxgiiQFmEs6/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FQ8oyaOm9NRfA/ABKI83d5foWeJ6Q8BsplJtun2CZatV9EjyMpslVCQlr2tTh8Nub pJXNz/wuAzDUCgHUHewb0GR5Ke3C8rrwfeMDKRmtvpwNJpFpR1gcQ0UJT/OybqdSWp LSi1Ua1Jzm6aC5Bpstm5TiitabZgJ7MkAl0VXQA42TOMhgT7vviENyCas6axzUi4Ty G3Un8D4RY1GyVrlxSeMCe9ksnBRYm2HdruNn1MWwyO1BxfI4lAXzWUwLMogoMw9/B6 dN2wL+Feoq7oCzrjyIqS4qHJs89xkCehmN1JZepFj/6cCEvIpEIr8oxcfNCwgeetS9 UDnA/PxVQ5FFA== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Alviro Iskandar Setiawan , Nugraha , "Paul E. McKenney" , Linux Kernel Mailing List , GNU/Weeb Mailing List Subject: [PATCH v2 1/9] tools/nolibc: x86-64: Update System V ABI document link Date: Tue, 29 Mar 2022 17:17:29 +0700 Message-Id: <20220329101737.58985-2-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> References: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The old link no longer works, update it. Signed-off-by: Ammar Faizi =3D=3D=3D @@ Changelog: Link v1: https://lore.kernel.org/lkml/20220324073039.140946-2-ammarfaizi= 2@gnuweeb.org v1 -> v2: * No changes * Link RFC v2: https://lore.kernel.org/lkml/20220322102115.186179-2-ammarf= aizi2@gnuweeb.org RFC v2 -> v1: * No changes * Link RFC v1: https://lore.kernel.org/lkml/20220320093750.159991-2-ammarf= aizi2@gnuweeb.org RFC v1 -> RFC v2: * No changes * Signed-off-by: Ammar Faizi Acked-by: Willy Tarreau --- tools/include/nolibc/arch-x86_64.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index fe517c16cd4d..a7b70ea51b68 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -61,7 +61,7 @@ struct sys_stat_struct { * - see also x86-64 ABI section A.2 AMD64 Linux Kernel Conventions, A.2= .1 * Calling Conventions. * - * Link x86-64 ABI: https://gitlab.com/x86-psABIs/x86-64-ABI/-/wikis/x86-6= 4-psABI + * Link x86-64 ABI: https://gitlab.com/x86-psABIs/x86-64-ABI/-/wikis/home * */ =20 --=20 Ammar Faizi From nobody Fri Jun 19 20:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7A1AC433F5 for ; Tue, 29 Mar 2022 10:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235057AbiC2KTm (ORCPT ); Tue, 29 Mar 2022 06:19:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235035AbiC2KTh (ORCPT ); Tue, 29 Mar 2022 06:19:37 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB38423EC63 for ; Tue, 29 Mar 2022 03:17:53 -0700 (PDT) Received: from integral2.. (unknown [182.2.70.161]) by gnuweeb.org (Postfix) with ESMTPSA id B15C47E731; Tue, 29 Mar 2022 10:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648549073; bh=IuxvxrijhzGvKD3N89ycTSu7sq6wYVroW0s6c2LHqVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VyqTe1AuDKVPbt78dld8WdGOyjUkCC+n3hzW2myNYWxMuZH9lTIFZXSWd3GTr4PMo IuWc6lX8o+vkWO25sGxauEXQveKYeVjVVwv6FVLKJN28n7rz+mzQ11Nw2z1IbnxHi+ YP2lS5PJLFcWpDPMlpp8Y0VH4xAzaOHsTENSCOIEYCGsDBsHDFGKtL89LMWp5fZ9Fp 2P+Sim6y4X2l9UxSZR9HKby/ftd9A2PWmdrOMAWISY/o4V8uY2sn0p0QicHeIqCVPe PI49zhfzfHrr1ngIPBqsN3CYwtCQv8z5MQpAYzMnxuvkvNhdUvTfpxBzD75Q7z7ppk 4vQQcMJMwYAsQ== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Alviro Iskandar Setiawan , Nugraha , "Paul E. McKenney" , Linux Kernel Mailing List , GNU/Weeb Mailing List Subject: [PATCH v2 2/9] tools/nolibc: Replace `asm` with `__asm__` Date: Tue, 29 Mar 2022 17:17:30 +0700 Message-Id: <20220329101737.58985-3-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> References: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace `asm` with `__asm__` to support compilation with -std flag. Using `asm` with -std flag makes GCC think `asm()` is a function call instead of an inline assembly. GCC doc says: For the C language, the `asm` keyword is a GNU extension. When writing C code that can be compiled with `-ansi` and the `-std` options that select C dialects without GNU extensions, use `__asm__` instead of `asm`. Link: https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html Reported-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi =3D=3D=3D In a private conversation with Alviro, we found that using -std flag hits the following errors: ``` In file included from arch.h:21, from nolibc.h:97, from test.c:2: arch-i386.h:177:5: error: expected declaration specifiers or =E2=80=98...= =E2=80=99 before string constant 177 | asm(".section .text\n" | ^~~~~~~~~~~~~~~~~~ sys.h: In function =E2=80=98sys_brk=E2=80=99: arch-i386.h:83:28: error: expected =E2=80=98=3D=E2=80=99, =E2=80=98,=E2= =80=99, =E2=80=98;=E2=80=99, =E2=80=98asm=E2=80=99 or =E2=80=98__attribute_= _=E2=80=99 before =E2=80=98asm=E2=80=99 83 | register long _num asm("eax") =3D (num); = \ | ^~~ sys.h:57:24: note: in expansion of macro =E2=80=98my_syscall1=E2=80=99 57 | return (void *)my_syscall1(__NR_brk, addr); | ^~~~~~~~~~~ arch-i386.h:83:28: warning: implicit declaration of function =E2=80=98asm= =E2=80=99 [-Wimplicit-function-declaration] 83 | register long _num asm("eax") =3D (num); = \ | ^~~ sys.h:57:24: note: in expansion of macro =E2=80=98my_syscall1=E2=80=99 57 | return (void *)my_syscall1(__NR_brk, addr); | ^~~~~~~~~~~ arch-i386.h:83:39: error: lvalue required as left operand of assignment 83 | register long _num asm("eax") =3D (num); = \ | ^ sys.h:57:24: note: in expansion of macro =E2=80=98my_syscall1=E2=80=99 57 | return (void *)my_syscall1(__NR_brk, addr); | ^~~~~~~~~~~ arch-i386.h:84:29: error: expected =E2=80=98=3D=E2=80=99, =E2=80=98,=E2= =80=99, =E2=80=98;=E2=80=99, =E2=80=98asm=E2=80=99 or =E2=80=98__attribute_= _=E2=80=99 before =E2=80=98asm=E2=80=99 84 | register long _arg1 asm("ebx") =3D (long)(arg1); = \ ``` It is because inline ASM is a GNU extension. So GCC thinks asm() is a function call. To make it always available for any kind of compilation, use `__asm__` instead of `asm`. @@ Changelog: Link v1: https://lore.gnuweeb.org/gwml/20220324073039.140946-2-ammarfaiz= i2@gnuweeb.org v1 -> v2: - Switch the order with the patch that fixes clang build. Acked-by: Willy Tarreau --- tools/include/nolibc/arch-aarch64.h | 74 ++++++++++++++--------------- tools/include/nolibc/arch-arm.h | 58 +++++++++++----------- tools/include/nolibc/arch-i386.h | 56 +++++++++++----------- tools/include/nolibc/arch-mips.h | 62 ++++++++++++------------ tools/include/nolibc/arch-riscv.h | 74 ++++++++++++++--------------- tools/include/nolibc/arch-x86_64.h | 72 ++++++++++++++-------------- 6 files changed, 198 insertions(+), 198 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arc= h-aarch64.h index 87d9e434820c..b68443f63980 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -64,10 +64,10 @@ struct sys_stat_struct { =20 #define my_syscall0(num) = \ ({ = \ - register long _num asm("x8") =3D (num); \ - register long _arg1 asm("x0"); \ + register long _num __asm__ ("x8") =3D (num); \ + register long _arg1 __asm__ ("x0"); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_num) \ @@ -78,10 +78,10 @@ struct sys_stat_struct { =20 #define my_syscall1(num, arg1) = \ ({ = \ - register long _num asm("x8") =3D (num); \ - register long _arg1 asm("x0") =3D (long)(arg1); \ + register long _num __asm__ ("x8") =3D (num); \ + register long _arg1 __asm__ ("x0") =3D (long)(arg1); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_arg1), \ @@ -93,11 +93,11 @@ struct sys_stat_struct { =20 #define my_syscall2(num, arg1, arg2) = \ ({ = \ - register long _num asm("x8") =3D (num); \ - register long _arg1 asm("x0") =3D (long)(arg1); \ - register long _arg2 asm("x1") =3D (long)(arg2); \ + register long _num __asm__ ("x8") =3D (num); \ + register long _arg1 __asm__ ("x0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("x1") =3D (long)(arg2); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_arg1), "r"(_arg2), \ @@ -109,12 +109,12 @@ struct sys_stat_struct { =20 #define my_syscall3(num, arg1, arg2, arg3) = \ ({ = \ - register long _num asm("x8") =3D (num); \ - register long _arg1 asm("x0") =3D (long)(arg1); \ - register long _arg2 asm("x1") =3D (long)(arg2); \ - register long _arg3 asm("x2") =3D (long)(arg3); \ + register long _num __asm__ ("x8") =3D (num); \ + register long _arg1 __asm__ ("x0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("x1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("x2") =3D (long)(arg3); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ @@ -126,13 +126,13 @@ struct sys_stat_struct { =20 #define my_syscall4(num, arg1, arg2, arg3, arg4) = \ ({ = \ - register long _num asm("x8") =3D (num); \ - register long _arg1 asm("x0") =3D (long)(arg1); \ - register long _arg2 asm("x1") =3D (long)(arg2); \ - register long _arg3 asm("x2") =3D (long)(arg3); \ - register long _arg4 asm("x3") =3D (long)(arg4); \ + register long _num __asm__ ("x8") =3D (num); \ + register long _arg1 __asm__ ("x0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("x1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("x2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("x3") =3D (long)(arg4); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -144,14 +144,14 @@ struct sys_stat_struct { =20 #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) = \ ({ = \ - register long _num asm("x8") =3D (num); \ - register long _arg1 asm("x0") =3D (long)(arg1); \ - register long _arg2 asm("x1") =3D (long)(arg2); \ - register long _arg3 asm("x2") =3D (long)(arg3); \ - register long _arg4 asm("x3") =3D (long)(arg4); \ - register long _arg5 asm("x4") =3D (long)(arg5); \ + register long _num __asm__ ("x8") =3D (num); \ + register long _arg1 __asm__ ("x0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("x1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("x2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("x3") =3D (long)(arg4); \ + register long _arg5 __asm__ ("x4") =3D (long)(arg5); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr" (_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -163,15 +163,15 @@ struct sys_stat_struct { =20 #define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) = \ ({ = \ - register long _num asm("x8") =3D (num); \ - register long _arg1 asm("x0") =3D (long)(arg1); \ - register long _arg2 asm("x1") =3D (long)(arg2); \ - register long _arg3 asm("x2") =3D (long)(arg3); \ - register long _arg4 asm("x3") =3D (long)(arg4); \ - register long _arg5 asm("x4") =3D (long)(arg5); \ - register long _arg6 asm("x5") =3D (long)(arg6); \ + register long _num __asm__ ("x8") =3D (num); \ + register long _arg1 __asm__ ("x0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("x1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("x2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("x3") =3D (long)(arg4); \ + register long _arg5 __asm__ ("x4") =3D (long)(arg5); \ + register long _arg6 __asm__ ("x5") =3D (long)(arg6); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr" (_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -182,7 +182,7 @@ struct sys_stat_struct { }) =20 /* startup code */ -asm(".section .text\n" +__asm__ (".section .text\n" ".weak _start\n" ".global _start\n" "_start:\n" diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 001a3c8c9ad5..55fd9439b2e2 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -77,10 +77,10 @@ struct sys_stat_struct { =20 #define my_syscall0(num) = \ ({ = \ - register long _num asm("r7") =3D (num); \ - register long _arg1 asm("r0"); \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0"); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_num) \ @@ -91,10 +91,10 @@ struct sys_stat_struct { =20 #define my_syscall1(num, arg1) = \ ({ = \ - register long _num asm("r7") =3D (num); \ - register long _arg1 asm("r0") =3D (long)(arg1); \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_arg1), \ @@ -106,11 +106,11 @@ struct sys_stat_struct { =20 #define my_syscall2(num, arg1, arg2) = \ ({ = \ - register long _num asm("r7") =3D (num); \ - register long _arg1 asm("r0") =3D (long)(arg1); \ - register long _arg2 asm("r1") =3D (long)(arg2); \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_arg1), "r"(_arg2), \ @@ -122,12 +122,12 @@ struct sys_stat_struct { =20 #define my_syscall3(num, arg1, arg2, arg3) = \ ({ = \ - register long _num asm("r7") =3D (num); \ - register long _arg1 asm("r0") =3D (long)(arg1); \ - register long _arg2 asm("r1") =3D (long)(arg2); \ - register long _arg3 asm("r2") =3D (long)(arg3); \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r2") =3D (long)(arg3); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ @@ -139,13 +139,13 @@ struct sys_stat_struct { =20 #define my_syscall4(num, arg1, arg2, arg3, arg4) = \ ({ = \ - register long _num asm("r7") =3D (num); \ - register long _arg1 asm("r0") =3D (long)(arg1); \ - register long _arg2 asm("r1") =3D (long)(arg2); \ - register long _arg3 asm("r2") =3D (long)(arg3); \ - register long _arg4 asm("r3") =3D (long)(arg4); \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r3") =3D (long)(arg4); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr"(_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -157,14 +157,14 @@ struct sys_stat_struct { =20 #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) = \ ({ = \ - register long _num asm("r7") =3D (num); \ - register long _arg1 asm("r0") =3D (long)(arg1); \ - register long _arg2 asm("r1") =3D (long)(arg2); \ - register long _arg3 asm("r2") =3D (long)(arg3); \ - register long _arg4 asm("r3") =3D (long)(arg4); \ - register long _arg5 asm("r4") =3D (long)(arg5); \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r3") =3D (long)(arg4); \ + register long _arg5 __asm__ ("r4") =3D (long)(arg5); \ \ - asm volatile ( \ + __asm__ volatile ( \ "svc #0\n" \ : "=3Dr" (_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -175,7 +175,7 @@ struct sys_stat_struct { }) =20 /* startup code */ -asm(".section .text\n" +__asm__ (".section .text\n" ".weak _start\n" ".global _start\n" "_start:\n" diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i= 386.h index d7e4d53325a3..136d5739e456 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -66,9 +66,9 @@ struct sys_stat_struct { #define my_syscall0(num) = \ ({ = \ long _ret; \ - register long _num asm("eax") =3D (num); \ + register long _num __asm__ ("eax") =3D (num); \ \ - asm volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=3Da" (_ret) \ : "0"(_num) \ @@ -80,10 +80,10 @@ struct sys_stat_struct { #define my_syscall1(num, arg1) = \ ({ = \ long _ret; \ - register long _num asm("eax") =3D (num); \ - register long _arg1 asm("ebx") =3D (long)(arg1); \ + register long _num __asm__ ("eax") =3D (num); \ + register long _arg1 __asm__ ("ebx") =3D (long)(arg1); \ \ - asm volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=3Da" (_ret) \ : "r"(_arg1), \ @@ -96,11 +96,11 @@ struct sys_stat_struct { #define my_syscall2(num, arg1, arg2) = \ ({ = \ long _ret; \ - register long _num asm("eax") =3D (num); \ - register long _arg1 asm("ebx") =3D (long)(arg1); \ - register long _arg2 asm("ecx") =3D (long)(arg2); \ + register long _num __asm__ ("eax") =3D (num); \ + register long _arg1 __asm__ ("ebx") =3D (long)(arg1); \ + register long _arg2 __asm__ ("ecx") =3D (long)(arg2); \ \ - asm volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=3Da" (_ret) \ : "r"(_arg1), "r"(_arg2), \ @@ -113,12 +113,12 @@ struct sys_stat_struct { #define my_syscall3(num, arg1, arg2, arg3) = \ ({ = \ long _ret; \ - register long _num asm("eax") =3D (num); \ - register long _arg1 asm("ebx") =3D (long)(arg1); \ - register long _arg2 asm("ecx") =3D (long)(arg2); \ - register long _arg3 asm("edx") =3D (long)(arg3); \ + register long _num __asm__ ("eax") =3D (num); \ + register long _arg1 __asm__ ("ebx") =3D (long)(arg1); \ + register long _arg2 __asm__ ("ecx") =3D (long)(arg2); \ + register long _arg3 __asm__ ("edx") =3D (long)(arg3); \ \ - asm volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=3Da" (_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ @@ -131,13 +131,13 @@ struct sys_stat_struct { #define my_syscall4(num, arg1, arg2, arg3, arg4) = \ ({ = \ long _ret; \ - register long _num asm("eax") =3D (num); \ - register long _arg1 asm("ebx") =3D (long)(arg1); \ - register long _arg2 asm("ecx") =3D (long)(arg2); \ - register long _arg3 asm("edx") =3D (long)(arg3); \ - register long _arg4 asm("esi") =3D (long)(arg4); \ + register long _num __asm__ ("eax") =3D (num); \ + register long _arg1 __asm__ ("ebx") =3D (long)(arg1); \ + register long _arg2 __asm__ ("ecx") =3D (long)(arg2); \ + register long _arg3 __asm__ ("edx") =3D (long)(arg3); \ + register long _arg4 __asm__ ("esi") =3D (long)(arg4); \ \ - asm volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=3Da" (_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -150,14 +150,14 @@ struct sys_stat_struct { #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) = \ ({ = \ long _ret; \ - register long _num asm("eax") =3D (num); \ - register long _arg1 asm("ebx") =3D (long)(arg1); \ - register long _arg2 asm("ecx") =3D (long)(arg2); \ - register long _arg3 asm("edx") =3D (long)(arg3); \ - register long _arg4 asm("esi") =3D (long)(arg4); \ - register long _arg5 asm("edi") =3D (long)(arg5); \ + register long _num __asm__ ("eax") =3D (num); \ + register long _arg1 __asm__ ("ebx") =3D (long)(arg1); \ + register long _arg2 __asm__ ("ecx") =3D (long)(arg2); \ + register long _arg3 __asm__ ("edx") =3D (long)(arg3); \ + register long _arg4 __asm__ ("esi") =3D (long)(arg4); \ + register long _arg5 __asm__ ("edi") =3D (long)(arg5); \ \ - asm volatile ( \ + __asm__ volatile ( \ "int $0x80\n" \ : "=3Da" (_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -174,7 +174,7 @@ struct sys_stat_struct { * 2) The deepest stack frame should be set to zero * */ -asm(".section .text\n" +__asm__ (".section .text\n" ".weak _start\n" ".global _start\n" "_start:\n" diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index c9a6aac87c6d..cd587e539d7d 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -69,10 +69,10 @@ struct sys_stat_struct { =20 #define my_syscall0(num) = \ ({ = \ - register long _num asm("v0") =3D (num); \ - register long _arg4 asm("a3"); \ + register long _num __asm__ ("v0") =3D (num); \ + register long _arg4 __asm__ ("a3"); \ \ - asm volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -86,11 +86,11 @@ struct sys_stat_struct { =20 #define my_syscall1(num, arg1) = \ ({ = \ - register long _num asm("v0") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg4 asm("a3"); \ + register long _num __asm__ ("v0") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg4 __asm__ ("a3"); \ \ - asm volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -105,12 +105,12 @@ struct sys_stat_struct { =20 #define my_syscall2(num, arg1, arg2) = \ ({ = \ - register long _num asm("v0") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg2 asm("a1") =3D (long)(arg2); \ - register long _arg4 asm("a3"); \ + register long _num __asm__ ("v0") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("a1") =3D (long)(arg2); \ + register long _arg4 __asm__ ("a3"); \ \ - asm volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -125,13 +125,13 @@ struct sys_stat_struct { =20 #define my_syscall3(num, arg1, arg2, arg3) = \ ({ = \ - register long _num asm("v0") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg2 asm("a1") =3D (long)(arg2); \ - register long _arg3 asm("a2") =3D (long)(arg3); \ - register long _arg4 asm("a3"); \ + register long _num __asm__ ("v0") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("a1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("a2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("a3"); \ \ - asm volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -146,13 +146,13 @@ struct sys_stat_struct { =20 #define my_syscall4(num, arg1, arg2, arg3, arg4) = \ ({ = \ - register long _num asm("v0") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg2 asm("a1") =3D (long)(arg2); \ - register long _arg3 asm("a2") =3D (long)(arg3); \ - register long _arg4 asm("a3") =3D (long)(arg4); \ + register long _num __asm__ ("v0") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("a1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("a2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("a3") =3D (long)(arg4); \ \ - asm volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "syscall\n" \ "addiu $sp, $sp, 32\n" \ @@ -167,14 +167,14 @@ struct sys_stat_struct { =20 #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) = \ ({ = \ - register long _num asm("v0") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg2 asm("a1") =3D (long)(arg2); \ - register long _arg3 asm("a2") =3D (long)(arg3); \ - register long _arg4 asm("a3") =3D (long)(arg4); \ + register long _num __asm__ ("v0") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("a1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("a2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("a3") =3D (long)(arg4); \ register long _arg5 =3D (long)(arg5); \ \ - asm volatile ( \ + __asm__ volatile ( \ "addiu $sp, $sp, -32\n" \ "sw %7, 16($sp)\n" \ "syscall\n " \ @@ -189,7 +189,7 @@ struct sys_stat_struct { }) =20 /* startup code, note that it's called __start on MIPS */ -asm(".section .text\n" +__asm__ (".section .text\n" ".weak __start\n" ".set nomips16\n" ".global __start\n" diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index bc10b7b5706d..8ec4c05fa69b 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -66,10 +66,10 @@ struct sys_stat_struct { =20 #define my_syscall0(num) = \ ({ = \ - register long _num asm("a7") =3D (num); \ - register long _arg1 asm("a0"); \ + register long _num __asm__ ("a7") =3D (num); \ + register long _arg1 __asm__ ("a0"); \ \ - asm volatile ( \ + __asm__ volatile ( \ "ecall\n\t" \ : "=3Dr"(_arg1) \ : "r"(_num) \ @@ -80,10 +80,10 @@ struct sys_stat_struct { =20 #define my_syscall1(num, arg1) = \ ({ = \ - register long _num asm("a7") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ + register long _num __asm__ ("a7") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ \ - asm volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_num) \ @@ -94,11 +94,11 @@ struct sys_stat_struct { =20 #define my_syscall2(num, arg1, arg2) = \ ({ = \ - register long _num asm("a7") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg2 asm("a1") =3D (long)(arg2); \ + register long _num __asm__ ("a7") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("a1") =3D (long)(arg2); \ \ - asm volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_arg2), \ @@ -110,12 +110,12 @@ struct sys_stat_struct { =20 #define my_syscall3(num, arg1, arg2, arg3) = \ ({ = \ - register long _num asm("a7") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg2 asm("a1") =3D (long)(arg2); \ - register long _arg3 asm("a2") =3D (long)(arg3); \ + register long _num __asm__ ("a7") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("a1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("a2") =3D (long)(arg3); \ \ - asm volatile ( \ + __asm__ volatile ( \ "ecall\n\t" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), \ @@ -127,13 +127,13 @@ struct sys_stat_struct { =20 #define my_syscall4(num, arg1, arg2, arg3, arg4) = \ ({ = \ - register long _num asm("a7") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg2 asm("a1") =3D (long)(arg2); \ - register long _arg3 asm("a2") =3D (long)(arg3); \ - register long _arg4 asm("a3") =3D (long)(arg4); \ + register long _num __asm__ ("a7") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("a1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("a2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("a3") =3D (long)(arg4); \ \ - asm volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -145,14 +145,14 @@ struct sys_stat_struct { =20 #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) = \ ({ = \ - register long _num asm("a7") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg2 asm("a1") =3D (long)(arg2); \ - register long _arg3 asm("a2") =3D (long)(arg3); \ - register long _arg4 asm("a3") =3D (long)(arg4); \ - register long _arg5 asm("a4") =3D (long)(arg5); \ + register long _num __asm__ ("a7") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("a1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("a2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("a3") =3D (long)(arg4); \ + register long _arg5 __asm__ ("a4") =3D (long)(arg5); \ \ - asm volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -164,15 +164,15 @@ struct sys_stat_struct { =20 #define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) = \ ({ = \ - register long _num asm("a7") =3D (num); \ - register long _arg1 asm("a0") =3D (long)(arg1); \ - register long _arg2 asm("a1") =3D (long)(arg2); \ - register long _arg3 asm("a2") =3D (long)(arg3); \ - register long _arg4 asm("a3") =3D (long)(arg4); \ - register long _arg5 asm("a4") =3D (long)(arg5); \ - register long _arg6 asm("a5") =3D (long)(arg6); \ + register long _num __asm__ ("a7") =3D (num); \ + register long _arg1 __asm__ ("a0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("a1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("a2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("a3") =3D (long)(arg4); \ + register long _arg5 __asm__ ("a4") =3D (long)(arg5); \ + register long _arg6 __asm__ ("a5") =3D (long)(arg6); \ \ - asm volatile ( \ + __asm__ volatile ( \ "ecall\n" \ : "+r"(_arg1) \ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), "r"(_arg6), \ @@ -183,7 +183,7 @@ struct sys_stat_struct { }) =20 /* startup code */ -asm(".section .text\n" +__asm__ (".section .text\n" ".weak _start\n" ".global _start\n" "_start:\n" diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index a7b70ea51b68..490530429ac9 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -68,9 +68,9 @@ struct sys_stat_struct { #define my_syscall0(num) = \ ({ = \ long _ret; \ - register long _num asm("rax") =3D (num); \ + register long _num __asm__ ("rax") =3D (num); \ \ - asm volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=3Da"(_ret) \ : "0"(_num) \ @@ -82,10 +82,10 @@ struct sys_stat_struct { #define my_syscall1(num, arg1) = \ ({ = \ long _ret; \ - register long _num asm("rax") =3D (num); \ - register long _arg1 asm("rdi") =3D (long)(arg1); \ + register long _num __asm__ ("rax") =3D (num); \ + register long _arg1 __asm__ ("rdi") =3D (long)(arg1); \ \ - asm volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=3Da"(_ret) \ : "r"(_arg1), \ @@ -98,11 +98,11 @@ struct sys_stat_struct { #define my_syscall2(num, arg1, arg2) = \ ({ = \ long _ret; \ - register long _num asm("rax") =3D (num); \ - register long _arg1 asm("rdi") =3D (long)(arg1); \ - register long _arg2 asm("rsi") =3D (long)(arg2); \ + register long _num __asm__ ("rax") =3D (num); \ + register long _arg1 __asm__ ("rdi") =3D (long)(arg1); \ + register long _arg2 __asm__ ("rsi") =3D (long)(arg2); \ \ - asm volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=3Da"(_ret) \ : "r"(_arg1), "r"(_arg2), \ @@ -115,12 +115,12 @@ struct sys_stat_struct { #define my_syscall3(num, arg1, arg2, arg3) = \ ({ = \ long _ret; \ - register long _num asm("rax") =3D (num); \ - register long _arg1 asm("rdi") =3D (long)(arg1); \ - register long _arg2 asm("rsi") =3D (long)(arg2); \ - register long _arg3 asm("rdx") =3D (long)(arg3); \ + register long _num __asm__ ("rax") =3D (num); \ + register long _arg1 __asm__ ("rdi") =3D (long)(arg1); \ + register long _arg2 __asm__ ("rsi") =3D (long)(arg2); \ + register long _arg3 __asm__ ("rdx") =3D (long)(arg3); \ \ - asm volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=3Da"(_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ @@ -133,13 +133,13 @@ struct sys_stat_struct { #define my_syscall4(num, arg1, arg2, arg3, arg4) = \ ({ = \ long _ret; \ - register long _num asm("rax") =3D (num); \ - register long _arg1 asm("rdi") =3D (long)(arg1); \ - register long _arg2 asm("rsi") =3D (long)(arg2); \ - register long _arg3 asm("rdx") =3D (long)(arg3); \ - register long _arg4 asm("r10") =3D (long)(arg4); \ + register long _num __asm__ ("rax") =3D (num); \ + register long _arg1 __asm__ ("rdi") =3D (long)(arg1); \ + register long _arg2 __asm__ ("rsi") =3D (long)(arg2); \ + register long _arg3 __asm__ ("rdx") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r10") =3D (long)(arg4); \ \ - asm volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=3Da"(_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ @@ -152,14 +152,14 @@ struct sys_stat_struct { #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) = \ ({ = \ long _ret; \ - register long _num asm("rax") =3D (num); \ - register long _arg1 asm("rdi") =3D (long)(arg1); \ - register long _arg2 asm("rsi") =3D (long)(arg2); \ - register long _arg3 asm("rdx") =3D (long)(arg3); \ - register long _arg4 asm("r10") =3D (long)(arg4); \ - register long _arg5 asm("r8") =3D (long)(arg5); \ + register long _num __asm__ ("rax") =3D (num); \ + register long _arg1 __asm__ ("rdi") =3D (long)(arg1); \ + register long _arg2 __asm__ ("rsi") =3D (long)(arg2); \ + register long _arg3 __asm__ ("rdx") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r10") =3D (long)(arg4); \ + register long _arg5 __asm__ ("r8") =3D (long)(arg5); \ \ - asm volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=3Da"(_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -172,15 +172,15 @@ struct sys_stat_struct { #define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) = \ ({ = \ long _ret; \ - register long _num asm("rax") =3D (num); \ - register long _arg1 asm("rdi") =3D (long)(arg1); \ - register long _arg2 asm("rsi") =3D (long)(arg2); \ - register long _arg3 asm("rdx") =3D (long)(arg3); \ - register long _arg4 asm("r10") =3D (long)(arg4); \ - register long _arg5 asm("r8") =3D (long)(arg5); \ - register long _arg6 asm("r9") =3D (long)(arg6); \ + register long _num __asm__ ("rax") =3D (num); \ + register long _arg1 __asm__ ("rdi") =3D (long)(arg1); \ + register long _arg2 __asm__ ("rsi") =3D (long)(arg2); \ + register long _arg3 __asm__ ("rdx") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r10") =3D (long)(arg4); \ + register long _arg5 __asm__ ("r8") =3D (long)(arg5); \ + register long _arg6 __asm__ ("r9") =3D (long)(arg6); \ \ - asm volatile ( \ + __asm__ volatile ( \ "syscall\n" \ : "=3Da"(_ret) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ @@ -197,7 +197,7 @@ struct sys_stat_struct { * 2) The deepest stack frame should be zero (the %rbp). * */ -asm(".section .text\n" +__asm__ (".section .text\n" ".weak _start\n" ".global _start\n" "_start:\n" --=20 Ammar Faizi From nobody Fri Jun 19 20:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FAAAC433F5 for ; Tue, 29 Mar 2022 10:18:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235059AbiC2KTt (ORCPT ); Tue, 29 Mar 2022 06:19:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235052AbiC2KTk (ORCPT ); Tue, 29 Mar 2022 06:19:40 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CDB323F380 for ; Tue, 29 Mar 2022 03:17:57 -0700 (PDT) Received: from integral2.. (unknown [182.2.70.161]) by gnuweeb.org (Postfix) with ESMTPSA id 0B6817E732; Tue, 29 Mar 2022 10:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648549076; bh=+Y1H++Cm4dLdDCCVAJkzYBwn8t5y6DjxZNCzIJywHNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ESPsCv9RkCAopVivFlHhPa+6kkDoCW4kGs7/lGKz5Td1K1oDFvvsRSH53apN9Z0DD Jsh0Y3pwyFGMk2sg0nfime+ReU/u1mKfp386Ql30k1lopMbHWowP6darrnIcps5VjW vrQuMhVC5+rJdXv1CDTEj21FVdl//wccJA/4qBZbQhWKhghG2ksmRrrEokS5Fd05gK dn9dVgI6WqZcUyVxoNSdH9YA4UVAbygEmuR7Q9/exf+n0cMqV/tHLvCkhz3TSWYrsk dKmqx6I//1KgK5aTon+riBHLmMlzurBIfiiEKk4VUKuo6Nq75ziouCrFbbp4NzVuPZ JtPOdOR06MeEw== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Alviro Iskandar Setiawan , Nugraha , "Paul E. McKenney" , Linux Kernel Mailing List , GNU/Weeb Mailing List , llvm@lists.linux.dev, Nick Desaulniers Subject: [PATCH v2 3/9] tools/nolibc: Remove .global _start from the entry point code Date: Tue, 29 Mar 2022 17:17:31 +0700 Message-Id: <20220329101737.58985-4-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> References: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Building with clang yields the following error: ``` :3:1: error: _start changed binding to STB_GLOBAL .global _start ^ 1 error generated. ``` Make sure only specify one between `.global _start` and `.weak _start`. Remove `.global _start`. Cc: llvm@lists.linux.dev Reviewed-by: Nick Desaulniers Signed-off-by: Ammar Faizi =3D=3D=3D @@ Changelog: Link v1: https://lore.gnuweeb.org/gwml/20220324073039.140946-3-ammarfaiz= i2@gnuweeb.org v1 -> v2: - Switch the order with the patch that replaces `asm` with `__asm__`. Link RFC v2: https://lore.kernel.org/llvm/20220322102115.186179-3-ammarf= aizi2@gnuweeb.org RFC v2 -> v1: - Append Reviewed-by tag from Nick. - s/Removing/remove/ Link RFC v1: https://lore.kernel.org/llvm/20220320093750.159991-3-ammarf= aizi2@gnuweeb.org RFC v1 -> RFC v2: - Remove all `.global _start` for all build (GCC and Clang) instead of removing all `.weak _start` for clang build (Comment from Willy). Acked-by: Willy Tarreau --- tools/include/nolibc/arch-aarch64.h | 1 - tools/include/nolibc/arch-arm.h | 1 - tools/include/nolibc/arch-i386.h | 1 - tools/include/nolibc/arch-mips.h | 1 - tools/include/nolibc/arch-riscv.h | 1 - tools/include/nolibc/arch-x86_64.h | 1 - 6 files changed, 6 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arc= h-aarch64.h index b68443f63980..f68baf8f395f 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -184,7 +184,6 @@ struct sys_stat_struct { /* startup code */ __asm__ (".section .text\n" ".weak _start\n" - ".global _start\n" "_start:\n" "ldr x0, [sp]\n" // argc (x0) was in the stack "add x1, sp, 8\n" // argv (x1) =3D sp diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 55fd9439b2e2..f31be8e967d6 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -177,7 +177,6 @@ struct sys_stat_struct { /* startup code */ __asm__ (".section .text\n" ".weak _start\n" - ".global _start\n" "_start:\n" #if defined(__THUMBEB__) || defined(__THUMBEL__) /* We enter here in 32-bit mode but if some previous functions were in diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i= 386.h index 136d5739e456..10aada40680d 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -176,7 +176,6 @@ struct sys_stat_struct { */ __asm__ (".section .text\n" ".weak _start\n" - ".global _start\n" "_start:\n" "pop %eax\n" // argc (first arg, %eax) "mov %esp, %ebx\n" // argv[] (second arg, %ebx) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index cd587e539d7d..5fc5b8029bff 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -192,7 +192,6 @@ struct sys_stat_struct { __asm__ (".section .text\n" ".weak __start\n" ".set nomips16\n" - ".global __start\n" ".set noreorder\n" ".option pic0\n" ".ent __start\n" diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index 8ec4c05fa69b..95e2b7924925 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -185,7 +185,6 @@ struct sys_stat_struct { /* startup code */ __asm__ (".section .text\n" ".weak _start\n" - ".global _start\n" "_start:\n" ".option push\n" ".option norelax\n" diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index 490530429ac9..0e1e9eb8545d 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -199,7 +199,6 @@ struct sys_stat_struct { */ __asm__ (".section .text\n" ".weak _start\n" - ".global _start\n" "_start:\n" "pop %rdi\n" // argc (first arg, %rdi) "mov %rsp, %rsi\n" // argv[] (second arg, %rsi) --=20 Ammar Faizi From nobody Fri Jun 19 20:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7285C433EF for ; Tue, 29 Mar 2022 10:18:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235101AbiC2KTy (ORCPT ); Tue, 29 Mar 2022 06:19:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235048AbiC2KTr (ORCPT ); Tue, 29 Mar 2022 06:19:47 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D47AC23F398 for ; Tue, 29 Mar 2022 03:18:01 -0700 (PDT) Received: from integral2.. (unknown [182.2.70.161]) by gnuweeb.org (Postfix) with ESMTPSA id 632E27E72A; Tue, 29 Mar 2022 10:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648549081; bh=sOa5bTrQEKERvFJedlayh1Unbt9LOKPwsCzeI50Bj1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lx/7IuFTk6fAH3rYLwr/TJtsTaUHd3qTJqK3lcjI/hhU25WOBbGYuKY+Mj8ceN5r9 rokZey+MbRFLdlrhTRRWlmeJS4uX3W41mpW/z5cNbO74neTuvt2hHNNEqWCcuw56nS AdbA0hKG4w7mjEtBtJloml4CGj8b9N6IdAvEIMz+7/m2h7tbq+d1kSMmUfHo9fBJo0 BTd0yG2LtbHaaNTVdBo2IcvtDE8cRCH1Kg2CIuIQ+a0COLQOrxORp/xmVZqTQ5TgsN xTEBIWaqDWvCTOV2N+UyIQ9IDxTUUsIJ+pRkhnKO2lY6sr4/NGjUq7iypI17bKvJWJ N3kZ5duH8YYuA== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Alviro Iskandar Setiawan , Nugraha , "Paul E. McKenney" , Linux Kernel Mailing List , GNU/Weeb Mailing List , x86@kernel.org, llvm@lists.linux.dev, David Laight Subject: [PATCH v2 4/9] tools/nolibc: i386: Implement syscall with 6 arguments Date: Tue, 29 Mar 2022 17:17:32 +0700 Message-Id: <20220329101737.58985-5-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> References: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On i386, the 6th argument of syscall goes in %ebp. However, both Clang and GCC cannot use %ebp in the clobber list and in the "r" constraint without using -fomit-frame-pointer. To make it always available for any kind of compilation, the below workaround is implemented. 1) Push the 6-th argument. 2) Push %ebp. 3) Load the 6-th argument from 4(%esp) to %ebp. 4) Do the syscall (int $0x80). 5) Pop %ebp (restore the old value of %ebp). 6) Add %esp by 4 (undo the stack pointer). Cc: x86@kernel.org Cc: llvm@lists.linux.dev Link: https://lore.kernel.org/lkml/2e335ac54db44f1d8496583d97f9dab0@AcuMS.a= culab.com Suggested-by: David Laight Signed-off-by: Ammar Faizi =3D=3D=3D @@ Changelog: Link v1: https://lore.gnuweeb.org/gwml/20220324073039.140946-7-ammarfaiz= i2@gnuweeb.org v1 -> v2: * No changes * Link RFC v2: https://lore.kernel.org/lkml/20220322102115.186179-4-ammarf= aizi2@gnuweeb.org RFC v2 -> v1: - Use the same pattern for syscall6, regardless using GCC or Clang (comment from David). - Use appropriate constraints for syscall6 instead of always using register variables (comment from David). Link RFC v1: https://lore.kernel.org/llvm/20220320093750.159991-4-ammarf= aizi2@gnuweeb.org RFC v1 -> RFC v2: - Fix %ebp saving method. Don't use redzone, i386 doesn't have a redzone (comment from David and Alviro). Acked-by: Willy Tarreau --- tools/include/nolibc/arch-i386.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i= 386.h index 10aada40680d..d7e7212346e2 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -167,6 +167,29 @@ struct sys_stat_struct { _ret; \ }) =20 +#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ +({ \ + long _eax =3D (long)(num); \ + long _arg6 =3D (long)(arg6); /* Always in memory */ \ + __asm__ volatile ( \ + "pushl %[_arg6]\n\t" \ + "pushl %%ebp\n\t" \ + "movl 4(%%esp),%%ebp\n\t" \ + "int $0x80\n\t" \ + "popl %%ebp\n\t" \ + "addl $4,%%esp\n\t" \ + : "+a"(_eax) /* %eax */ \ + : "b"(arg1), /* %ebx */ \ + "c"(arg2), /* %ecx */ \ + "d"(arg3), /* %edx */ \ + "S"(arg4), /* %esi */ \ + "D"(arg5), /* %edi */ \ + [_arg6]"m"(_arg6) /* memory */ \ + : "memory", "cc" \ + ); \ + _eax; \ +}) + /* startup code */ /* * i386 System V ABI mandates: --=20 Ammar Faizi From nobody Fri Jun 19 20:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34CC4C433F5 for ; Tue, 29 Mar 2022 10:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235061AbiC2KUK (ORCPT ); Tue, 29 Mar 2022 06:20:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235093AbiC2KTy (ORCPT ); Tue, 29 Mar 2022 06:19:54 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 795722405BD for ; Tue, 29 Mar 2022 03:18:05 -0700 (PDT) Received: from integral2.. (unknown [182.2.70.161]) by gnuweeb.org (Postfix) with ESMTPSA id 151CE7E734; Tue, 29 Mar 2022 10:18:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648549085; bh=DJZFv4JotEMo5L83nTqipusJFM8ZYgW9v7ot8diz0vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VQtJiwB00c4DkarcuHtgJpo5lMxauXI6ZY2BAAz027atQbihyJahtmO5ASq05SpoE ER3x8AqZZW9Y9A3fvGB15CFuVCrQV4XyqQnmfHXEJ1FURvektiK4j2H45gOiTdEBYG IimqHvHsTCdJqTS+3pShi5ZkhSbvAXYehNuUwpjVu0FLR7MxmD5DSd8O3Z/3u+VsEB A9/hbEPCnBmGEWuWkStjGKZ4GmjbArtmA/2E4Fux7IB+7JP9kR/txZuXAktrIcbSlu B36r1OxolWe0Sb7enkTZcTd44Ys++bsNJC/MVcDpSZnhaHFHOseDbsbNhWaqE4FzNM RT15qfrBhKR1Q== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Alviro Iskandar Setiawan , Nugraha , "Paul E. McKenney" , Linux Kernel Mailing List , GNU/Weeb Mailing List Subject: [PATCH v2 5/9] tools/nolibc/sys: Implement `mmap()` and `munmap()` Date: Tue, 29 Mar 2022 17:17:33 +0700 Message-Id: <20220329101737.58985-6-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> References: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Implement mmap() and munmap(). Currently, they are only available for architecures that have my_syscall6 macro. For architectures that don't have, this function will return -1 with errno set to ENOSYS (Function not implemented). This has been tested on x86 and i386. Notes for i386: 1) The common mmap() syscall implementation uses __NR_mmap2 instead of __NR_mmap. 2) The offset must be shifted-right by 12-bit. Signed-off-by: Ammar Faizi =3D=3D=3D @@ Changelog: Link v1: https://lore.gnuweeb.org/gwml/20220324073039.140946-8-ammarfaiz= i2@gnuweeb.org v1 -> v2: * No changes * Link RFC v2: https://lore.kernel.org/lkml/20220322102115.186179-5-ammarf= aizi2@gnuweeb.org RFC v2 -> v1: * No changes * Link RFC v1: https://lore.kernel.org/lkml/20220320093750.159991-5-ammarf= aizi2@gnuweeb.org RFC v1 -> RFC v2: * No changes * Acked-by: Willy Tarreau --- tools/include/nolibc/sys.h | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 4d4308d5d111..08491070387b 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -14,6 +14,7 @@ #include #include // for SIGCHLD #include +#include #include #include #include @@ -675,6 +676,67 @@ int mknod(const char *path, mode_t mode, dev_t dev) return ret; } =20 +#ifndef MAP_SHARED +#define MAP_SHARED 0x01 /* Share changes */ +#define MAP_PRIVATE 0x02 /* Changes are private */ +#define MAP_SHARED_VALIDATE 0x03 /* share + validate extension flags */ +#endif + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + +static __attribute__((unused)) +void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, + off_t offset) +{ +#ifndef my_syscall6 + /* Function not implemented. */ + return -ENOSYS; +#else + + int n; + +#if defined(__i386__) + n =3D __NR_mmap2; + offset >>=3D 12; +#else + n =3D __NR_mmap; +#endif + + return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset); +#endif +} + +static __attribute__((unused)) +void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t o= ffset) +{ + void *ret =3D sys_mmap(addr, length, prot, flags, fd, offset); + + if ((unsigned long)ret >=3D -4095UL) { + SET_ERRNO(-(long)ret); + ret =3D MAP_FAILED; + } + return ret; +} + +static __attribute__((unused)) +int sys_munmap(void *addr, size_t length) +{ + return my_syscall2(__NR_munmap, addr, length); +} + +static __attribute__((unused)) +int munmap(void *addr, size_t length) +{ + int ret =3D sys_munmap(addr, length); + + if (ret < 0) { + SET_ERRNO(-ret); + ret =3D -1; + } + return ret; +} =20 /* * int mount(const char *source, const char *target, --=20 Ammar Faizi From nobody Fri Jun 19 20:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C438C433F5 for ; Tue, 29 Mar 2022 10:19:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235118AbiC2KUo (ORCPT ); Tue, 29 Mar 2022 06:20:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235105AbiC2KT4 (ORCPT ); Tue, 29 Mar 2022 06:19:56 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 494482414D2 for ; Tue, 29 Mar 2022 03:18:09 -0700 (PDT) Received: from integral2.. (unknown [182.2.70.161]) by gnuweeb.org (Postfix) with ESMTPSA id EE7447E726; Tue, 29 Mar 2022 10:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648549088; bh=IyJY9APPUs2Jm0t28TfIT9sgV0eTR+GH3x1eZDSz5/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ARsHG3hF9MVFev9wunSZZCkONyT2C3efkgmQmEfQ17AauzFAyNh5n6IGVNXurrPuL raOclWhgZam5LbHBvWzkIhC7PiQihr5Gfk/cS8/kye//ks3z7KLCcw75x9oTwRgKYx OVbzvFKJLNLeujgAkd7UInBvvf9mNxM/S2fI0Wx5JNrvz8i6TQZnSD5baSqai+Zsqq PgvX0OMI4RQzumlV+A3McOE3YuPD+IkOVwetPEA+0QcJZyYeRWoa6AXS13185vu77a pSsxcI5kTT91EjcGEwOVxqiO+0Ebgvg4EveGwERp0v5KzS65VEgEqm4LnirTrw8XSu 4n76w7yxbG68Q== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Alviro Iskandar Setiawan , Nugraha , "Paul E. McKenney" , Linux Kernel Mailing List , GNU/Weeb Mailing List Subject: [PATCH v2 6/9] tools/nolibc/types: Implement `offsetof()` and `container_of()` macro Date: Tue, 29 Mar 2022 17:17:34 +0700 Message-Id: <20220329101737.58985-7-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> References: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Implement `offsetof()` and `container_of()` macro. The first use case of these macros is for `malloc()`, `realloc()` and `free()`. Signed-off-by: Ammar Faizi =3D=3D=3D @@ Changelog: Link v1: https://lore.gnuweeb.org/gwml/20220324073039.140946-9-ammarfaiz= i2@gnuweeb.org v1 -> v2: * No changes * Link RFC v2: https://lore.kernel.org/lkml/20220322102115.186179-6-ammarf= aizi2@gnuweeb.org RFC v2 -> v1: * No changes * Signed-off-by: Ammar Faizi Acked-by: Willy Tarreau --- tools/include/nolibc/types.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index 357e60ad38a8..959997034e55 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -191,4 +191,15 @@ struct stat { #define major(dev) ((unsigned int)(((dev) >> 8) & 0xfff)) #define minor(dev) ((unsigned int)(((dev) & 0xff)) =20 +#ifndef offsetof +#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD) +#endif + +#ifndef container_of +#define container_of(PTR, TYPE, FIELD) ({ \ + __typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR =3D (PTR); \ + (TYPE *)((char *) __FIELD_PTR - offsetof(TYPE, FIELD)); \ +}) +#endif + #endif /* _NOLIBC_TYPES_H */ --=20 Ammar Faizi From nobody Fri Jun 19 20:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCA12C433EF for ; Tue, 29 Mar 2022 10:18:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235081AbiC2KUS (ORCPT ); Tue, 29 Mar 2022 06:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235090AbiC2KUF (ORCPT ); Tue, 29 Mar 2022 06:20:05 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99BDB241A04 for ; Tue, 29 Mar 2022 03:18:12 -0700 (PDT) Received: from integral2.. (unknown [182.2.70.161]) by gnuweeb.org (Postfix) with ESMTPSA id 67C7A7E736; Tue, 29 Mar 2022 10:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648549092; bh=4ayk0palimnVIsRYgwXKtHchFZ/kzcSyKrT7RjDdssQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QYIJB9B6WLqpi0pvZ2g54PBXl0K8QYpmDfzFNOprQssxrGTfZXy7/ofwWo2qyJbbH /b9SNLnIihktUfxLCov2HfkRbjiqJziy+HYX2q+Wp4llDlRzbe04bSotQiSG88qF7G OaI0oyvw9+wylaa4XZVt0Qh6lB7IK1/IeK0qd/Gy/2Xl4LdqLUy3owjzc1iCIAEbd9 071ZYXdfTEDnSh5RY3j1aumnUVzFoy4oa1MaNaO8tAe/AsStAI/3HjBpmXGmlMdZb4 C4hKgYv9DQ5yv8RKvmdaP3e3PlhGE0zVE+OVqnABCZWn1G8J1FvDPzeTK+dSTiH25T W5dMYxhc9YwPg== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Alviro Iskandar Setiawan , Nugraha , "Paul E. McKenney" , Linux Kernel Mailing List , GNU/Weeb Mailing List , David Laight Subject: [PATCH v2 7/9] tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()` Date: Tue, 29 Mar 2022 17:17:35 +0700 Message-Id: <20220329101737.58985-8-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> References: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Implement basic dynamic allocator functions. These functions are currently only available on architectures that have nolibc mmap() syscall implemented. These are not a super-fast memory allocator, but at least they can satisfy basic needs for having heap without libc. Cc: David Laight Signed-off-by: Ammar Faizi =3D=3D=3D @@ Changelog: Link v1: https://lore.gnuweeb.org/gwml/20220324073039.140946-10-ammarfai= zi2@gnuweeb.org v1 -> v2: * No changes * Link v2: https://lore.kernel.org/lkml/20220322102115.186179-7-ammarfaizi= 2@gnuweeb.org RFC v2 -> v1: - Round up the malloc() allocation to 4096 (comment from David). - Don't realloc() if we still have enough memory to contain the requested new size (comment from David). - Fix conflict with getenv() fix (after rebase). Link v1: https://lore.kernel.org/lkml/20220320093750.159991-6-ammarfaizi= 2@gnuweeb.org RFC v1 -> RFC v2: - Move container_of() and offsetof() macro to types.h with a separate patch (comment from Willy). Acked-by: Willy Tarreau --- tools/include/nolibc/stdlib.h | 81 +++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 8a07e263f0d0..8fd32eaf8037 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -11,7 +11,12 @@ #include "arch.h" #include "types.h" #include "sys.h" +#include "string.h" =20 +struct nolibc_heap { + size_t len; + char user_p[] __attribute__((__aligned__)); +}; =20 /* Buffer used to store int-to-ASCII conversions. Will only be implemented= if * any of the related functions is implemented. The area is large enough to @@ -60,6 +65,18 @@ int atoi(const char *s) return atol(s); } =20 +static __attribute__((unused)) +void free(void *ptr) +{ + struct nolibc_heap *heap; + + if (!ptr) + return; + + heap =3D container_of(ptr, struct nolibc_heap, user_p); + munmap(heap, heap->len); +} + /* getenv() tries to find the environment variable named in the * environment array pointed to by global variable "environ" which must be * declared as a char **, and must be terminated by a NULL (it is recommen= ded @@ -91,6 +108,70 @@ char *getenv(const char *name) return _getenv(name, environ); } =20 +static __attribute__((unused)) +void *malloc(size_t len) +{ + struct nolibc_heap *heap; + + /* Always allocate memory with size multiple of 4096. */ + len =3D sizeof(*heap) + len; + len =3D (len + 4095UL) & -4096UL; + heap =3D mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, + -1, 0); + if (__builtin_expect(heap =3D=3D MAP_FAILED, 0)) + return NULL; + + heap->len =3D len; + return heap->user_p; +} + +static __attribute__((unused)) +void *calloc(size_t size, size_t nmemb) +{ + void *orig; + size_t res =3D 0; + + if (__builtin_expect(__builtin_mul_overflow(nmemb, size, &res), 0)) { + SET_ERRNO(ENOMEM); + return NULL; + } + + /* + * No need to zero the heap, the MAP_ANONYMOUS in malloc() + * already does it. + */ + return malloc(res); +} + +static __attribute__((unused)) +void *realloc(void *old_ptr, size_t new_size) +{ + struct nolibc_heap *heap; + size_t user_p_len; + void *ret; + + if (!old_ptr) + return malloc(new_size); + + heap =3D container_of(old_ptr, struct nolibc_heap, user_p); + user_p_len =3D heap->len - sizeof(*heap); + /* + * Don't realloc() if @user_p_len >=3D @new_size, this block of + * memory is still enough to handle the @new_size. Just return + * the same pointer. + */ + if (user_p_len >=3D new_size) + return old_ptr; + + ret =3D malloc(new_size); + if (__builtin_expect(!ret, 0)) + return NULL; + + memcpy(ret, heap->user_p, heap->len); + munmap(heap, heap->len); + return ret; +} + /* Converts the unsigned long integer to its hex representation into * buffer , which must be long enough to store the number and the * trailing zero (17 bytes for "ffffffffffffffff" or 9 for "ffffffff"). The --=20 Ammar Faizi From nobody Fri Jun 19 20:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3298C433F5 for ; Tue, 29 Mar 2022 10:18:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235106AbiC2KUd (ORCPT ); Tue, 29 Mar 2022 06:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235129AbiC2KUG (ORCPT ); Tue, 29 Mar 2022 06:20:06 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 116D431372 for ; Tue, 29 Mar 2022 03:18:15 -0700 (PDT) Received: from integral2.. (unknown [182.2.70.161]) by gnuweeb.org (Postfix) with ESMTPSA id 8A8AE7E733; Tue, 29 Mar 2022 10:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648549094; bh=FxtBrp49dfrBIXa72go2hDycnGwH5xLsPNTZN2AYVhY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z4PjSn0zimerFsS+87aNyp/EZZoZauwsQvsU/2PIY2lVb7zfdJTrrk0UbA8wg5+eF Z4dC8ou5hL1Ijrnpyxs3Grepe3q0OsrDqeON2quFdTebEgVyt/1cEzrnalRByFD2ds bawZlJEq6iS0vYxCCOT48JabpWTPFJubpOZarNknj/nPw7sa8EpLw+9XIYNTd1jTKN HzJODGnYbqk8quAduX3IC0sit5YH1A9C1q63CuoFWLaCp7lLlSBaLAhGZZzbRrwNVz +bVJHfyWZbuJ3BKSIOSeTjGOK7J8wVh3Xbb6hZKjVUrfgxiNZUQnznhOpmOtDupdK/ 84I1LYdb2BbEA== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Alviro Iskandar Setiawan , Nugraha , "Paul E. McKenney" , Linux Kernel Mailing List , GNU/Weeb Mailing List Subject: [PATCH v2 8/9] tools/nolibc/string: Implement `strnlen()` Date: Tue, 29 Mar 2022 17:17:36 +0700 Message-Id: <20220329101737.58985-9-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> References: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" size_t strnlen(const char *str, size_t maxlen); The strnlen() function returns the number of bytes in the string pointed to by sstr, excluding the terminating null byte ('\0'), but at most maxlen. In doing this, strnlen() looks only at the first maxlen characters in the string pointed to by str and never beyond str[maxlen-1]. The first use case of this function is for determining the memory allocation size in the strndup() function. Link: https://lore.kernel.org/lkml/CAOG64qMpEMh+EkOfjNdAoueC+uQyT2Uv3689_sO= r37-JxdJf4g@mail.gmail.com Suggested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi =3D=3D=3D @@ Changelog: Link v1: https://lore.gnuweeb.org/gwml/20220324073039.140946-11-ammarfai= zi2@gnuweeb.org v1 -> v2: * No changes * Link v2: https://lore.kernel.org/lkml/20220322102115.186179-8-ammarfaizi= 2@gnuweeb.org RFC v2 -> v1: * No changes * Acked-by: Willy Tarreau --- tools/include/nolibc/string.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index 75a453870498..f43d52a44d09 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -147,6 +147,15 @@ size_t nolibc_strlen(const char *str) #define strlen(str) nolibc_strlen((str)) #endif =20 +static __attribute__((unused)) +size_t strnlen(const char *str, size_t maxlen) +{ + size_t len; + + for (len =3D 0; (len < maxlen) && str[len]; len++); + return len; +} + static __attribute__((unused)) size_t strlcat(char *dst, const char *src, size_t size) { --=20 Ammar Faizi From nobody Fri Jun 19 20:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50EE1C433F5 for ; Tue, 29 Mar 2022 10:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235102AbiC2KU0 (ORCPT ); Tue, 29 Mar 2022 06:20:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235130AbiC2KUG (ORCPT ); Tue, 29 Mar 2022 06:20:06 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B76A13CEE for ; Tue, 29 Mar 2022 03:18:18 -0700 (PDT) Received: from integral2.. (unknown [182.2.70.161]) by gnuweeb.org (Postfix) with ESMTPSA id 91AE17E728; Tue, 29 Mar 2022 10:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648549098; bh=xHCPU9NOBSts5NOJLTkMXjyz0B2Gtmos6nJsWrNZUJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lDYHBaduwYvLQzNN7zQCJmfIfWdPud/oAw0V3IysxTH4DX2QF2HuWlhCCoBqpk+aB 6WUq8b/Iq6QZ21koMJUszKRtCAOEeIgNZXlCUSLtc7VohKyWHwCLj7VEt9zVVVQarf qP25RXW4YNUHfzYD2hebJjONlSLQNrTA46kFCl8pY0Q6yLLg9A1E/24FAiwqno39X1 WkFLufjcQzcEs+GRzvbeASmjT2ornLMcSZNtVMgmI+DH4tgJbOQWjFEiixvPO+yrmG qM2gYcCSet6FAZCoHYGGrU4P/Nh4sIldifaEaY9EYvbFpVYxn0uh0GhFs293eGBAzU lVutbfp6zNw3A== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Alviro Iskandar Setiawan , Nugraha , "Paul E. McKenney" , Linux Kernel Mailing List , GNU/Weeb Mailing List Subject: [PATCH v2 9/9] tools/include/string: Implement `strdup()` and `strndup()` Date: Tue, 29 Mar 2022 17:17:37 +0700 Message-Id: <20220329101737.58985-10-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> References: <20220329101737.58985-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" These functions are currently only available on architectures that have my_syscall6() macro implemented. Since these functions use malloc(), malloc() uses mmap(), mmap() depends on my_syscall6() macro. On architectures that don't support my_syscall6(), these function will always return NULL with errno set to ENOSYS. Signed-off-by: Ammar Faizi =3D=3D=3D @@ Changelog: Link v1: https://lore.gnuweeb.org/gwml/20220324073039.140946-12-ammarfai= zi2@gnuweeb.org v1 -> v2: * No changes * Link RFC v2: https://lore.kernel.org/lkml/20220322102115.186179-9-ammarf= aizi2@gnuweeb.org RFC v2 -> v1: * No changes * Link RFC v1: https://lore.kernel.org/lkml/20220320093750.159991-7-ammarf= aizi2@gnuweeb.org RFC v1 -> RFC v2: - Update strdup and strndup implementation, use strlen and strnlen to g= et the string length first (comment from Willy and Alviro). - Fix the subject line prefix, it was "tools/include/string: ", it shou= ld be "tools/nolibc/string: ". Acked-by: Willy Tarreau --- tools/include/nolibc/string.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index f43d52a44d09..bef35bee9c44 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -9,6 +9,8 @@ =20 #include "std.h" =20 +static void *malloc(size_t len); + /* * As much as possible, please keep functions alphabetically sorted. */ @@ -156,6 +158,36 @@ size_t strnlen(const char *str, size_t maxlen) return len; } =20 +static __attribute__((unused)) +char *strdup(const char *str) +{ + size_t len; + char *ret; + + len =3D strlen(str); + ret =3D malloc(len + 1); + if (__builtin_expect(ret !=3D NULL, 1)) + memcpy(ret, str, len + 1); + + return ret; +} + +static __attribute__((unused)) +char *strndup(const char *str, size_t maxlen) +{ + size_t len; + char *ret; + + len =3D strnlen(str, maxlen); + ret =3D malloc(len + 1); + if (__builtin_expect(ret !=3D NULL, 1)) { + memcpy(ret, str, len); + ret[len] =3D '\0'; + } + + return ret; +} + static __attribute__((unused)) size_t strlcat(char *dst, const char *src, size_t size) { --=20 Ammar Faizi