1 | #!/bin/sh
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Copyright (C) 2006-2022 Oracle and/or its affiliates.
|
---|
5 | #
|
---|
6 | # This file is part of VirtualBox base platform packages, as
|
---|
7 | # available from https://www.virtualbox.org.
|
---|
8 | #
|
---|
9 | # This program is free software; you can redistribute it and/or
|
---|
10 | # modify it under the terms of the GNU General Public License
|
---|
11 | # as published by the Free Software Foundation, in version 3 of the
|
---|
12 | # License.
|
---|
13 | #
|
---|
14 | # This program is distributed in the hope that it will be useful, but
|
---|
15 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
17 | # General Public License for more details.
|
---|
18 | #
|
---|
19 | # You should have received a copy of the GNU General Public License
|
---|
20 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
21 | #
|
---|
22 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
23 | #
|
---|
24 |
|
---|
25 | #
|
---|
26 | # Compare undefined symbols in a shared or static object against a new-line
|
---|
27 | # separated list of grep patterns in a set of text files and complain if
|
---|
28 | # symbols are found which aren't in the files.
|
---|
29 | #
|
---|
30 | # Usage: /bin/sh <script name> <object> [--static] <undefined symbol file...>
|
---|
31 | #
|
---|
32 | # Currently only works for native objects on Linux (and Solaris?) platforms.
|
---|
33 | #
|
---|
34 |
|
---|
35 | echoerr()
|
---|
36 | {
|
---|
37 | echo $* 1>&2
|
---|
38 | }
|
---|
39 |
|
---|
40 | hostos="${1}"
|
---|
41 | target="${2}"
|
---|
42 | shift 2
|
---|
43 | if test "${1}" = "--static"; then
|
---|
44 | static="${1}"
|
---|
45 | shift
|
---|
46 | fi
|
---|
47 |
|
---|
48 | if test $# -lt 1; then
|
---|
49 | echoerr "${0}: Wrong number of arguments"
|
---|
50 | args_ok="no"
|
---|
51 | fi
|
---|
52 | if test ! -r "${target}"; then
|
---|
53 | echoerr "${0}: '${target}' not readable"
|
---|
54 | args_ok="no"
|
---|
55 | fi
|
---|
56 | for i in "${@}"; do
|
---|
57 | if test ! -r "${i}"; then
|
---|
58 | echoerr "${0}: '${i}' not readable"
|
---|
59 | args_ok="no"
|
---|
60 | fi
|
---|
61 | done
|
---|
62 |
|
---|
63 | if test "$args_ok" = "no"; then
|
---|
64 | echoerr "Usage: $0 <object> [--static] <undefined symbol file...>"
|
---|
65 | exit 1
|
---|
66 | fi
|
---|
67 |
|
---|
68 | if test "$hostos" = "solaris"; then
|
---|
69 | objdumpbin=/usr/sfw/bin/gobjdump
|
---|
70 | grepbin=/usr/sfw/bin/ggrep
|
---|
71 | elif test "$hostos" = "linux"; then
|
---|
72 | objdumpbin=`which objdump`
|
---|
73 | grepbin=`which grep`
|
---|
74 | else
|
---|
75 | echoerr "$0: '$hostos' not a valid hostos string. supported 'linux' 'solaris'"
|
---|
76 | exit 1
|
---|
77 | fi
|
---|
78 |
|
---|
79 | command="-T"
|
---|
80 | if test "$static" = "--static"; then
|
---|
81 | command="-t"
|
---|
82 | fi
|
---|
83 |
|
---|
84 | if test ! -x "${objdumpbin}"; then
|
---|
85 | echoerr "${0}: '${objdumpbin}' not found or not executable."
|
---|
86 | exit 1
|
---|
87 | fi
|
---|
88 |
|
---|
89 | undefined=`"${objdumpbin}" ${command} "${target}" | kmk_sed -n 's/.*\*UND\*.*\s\([:graph:]*\)/\1/p'`
|
---|
90 | for i in "${@}"; do
|
---|
91 | undefined=`echo "${undefined}" | "${grepbin}" -w -v -f "${i}"`
|
---|
92 | done
|
---|
93 | num_undef=`echo $undefined | wc -w`
|
---|
94 |
|
---|
95 | if test $num_undef -ne 0; then
|
---|
96 | echoerr "${0}: following symbols not defined in the files ${@}:"
|
---|
97 | echoerr "${undefined}"
|
---|
98 | exit 1
|
---|
99 | fi
|
---|
100 | # Return code
|
---|
101 | exit 0
|
---|
102 |
|
---|