kernel_optimize_test/tools/perf/trace/beauty/arch_errno_names.sh
Ian Rogers 6d1f916265 perf beauty: Allow the CC used in the arch errno names script to acccept CFLAGS
Allow the CC compiler to accept a CFLAGS environment variable.  This
doesn't change the code generated but makes it easier to integrate
running the shell script in build systems like bazel.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexios Zavras <alexios.zavras@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Igor Lubashev <ilubashe@akamai.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Li <liwei391@huawei.com>
Link: http://lore.kernel.org/lkml/20200306071110.130202-4-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-28 10:03:26 -03:00

101 lines
2.1 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
cat <<EoFuncBegin
static const char *errno_to_name__$arch(int err)
{
switch (err) {
EoFuncBegin
while read name nr; do
printf '\tcase %d: return "%s";\n' $nr $name
done
cat <<EoFuncEnd
default:
return "(unknown)";
}
}
EoFuncEnd
}
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 and ignore those that do not appear
# in tools/perf/arch
archlist=""
for arch in $(find $toolsdir/arch -maxdepth 1 -mindepth 1 -type d -printf "%f\n" | grep -v x86 | sort); do
test -d $toolsdir/perf/arch/$arch && archlist="$archlist $arch"
done
for arch in x86 $archlist generic; do
process_arch "$arch"
done
create_arch_errno_table_func "x86 $archlist" "generic"