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