[43257] | 1 | #!/bin/sh
|
---|
[20934] | 2 |
|
---|
| 3 | #
|
---|
[96407] | 4 | # Copyright (C) 2006-2022 Oracle and/or its affiliates.
|
---|
[26337] | 5 | #
|
---|
[96407] | 6 | # This file is part of VirtualBox base platform packages, as
|
---|
| 7 | # available from https://www.virtualbox.org.
|
---|
[20934] | 8 | #
|
---|
[96407] | 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 | #
|
---|
[20934] | 24 |
|
---|
[26337] | 25 | #
|
---|
[20934] | 26 | # Compare undefined symbols in a shared or static object against a new-line
|
---|
[44473] | 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.
|
---|
[20934] | 29 | #
|
---|
[44473] | 30 | # Usage: /bin/sh <script name> <object> [--static] <undefined symbol file...>
|
---|
[20934] | 31 | #
|
---|
[44473] | 32 | # Currently only works for native objects on Linux (and Solaris?) platforms.
|
---|
[26337] | 33 | #
|
---|
[20934] | 34 |
|
---|
| 35 | echoerr()
|
---|
| 36 | {
|
---|
| 37 | echo $* 1>&2
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[44473] | 40 | hostos="${1}"
|
---|
| 41 | target="${2}"
|
---|
| 42 | shift 2
|
---|
| 43 | if test "${1}" = "--static"; then
|
---|
| 44 | static="${1}"
|
---|
| 45 | shift
|
---|
[20934] | 46 | fi
|
---|
| 47 |
|
---|
[44473] | 48 | if test $# -lt 1; then
|
---|
| 49 | echoerr "${0}: Wrong number of arguments"
|
---|
| 50 | args_ok="no"
|
---|
[20934] | 51 | fi
|
---|
[44473] | 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
|
---|
[20934] | 62 |
|
---|
[20962] | 63 | if test "$args_ok" = "no"; then
|
---|
[44473] | 64 | echoerr "Usage: $0 <object> [--static] <undefined symbol file...>"
|
---|
[20934] | 65 | exit 1
|
---|
| 66 | fi
|
---|
| 67 |
|
---|
[20962] | 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 |
|
---|
[20934] | 79 | command="-T"
|
---|
[20962] | 80 | if test "$static" = "--static"; then
|
---|
[20934] | 81 | command="-t"
|
---|
| 82 | fi
|
---|
| 83 |
|
---|
[44473] | 84 | if test ! -x "${objdumpbin}"; then
|
---|
| 85 | echoerr "${0}: '${objdumpbin}' not found or not executable."
|
---|
[20962] | 86 | exit 1
|
---|
| 87 | fi
|
---|
| 88 |
|
---|
[44473] | 89 | undefined=`"${objdumpbin}" ${command} "${target}" | kmk_sed -n 's/.*\*UND\*.*\s\([:graph:]*\)/\1/p'`
|
---|
| 90 | for i in "${@}"; do
|
---|
[44478] | 91 | undefined=`echo "${undefined}" | "${grepbin}" -w -v -f "${i}"`
|
---|
[44473] | 92 | done
|
---|
[20934] | 93 | num_undef=`echo $undefined | wc -w`
|
---|
| 94 |
|
---|
[20962] | 95 | if test $num_undef -ne 0; then
|
---|
[44473] | 96 | echoerr "${0}: following symbols not defined in the files ${@}:"
|
---|
| 97 | echoerr "${undefined}"
|
---|
[20962] | 98 | exit 1
|
---|
[20934] | 99 | fi
|
---|
| 100 | # Return code
|
---|
[20962] | 101 | exit 0
|
---|
| 102 |
|
---|