• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright (C) 2021 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Usage:
18#   development/gki/kmi_abi_chk/kmi_static_chk.sh \
19#     <current_symbol_info> <previous_symbol_info> ...
20#
21if [[ "$#" -lt 2 ]]; then
22  echo "Usage: $0 <current_symbol_info> <previous_symbol_info> ..."
23  exit 1
24fi
25
26ret=0
27for f in "$@"; do
28  if [[ ! -e "$f" ]]; then
29    echo "Kernel symbol file $f does not exist!" >&2
30    ret=1
31  elif ! grep -iE "^0x[0-9a-f]{8}+.[_0-9a-z]+.vmlinux.EXPORT_SYMBOL" $f > /dev/null; then
32    ret=1
33    echo "$f doesn't look like kernel symbol file!" >&2
34  fi
35done
36
37if [[ ! ret -eq 0 ]]; then
38  exit $ret
39fi
40
41tmp=$(mktemp /tmp/linux-symvers.XXXXXX)
42trap "rm -f $tmp" EXIT
43
44curr=$1
45shift
46
47# Filter for vmlinux EXPORTE_SYMBOL* and remove trailing white spaces.
48# The reason trailing white spaces is removed only for the current
49# symbol file is because the following example/possibility:
50#
51# In the current symbol file:
52# 0x8581ad8e	get_net_ns_by_fd	vmlinux	EXPORT_SYMBOL\t
53#
54# In the previous symbol file:
55# 0x8581ad8e	get_net_ns_by_fd	vmlinux	EXPORT_SYMBOL_GPL\t
56#
57# The symbol is GPLed previously, but not in the current release, which won't
58# break KMI ABI, because the requirement is "relaxed". We want this case to
59# pass so a keyword like "...EXPORT_SYMBOL" in the current symbol file can
60# still match "...EXPORT_SYMBOL_GPL" in the previous symbol file.
61grep "vmlinux.EXPORT_SYMBOL" $curr | sed 's/[ \t]*$//' > $tmp
62
63echo "Current kernel symbol file, $curr, is checking against:"
64
65for f in "$@"; do
66  echo "	$f"
67# if nothing is found, grep returns 1, which means every symbol in the
68# previous release (usually in *.symvers-$BID) can be found in the current
69# release, so is considered successful here.
70# if grep returns 0, which means some symbols are found in the previous
71# symbol file but not in the current symbol file, then something wrong!
72  if grep -vf $tmp $f; then
73    ret=1
74    echo "$f contains symbol(s) not found in, or incompatible with, $curr." >&2
75  fi
76done
77
78exit $ret
79