Blob Blame History Raw
#! /bin/bash

#############################################################################
# Copyright (c) 2007 Novell, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#############################################################################

# The symtypes file format is as follows:
#
#  * Each object file has its own, independent section in the symtypes file.
#    Except to avoid repeated identical definitions as explained later, each
#    of these sections is independent.
#
#  * Lines starting with x# are definitions of types that are used later.
#    Only definitions that are actually used show up in the dump. Lines not
#    starting with x# indicate an exported symbol, e.g.,
#
#    t#u32 typedef unsigned int u32
#    acpi_register_gsi int acpi_register_gsi (t#u32, int, int)
#
#  * To keep the dumps reasonably small, identical definitions are not
#    repeated. Instead, only the fact that a symbols is being defined is noted.
#    So instead of the full t#u32 definition from above, only "t#u32" appears
#    after the first definition. If a type is defined differently in different
#    places, the full definitions are given.
#
#
# The checksums are computed taking into consideration all the definitions
# known, recursively. For example, wherever struct acpi_processor_tx is used,
# the defintions of typedef u16 as well as struct acpi_processor_tx define
# the result:
#
#    t#u16 typedef unsigned short u16
#    s#acpi_processor_tx struct acpi_processor_tx {t#u16 power;
#                                                  t#u16 performance}
#
# Forward declarations are a problem: if a symbol only has been forward
# declared it may be used, but the checksum will not include its definition.
# If the symbols's definition later becomes known before the symbol is used,
# this will change the checksum even if the actual types did not change.
# This is an unsolved problem.

if [ $# -ne 2 ]; then
    echo "Usage: ${0##*/} <symtypes1.gz> <symtypes2.gz>"
    echo "Show the differences between two /boot/symtypes-*.gz files."
    exit
fi

verbose_symtypes() {
    # The symtypes dumps have repeated identical type definitions stripped out.
    # Fill in the stripped-out definition to make the diff easier to understand.

    gzip -df < "$1" \
    | awk '
	$1 ~ /^.#.*/ {
	    if (NF != 1)
		syms[$1] = $0;
	    print syms[$1];
	    next;
	}
	{ print }
    '
}

diff -U0 --show-function-line='^/\*' --label "$1" --label "$2" \
    <(verbose_symtypes "$1") <(verbose_symtypes "$2")