check-headers.sh 5.97 KB
Newer Older
1
#!/bin/bash
2
# SPDX-License-Identifier: GPL-2.0
3

4 5 6 7 8 9 10 11 12 13 14 15 16 17
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

declare -a FILES
FILES=(
  "include/uapi/linux/const.h"
  "include/uapi/drm/drm.h"
  "include/uapi/drm/i915_drm.h"
  "include/uapi/linux/fadvise.h"
  "include/uapi/linux/fscrypt.h"
  "include/uapi/linux/kcmp.h"
  "include/uapi/linux/kvm.h"
  "include/uapi/linux/in.h"
  "include/uapi/linux/perf_event.h"
18
  "include/uapi/linux/seccomp.h"
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  "include/uapi/linux/vhost.h"
  "include/linux/bits.h"
  "include/vdso/bits.h"
  "include/linux/const.h"
  "include/vdso/const.h"
  "include/linux/hash.h"
  "include/linux/list-sort.h"
  "include/uapi/linux/hw_breakpoint.h"
  "arch/x86/include/asm/disabled-features.h"
  "arch/x86/include/asm/required-features.h"
  "arch/x86/include/asm/cpufeatures.h"
  "arch/x86/include/asm/inat_types.h"
  "arch/x86/include/asm/emulate_prefix.h"
  "arch/x86/include/asm/msr-index.h"
  "arch/x86/lib/x86-opcode-map.txt"
  "arch/x86/tools/gen-insn-attr-x86.awk"
  "arch/arm/include/uapi/asm/perf_regs.h"
  "arch/arm64/include/uapi/asm/perf_regs.h"
  "arch/loongarch/include/uapi/asm/perf_regs.h"
  "arch/mips/include/uapi/asm/perf_regs.h"
  "arch/powerpc/include/uapi/asm/perf_regs.h"
  "arch/s390/include/uapi/asm/perf_regs.h"
  "arch/x86/include/uapi/asm/perf_regs.h"
  "arch/x86/include/uapi/asm/kvm.h"
  "arch/x86/include/uapi/asm/kvm_perf.h"
  "arch/x86/include/uapi/asm/svm.h"
  "arch/x86/include/uapi/asm/unistd.h"
  "arch/x86/include/uapi/asm/vmx.h"
  "arch/powerpc/include/uapi/asm/kvm.h"
  "arch/s390/include/uapi/asm/kvm.h"
  "arch/s390/include/uapi/asm/kvm_perf.h"
  "arch/s390/include/uapi/asm/sie.h"
  "arch/arm/include/uapi/asm/kvm.h"
  "arch/arm64/include/uapi/asm/kvm.h"
  "arch/arm64/include/uapi/asm/unistd.h"
  "arch/alpha/include/uapi/asm/errno.h"
  "arch/mips/include/asm/errno.h"
  "arch/mips/include/uapi/asm/errno.h"
  "arch/parisc/include/uapi/asm/errno.h"
  "arch/powerpc/include/uapi/asm/errno.h"
  "arch/sparc/include/uapi/asm/errno.h"
  "arch/x86/include/uapi/asm/errno.h"
  "include/asm-generic/bitops/arch_hweight.h"
  "include/asm-generic/bitops/const_hweight.h"
  "include/asm-generic/bitops/__fls.h"
  "include/asm-generic/bitops/fls.h"
  "include/asm-generic/bitops/fls64.h"
  "include/linux/coresight-pmu.h"
  "include/uapi/asm-generic/errno.h"
  "include/uapi/asm-generic/errno-base.h"
  "include/uapi/asm-generic/ioctls.h"
  "include/uapi/asm-generic/mman-common.h"
  "include/uapi/asm-generic/unistd.h"
)

declare -a SYNC_CHECK_FILES
SYNC_CHECK_FILES=(
  "arch/x86/include/asm/inat.h"
  "arch/x86/include/asm/insn.h"
  "arch/x86/lib/inat.c"
  "arch/x86/lib/insn.c"
)
81

82 83 84 85 86
# These copies are under tools/perf/trace/beauty/ as they are not used to in
# building object files only by scripts in tools/perf/trace/beauty/ to generate
# tables that then gets included in .c files for things like id->string syscall
# tables (and the reverse lookup as well: string -> id)

87 88
declare -a BEAUTY_FILES
BEAUTY_FILES=(
89
  "arch/x86/include/asm/irq_vectors.h"
90
  "arch/x86/include/uapi/asm/prctl.h"
91
  "include/linux/socket.h"
92
  "include/uapi/linux/fcntl.h"
93
  "include/uapi/linux/fs.h"
94
  "include/uapi/linux/mount.h"
95
  "include/uapi/linux/prctl.h"
96
  "include/uapi/linux/sched.h"
97
  "include/uapi/linux/usbdevice_fs.h"
98
  "include/uapi/sound/asound.h"
99 100 101
)

declare -a FAILURES
102

103
check_2 () {
104 105
  tools_file=$1
  orig_file=$2
106

107
  shift
108 109
  shift

110
  cmd="diff $* $tools_file $orig_file > /dev/null"
111

112 113 114 115 116 117
  if [ -f "$orig_file" ] && ! eval "$cmd"
  then
    FAILURES+=(
      "$tools_file $orig_file"
    )
  fi
118 119
}

120 121 122 123 124
check () {
  file=$1

  shift

125
  check_2 "tools/$file" "$file" "$@"
126
}
127

128 129 130 131 132
beauty_check () {
  file=$1

  shift

133
  check_2 "tools/perf/trace/beauty/$file" "$file" "$@"
134 135
}

136 137 138
# Check if we have the kernel headers (tools/perf/../../include), else
# we're probably on a detached tarball, so no point in trying to check
# differences.
139 140 141 142 143
if ! [ -d ../../include ]
then
  echo -e "${YELLOW}Warning${NC}: Skipped check-headers due to missing ../../include"
  exit 0
fi
144

145 146
cd ../..

147
# simple diff check
148 149 150
for i in "${FILES[@]}"
do
  check "$i" -B
151 152
done

153 154 155
for i in "${SYNC_CHECK_FILES[@]}"
do
  check "$i" '-I "^.*\/\*.*__ignore_sync_check__.*\*\/.*$"'
156 157
done

158
# diff with extra ignore lines
159
check 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>"'
160
check arch/x86/lib/memset_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memset_\(erms\|orig\))"'
161
check arch/x86/include/asm/amd-ibs.h  '-I "^#include [<\"]\(asm/\)*msr-index.h"'
Ali Saidi's avatar
Ali Saidi committed
162
check arch/arm64/include/asm/cputype.h '-I "^#include [<\"]\(asm/\)*sysreg.h"'
163
check include/asm-generic/unaligned.h '-I "^#include <linux/unaligned/packed_struct.h>" -I "^#include <asm/byteorder.h>" -I "^#pragma GCC diagnostic"'
164
check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common\(-tools\)*.h>"'
165
check include/uapi/linux/mman.h       '-I "^#include <\(uapi/\)*asm/mman.h>"'
166
check include/linux/build_bug.h       '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
167 168
check include/linux/ctype.h	      '-I "isdigit("'
check lib/ctype.c		      '-I "^EXPORT_SYMBOL" -I "^#include <linux/export.h>" -B'
169
check lib/list_sort.c		      '-I "^#include <linux/bug.h>"'
170

171 172
# diff non-symmetric files
check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl
173
check_2 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl arch/powerpc/kernel/syscalls/syscall.tbl
174
check_2 tools/perf/arch/s390/entry/syscalls/syscall.tbl arch/s390/kernel/syscalls/syscall.tbl
175
check_2 tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl arch/mips/kernel/syscalls/syscall_n64.tbl
176

177 178 179
for i in "${BEAUTY_FILES[@]}"
do
  beauty_check "$i" -B
180
done
181

182 183 184 185
# check duplicated library files
check_2 tools/perf/util/hashmap.h tools/lib/bpf/hashmap.h
check_2 tools/perf/util/hashmap.c tools/lib/bpf/hashmap.c

186
cd tools/perf || exit
187 188 189 190 191 192 193 194 195

if [ ${#FAILURES[@]} -gt 0 ]
then
  echo -e "${YELLOW}Warning${NC}: Kernel ABI header differences:"
  for i in "${FAILURES[@]}"
  do
    echo "  diff -u $i"
  done
fi