mirror of
https://github.com/torvalds/linux.git
synced 2024-11-11 14:42:24 +00:00
3713e2494b
For some reason using: cat <<EoFuncBegin static const char *errno_to_name__$arch(int err) { switch (err) { EoFuncBegin In tools/perf/trace/beauty/arch_errno_names.sh isn't working on ALT Linux sisyphus (development version), which could be some distro specific glitch, so just get this done in an alternative way that works everywhere while giving notice to the people working on that distro to try and figure our what really took place. Cc: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
90 lines
2.0 KiB
Bash
Executable File
90 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Generate C file mapping errno codes to errno names.
|
|
#
|
|
# Copyright IBM Corp. 2018
|
|
# Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
|
|
|
|
gcc="$1"
|
|
toolsdir="$2"
|
|
include_path="-I$toolsdir/include/uapi"
|
|
|
|
arch_string()
|
|
{
|
|
echo "$1" |sed -e 'y/- /__/' |tr '[[:upper:]]' '[[:lower:]]'
|
|
}
|
|
|
|
asm_errno_file()
|
|
{
|
|
local arch="$1"
|
|
local header
|
|
|
|
header="$toolsdir/arch/$arch/include/uapi/asm/errno.h"
|
|
if test -r "$header"; then
|
|
echo "$header"
|
|
else
|
|
echo "$toolsdir/include/uapi/asm-generic/errno.h"
|
|
fi
|
|
}
|
|
|
|
create_errno_lookup_func()
|
|
{
|
|
local arch=$(arch_string "$1")
|
|
local nr name
|
|
|
|
printf "static const char *errno_to_name__%s(int err)\n{\n\tswitch (err) {\n" $arch
|
|
|
|
while read name nr; do
|
|
printf '\tcase %d: return "%s";\n' $nr $name
|
|
done
|
|
|
|
printf '\tdefault: return "(unknown)";\n\t}\n}\n'
|
|
}
|
|
|
|
process_arch()
|
|
{
|
|
local arch="$1"
|
|
local asm_errno=$(asm_errno_file "$arch")
|
|
|
|
$gcc $CFLAGS $include_path -E -dM -x c $asm_errno \
|
|
|grep -hE '^#define[[:blank:]]+(E[^[:blank:]]+)[[:blank:]]+([[:digit:]]+).*' \
|
|
|awk '{ print $2","$3; }' \
|
|
|sort -t, -k2 -nu \
|
|
|IFS=, create_errno_lookup_func "$arch"
|
|
}
|
|
|
|
create_arch_errno_table_func()
|
|
{
|
|
local archlist="$1"
|
|
local default="$2"
|
|
local arch
|
|
|
|
printf 'const char *arch_syscalls__strerrno(const char *arch, int err)\n'
|
|
printf '{\n'
|
|
for arch in $archlist; do
|
|
printf '\tif (!strcmp(arch, "%s"))\n' $(arch_string "$arch")
|
|
printf '\t\treturn errno_to_name__%s(err);\n' $(arch_string "$arch")
|
|
done
|
|
printf '\treturn errno_to_name__%s(err);\n' $(arch_string "$default")
|
|
printf '}\n'
|
|
}
|
|
|
|
cat <<EoHEADER
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#include <string.h>
|
|
|
|
EoHEADER
|
|
|
|
# Create list of architectures that have a specific errno.h.
|
|
archlist=""
|
|
for arch in $(find $toolsdir/arch -maxdepth 1 -mindepth 1 -type d -printf "%f\n" | sort -r); do
|
|
test -f $toolsdir/arch/$arch/include/uapi/asm/errno.h && archlist="$archlist $arch"
|
|
done
|
|
|
|
for arch in generic $archlist; do
|
|
process_arch "$arch"
|
|
done
|
|
create_arch_errno_table_func "$archlist" "generic"
|