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