xref: /openbmc/linux/tools/perf/check-headers.sh (revision 6db6b729)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4YELLOW='\033[0;33m'
5NC='\033[0m' # No Color
6
7declare -a FILES
8FILES=(
9  "include/uapi/linux/const.h"
10  "include/uapi/drm/drm.h"
11  "include/uapi/drm/i915_drm.h"
12  "include/uapi/linux/fadvise.h"
13  "include/uapi/linux/fcntl.h"
14  "include/uapi/linux/fs.h"
15  "include/uapi/linux/fscrypt.h"
16  "include/uapi/linux/kcmp.h"
17  "include/uapi/linux/kvm.h"
18  "include/uapi/linux/in.h"
19  "include/uapi/linux/mount.h"
20  "include/uapi/linux/openat2.h"
21  "include/uapi/linux/perf_event.h"
22  "include/uapi/linux/prctl.h"
23  "include/uapi/linux/sched.h"
24  "include/uapi/linux/seccomp.h"
25  "include/uapi/linux/stat.h"
26  "include/uapi/linux/usbdevice_fs.h"
27  "include/uapi/linux/vhost.h"
28  "include/uapi/sound/asound.h"
29  "include/linux/bits.h"
30  "include/vdso/bits.h"
31  "include/linux/const.h"
32  "include/vdso/const.h"
33  "include/linux/hash.h"
34  "include/linux/list-sort.h"
35  "include/uapi/linux/hw_breakpoint.h"
36  "arch/x86/include/asm/disabled-features.h"
37  "arch/x86/include/asm/required-features.h"
38  "arch/x86/include/asm/cpufeatures.h"
39  "arch/x86/include/asm/inat_types.h"
40  "arch/x86/include/asm/emulate_prefix.h"
41  "arch/x86/include/asm/irq_vectors.h"
42  "arch/x86/include/asm/msr-index.h"
43  "arch/x86/include/uapi/asm/prctl.h"
44  "arch/x86/lib/x86-opcode-map.txt"
45  "arch/x86/tools/gen-insn-attr-x86.awk"
46  "arch/arm/include/uapi/asm/perf_regs.h"
47  "arch/arm64/include/uapi/asm/perf_regs.h"
48  "arch/loongarch/include/uapi/asm/perf_regs.h"
49  "arch/mips/include/uapi/asm/perf_regs.h"
50  "arch/powerpc/include/uapi/asm/perf_regs.h"
51  "arch/s390/include/uapi/asm/perf_regs.h"
52  "arch/x86/include/uapi/asm/perf_regs.h"
53  "arch/x86/include/uapi/asm/kvm.h"
54  "arch/x86/include/uapi/asm/kvm_perf.h"
55  "arch/x86/include/uapi/asm/svm.h"
56  "arch/x86/include/uapi/asm/unistd.h"
57  "arch/x86/include/uapi/asm/vmx.h"
58  "arch/powerpc/include/uapi/asm/kvm.h"
59  "arch/s390/include/uapi/asm/kvm.h"
60  "arch/s390/include/uapi/asm/kvm_perf.h"
61  "arch/s390/include/uapi/asm/sie.h"
62  "arch/arm/include/uapi/asm/kvm.h"
63  "arch/arm64/include/uapi/asm/kvm.h"
64  "arch/arm64/include/uapi/asm/unistd.h"
65  "arch/alpha/include/uapi/asm/errno.h"
66  "arch/mips/include/asm/errno.h"
67  "arch/mips/include/uapi/asm/errno.h"
68  "arch/parisc/include/uapi/asm/errno.h"
69  "arch/powerpc/include/uapi/asm/errno.h"
70  "arch/sparc/include/uapi/asm/errno.h"
71  "arch/x86/include/uapi/asm/errno.h"
72  "include/asm-generic/bitops/arch_hweight.h"
73  "include/asm-generic/bitops/const_hweight.h"
74  "include/asm-generic/bitops/__fls.h"
75  "include/asm-generic/bitops/fls.h"
76  "include/asm-generic/bitops/fls64.h"
77  "include/linux/coresight-pmu.h"
78  "include/uapi/asm-generic/errno.h"
79  "include/uapi/asm-generic/errno-base.h"
80  "include/uapi/asm-generic/ioctls.h"
81  "include/uapi/asm-generic/mman-common.h"
82  "include/uapi/asm-generic/unistd.h"
83)
84
85declare -a SYNC_CHECK_FILES
86SYNC_CHECK_FILES=(
87  "arch/x86/include/asm/inat.h"
88  "arch/x86/include/asm/insn.h"
89  "arch/x86/lib/inat.c"
90  "arch/x86/lib/insn.c"
91)
92
93# These copies are under tools/perf/trace/beauty/ as they are not used to in
94# building object files only by scripts in tools/perf/trace/beauty/ to generate
95# tables that then gets included in .c files for things like id->string syscall
96# tables (and the reverse lookup as well: string -> id)
97
98declare -a BEAUTY_FILES
99BEAUTY_FILES=(
100  "include/linux/socket.h"
101)
102
103declare -a FAILURES
104
105check_2 () {
106  tools_file=$1
107  orig_file=$2
108
109  shift
110  shift
111
112  cmd="diff $* $tools_file $orig_file > /dev/null"
113
114  if [ -f "$orig_file" ] && ! eval "$cmd"
115  then
116    FAILURES+=(
117      "$tools_file $orig_file"
118    )
119  fi
120}
121
122check () {
123  file=$1
124
125  shift
126
127  check_2 "tools/$file" "$file" "$@"
128}
129
130beauty_check () {
131  file=$1
132
133  shift
134
135  check_2 "tools/perf/trace/beauty/$file" "$file" "$@"
136}
137
138# Check if we have the kernel headers (tools/perf/../../include), else
139# we're probably on a detached tarball, so no point in trying to check
140# differences.
141if ! [ -d ../../include ]
142then
143  echo -e "${YELLOW}Warning${NC}: Skipped check-headers due to missing ../../include"
144  exit 0
145fi
146
147cd ../..
148
149# simple diff check
150for i in "${FILES[@]}"
151do
152  check "$i" -B
153done
154
155for i in "${SYNC_CHECK_FILES[@]}"
156do
157  check "$i" '-I "^.*\/\*.*__ignore_sync_check__.*\*\/.*$"'
158done
159
160# diff with extra ignore lines
161check arch/x86/lib/memcpy_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memcpy_\(erms\|orig\))" -I"^#include <linux/cfi_types.h>"'
162check arch/x86/lib/memset_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memset_\(erms\|orig\))"'
163check arch/x86/include/asm/amd-ibs.h  '-I "^#include [<\"]\(asm/\)*msr-index.h"'
164check arch/arm64/include/asm/cputype.h '-I "^#include [<\"]\(asm/\)*sysreg.h"'
165check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common\(-tools\)*.h>"'
166check include/uapi/linux/mman.h       '-I "^#include <\(uapi/\)*asm/mman.h>"'
167check include/linux/build_bug.h       '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
168check include/linux/ctype.h	      '-I "isdigit("'
169check lib/ctype.c		      '-I "^EXPORT_SYMBOL" -I "^#include <linux/export.h>" -B'
170check lib/list_sort.c		      '-I "^#include <linux/bug.h>"'
171
172# diff non-symmetric files
173check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl
174check_2 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl arch/powerpc/kernel/syscalls/syscall.tbl
175check_2 tools/perf/arch/s390/entry/syscalls/syscall.tbl arch/s390/kernel/syscalls/syscall.tbl
176check_2 tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl arch/mips/kernel/syscalls/syscall_n64.tbl
177
178for i in "${BEAUTY_FILES[@]}"
179do
180  beauty_check "$i" -B
181done
182
183# check duplicated library files
184check_2 tools/perf/util/hashmap.h tools/lib/bpf/hashmap.h
185check_2 tools/perf/util/hashmap.c tools/lib/bpf/hashmap.c
186
187cd tools/perf || exit
188
189if [ ${#FAILURES[@]} -gt 0 ]
190then
191  echo -e "${YELLOW}Warning${NC}: Kernel ABI header differences:"
192  for i in "${FAILURES[@]}"
193  do
194    echo "  diff -u $i"
195  done
196fi
197