omap3: pandora: board file updates for .33
[safe/jmp/linux-2.6] / scripts / recordmcount.pl
index b80e5d0..f0d1445 100755 (executable)
@@ -92,7 +92,7 @@
 #
 # Here are the steps we take:
 #
-# 1) Record all the local symbols by using 'nm'
+# 1) Record all the local and weak symbols by using 'nm'
 # 2) Use objdump to find all the call site offsets and sections for
 #    mcount.
 # 3) Compile the list into its own object.
@@ -152,13 +152,47 @@ my %weak;         # List of weak functions
 my %convert;           # List of local functions used that needs conversion
 
 my $type;
-my $nm_regex;          # Find the local functions (return function)
+my $local_regex;       # Match a local function (return function)
+my $weak_regex;        # Match a weak function (return function)
 my $section_regex;     # Find the start of a section
 my $function_regex;    # Find the name of a function
                        #    (return offset and func name)
 my $mcount_regex;      # Find the call site to mcount (return offset)
 my $alignment;         # The .align value to use for $mcount_section
 my $section_type;      # Section header plus possible alignment command
+my $can_use_local = 0;         # If we can use local function references
+
+# Shut up recordmcount if user has older objcopy
+my $quiet_recordmcount = ".tmp_quiet_recordmcount";
+my $print_warning = 1;
+$print_warning = 0 if ( -f $quiet_recordmcount);
+
+##
+# check_objcopy - whether objcopy supports --globalize-symbols
+#
+#  --globalize-symbols came out in 2.17, we must test the version
+#  of objcopy, and if it is less than 2.17, then we can not
+#  record local functions.
+sub check_objcopy
+{
+    open (IN, "$objcopy --version |") or die "error running $objcopy";
+    while (<IN>) {
+       if (/objcopy.*\s(\d+)\.(\d+)/) {
+           $can_use_local = 1 if ($1 > 2 || ($1 == 2 && $2 >= 17));
+           last;
+       }
+    }
+    close (IN);
+
+    if (!$can_use_local && $print_warning) {
+       print STDERR "WARNING: could not find objcopy version or version " .
+           "is less than 2.17.\n" .
+           "\tLocal function references are disabled.\n";
+       open (QUIET, ">$quiet_recordmcount");
+       printf QUIET "Disables the warning from recordmcount.pl\n";
+       close QUIET;
+    }
+}
 
 if ($arch eq "x86") {
     if ($bits == 64) {
@@ -172,7 +206,8 @@ if ($arch eq "x86") {
 # We base the defaults off of i386, the other archs may
 # feel free to change them in the below if statements.
 #
-$nm_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\S+)";
+$local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\S+)";
+$weak_regex = "^[0-9a-fA-F]+\\s+([wW])\\s+(\\S+)";
 $section_regex = "Disassembly of section\\s+(\\S+):";
 $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:";
 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$";
@@ -221,7 +256,7 @@ if ($arch eq "x86_64") {
     $cc .= " -m32";
 
 } elsif ($arch eq "powerpc") {
-    $nm_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\.?\\S+)";
+    $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\.?\\S+)";
     $function_regex = "^([0-9a-fA-F]+)\\s+<(\\.?.*?)>:";
     $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s\\.?_mcount\$";
 
@@ -293,44 +328,17 @@ if ($filename =~ m,^(.*)(\.\S),) {
 my $mcount_s = $dirname . "/.tmp_mc_" . $prefix . ".s";
 my $mcount_o = $dirname . "/.tmp_mc_" . $prefix . ".o";
 
-#
-# --globalize-symbols came out in 2.17, we must test the version
-# of objcopy, and if it is less than 2.17, then we can not
-# record local functions.
-my $use_locals = 01;
-my $local_warn_once = 0;
-my $found_version = 0;
-
-open (IN, "$objcopy --version |") || die "error running $objcopy";
-while (<IN>) {
-    if (/objcopy.*\s(\d+)\.(\d+)/) {
-       my $major = $1;
-       my $minor = $2;
-
-       $found_version = 1;
-       if ($major < 2 ||
-           ($major == 2 && $minor < 17)) {
-           $use_locals = 0;
-       }
-       last;
-    }
-}
-close (IN);
-
-if (!$found_version) {
-    print STDERR "WARNING: could not find objcopy version.\n" .
-       "\tDisabling local function references.\n";
-}
+check_objcopy();
 
 #
 # Step 1: find all the local (static functions) and weak symbols.
-#        't' is local, 'w/W' is weak (we never use a weak function)
+#         't' is local, 'w/W' is weak
 #
 open (IN, "$nm $inputfile|") || die "error running $nm";
 while (<IN>) {
-    if (/$nm_regex/) {
+    if (/$local_regex/) {
        $locals{$1} = 1;
-    } elsif (/^[0-9a-fA-F]+\s+([wW])\s+(\S+)/) {
+    } elsif (/$weak_regex/) {
        $weak{$2} = $1;
     }
 }
@@ -348,26 +356,20 @@ my $offset = 0;           # offset of ref_func to section beginning
 #
 sub update_funcs
 {
-    return if ($#offsets < 0);
-
-    defined($ref_func) || die "No function to reference";
+    return unless ($ref_func and @offsets);
 
-    # A section only had a weak function, to represent it.
-    # Unfortunately, a weak function may be overwritten by another
-    # function of the same name, making all these offsets incorrect.
-    # To be safe, we simply print a warning and bail.
+    # Sanity check on weak function. A weak function may be overwritten by
+    # another function of the same name, making all these offsets incorrect.
     if (defined $weak{$ref_func}) {
-       print STDERR
-           "$inputfile: WARNING: referencing weak function" .
+       die "$inputfile: ERROR: referencing weak function" .
            " $ref_func for mcount\n";
-       return;
     }
 
     # is this function static? If so, note this fact.
     if (defined $locals{$ref_func}) {
 
        # only use locals if objcopy supports globalize-symbols
-       if (!$use_locals) {
+       if (!$can_use_local) {
            return;
        }
        $convert{$ref_func} = 1;
@@ -393,9 +395,27 @@ open(IN, "$objdump -hdr $inputfile|") || die "error running $objdump";
 
 my $text;
 
+
+# read headers first
 my $read_headers = 1;
 
 while (<IN>) {
+
+    if ($read_headers && /$mcount_section/) {
+       #
+       # Somehow the make process can execute this script on an
+       # object twice. If it does, we would duplicate the mcount
+       # section and it will cause the function tracer self test
+       # to fail. Check if the mcount section exists, and if it does,
+       # warn and exit.
+       #
+       print STDERR "ERROR: $mcount_section already in $inputfile\n" .
+           "\tThis may be an indication that your build is corrupted.\n" .
+           "\tDelete $inputfile and try again. If the same object file\n" .
+           "\tstill causes an issue, then disable CONFIG_DYNAMIC_FTRACE.\n";
+       exit(-1);
+    }
+
     # is it a section?
     if (/$section_regex/) {
        $read_headers = 0;
@@ -407,7 +427,7 @@ while (<IN>) {
            $read_function = 0;
        }
        # print out any recorded offsets
-       update_funcs() if (defined($ref_func));
+       update_funcs();
 
        # reset all markers and arrays
        $text_found = 0;
@@ -436,21 +456,7 @@ while (<IN>) {
                $offset = hex $1;
            }
        }
-    } elsif ($read_headers && /$mcount_section/) {
-       #
-       # Somehow the make process can execute this script on an
-       # object twice. If it does, we would duplicate the mcount
-       # section and it will cause the function tracer self test
-       # to fail. Check if the mcount section exists, and if it does,
-       # warn and exit.
-       #
-       print STDERR "ERROR: $mcount_section already in $inputfile\n" .
-           "\tThis may be an indication that your build is corrupted.\n" .
-           "\tDelete $inputfile and try again. If the same object file\n" .
-           "\tstill causes an issue, then disable CONFIG_DYNAMIC_FTRACE.\n";
-       exit(-1);
     }
-
     # is this a call site to mcount? If so, record it to print later
     if ($text_found && /$mcount_regex/) {
        $offsets[$#offsets + 1] = hex $1;
@@ -458,7 +464,7 @@ while (<IN>) {
 }
 
 # dump out anymore offsets that may have been found
-update_funcs() if (defined($ref_func));
+update_funcs();
 
 # If we did not find any mcount callers, we are done (do nothing).
 if (!$opened) {