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
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Use is subject to license terms.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# This perl module contains code shared between the ELF analysis
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# tools found in this directory: find_elf, check_rtime, interface_check,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# and interface_cmp.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## GetLine(FileHandleRef, LineNumRef)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Read the next non-empty line from the given file handle reference
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# and return it.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# FileHandleRef - Reference to open file handle to read from
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# LineNumRef - Reference to integer to increment as lines are input
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # A backslash at the end of the line indicates that the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # following line is a continuation of this line if the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # backslash is the only character on the line, or if it is
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # preceded by a space.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # The # character starts a comment if it is the first
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # character on the line, or if it is preceeded by a space.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # If our result string is still null, act as if a
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # continuation is present and read another line.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # The above loop won't exit while $ret_line is a null string
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # unless the read failed, so return undef() in that case.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Otherwise, use the value in $ret_line.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## LoadExceptionsToEXRE(name)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Locate the exceptions file and process its contents. This function can be
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# used by any program with exception files that consist of a single
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# verb, followed by a single regular expression:
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# For each such verb, the global level of the main:: namespace must
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# have a variable named $EXRE_verb. The $EXRE_ prefix must only be used
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# for these variables, and not for any other. The caller must define these
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# variables, but leave them undefined.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Any variables in the main:: global symbol table starting with
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# the prefix 'EXRE_xxx' are taken to represent the regular expression
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# for the exception named xxx.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# name - Name of script (i.e. 'check_rtime')
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# $main::opt{e} - Calling program must accept a '-e' option
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# that allows the user to specify an exception file
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# to use, and the value of that option must be found
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# in $main::opt{e}.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# The $main::EXRE_xxx variables are updated to contain any regular
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# expressions specified by the exception file. If a given exception
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# is not encountered, its variable is not modified.
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 # Examine the main global symbol table and find all variables
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # named EXRE_xxx. By convention established for this program,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # all such variables contain the regular expression for the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # exception named xxx.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami $except_names{$entry} = 1 if $entry =~ /^EXRE_/;
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/$name";
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/$name";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # No exception file was found.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami die "$name: 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)?/;
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # %except_re is a hash indexed by regular expression variable
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # name, with a value that contains the corresponding regular
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # expression string. If we recognize an exception verb, add
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # it to %except_re.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami if ($Line =~ /^\s*([^\s]+)\s+(.*)$/i) {
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami $verb =~ tr/A-Z/a-z/;
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami "line $LineNum: $Line\n");
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Every exception that we encountered in the file exists
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # in %except_re. Compile them and assign the results into the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # global symbol of the same name.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Note that this leaves the global symbols for unused exceptions
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # untouched, and therefore, undefined. All users of these variables
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # are required to test them with defined() before using them.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # Turn off strict refs so that we can do a symbolic
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # indirection to set the global variable of the name given
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # by verb in the main namespace. 'strict' is lexically scoped,
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # so its influence is limited to this enclosing block.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami no strict 'refs';
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## OutMsg(FileHandleRef, Ttl, obj, msg)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## OutMsg2(FileHandleRef, Ttl, old_obj, new_obj, msg)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Create an output message, either a one-liner (under -o) or preceded by the
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# files relative pathname as a title.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# OutMsg() is used when issuing a message about a single object.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# OutMsg2() is for when the message involves an old and new instance
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# of the same object. If old_obj and new_obj are the same, as is usually
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# the case, then the output is the same as generated by OutMsg(). If they
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# differ, as can happen when the new object has changed names, and has been
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# found via an alias, both the old and new names are shown.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# FileHandleRef - File handle to output file
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Ttl - Reference to variable containing the number of times
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# this function has been called for the current object.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# obj - For OutMsg, the path for the current object
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# old_obj, new_obj - For OutMsg2, the names of the "old" and "new"
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# msg - Message to output
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# $main::opt{o} - Calling program must accept a '-o' option
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# that allows the user to specify "one-line-mode',
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# and the value of that option must be found
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# in $main::opt{o}.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # If old and new are the same, give it to OutMsg()
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "old $old_obj: new $new_obj: $msg\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "==== old: $old_obj / new: $new_obj ====\n"
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print "\t$msg\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami## header(FileHandleRef, ScriptPath, Argv)
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Generate a header for the top of generated output, including a copyright
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# and CDDL, such that the file will pass ON copyright/CDDL rules if it is
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# checked into the repository.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# FileHandleRef - File handle reference to output text to
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# ScriptPath - Value of $0 from caller, giving path to running script
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Argv - Reference to array containing @ARGV from caller.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# We assume that the calling script contains a value CDDL block.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print $fh "# Copyright $year Sun Microsystems, Inc. ",
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami "All rights reserved.\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print $fh "# Use is subject to license terms.\n#\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # The CDDL text is copied from this script, the path to which is
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami # assigned to $0 by the Perl interpreter.
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print $fh '# Date: ', scalar(localtime()), "\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami $ScriptPath =~ s/^.*\///;
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami print $fh "# Command: $ScriptPath ", join(' ', @$Argv), "\n\n";
75ce41a57ff334bd8fe2cb9ed51eea835892f944Ali Bahrami# Perl modules pulled in via 'require' must return an exit status.