75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# CDDL HEADER START
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# The contents of this file are subject to the terms of the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Common Development and Distribution License (the "License").
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# You may not use this file except in compliance with the License.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# See the License for the specific language governing permissions
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# and limitations under the License.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# When distributing Covered Code, include this CDDL HEADER in each
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# If applicable, add the following below this CDDL HEADER, with the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# fields enclosed by brackets "[]" replaced with your own identifying
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# information: Portions Copyright [yyyy] [name of copyright owner]
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# CDDL HEADER END
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# interface_cmp audits two interface definition files (as created by
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# interface_check) against one another, and confirms that:
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# o All versioned libraries that were present in the previous interface
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# are present in the new interface
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# o for each non-private interface in a library confirm that no symbols
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# have been removed and that no symbols have been added to it between
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# the two revisions
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Return codes:
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# 0 All interfaces in the new release are identical in old release.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# 1 Something is different refer to the error messages.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami#### Define all global variables (required for strict)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahramiuse vars qw($Prog);
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahramiuse vars qw(%opt);
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahramiuse vars qw(%old_hash %old_alias %new_hash %new_alias);
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Exception Arrays:
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# The ADDSYM and DELSYM exceptions are maintained on the @AddSymList
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# and @DelSymList arrays, respectively. Each array element is a reference
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# to a subarray of triples:
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# (sym_re, ver_re, obj_re)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# where each item in the tripple is a regular expression, used to
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# match a particular symbol/version/object combination.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# The EMPTY_TOPVERSION exceptions are maintained on the @EmptyTopVerList
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# array. Each array element is a reference to a subarray of pairs:
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# (ver_re, obj_re)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# where each item in the pair is a regular expression, used to
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# match a particular version/object combination.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahramiuse vars qw(@AddSymList @DelSymList @EmptyTopVerList);
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## LoadExceptions
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Locate the exceptions file and process its contents. We can't use
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# onbld_elfmod::LoadExceptionsToEXRE() for this, because our exceptions
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# need to support more than a single regular expression.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# @AddSymList, @DelSymList, and @EmptyTopVerList have been updated
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# We expand strings of the form MACH(dir) to match the given
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# directory as well as any 64-bit architecture subdirectory that
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# might be present (i.e. amd64, sparcv9).
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Locate the exception file
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # If -e is specified, that file must be used
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # If this is an activated workspace, use the exception
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # file found in the exceptions_list directory.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami $file = "$ENV{CODEMGR_WS}/exception_lists/interface_cmp";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # As a final backstop, the SUNWonbld package provides a
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # copy of the exception file. This can be useful if we
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # are being used with an older workspace.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # This script is installed in the SUNWonbld bin directory,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # while the exception file is in etc/exception_lists. Find
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # it relative to the script location given by $0.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami $file = dirname($0) . "/../etc/exception_lists/interface_cmp";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # No exception file was found.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami die "$Prog: unable to open exceptions file: $file";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami while ($Line = onbld_elfmod::GetLine(\*EFILE, \$LineNum)) {
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Expand MACH()
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami $Line =~ s/MACH\(([^)]+)\)/$1(\/amd64|\/sparcv9)?/g;
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami push @DelSymList, [ $sym_re, $ver_re, $obj_re ];
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami push @AddSymList, [ $sym_re, $ver_re, $obj_re ];
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami my ($item, $ver_re, $obj_re) = split(/\s+/, $Line, 3);
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami "line $LineNum: $Line\n");
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## ExSym(SymList, sym, ver, obj)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Compare a given symbol/version/object combination against the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# exceptions found in the given list.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# SymList - Reference to @AddSymList, or @DelSymList.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# sym, ver, obj - Combination to be compared against exception list
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Returns True (1) if there is a match, and False (0) otherwise.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami return 1 if ($obj =~ /$$ex[2]/) && ($ver =~ /$$ex[1]/) &&
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## ExTopVer(ver, obj)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Compare a given version/object combination against the pairs found
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# in @EmptyTopVerList.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# ver, obj - Combination to be compared against empty top version list
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Returns True (1) if there is a match, and False (0) otherwise.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami return 1 if ($obj =~ /$$ex[1]/) && ($ver =~ /$$ex[0]/);
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## ExpandInheritance(objhashref)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# For each version contained in the specified object hash reference,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# add the inherited symbols.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Versions to process. Typically, inheriting versions come before
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # the versions they inherit. Processing the list in reverse order
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # maximizes the odds that a needed sub-version will have already
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # have been processed.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Versions to process in the next pass
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Hash, indexed by version name, that reflects whether the version
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # has been expanded yet or not.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami my $cur_version = $obj->{'VERSION_INFO'}{$name};
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami my ($top, $direct, $total, $symhash, $inheritarr) =
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # In order to expand this version, all the inherited
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # versions must already have been done. If not, put
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # this version on @next_vers for the next pass.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Add all the symbols from the inherited versions
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # to this one.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## ReadInterface(file, alias)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Read the interface description file, as produced by interface_check, and
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# return a hash describing it.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# file - Interface file to read.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# alias - Refence to hash to be filled in with any aliases
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# that are seen in the file. The alias name is the key,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# and the object is the value.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# The hash referenced by alias has been updated.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# The return value is a hash that encapsulates the interface
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# information. This hash returned uses the object names as the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# key. Each key references a sub-hash that contains information
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# for that object:
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# CLASS -> ELFCLASS
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# TYPE -> ELF type
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# VERSION_NAMES -> Reference to array [1..n] of version names, in the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# order they come from the input file.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# VERSION_INFO -> Reference to hash indexed by version name, yielding
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# a reference to an array containing information about
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# that version.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# The arrays referenced via VERSION_INFO are of the form:
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# (top, new, total, symhashref, inheritarrref)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# top - 1 if version is a TOP_VERSION, 0 for a regular VERSION
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# new - Number of symbols defined explicitly by version
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# total - Number of symbols included in version, both new,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# and via inheritance.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# symhashref - Reference to hash indexed by symbol names, and
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# yielding true (1).
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# inheritarrref - Reference to array of names of versions
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# inherited by this one.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami open(FILE, $file) || die "$Prog: Unable to open: $file";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Until we see an OBJECT line, nothing else is valid. To
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # simplify the error handling, use a simple initial loop to
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # read the file up to that point
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami while ($Line = onbld_elfmod::GetLine(\*FILE, \$LineNum)) {
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami die "$file: OBJECT expected on line $LineNum: $Line\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Read the remainder of the file
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami while ($Line = onbld_elfmod::GetLine(\*FILE, \$LineNum)) {
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Items are parsed in order of decreasing frequency
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami /^SYMBOL\s+([^\s]+)$/i) {
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami die "$file: SYMBOL not expected on line $LineNum: $Line\n"
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami if ($Line =~ /^((TOP_)?VERSION)\s+([^\s]+)(\s+\{(.*)\})?\s*$/i) {
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami split /[,{\s]+/, $inherit : ();
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami $cur_version = [ $top, 0, 0, {}, \@inheritarr ];
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami $obj_hash->{'VERSION_INFO'}{$name} = $cur_version;
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Expand the versions for the object just processed
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami die "$file: unrecognized item on line $LineNum: $Line\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Expand the versions for the final object from the file
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## PrintInterface(main_hash, alias)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Dump the contents of main_hash and alias to stdout in the same format
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# used by interface_check to produce the input interface file. This output
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# should diff cleanly against the original (ignoring the header comments).
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "OBJECT\t$obj\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "CLASS\t$main_hash->{$obj}{'CLASS'}\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "TYPE\t$main_hash->{$obj}{'TYPE'}\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # This is inefficient, but good enough for debugging
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Look at all the aliases and print those that belong
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # to this object.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "ALIAS\t$alias\n"
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami next if !defined($main_hash->{$obj}{'VERSION_NAMES'});
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami my $num = scalar(@{$main_hash->{$obj}{'VERSION_NAMES'}});
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami my $name = $main_hash->{$obj}{'VERSION_NAMES'}[$i];
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami my ($top, $direct, $total, $symhash, $inheritarr) =
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "${top}VERSION\t$name$inherit\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "\t$symhash->{$sym}\t$sym\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Compare the old interface definition contained in (%old_hash, %old_alias)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# with the new interface contained in (%new_hash, %new_alias).
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # If the object does not exist in the new interface,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # then see if there's an alias for it. Failing that,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # we simply ignore the object.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Every version in the old object must exist in the new object,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # and there must be exactly the same symbols in each.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # New object must have this version
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami onbld_elfmod::OutMsg2(\*STDOUT, \$Ttl, $old_obj,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami my ($old_top, $old_direct, $old_total, $old_symhash) =
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami my ($new_top, $new_direct, $new_total, $new_symhash) =
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # If this is an empty top version, and the old object
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # has the EMPTY_TOPVERSION exception set, then we
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # skip it as if it were not present.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # We check that every symbol in the old object is
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # in the new one to detect deleted symbols. We then
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # check that every symbol in the new object is also
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # in the old object, to find added symbols. If the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # "deleted" check is clean, and the two objects have
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # the same number of symbols in their versions, then we
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # can skip the "added" test, because we know that
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # there is no room for an addition to have happened.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Since most objects satisfy these constraints, we
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # end up doing roughly half the number of comparisons
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # that would otherwise be needed.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Every symbol in the old version must be in the new one
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami "$name: deleted interface: $sym")
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Do the "added" check, unless we can optimize it away.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Every symbol in the new version must be in the old one.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami "$name: added interface: $sym");
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # We want to ensure that version numbers in an
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # inheritance chain don't go up by more than 1 in
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # any given release. If the version names are in the
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # numbered <PREFIX>x.y[.z] format, we can compare the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # two top versions and see if this has happened.
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # For a given <PREFIX>x.y[.z], valid sucessors would
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # be <PREFIX>x.(y+1) or <PREFIX>x.y.(z+1), where z is
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # assumed to be 0 if not present.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # This check only makes sense when the new interface
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # is a direct decendent of the old one, as specified
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # via the -d option. If the two interfaces are more
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # than one release apart, we should not do this test.
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # Known numbered version?
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # Key to @Cat contents:
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # [0] 'NUMBERED'
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # [1] number of dot separated numeric fields. 2 or 3.
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # [2] prefix
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # [3] major #
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # [4] minor #
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami # [5] micro # (only if [1] is 3)
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami my @Cat = onbld_elfmod_vertype::Category($name, '');
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami $iname2 = "$Cat[2]$Cat[3].$Cat[4]." . ($Cat[5] + 1);
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami "$name: inconsistant " .
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami "version increment: " .
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami "expect $iname1 or $iname2 ".
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami "to replace top version");
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami "$name: expected superseding " .
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami "top version to $name not " .
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami "present: $iname1 or $iname2");
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Empty versions in the established interface description
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # are usually the result of fixing a versioning mistake
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # at some point in the past. These versions are part of
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # the public record, and cannot be changed now. However, if
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # comparing two interface descriptions from the same gate,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # flag any empty versions in the new interface description
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # that are not present in the old one. These have yet to
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # become part of the official interface, and should be removed
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # before they do.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami next if !$opt{d};
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # If old object has this version, skip it
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # If explicitly whitelisted, skip it
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami my ($new_top, $new_direct, $new_total, $new_symhash) =
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami "$name: invalid empty new version");
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# -----------------------------------------------------------------------------
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Establish a program name for any error diagnostics.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Check that we have arguments. Normally, 2 plain arguments are required,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# but if -t is present, only one is allowed.
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahramiif ((getopts('c:de:ot', \%opt) == 0) || (scalar(@ARGV) != ($opt{t} ? 1 : 2))) {
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami print "usage: $Prog [-dot] [-c vtype_mod] [-e exfile] old new\n";
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami print "\t[-c vtype_mod]\tsupply alternative version category module\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "\t[-d]\t\tnew is a direct decendent of old\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "\t[-e exfile]\texceptions file\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "\t[-o]\t\tproduce one-liner output (prefixed with pathname)\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "\t[-t]\tParse old, and recreate to stdout\n";
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami# We depend on the onbld_elfmod and onbld_elfmod_vertype perl modules.
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami# Both modules are maintained in the same directory as this script,
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami# and are installed in ../lib/perl. Use the local one if present,
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami# and the installed one otherwise.
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami# The caller is allowed to supply an alternative implementation for
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami# onbld_elfmod_vertype via the -c option. In this case, the alternative
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami# implementation is expected to provide the same interface as the standard
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami# copy, and is loaded instead.
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami$moddir = "$moddir/../lib/perl" if ! -f "$moddir/onbld_elfmod.pm";
5253169e90b276216b53d82f9ba4c56334db5740Ali Bahrami require "$opt{c}";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Locate and process the exceptions file
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami%old_hash = ReadInterface($ARGV[0], \%old_alias);
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# If -t is present, only one argument is allowed --- we parse it, and then
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# print the same information back to stderr in the same format as the original.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# This is useful for debugging, to verify that the parsing is correct.