aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/recordmcount.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/recordmcount.pl')
-rwxr-xr-xscripts/recordmcount.pl46
1 files changed, 24 insertions, 22 deletions
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
index ea6f6e3adaea..e67f05486087 100755
--- a/scripts/recordmcount.pl
+++ b/scripts/recordmcount.pl
@@ -136,13 +136,14 @@ my %text_sections = (
136 ".text.unlikely" => 1, 136 ".text.unlikely" => 1,
137); 137);
138 138
139$objdump = "objdump" if ((length $objdump) == 0); 139# Note: we are nice to C-programmers here, thus we skip the '||='-idiom.
140$objcopy = "objcopy" if ((length $objcopy) == 0); 140$objdump = 'objdump' if (!$objdump);
141$cc = "gcc" if ((length $cc) == 0); 141$objcopy = 'objcopy' if (!$objcopy);
142$ld = "ld" if ((length $ld) == 0); 142$cc = 'gcc' if (!$cc);
143$nm = "nm" if ((length $nm) == 0); 143$ld = 'ld' if (!$ld);
144$rm = "rm" if ((length $rm) == 0); 144$nm = 'nm' if (!$nm);
145$mv = "mv" if ((length $mv) == 0); 145$rm = 'rm' if (!$rm);
146$mv = 'mv' if (!$mv);
146 147
147#print STDERR "running: $P '$arch' '$objdump' '$objcopy' '$cc' '$ld' " . 148#print STDERR "running: $P '$arch' '$objdump' '$objcopy' '$cc' '$ld' " .
148# "'$nm' '$rm' '$mv' '$inputfile'\n"; 149# "'$nm' '$rm' '$mv' '$inputfile'\n";
@@ -158,6 +159,7 @@ my $section_regex; # Find the start of a section
158my $function_regex; # Find the name of a function 159my $function_regex; # Find the name of a function
159 # (return offset and func name) 160 # (return offset and func name)
160my $mcount_regex; # Find the call site to mcount (return offset) 161my $mcount_regex; # Find the call site to mcount (return offset)
162my $mcount_adjust; # Address adjustment to mcount offset
161my $alignment; # The .align value to use for $mcount_section 163my $alignment; # The .align value to use for $mcount_section
162my $section_type; # Section header plus possible alignment command 164my $section_type; # Section header plus possible alignment command
163my $can_use_local = 0; # If we can use local function references 165my $can_use_local = 0; # If we can use local function references
@@ -212,6 +214,7 @@ $section_regex = "Disassembly of section\\s+(\\S+):";
212$function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:"; 214$function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:";
213$mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$"; 215$mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$";
214$section_type = '@progbits'; 216$section_type = '@progbits';
217$mcount_adjust = 0;
215$type = ".long"; 218$type = ".long";
216 219
217if ($arch eq "x86_64") { 220if ($arch eq "x86_64") {
@@ -325,7 +328,7 @@ if ($arch eq "x86_64") {
325 # 14: R_MIPS_NONE *ABS* 328 # 14: R_MIPS_NONE *ABS*
326 # 18: 00020021 nop 329 # 18: 00020021 nop
327 if ($is_module eq "0") { 330 if ($is_module eq "0") {
328 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; 331 $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_26\\s+_mcount\$";
329 } else { 332 } else {
330 $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$"; 333 $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$";
331 } 334 }
@@ -350,6 +353,9 @@ if ($arch eq "x86_64") {
350} elsif ($arch eq "microblaze") { 353} elsif ($arch eq "microblaze") {
351 # Microblaze calls '_mcount' instead of plain 'mcount'. 354 # Microblaze calls '_mcount' instead of plain 'mcount'.
352 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; 355 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
356} elsif ($arch eq "blackfin") {
357 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s__mcount\$";
358 $mcount_adjust = -4;
353} else { 359} else {
354 die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD"; 360 die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD";
355} 361}
@@ -432,14 +438,14 @@ sub update_funcs
432 438
433 # Loop through all the mcount caller offsets and print a reference 439 # Loop through all the mcount caller offsets and print a reference
434 # to the caller based from the ref_func. 440 # to the caller based from the ref_func.
435 for (my $i=0; $i <= $#offsets; $i++) { 441 if (!$opened) {
436 if (!$opened) { 442 open(FILE, ">$mcount_s") || die "can't create $mcount_s\n";
437 open(FILE, ">$mcount_s") || die "can't create $mcount_s\n"; 443 $opened = 1;
438 $opened = 1; 444 print FILE "\t.section $mcount_section,\"a\",$section_type\n";
439 print FILE "\t.section $mcount_section,\"a\",$section_type\n"; 445 print FILE "\t.align $alignment\n" if (defined($alignment));
440 print FILE "\t.align $alignment\n" if (defined($alignment)); 446 }
441 } 447 foreach my $cur_offset (@offsets) {
442 printf FILE "\t%s %s + %d\n", $type, $ref_func, $offsets[$i] - $offset; 448 printf FILE "\t%s %s + %d\n", $type, $ref_func, $cur_offset - $offset;
443 } 449 }
444} 450}
445 451
@@ -476,11 +482,7 @@ while (<IN>) {
476 $read_headers = 0; 482 $read_headers = 0;
477 483
478 # Only record text sections that we know are safe 484 # Only record text sections that we know are safe
479 if (defined($text_sections{$1})) { 485 $read_function = defined($text_sections{$1});
480 $read_function = 1;
481 } else {
482 $read_function = 0;
483 }
484 # print out any recorded offsets 486 # print out any recorded offsets
485 update_funcs(); 487 update_funcs();
486 488
@@ -514,7 +516,7 @@ while (<IN>) {
514 } 516 }
515 # is this a call site to mcount? If so, record it to print later 517 # is this a call site to mcount? If so, record it to print later
516 if ($text_found && /$mcount_regex/) { 518 if ($text_found && /$mcount_regex/) {
517 $offsets[$#offsets + 1] = hex $1; 519 push(@offsets, (hex $1) + $mcount_adjust);
518 } 520 }
519} 521}
520 522