From nobody Thu Oct 9 04:14:04 2025 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F287C23AB8A for ; Fri, 20 Jun 2025 10:37:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=163.172.96.212 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750415856; cv=none; b=TjimS3SLEAIEtFt2rH6JBwgZhhxh87F3lqZRw4enQGBWFLe9Pf4Q4KKibP+9iKBPcCjik1lSlQZwxO194tYwF0P3913b6HEYTtqBX+OjJmAU//cjQWYbSHb8EBX4wEuvGXBxMHPObcofNZgDC9Z4d6PGOjWhBKa0kHo5LlOhqOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750415856; c=relaxed/simple; bh=AJhPoQfgBnZIPevgOsEDb/+kr7SrcNFqDlxlJGlGQs4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=qQ+P9VQxVMqG9IDChYepCWYyTlbKRYWzXOrUFE50VdDC7v2yfvdGxr9Xk+EJXPzwxSqvM4IZCu80h1XWwZX4QSfAD6Npb5wq3seBZh2j1YS7gvmxQjR4FeZ+B5qndr2mkwSM1H6rHgx0cbEWP0ihCJ1OxGM5QQeQwe6pva8ae2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; arc=none smtp.client-ip=163.172.96.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 55KAbPqk010254; Fri, 20 Jun 2025 12:37:25 +0200 From: Willy Tarreau To: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Arnd Bergmann , Willy Tarreau Subject: [RFC PATCH 1/3] tools/nolibc: merge i386 and x86_64 into a single x86 arch Date: Fri, 20 Jun 2025 12:37:03 +0200 Message-Id: <20250620103705.10208-2-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20250620103705.10208-1-w@1wt.eu> References: <20250620103705.10208-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This remained the only exception to the kernel's architectures organization and it's always a bit cumbersome to deal with. Let's merge i386 and x86_64 into x86. This will result in a single arch-x86.h file by default, and we'll no longer need to merge the two manually during installation. Requesting either i386 or x86_64 will also result in installing x86. Signed-off-by: Willy Tarreau Acked-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/Makefile | 10 +- tools/include/nolibc/arch-i386.h | 178 ----------------- .../nolibc/{arch-x86_64.h =3D> arch-x86.h} | 180 +++++++++++++++++- tools/include/nolibc/arch.h | 6 +- 4 files changed, 179 insertions(+), 195 deletions(-) delete mode 100644 tools/include/nolibc/arch-i386.h rename tools/include/nolibc/{arch-x86_64.h =3D> arch-x86.h} (53%) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 823bfa08c6756..9197c79b267a4 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -93,18 +93,12 @@ help: @echo " OUTPUT =3D $(OUTPUT)" @echo "" =20 -# Note: when ARCH is "x86" we concatenate both x86_64 and i386 headers: $(Q)mkdir -p $(OUTPUT)sysroot $(Q)mkdir -p $(OUTPUT)sysroot/include $(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/ - $(Q)if [ "$(ARCH)" =3D "x86" ]; then \ - sed -e \ - 's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) = \&\& defined(__x86_64__),' \ - arch-x86_64.h; \ - sed -e \ - 's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\&= !defined(__x86_64__),' \ - arch-i386.h; \ + $(Q)if [ "$(ARCH)" =3D "i386" -o "$(ARCH)" =3D "x86_64" ]; then \ + cat arch-x86.h; \ elif [ -e "$(arch_file)" ]; then \ cat $(arch_file); \ else \ diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i= 386.h deleted file mode 100644 index 7c9b38e964183..0000000000000 --- a/tools/include/nolibc/arch-i386.h +++ /dev/null @@ -1,178 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ -/* - * i386 specific definitions for NOLIBC - * Copyright (C) 2017-2022 Willy Tarreau - */ - -#ifndef _NOLIBC_ARCH_I386_H -#define _NOLIBC_ARCH_I386_H - -#include "compiler.h" -#include "crt.h" - -/* Syscalls for i386 : - * - mostly similar to x86_64 - * - registers are 32-bit - * - syscall number is passed in eax - * - arguments are in ebx, ecx, edx, esi, edi, ebp respectively - * - all registers are preserved (except eax of course) - * - the system call is performed by calling int $0x80 - * - syscall return comes in eax - * - the arguments are cast to long and assigned into the target registe= rs - * which are then simply passed as registers to the asm code, so that = we - * don't have to experience issues with register constraints. - * - the syscall number is always specified last in order to allow to fo= rce - * some registers before (gcc refuses a %-register at the last positio= n). - * - * Also, i386 supports the old_select syscall if newselect is not available - */ -#define __ARCH_WANT_SYS_OLD_SELECT - -#define my_syscall0(num) = \ -({ = \ - long _ret; \ - register long _num __asm__ ("eax") =3D (num); \ - \ - __asm__ volatile ( \ - "int $0x80\n" \ - : "=3Da" (_ret) \ - : "0"(_num) \ - : "memory", "cc" \ - ); \ - _ret; \ -}) - -#define my_syscall1(num, arg1) = \ -({ = \ - long _ret; \ - register long _num __asm__ ("eax") =3D (num); \ - register long _arg1 __asm__ ("ebx") =3D (long)(arg1); \ - \ - __asm__ volatile ( \ - "int $0x80\n" \ - : "=3Da" (_ret) \ - : "r"(_arg1), \ - "0"(_num) \ - : "memory", "cc" \ - ); \ - _ret; \ -}) - -#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); \ - \ - __asm__ volatile ( \ - "int $0x80\n" \ - : "=3Da" (_ret) \ - : "r"(_arg1), "r"(_arg2), \ - "0"(_num) \ - : "memory", "cc" \ - ); \ - _ret; \ -}) - -#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); \ - \ - __asm__ volatile ( \ - "int $0x80\n" \ - : "=3Da" (_ret) \ - : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ - "0"(_num) \ - : "memory", "cc" \ - ); \ - _ret; \ -}) - -#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); \ - \ - __asm__ volatile ( \ - "int $0x80\n" \ - : "=3Da" (_ret) \ - : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ - "0"(_num) \ - : "memory", "cc" \ - ); \ - _ret; \ -}) - -#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); \ - \ - __asm__ volatile ( \ - "int $0x80\n" \ - : "=3Da" (_ret) \ - : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ - "0"(_num) \ - : "memory", "cc" \ - ); \ - _ret; \ -}) - -#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: - * 1) last pushed argument must be 16-byte aligned. - * 2) The deepest stack frame should be set to zero - * - */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) -{ - __asm__ volatile ( - "xor %ebp, %ebp\n" /* zero the stack frame = */ - "mov %esp, %eax\n" /* save stack pointer to %eax, as arg1 of _sta= rt_c */ - "sub $12, %esp\n" /* sub 12 to keep it aligned after the push %e= ax */ - "push %eax\n" /* push arg1 on stack to support plain stack m= odes too */ - "call _start_c\n" /* transfer to c runtime = */ - "hlt\n" /* ensure it does not return = */ - ); - __nolibc_entrypoint_epilogue(); -} - -#endif /* _NOLIBC_ARCH_I386_H */ diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86.h similarity index 53% rename from tools/include/nolibc/arch-x86_64.h rename to tools/include/nolibc/arch-x86.h index 67305e24dbefd..d3efc0c3b8adc 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86.h @@ -1,15 +1,184 @@ /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ /* - * x86_64 specific definitions for NOLIBC - * Copyright (C) 2017-2022 Willy Tarreau + * x86 specific definitions for NOLIBC (both 32- and 64-bit) + * Copyright (C) 2017-2025 Willy Tarreau */ =20 -#ifndef _NOLIBC_ARCH_X86_64_H -#define _NOLIBC_ARCH_X86_64_H +#ifndef _NOLIBC_ARCH_X86_H +#define _NOLIBC_ARCH_X86_H =20 #include "compiler.h" #include "crt.h" =20 +#if !defined(__x86_64__) + +/* Syscalls for i386 : + * - mostly similar to x86_64 + * - registers are 32-bit + * - syscall number is passed in eax + * - arguments are in ebx, ecx, edx, esi, edi, ebp respectively + * - all registers are preserved (except eax of course) + * - the system call is performed by calling int $0x80 + * - syscall return comes in eax + * - the arguments are cast to long and assigned into the target registe= rs + * which are then simply passed as registers to the asm code, so that = we + * don't have to experience issues with register constraints. + * - the syscall number is always specified last in order to allow to fo= rce + * some registers before (gcc refuses a %-register at the last positio= n). + * + * Also, i386 supports the old_select syscall if newselect is not available + */ +#define __ARCH_WANT_SYS_OLD_SELECT + +#define my_syscall0(num) = \ +({ = \ + long _ret; \ + register long _num __asm__ ("eax") =3D (num); \ + \ + __asm__ volatile ( \ + "int $0x80\n" \ + : "=3Da" (_ret) \ + : "0"(_num) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#define my_syscall1(num, arg1) = \ +({ = \ + long _ret; \ + register long _num __asm__ ("eax") =3D (num); \ + register long _arg1 __asm__ ("ebx") =3D (long)(arg1); \ + \ + __asm__ volatile ( \ + "int $0x80\n" \ + : "=3Da" (_ret) \ + : "r"(_arg1), \ + "0"(_num) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#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); \ + \ + __asm__ volatile ( \ + "int $0x80\n" \ + : "=3Da" (_ret) \ + : "r"(_arg1), "r"(_arg2), \ + "0"(_num) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#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); \ + \ + __asm__ volatile ( \ + "int $0x80\n" \ + : "=3Da" (_ret) \ + : "r"(_arg1), "r"(_arg2), "r"(_arg3), \ + "0"(_num) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#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); \ + \ + __asm__ volatile ( \ + "int $0x80\n" \ + : "=3Da" (_ret) \ + : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ + "0"(_num) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#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); \ + \ + __asm__ volatile ( \ + "int $0x80\n" \ + : "=3Da" (_ret) \ + : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ + "0"(_num) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#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: + * 1) last pushed argument must be 16-byte aligned. + * 2) The deepest stack frame should be set to zero + * + */ +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) +{ + __asm__ volatile ( + "xor %ebp, %ebp\n" /* zero the stack frame = */ + "mov %esp, %eax\n" /* save stack pointer to %eax, as arg1 of _sta= rt_c */ + "sub $12, %esp\n" /* sub 12 to keep it aligned after the push %e= ax */ + "push %eax\n" /* push arg1 on stack to support plain stack m= odes too */ + "call _start_c\n" /* transfer to c runtime = */ + "hlt\n" /* ensure it does not return = */ + ); + __nolibc_entrypoint_epilogue(); +} + +#else /* !defined(__x86_64__) */ + /* Syscalls for x86_64 : * - registers are 64-bit * - syscall number is passed in rax @@ -214,4 +383,5 @@ __asm__ ( "retq\n" ); =20 -#endif /* _NOLIBC_ARCH_X86_64_H */ +#endif /* !defined(__x86_64__) */ +#endif /* _NOLIBC_ARCH_X86_H */ diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h index d20b2304aac21..4ae57aaf97796 100644 --- a/tools/include/nolibc/arch.h +++ b/tools/include/nolibc/arch.h @@ -15,10 +15,8 @@ #ifndef _NOLIBC_ARCH_H #define _NOLIBC_ARCH_H =20 -#if defined(__x86_64__) -#include "arch-x86_64.h" -#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defin= ed(__i686__) -#include "arch-i386.h" +#if defined(__x86_64__) || defined(__i386__) || defined(__i486__) || defin= ed(__i586__) || defined(__i686__) +#include "arch-x86.h" #elif defined(__ARM_EABI__) #include "arch-arm.h" #elif defined(__aarch64__) --=20 2.17.5 From nobody Thu Oct 9 04:14:04 2025 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 850AB23ABB3 for ; Fri, 20 Jun 2025 10:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=163.172.96.212 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750415855; cv=none; b=WkjEsVCQpxH8J8mwOd8/9KCASoxGoy9UipYIGVz/EtG1JtJ0V46Fjf6TjT/p5YwWB9Pxa8QFOaskjPOUYuBujYwQ+035mAruawz7r2VN9vmRHb5gBouDRxOJAHvYFVNuJtAlKpP+HZ4uFmclQo6btqSgJRXMxHEHmyvhJv6sC9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750415855; c=relaxed/simple; bh=3qKNaEjgInflBHOaU8rjAHsxtVNSXL2xnI6SOmj6QnU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=PUR0VhivQ/B/2/TMB6yICj6Vzd8zO41j3rD3fqWB8ch+DpVU4SEl2JTU4D8E3c9OE2Grlyp0f138cpx7LL4Z9aaNiPH73d1QFu0xP9d0CoOhYnDE4s88FYR2/dxtINnUWPtqKbFinaZEku508qYIGHAQcPAs/gT0Kxmj2FkPgpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; arc=none smtp.client-ip=163.172.96.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 55KAbPp1010255; Fri, 20 Jun 2025 12:37:25 +0200 From: Willy Tarreau To: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Arnd Bergmann , Willy Tarreau Subject: [RFC PATCH 2/3] tools/nolibc: add a new target "headers_all_archs" to loop over all archs Date: Fri, 20 Jun 2025 12:37:04 +0200 Message-Id: <20250620103705.10208-3-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20250620103705.10208-1-w@1wt.eu> References: <20250620103705.10208-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This target allows to install the nolibc headers for all supported architectures at once, just like it is in the development tree. This is a first step to support full multi-architecture support. Signed-off-by: Willy Tarreau --- tools/include/nolibc/Makefile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 9197c79b267a4..8de6ac5cec425 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -23,6 +23,8 @@ else Q=3D@ endif =20 +nolibc_supported_archs :=3D aarch64 arm loongarch m68k mips powerpc riscv = s390 sparc x86 + nolibc_arch :=3D $(patsubst arm64,aarch64,$(ARCH)) arch_file :=3D arch-$(nolibc_arch).h all_files :=3D \ @@ -83,6 +85,7 @@ help: @echo " all call \"headers\"" @echo " clean clean the sysroot" @echo " headers prepare a sysroot in \$${OUTPUT}sysroot" + @echo " headers_all_archs prepare a multi-arch sysroot in \$${OUTPUT}s= ysroot" @echo " headers_standalone like \"headers\", and also install kernel he= aders" @echo " help this help" @echo "" @@ -110,6 +113,13 @@ headers_standalone: headers $(Q)$(MAKE) -C $(srctree) headers $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=3D$(OUTPUT)sys= root =20 +# installs headers for all archs at once. +headers_all_archs: + $(Q)mkdir -p "$(OUTPUT)sysroot" + $(Q)mkdir -p "$(OUTPUT)sysroot/include" + $(Q)cp --parents $(all_files) arch.h "$(OUTPUT)sysroot/include/" + $(Q)cp $(addsuffix .h,$(addprefix arch-,$(nolibc_supported_archs))) "$(OU= TPUT)sysroot/include/" + # GCC uses "s390", clang "systemz" CLANG_CROSS_FLAGS :=3D $(subst --target=3Ds390-linux,--target=3Dsystemz-li= nux,$(CLANG_CROSS_FLAGS)) =20 --=20 2.17.5 From nobody Thu Oct 9 04:14:04 2025 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9104023E325 for ; Fri, 20 Jun 2025 10:37:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=163.172.96.212 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750415855; cv=none; b=lSu2K8U+LsLXir9uoqjT4KxvpQ48CG920I1zFZedZPe9n07LP2BOi+l5y8ykImgh8x2tbGhahGWfV/NNO+pRGV6uSmk2MP9fqYwsFId9uT0hUiR3x6SCSEwhN4Q/pO9yYvfNGNPug4dxpeNok+ZD6mBFWrwy0gDpJfaNMku3SUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750415855; c=relaxed/simple; bh=sr18R6sd48OdpaBt0pb4YucvjAl/AlGmSjFBN2u0WQg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=gVdsyzX8Kl4z6C5adzcG39zzDIfQctctTvGIkZMUR/gXwDCtRUSz8joaMwNWWVRBBS/pX9J/e+GiWbpaUiCD0ylTOMHvSo0LzuQ5VTVaLY7dRjwtlpdPEMbJpiUPeMf4WeMgVlX7zYR1rjeTm5L37qZ9StK9xpbIr8CQs3kR2RA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; arc=none smtp.client-ip=163.172.96.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 55KAbQIP010256; Fri, 20 Jun 2025 12:37:26 +0200 From: Willy Tarreau To: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Arnd Bergmann , Willy Tarreau Subject: [RFC PATCH 3/3] tools/nolibc: add a new "install_all_archs" target Date: Fri, 20 Jun 2025 12:37:05 +0200 Message-Id: <20250620103705.10208-4-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20250620103705.10208-1-w@1wt.eu> References: <20250620103705.10208-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This installs all supported archs together, both from nolibc and kernel headers. The arch-specific asm/ subdirs are renamed to asm-arch-$arch, and asm/ is rebuilt from all these files in order to include the right one depending on the build architecture. This allows to use a single unified sysroot for all archs, and to only change the compiler or the target architecture. This way, a complete sysroot is much easier to use (a single directory is needed) and much smaller. Signed-off-by: Willy Tarreau --- tools/include/nolibc/Makefile | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 8de6ac5cec425..b6ed11d0b5419 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -88,6 +88,7 @@ help: @echo " headers_all_archs prepare a multi-arch sysroot in \$${OUTPUT}s= ysroot" @echo " headers_standalone like \"headers\", and also install kernel he= aders" @echo " help this help" + @echo " install_all_archs install a multi-arch sysroot + kernel header= s in \$${OUTPUT}sysroot" @echo "" @echo "These targets may also be called from tools as \"make nolibc_\"." @echo "" @@ -120,6 +121,44 @@ headers_all_archs: $(Q)cp --parents $(all_files) arch.h "$(OUTPUT)sysroot/include/" $(Q)cp $(addsuffix .h,$(addprefix arch-,$(nolibc_supported_archs))) "$(OU= TPUT)sysroot/include/" =20 +install_all_archs: headers_all_archs + @# install common headers for any arch, take them all. This will clear ev= erything. + $(Q)$(MAKE) -C $(srctree) ARCH=3Dx86 mrproper + $(Q)$(MAKE) -C $(srctree) ARCH=3Dx86 headers_install no-export-headers=3D= INSTALL_HDR_PATH=3D"$(OUTPUT)sysroot" + @# remove the contents of the unused asm dir which we will rebuild from t= he arch ones + $(Q)rm -rf "$(OUTPUT)sysroot/include/asm" + $(Q)mkdir -p "$(OUTPUT)sysroot/include/asm" + @# Now install headers for all archs + $(Q)for arch in $(patsubst aarch64,arm64,$(nolibc_supported_archs)); do \ + echo "# installing $$arch"; \ + if ! [ -d $(OUTPUT)sysroot/include/asm-arch-$$arch ]; then \ + $(MAKE) -C $(srctree) ARCH=3D$$arch mrproper; \ + $(MAKE) -C $(srctree) ARCH=3D$$arch headers_install no-export-headers= =3D \ + INSTALL_HDR_PATH=3D"$(OUTPUT)sysroot/include/$$arch" >/dev/null; \ + mv "$(OUTPUT)sysroot/include/$$arch/include/asm" "$(OUTPUT)sysroot/incl= ude/asm-arch-$$arch"; \ + rm -rf "$(OUTPUT)sysroot/include/$$arch"; \ + case "$$arch" in \ + arm) cond=3D"defined(__ARM_EABI__)" ;; \ + arm64) cond=3D"defined(__aarch64__)" ;; \ + loongarch) cond=3D"defined(__loongarch__)" ;; \ + m68k) cond=3D"defined(__m68k__)" ;; \ + mips) cond=3D"defined(__mips__)" ;; \ + powerpc) cond=3D"defined(__powerpc__)" ;; \ + riscv) cond=3D"defined(__riscv__)" ;; \ + s390) cond=3D"defined(__s390__) || defined(__s390x__)" ;; \ + sparc) cond=3D"defined(__sparc__)" ;; \ + x86) cond=3D"defined(__i386__) || defined(__i486__) || defined(_= _i586__) || defined(__i686__) || defined(__x86_64__)";; \ + *) echo "Unsupported arch" >&2; exit 1;; \ + esac;\ + for file in "$(OUTPUT)sysroot/include/asm-arch-$$arch/"*.h; do \ + base=3D"$${file##*/}"; \ + ( echo "#if $$cond"; \ + echo "#include \"../asm-arch-$$arch/$$base\""; \ + echo "#endif" ) >> "$(OUTPUT)sysroot/include/asm/$$base"; \ + done; \ + fi;\ + done + # GCC uses "s390", clang "systemz" CLANG_CROSS_FLAGS :=3D $(subst --target=3Ds390-linux,--target=3Dsystemz-li= nux,$(CLANG_CROSS_FLAGS)) =20 --=20 2.17.5