From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5 2/3] Add script to generate arch(s) dependant syscalls
Date: Wed, 30 Oct 2024 09:53:01 +0100 [thread overview]
Message-ID: <20241030-generate_syscalls-v5-2-eed6a87dc787@suse.com> (raw)
In-Reply-To: <20241030-generate_syscalls-v5-0-eed6a87dc787@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Add generate_arch.sh script which can be used to generate arch(s)
dependant syscalls file. The way it works is pretty simple: for each
architecture defined into supported-arch.txt, compile kernel headers,
extract the list of syscalls and generate a .in file containing all of
them, associated with their own syscall's number.
The way syscalls files are generated, passes through a C application
which is automatically checking the availability of the syscalls in
the user space environment.
Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/syscalls/{aarch64.in => arm64.in} | 0
include/lapi/syscalls/generate_arch.sh | 211 +++++++++++++++++++++
.../lapi/syscalls/{loongarch.in => loongarch64.in} | 0
include/lapi/syscalls/{mips_n64.in => mips64.in} | 0
.../lapi/syscalls/{mips_n32.in => mips64n32.in} | 0
include/lapi/syscalls/{mips_o32.in => mipso32.in} | 0
include/lapi/syscalls/{hppa.in => parisc.in} | 0
include/lapi/syscalls/supported-arch.txt | 12 +-
8 files changed, 217 insertions(+), 6 deletions(-)
diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/arm64.in
similarity index 100%
rename from include/lapi/syscalls/aarch64.in
rename to include/lapi/syscalls/arm64.in
diff --git a/include/lapi/syscalls/generate_arch.sh b/include/lapi/syscalls/generate_arch.sh
new file mode 100755
index 0000000000000000000000000000000000000000..c88ca945127c3c26162a48babcd6b0f8ca552311
--- /dev/null
+++ b/include/lapi/syscalls/generate_arch.sh
@@ -0,0 +1,211 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# This is an adaptation of the update-tables.sh script, included in the
+# syscalls-table project (https://github.com/hrw/syscalls-table) and released
+# under the MIT license.
+#
+# Author: Andrea Cervesato <andrea.cervesato@suse.com>
+
+KERNELSRC="$1"
+
+# to keep sorting in order
+export LC_ALL=C
+
+if [ -z "$KERNELSRC" ]; then
+ echo "Please provide kernel sources:"
+ echo ""
+ echo "$0 path/to/Linux/kernel/sources"
+ echo ""
+ exit 1
+fi
+
+if [ ! -d "$KERNELSRC" ]; then
+ echo "$KERNELSRC is not a directory"
+ exit 1
+fi
+
+if [ ! -e "${KERNELSRC}/Makefile" ]; then
+ echo "No Makefile in $KERNELSRC directory"
+ exit 1
+fi
+
+TEMP="$(mktemp -d)"
+KVER="$(make -C ${KERNELSRC} kernelversion -s)"
+
+SCRIPT_DIR="$(realpath $(dirname "$0"))"
+SUPPORTED_ARCH="${SCRIPT_DIR}/supported-arch.txt"
+LINUX_HEADERS="${TEMP}/headers"
+
+grab_syscall_names_from_tables()
+{
+ for tbl_file in $(find ${KERNELSRC}/arch -name syscall*.tbl); do
+ grep -E -v "(^#|^$|sys_ni_syscall)" $tbl_file |
+ awk '{ print $3 }' >> ${TEMP}/syscall-names.tosort
+ done
+
+ drop_bad_entries
+}
+
+grab_syscall_names_from_unistd_h()
+{
+ grep -E -h "^#define __NR_" \
+ ${LINUX_HEADERS}/usr/include/asm/unistd*.h \
+ ${LINUX_HEADERS}/usr/include/asm-generic/unistd.h \
+ >${TEMP}/syscall-names.tosort
+
+ drop_bad_entries
+}
+
+drop_bad_entries()
+{
+ grep -E -v "(unistd.h|NR3264|__NR_syscall|__SC_COMP|__NR_.*Linux|__NR_FAST)" \
+ ${TEMP}/syscall-names.tosort |
+ grep -E -v "(__SYSCALL|SYSCALL_BASE|SYSCALL_MASK)" |
+ sed -e "s/#define\s*__NR_//g" -e "s/\s.*//g" |
+ sort -u >${TEMP}/syscall-names.txt
+}
+
+generate_table()
+{
+ echo "- $arch"
+
+ if [ $bits == 32 ]; then
+ extraflags="${extraflags} -D__BITS_PER_LONG=32"
+ fi
+
+ local uppercase_arch=$(echo "$arch" | tr '[:lower:]' '[:upper:]')
+
+ gcc ${TEMP}/list-syscalls.c -U__LP64__ -U__ILP32__ -U__i386__ \
+ -D${uppercase_arch} \
+ -D__${arch}__ ${extraflags} \
+ -I ${LINUX_HEADERS}/usr/include/ \
+ -o ${TEMP}/list-syscalls &>/dev/null
+
+ ${TEMP}/list-syscalls > "${TEMP}/${arch}.in.tosort"
+
+ sort -k2,2n "${TEMP}/${arch}.in.tosort" > "${TEMP}/${arch}.in"
+}
+
+generate_list_syscalls_c()
+{
+ (
+ echo
+ echo "
+ #include <stdio.h>
+ #include <asm/unistd.h>
+
+ int main(void)
+ {
+ "
+ for syscall in $(cat ${TEMP}/syscall-names.txt); do
+ echo "
+ #ifdef __NR_$syscall
+ printf(\"$syscall %d\\n\", __NR_$syscall);
+ #endif
+ "
+ done
+ echo " return 0;
+ }"
+ ) > ${TEMP}/list-syscalls.c
+}
+
+export_headers()
+{
+ make -s -C ${KERNELSRC} ARCH=${arch} O=${LINUX_HEADERS} \
+ headers_install &>/dev/null
+}
+
+do_all_tables()
+{
+ for archdir in ${KERNELSRC}/arch/*; do
+ arch=$(basename $archdir)
+
+ bits=64
+ extraflags=
+
+ case ${arch} in
+ Kconfig)
+ continue
+ ;;
+ um)
+ continue
+ ;;
+ esac
+
+ export_headers
+ grab_syscall_names_from_unistd_h
+
+ case ${arch} in
+ arm)
+ bits=32
+ arch=armoabi extraflags= generate_table
+ arch=arm extraflags=-D__ARM_EABI__ generate_table
+ ;;
+ loongarch)
+ # 32-bit variant of loongarch may appear
+ arch=loongarch64 extraflags=-D_LOONGARCH_SZLONG=64 generate_table
+ ;;
+ mips)
+ arch=mips64 extraflags=-D_MIPS_SIM=_MIPS_SIM_ABI64 generate_table
+ bits=32
+ arch=mipso32 extraflags=-D_MIPS_SIM=_MIPS_SIM_ABI32 generate_table
+ arch=mips64n32 extraflags=-D_MIPS_SIM=_MIPS_SIM_NABI32 generate_table
+ ;;
+ powerpc)
+ generate_table
+ arch=powerpc64 generate_table
+ ;;
+ riscv)
+ arch=riscv64 extraflags=-D__LP64__ generate_table
+ bits=32
+ arch=riscv32 extraflags=-D__SIZEOF_POINTER__=4 generate_table
+ ;;
+ s390)
+ bits=32
+ generate_table
+ bits=64
+ arch=s390x generate_table
+ ;;
+ sparc)
+ bits=32
+ extraflags=-D__32bit_syscall_numbers__ generate_table
+ bits=64
+ arch=sparc64 extraflags=-D__arch64__ generate_table
+ ;;
+ x86)
+ arch=x86_64 extraflags=-D__LP64__ generate_table
+ bits=32
+ arch=i386 generate_table
+ arch=x32 extraflags=-D__ILP32__ generate_table
+ ;;
+ arc | csky | hexagon | m68k | microblaze | nios2 | openrisc | sh | xtensa)
+ bits=32 generate_table
+ ;;
+ *)
+ generate_table
+ ;;
+ esac
+ done
+}
+
+copy_supported_arch()
+{
+ while IFS= read -r arch; do
+ if [ -f "${TEMP}/${arch}.in" ]; then
+ echo "- ${arch}"
+ cp "${TEMP}/${arch}.in" "${SCRIPT_DIR}/${arch}.in"
+ fi
+ done < ${SUPPORTED_ARCH}
+}
+
+echo "Temporary directory ${TEMP}"
+echo "Extracting syscalls"
+
+grab_syscall_names_from_tables
+generate_list_syscalls_c
+
+do_all_tables
+
+echo "Copying supported syscalls"
+copy_supported_arch
diff --git a/include/lapi/syscalls/loongarch.in b/include/lapi/syscalls/loongarch64.in
similarity index 100%
rename from include/lapi/syscalls/loongarch.in
rename to include/lapi/syscalls/loongarch64.in
diff --git a/include/lapi/syscalls/mips_n64.in b/include/lapi/syscalls/mips64.in
similarity index 100%
rename from include/lapi/syscalls/mips_n64.in
rename to include/lapi/syscalls/mips64.in
diff --git a/include/lapi/syscalls/mips_n32.in b/include/lapi/syscalls/mips64n32.in
similarity index 100%
rename from include/lapi/syscalls/mips_n32.in
rename to include/lapi/syscalls/mips64n32.in
diff --git a/include/lapi/syscalls/mips_o32.in b/include/lapi/syscalls/mipso32.in
similarity index 100%
rename from include/lapi/syscalls/mips_o32.in
rename to include/lapi/syscalls/mipso32.in
diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/parisc.in
similarity index 100%
rename from include/lapi/syscalls/hppa.in
rename to include/lapi/syscalls/parisc.in
diff --git a/include/lapi/syscalls/supported-arch.txt b/include/lapi/syscalls/supported-arch.txt
index c18aa38cf4546cdf3ac8c89a45bd1b202ffa7711..c5c5191ac08482d89f0a8c39dfae936538f58f7f 100644
--- a/include/lapi/syscalls/supported-arch.txt
+++ b/include/lapi/syscalls/supported-arch.txt
@@ -1,13 +1,13 @@
-aarch64
arc
+arm64
arm
-hppa
i386
ia64
-loongarch
-mips_n32
-mips_n64
-mips_o32
+loongarch64
+mips64n32
+mips64
+mipso32
+parisc
powerpc64
powerpc
s390x
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-10-30 8:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-30 8:52 [LTP] [PATCH v5 0/3] Automatically generate syscalls.h Andrea Cervesato
2024-10-30 8:53 ` [LTP] [PATCH v5 1/3] Refactor regen.sh script to generate syscalls Andrea Cervesato
2024-10-30 13:47 ` Cyril Hrubis
2024-10-30 14:20 ` Andrea Cervesato via ltp
2024-10-30 17:43 ` Cyril Hrubis
2024-10-30 14:49 ` Petr Vorel
2024-10-30 15:34 ` Andrea Cervesato via ltp
2024-10-30 16:49 ` Petr Vorel
2024-10-30 8:53 ` Andrea Cervesato [this message]
2024-10-30 14:04 ` [LTP] [PATCH v5 2/3] Add script to generate arch(s) dependant syscalls Cyril Hrubis
2024-10-30 15:15 ` Petr Vorel
2024-10-30 15:24 ` Andrea Cervesato via ltp
2024-10-30 8:53 ` [LTP] [PATCH v5 3/3] Delete obsolete strip_syscall.awk file Andrea Cervesato
2024-10-30 14:04 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241030-generate_syscalls-v5-2-eed6a87dc787@suse.com \
--to=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.