#!/bin/ksh -p # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" # # Find dead functions in a given kernel module. Requires that system its # running on matches the source tree # GATE=${GATE:-/ws/onnv-gate} export GATE BUILD_TOOLS=${BUILD_TOOLS:-/ws/onnv-tools} export BUILD_TOOLS TMPDIR=/tmp/dead-funcs.$$ export TMPDIR PATH=/usr/bin:/usr/ccs/bin:${BUILD_TOOLS}/onbld/bin/`uname -p`/ export PATH unset CSCOPEOPTIONS prog=`basename $0` trap 'rm -rf $TMPDIR' EXIT die() { print -u2 "$prog: fatal: $*" cd / exit 1 } warn() { print -u2 "$prog: warning: $*" } info() { print "$prog: $*" } [[ "$#" -lt 1 ]] && die "usage: $prog ..." mkdir $TMPDIR || die "cannot create $TMPDIR" for kmod; do if [[ ! -f $kmod ]]; then warn "$kmod does not exist" continue fi # # Get kernel module symbol list # nm -P $kmod | grep ' [tT]' | cut -f1 -d' ' > $TMPDIR/kmodsyms # # Cross-reference symbol list against cscope # cd $GATE/usr/src/uts || die "cannot access $GATE/usr/src/uts" while read sym; do def=`cscope-fast -dq -L1${sym}` cscope-fast -dq -L0${sym} | awk ' /extern/ { next } /static/ { next } $0 == def { next } { ref++; } END { if (ref == 0) print kmod": " sym " unused" }'\ kmod=$kmod sym=$sym def="$def" done < $TMPDIR/kmodsyms done exit 0