File list-exported-symbols of Package kernel-source

#! /bin/sh

# Generate a Module.symvers-like list of symbols a module exports.

usage() {
    echo "USAGE: ${0##*/} [-n name] objfile" >&2
    exit 1
}

options=`getopt -o n: -- "$@"`
[ $? -eq 0 ] || usage

eval set -- "$options"
while :; do
    case "$1" in
    -n)
	opt_n=$2
	shift
	;;
    --)
	shift
	break
	;;
    esac
    shift
done

[ $# -eq 1 ] || usage

if [ -z "$opt_n" ]; then
    opt_n=${1%.ko}
    opt_n=${opt_n%.o}
    opt_n=${opt_n#*/kernel/}
fi

objdump -t "$1" | awk '
BEGIN { known_types["__ksymtab"] = "EXPORT_SYMBOL"
	known_types["__ksymtab_unused"] = "EXPORT_UNUSED_SYMBOL"
	known_types["__ksymtab_gpl"] = "EXPORT_SYMBOL_GPL"
	known_types["__ksymtab_unused_gpl"] = "EXPORT_UNUSED_SYMBOL_GPL"
	known_types["__ksymtab_gpl_future"] = "EXPORT_SYMBOL_GPL_FUTURE"
      }
      { if (NF < 3)
	  next
	if (substr($0, index($0, " ") + 6, 1) == "d")
	  next  # debug symbol
	if (gsub(/^__crc_/, "", $NF))
	  crcs[$NF] = gensub(/^00000000(.+)/, "\\1", "", $1)
	else if (gsub(/^__ksymtab_/, "", $NF) &&
		 ($(NF-2) in known_types))
	  types[$NF] = known_types[$(NF-2)]
      }
END   { for (sym in types) {
	  crc = (sym in crcs ? crcs[sym] : "00000000")
	  print "0x" crc "\t" sym "\t" module "\t" types[sym]
	}
      }
' module="$opt_n"
openSUSE Build Service is sponsored by