xref: /linux/tools/perf/check-headers.sh (revision 06a130e42a5bfc84795464bff023bff4c16f58c5)
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
139check_ignore_some_hunks () {
140  orig_file="$1"
141  tools_file="tools/$orig_file"
142  hunks_to_ignore="tools/perf/check-header_ignore_hunks/$orig_file"
143
144  if [ ! -f "$hunks_to_ignore" ]; then
145    echo "$hunks_to_ignore not found. Skipping $orig_file check."
146    FAILURES+=(
147      "$tools_file $orig_file"
148    )
149    return
150  fi
151
152  cmd="diff -u \"$tools_file\" \"$orig_file\" | grep -vf \"$hunks_to_ignore\" | wc -l | grep -qw 0"
153
154  if [ -f "$orig_file" ] && ! eval "$cmd"
155  then
156    FAILURES+=(
157      "$tools_file $orig_file"
158    )
159  fi
160}
161
162
163# Check if we have the kernel headers (tools/perf/../../include), else
164# we're probably on a detached tarball, so no point in trying to check
165# differences.
166if ! [ -d ../../include ]
167then
168  echo -e "${YELLOW}Warning${NC}: Skipped check-headers due to missing ../../include"
169  exit 0
170fi
171
172cd ../..
173
174# simple diff check
175for i in "${FILES[@]}"
176do
177  check "$i" -B
178done
179
180for i in "${SYNC_CHECK_FILES[@]}"
181do
182  check "$i" '-I "^.*\/\*.*__ignore_sync_check__.*\*\/.*$"'
183done
184
185# diff with extra ignore lines
186check 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>"'
187check arch/x86/lib/memset_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memset_\(erms\|orig\))"'
188check arch/x86/include/asm/amd-ibs.h  '-I "^#include [<\"]\(asm/\)*msr-index.h"'
189check arch/arm64/include/asm/cputype.h '-I "^#include [<\"]\(asm/\)*sysreg.h"'
190check include/linux/unaligned.h '-I "^#include <linux/unaligned/packed_struct.h>" -I "^#include <asm/byteorder.h>" -I "^#pragma GCC diagnostic"'
191check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common\(-tools\)*.h>"'
192check include/uapi/linux/mman.h       '-I "^#include <\(uapi/\)*asm/mman.h>"'
193check include/linux/build_bug.h       '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
194check include/linux/ctype.h	      '-I "isdigit("'
195check lib/ctype.c		      '-I "^EXPORT_SYMBOL" -I "^#include <linux/export.h>" -B'
196
197# diff non-symmetric files
198check_2 tools/perf/arch/x86/entry/syscalls/syscall_32.tbl arch/x86/entry/syscalls/syscall_32.tbl
199check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl
200check_2 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl arch/powerpc/kernel/syscalls/syscall.tbl
201check_2 tools/perf/arch/s390/entry/syscalls/syscall.tbl arch/s390/kernel/syscalls/syscall.tbl
202check_2 tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl arch/mips/kernel/syscalls/syscall_n64.tbl
203
204for i in "${BEAUTY_FILES[@]}"
205do
206  beauty_check "$i" -B
207done
208
209# check duplicated library files
210check_2 tools/perf/util/hashmap.h tools/lib/bpf/hashmap.h
211check_2 tools/perf/util/hashmap.c tools/lib/bpf/hashmap.c
212
213# Files with larger differences
214
215check_ignore_some_hunks lib/list_sort.c
216
217cd tools/perf || exit
218
219if [ ${#FAILURES[@]} -gt 0 ]
220then
221  echo -e "${YELLOW}Warning${NC}: Kernel ABI header differences:"
222  for i in "${FAILURES[@]}"
223  do
224    echo "  diff -u $i"
225  done
226fi
227