checkUndefined.sh revision 41afa0fe1d4d91d48502f164a70c92549adde3e5
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#! /bin/sh
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# Copyright (C) 2006-2010 Sun Microsystems, Inc.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# This file is part of VirtualBox Open Source Edition (OSE), as
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers# available from http://www.virtualbox.org. This file is free software;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# you can redistribute it and/or modify it under the terms of the GNU
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# General Public License (GPL) as published by the Free Software
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# Foundation, in version 2 as it comes in the "COPYING" file of the
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# Clara, CA 95054 USA or visit http://www.sun.com if you need
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# additional information or have any questions.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# Compare undefined symbols in a shared or static object against a new-line
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering# separated list of grep patterns in a text file.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poettering# Usage: /bin/sh <script name> <object> <allowed undefined symbols> [--static]
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poettering#
a9cdc94f7ff40f22a3cf9472f612a80730a1b010Dave Reisner# Currently only works for native objects on Linux platforms
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringechoerr()
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering{
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers echo $* 1>&2
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poettering}
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poetteringhostos=$1
0732ef7acf37473847992888bcb6446726d9d877Zbigniew Jędrzejewski-Szmektarget=$2
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarsymbols=$3
7568345034f2890af745747783c5abfbf6eccf0fLennart Poetteringstatic=$4
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poettering
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poetteringif test $# -lt 3 || test $# -gt 4 || test ! -r "$target" || test ! -r "$symbols"; then
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poettering if test ! -r "$target"; then
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poettering echoerr "$0: '$target' not readable"
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poettering elif test ! -r "$symbols"; then
3f6fd1ba65f962702753c4ad284b588e59689a23Lennart Poettering echoerr "$0: '$symbols' not readable"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering else
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering echoerr "$0: Wrong number of arguments"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering fi
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers args_ok="no"
7085053a437456ab87d726f3697002dd811fdf7aDaniel Wallacefi
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringif test $# -eq 4 && test "$static" != "--static"; then
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering args_ok="no"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringfi
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringif test "$args_ok" = "no"; then
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering echoerr "Usage: $0 <object> <allowed undefined symbols> [--static]"
1b12a7b5896f94bdf33b3a6661ebabd761ea6adcHarald Hoyer exit 1
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringfi
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringif test "$hostos" = "solaris"; then
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering objdumpbin=/usr/sfw/bin/gobjdump
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering grepbin=/usr/sfw/bin/ggrep
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringelif test "$hostos" = "linux"; then
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering objdumpbin=`which objdump`
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering grepbin=`which grep`
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poetteringelse
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering echoerr "$0: '$hostos' not a valid hostos string. supported 'linux' 'solaris'"
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering exit 1
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringfi
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringcommand="-T"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringif test "$static" = "--static"; then
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering command="-t"
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannfi
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannif test ! -x "$objdumpbin"; then
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann echoerr "$0: '$objdumpbin' not found or not executable."
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann exit 1
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannfi
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringundefined=`$objdumpbin $command $target | $grepbin '*UND*' | $grepbin -v -f $symbols | kmk_sed -e 's/^.*[[:blank:]]\(.*\)/\1/'`
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannnum_undef=`echo $undefined | wc -w`
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannif test $num_undef -ne 0; then
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann echoerr "$0: following symbols not defined in $symbols:"
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann echoerr "$undefined"
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann exit 1
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannfi
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann# Return code
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannexit 0
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann