]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - scripts/recordmcount.pl
memory hotplug: fix page_zone() calculation in test_pages_isolated()
[linux-2.6-omap-h63xx.git] / scripts / recordmcount.pl
index 1891cf9743fcd3c44fc82cd522b50ece175bb8b0..6b9fe3eb836027bff637b912798b3b024a4baeba 100755 (executable)
@@ -106,7 +106,13 @@ if ($#ARGV < 6) {
        exit(1);
 }
 
-my ($arch, $objdump, $objcopy, $cc, $ld, $nm, $rm, $mv, $inputfile) = @ARGV;
+my ($arch, $bits, $objdump, $objcopy, $cc,
+    $ld, $nm, $rm, $mv, $inputfile) = @ARGV;
+
+# Acceptable sections to record.
+my %text_sections = (
+     ".text" => 1,
+);
 
 $objdump = "objdump" if ((length $objdump) == 0);
 $objcopy = "objcopy" if ((length $objcopy) == 0);
@@ -129,8 +135,16 @@ 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)
 
+if ($arch eq "x86") {
+    if ($bits == 64) {
+       $arch = "x86_64";
+    } else {
+       $arch = "i386";
+    }
+}
+
 if ($arch eq "x86_64") {
-    $section_regex = "Disassembly of section";
+    $section_regex = "Disassembly of section\\s+(\\S+):";
     $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:";
     $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount([+-]0x[0-9a-zA-Z]+)?\$";
     $type = ".quad";
@@ -142,7 +156,7 @@ if ($arch eq "x86_64") {
     $cc .= " -m64";
 
 } elsif ($arch eq "i386") {
-    $section_regex = "Disassembly of section";
+    $section_regex = "Disassembly of section\\s+(\\S+):";
     $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:";
     $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$";
     $type = ".long";
@@ -186,6 +200,36 @@ 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";
+}
+
+
 #
 # Step 1: find all the local (static functions) and weak symbols.
 #        't' is local, 'w/W' is weak (we never use a weak function)
@@ -229,6 +273,11 @@ sub update_funcs
 
     # 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) {
+           return;
+       }
        $convert{$ref_func} = 1;
     }
 
@@ -254,7 +303,13 @@ my $text;
 while (<IN>) {
     # is it a section?
     if (/$section_regex/) {
-       $read_function = 1;
+
+       # Only record text sections that we know are safe
+       if (defined($text_sections{$1})) {
+           $read_function = 1;
+       } else {
+           $read_function = 0;
+       }
        # print out any recorded offsets
        update_funcs() if ($text_found);