2020-12-28 02:44:06

by Hans-Peter Nilsson

[permalink] [raw]
Subject: [PATCH] perf arm64: Simplify mksyscalltbl

This patch isn't intended to have any effect on the compiled
code. It just removes one level of indirection: calling the
*host* compiler to build and then run a program that just
printf:s the numerical entries of the syscall-table. In other
words, the generated syscalls.c changes from:
[46] = "ftruncate",
to:
[__NR3264_ftruncate] = "ftruncate",
The latter is as good as the former to the user of perf, and
this can be done directly by the shell-script. The syscalls
defined as non-literal values (like "#define __NR_ftruncate
__NR3264_ftruncate") are trivially resolved at compile-time
without namespace-leaking and/or collision for its sole user,
perf/util/syscalltbl.c, that just #includes the generated file.
A future "-mabi=32" support would probably have to handle this
differently, but that is a pre-existing problem not affected by
this simplification.

Calling the *host* compiler only complicates things and
accidentally can get a completely wrong set of files and syscall
numbers, see earlier commits. Note that the script parameter
hostcc is now unused.

At the time of this patch, powerpc (the origin, see comments),
and also e.g. x86 has moved on, from filtering "gcc -dM -E"
output to reading separate specific text-file, a table of
syscall numbers. IMHO should arm64 consider adopting this.

Signed-off-by: Hans-Peter Nilsson <[email protected]>
Cc: John Garry <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Mathieu Poirier <[email protected]>
Cc: Leo Yan <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Kim Phillips <[email protected]>
---
tools/perf/arch/arm64/entry/syscalls/mksyscalltbl | 23 +++--------------------
1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl b/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl
index a7ca48d1e37b..22cdf911dd9a 100755
--- a/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl
+++ b/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl
@@ -23,34 +23,17 @@ create_table_from_c()
{
local sc nr last_sc

- create_table_exe=`mktemp ${TMPDIR:-/tmp}/create-table-XXXXXX`
-
- {
-
- cat <<-_EoHEADER
- #include <stdio.h>
- #include "$input"
- int main(int argc, char *argv[])
- {
- _EoHEADER
-
while read sc nr; do
- printf "%s\n" " printf(\"\\t[%d] = \\\"$sc\\\",\\n\", __NR_$sc);"
+ printf "%s\n" " [$nr] = \"$sc\","
last_sc=$sc
done

- printf "%s\n" " printf(\"#define SYSCALLTBL_ARM64_MAX_ID %d\\n\", __NR_$last_sc);"
- printf "}\n"
-
- } | $hostcc -I $incpath/include/uapi -o $create_table_exe -x c -
-
- $create_table_exe
-
- rm -f $create_table_exe
+ printf "%s\n" "#define SYSCALLTBL_ARM64_MAX_ID __NR_$last_sc"
}

create_table()
{
+ echo "#include \"$input\""
echo "static const char *syscalltbl_arm64[] = {"
create_table_from_c
echo "};"
--
2.11.0

brgds, H-P


2021-01-05 12:33:01

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH] perf arm64: Simplify mksyscalltbl

On Mon, Dec 28, 2020 at 3:44 AM Hans-Peter Nilsson <[email protected]> wrote:
>
> This patch isn't intended to have any effect on the compiled
> code. It just removes one level of indirection: calling the
> *host* compiler to build and then run a program that just
> printf:s the numerical entries of the syscall-table. In other
> words, the generated syscalls.c changes from:
> [46] = "ftruncate",
> to:
> [__NR3264_ftruncate] = "ftruncate",

If you include the file, why not just use the macros directly, like

#define __SYSCALL(nr, sym) [nr] = #sym ;
static const char *syscalltbl_arm64[] = {
#include <uapi/asm-generic/unistd.h>
};
#undef __SYSCALL

The leaves an extra "sys_" in front of every name, but if you
care, that could be left out afterwards.

> At the time of this patch, powerpc (the origin, see comments),
> and also e.g. x86 has moved on, from filtering "gcc -dM -E"
> output to reading separate specific text-file, a table of
> syscall numbers. IMHO should arm64 consider adopting this.

Right, we had patches to convert include/uapi/asm-generic/unistd.h
to the syscall.tbl format some time ago, but they were never
merged as there were a few remaining bugs. I had planned to
pick up that work but have not gotten around to it yet.

If anyone is interested in doing this, I can dig out the last version
of the patches.

Arnd