Debian Codegraph @

tools/check-abi/check-abi

raw
1 #!/usr/bin/env bash
2
3 #
4 # Licensed to the Apache Software Foundation (ASF) under one
5 # or more contributor license agreements. See the NOTICE file
6 # distributed with this work for additional information
7 # regarding copyright ownership. The ASF licenses this file
8 # to you under the Apache License, Version 2.0 (the
9 # "License"); you may not use this file except in compliance
10 # with the License. You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing,
15 # software distributed under the License is distributed on an
16 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 # KIND, either express or implied. See the License for the
18 # specific language governing permissions and limitations
19 # under the License.
20 #
21
22 MKTEMP="mktemp /tmp/tmp.XXXXXXXXXX"
23
24 rc=0
25 syms_desired=$($MKTEMP)
26 syms_library=$($MKTEMP)
27 syms_missing=$($MKTEMP)
28 syms_extra=$($MKTEMP)
29
30 trap 'rm $syms_desired $syms_library $syms_missing $syms_extra' EXIT
31
32 if [[ $# -lt 2 ]] ; then
33 echo "Usage:"
34 echo "check-abi <object-file> <expected-symbols-file>"
35 exit 1;
36 fi
37
38 LC_ALL=C
39 export LC_ALL
40
41 # Extract exported symbols from library
42 nm -DC --defined-only -f s $1 | cut -f1 -d'|' -s | sed -e "$(./cpp_abi)" -e "s/ *$//" | sort -u > $syms_library
43
44 # Process API syms (substitute in some typedefs etc.)
45 sed -e "
46 $(./expand_types)
47 /^\$/d
48 /^#.*\$/d
49 " $2 | sort -u > $syms_desired
50
51 comm -23 $syms_desired $syms_library > $syms_missing
52 comm -13 $syms_desired $syms_library > $syms_extra
53
54 if [[ -n "$(cat $syms_missing)" ]] ; then
55 (echo "Not exported from library (should be)"
56 echo "====================================="
57 cat $syms_missing ) 1>&2
58 rc=1
59 fi
60
61
62 if [[ -n "$(cat $syms_extra)" ]]; then
63 (echo "Exported by library but not in spec"
64 echo "==================================="
65 cat $syms_extra ) 1>&2
66 fi
67
68 exit $rc