VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
cb77f0d623ff3 (Kamil Rytarowski        2017-05-07 23:25:26 +0200   1) #!/usr/bin/env perl
4f19048fd0a00 (Thomas Gleixner         2019-05-27 08:55:14 +0200   2) # SPDX-License-Identifier: GPL-2.0-only
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400   3) # (c) 2008, Steven Rostedt <srostedt@redhat.com>
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400   4) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400   5) # recordmcount.pl - makes a section called __mcount_loc that holds
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400   6) #                   all the offsets to the calls to mcount.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400   7) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400   8) #
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800   9) # What we want to end up with this is that each object file will have a
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  10) # section called __mcount_loc that will hold the list of pointers to mcount
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  11) # callers. After final linking, the vmlinux will have within .init.data the
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  12) # list of all callers to mcount between __start_mcount_loc and __stop_mcount_loc.
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  13) # Later on boot up, the kernel will read this list, save the locations and turn
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  14) # them into nops. When tracing or profiling is later enabled, these locations
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  15) # will then be converted back to pointers to some function.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  16) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  17) # This is no easy feat. This script is called just after the original
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  18) # object is compiled and before it is linked.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  19) #
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  20) # When parse this object file using 'objdump', the references to the call
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  21) # sites are offsets from the section that the call site is in. Hence, all
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  22) # functions in a section that has a call site to mcount, will have the
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  23) # offset from the beginning of the section and not the beginning of the
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  24) # function.
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  25) #
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  26) # But where this section will reside finally in vmlinx is undetermined at
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  27) # this point. So we can't use this kind of offsets to record the final
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  28) # address of this call site.
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  29) #
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  30) # The trick is to change the call offset referring the start of a section to
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  31) # referring a function symbol in this section. During the link step, 'ld' will
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  32) # compute the final address according to the information we record.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  33) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  34) # e.g.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  35) #
31b6e76e21b2f (Tim Abbott              2009-04-30 20:06:11 -0400  36) #  .section ".sched.text", "ax"
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  37) #        [...]
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  38) #  func1:
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  39) #        [...]
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  40) #        call mcount  (offset: 0x10)
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  41) #        [...]
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  42) #        ret
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  43) #  .globl fun2
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  44) #  func2:             (offset: 0x20)
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  45) #        [...]
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  46) #        [...]
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  47) #        ret
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  48) #  func3:
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  49) #        [...]
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  50) #        call mcount (offset: 0x30)
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  51) #        [...]
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  52) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  53) # Both relocation offsets for the mcounts in the above example will be
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  54) # offset from .sched.text. If we choose global symbol func2 as a reference and
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  55) # make another file called tmp.s with the new offsets:
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  56) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  57) #  .section __mcount_loc
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  58) #  .quad  func2 - 0x10
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  59) #  .quad  func2 + 0x10
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  60) #
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  61) # We can then compile this tmp.s into tmp.o, and link it back to the original
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  62) # object.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  63) #
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  64) # In our algorithm, we will choose the first global function we meet in this
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  65) # section as the reference. But this gets hard if there is no global functions
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  66) # in this section. In such a case we have to select a local one. E.g. func1:
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  67) #
31b6e76e21b2f (Tim Abbott              2009-04-30 20:06:11 -0400  68) #  .section ".sched.text", "ax"
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  69) #  func1:
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  70) #        [...]
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  71) #        call mcount  (offset: 0x10)
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  72) #        [...]
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  73) #        ret
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  74) #  func2:
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  75) #        [...]
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  76) #        call mcount (offset: 0x20)
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  77) #        [...]
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  78) #  .section "other.section"
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  79) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  80) # If we make the tmp.s the same as above, when we link together with
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  81) # the original object, we will end up with two symbols for func1:
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  82) # one local, one global.  After final compile, we will end up with
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  83) # an undefined reference to func1 or a wrong reference to another global
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  84) # func1 in other files.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  85) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  86) # Since local objects can reference local variables, we need to find
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  87) # a way to make tmp.o reference the local objects of the original object
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  88) # file after it is linked together. To do this, we convert func1
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  89) # into a global symbol before linking tmp.o. Then after we link tmp.o
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  90) # we will only have a single symbol for func1 that is global.
d49f6aa76d24c (Li Hong                 2009-10-28 13:01:38 +0800  91) # We can convert func1 back into a local symbol and we are done.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  92) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  93) # Here are the steps we take:
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  94) #
306dcf47d28aa (Li Hong                 2009-10-28 13:06:19 +0800  95) # 1) Record all the local and weak symbols by using 'nm'
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  96) # 2) Use objdump to find all the call site offsets and sections for
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  97) #    mcount.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  98) # 3) Compile the list into its own object.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400  99) # 4) Do we have to deal with local functions? If not, go to step 8.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 100) # 5) Make an object that converts these local functions to global symbols
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 101) #    with objcopy.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 102) # 6) Link together this new object with the list object.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 103) # 7) Convert the local functions back to local symbols and rename
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 104) #    the result as the original object.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 105) # 8) Link the object with the list object.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 106) # 9) Move the result back to the original object.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 107) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 108) 
cb77f0d623ff3 (Kamil Rytarowski        2017-05-07 23:25:26 +0200 109) use warnings;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 110) use strict;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 111) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 112) my $P = $0;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 113) $P =~ s@.*/@@g;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 114) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 115) my $V = '0.1';
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 116) 
e6299d2677e60 (Wu Zhangjin             2009-11-20 20:34:31 +0800 117) if ($#ARGV != 11) {
e6299d2677e60 (Wu Zhangjin             2009-11-20 20:34:31 +0800 118) 	print "usage: $P arch endian bits objdump objcopy cc ld nm rm mv is_module inputfile\n";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 119) 	print "version: $V\n";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 120) 	exit(1);
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 121) }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 122) 
e6299d2677e60 (Wu Zhangjin             2009-11-20 20:34:31 +0800 123) my ($arch, $endian, $bits, $objdump, $objcopy, $cc,
18c167fd6d8fe (Shaohua Li              2009-01-12 10:00:51 +0800 124)     $ld, $nm, $rm, $mv, $is_module, $inputfile) = @ARGV;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 125) 
25aac9dc7c8c7 (Shaohua Li              2009-01-09 11:29:40 +0800 126) # This file refers to mcount and shouldn't be ftraced, so lets' ignore it
bdd3b052c63b2 (Li Hong                 2009-10-28 13:03:32 +0800 127) if ($inputfile =~ m,kernel/trace/ftrace\.o$,) {
25aac9dc7c8c7 (Shaohua Li              2009-01-09 11:29:40 +0800 128)     exit(0);
25aac9dc7c8c7 (Shaohua Li              2009-01-09 11:29:40 +0800 129) }
25aac9dc7c8c7 (Shaohua Li              2009-01-09 11:29:40 +0800 130) 
34698bcbdf7b0 (Steven Rostedt          2008-10-23 09:32:58 -0400 131) # Acceptable sections to record.
34698bcbdf7b0 (Steven Rostedt          2008-10-23 09:32:58 -0400 132) my %text_sections = (
34698bcbdf7b0 (Steven Rostedt          2008-10-23 09:32:58 -0400 133)      ".text" => 1,
42c269c88dc14 (Steven Rostedt (VMware) 2017-03-03 16:15:39 -0500 134)      ".init.text" => 1,
1274a9c2e9165 (Steven Rostedt          2011-02-11 16:43:33 -0500 135)      ".ref.text" => 1,
d144d5ee6a265 (Liming Wang             2008-11-26 10:29:26 +0800 136)      ".sched.text" => 1,
d144d5ee6a265 (Liming Wang             2008-11-26 10:29:26 +0800 137)      ".spinlock.text" => 1,
a0343e8231840 (Frederic Weisbecker     2008-12-09 23:53:16 +0100 138)      ".irqentry.text" => 1,
e436fd61a8f62 (Dmitry Vyukov           2016-09-28 15:22:36 -0700 139)      ".softirqentry.text" => 1,
9f087e7612115 (Steven Rostedt          2011-04-06 14:10:22 -0400 140)      ".kprobes.text" => 1,
6727ad9e206cc (Chris Metcalf           2016-10-07 17:02:55 -0700 141)      ".cpuidle.text" => 1,
4d8289494a37e (Jiri Olsa               2009-10-13 16:33:54 -0400 142)      ".text.unlikely" => 1,
34698bcbdf7b0 (Steven Rostedt          2008-10-23 09:32:58 -0400 143) );
34698bcbdf7b0 (Steven Rostedt          2008-10-23 09:32:58 -0400 144) 
9c8e2f6d3d361 (Joe Lawrence            2018-11-20 15:19:18 -0500 145) # Acceptable section-prefixes to record.
9c8e2f6d3d361 (Joe Lawrence            2018-11-20 15:19:18 -0500 146) my %text_section_prefixes = (
9c8e2f6d3d361 (Joe Lawrence            2018-11-20 15:19:18 -0500 147)      ".text." => 1,
9c8e2f6d3d361 (Joe Lawrence            2018-11-20 15:19:18 -0500 148) );
9c8e2f6d3d361 (Joe Lawrence            2018-11-20 15:19:18 -0500 149) 
dfaa9e2c5707b (Wolfram Sang            2010-01-05 21:41:22 +0100 150) # Note: we are nice to C-programmers here, thus we skip the '||='-idiom.
dfaa9e2c5707b (Wolfram Sang            2010-01-05 21:41:22 +0100 151) $objdump = 'objdump' if (!$objdump);
dfaa9e2c5707b (Wolfram Sang            2010-01-05 21:41:22 +0100 152) $objcopy = 'objcopy' if (!$objcopy);
dfaa9e2c5707b (Wolfram Sang            2010-01-05 21:41:22 +0100 153) $cc = 'gcc' if (!$cc);
dfaa9e2c5707b (Wolfram Sang            2010-01-05 21:41:22 +0100 154) $ld = 'ld' if (!$ld);
dfaa9e2c5707b (Wolfram Sang            2010-01-05 21:41:22 +0100 155) $nm = 'nm' if (!$nm);
dfaa9e2c5707b (Wolfram Sang            2010-01-05 21:41:22 +0100 156) $rm = 'rm' if (!$rm);
dfaa9e2c5707b (Wolfram Sang            2010-01-05 21:41:22 +0100 157) $mv = 'mv' if (!$mv);
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 158) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 159) #print STDERR "running: $P '$arch' '$objdump' '$objcopy' '$cc' '$ld' " .
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 160) #    "'$nm' '$rm' '$mv' '$inputfile'\n";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 161) 
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 162) my %locals;		# List of local (static) functions
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 163) my %weak;		# List of weak functions
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 164) my %convert;		# List of local functions used that needs conversion
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 165) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 166) my $type;
306dcf47d28aa (Li Hong                 2009-10-28 13:06:19 +0800 167) my $local_regex;	# Match a local function (return function)
306dcf47d28aa (Li Hong                 2009-10-28 13:06:19 +0800 168) my $weak_regex; 	# Match a weak function (return function)
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 169) my $section_regex;	# Find the start of a section
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 170) my $function_regex;	# Find the name of a function
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 171) 			#    (return offset and func name)
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 172) my $mcount_regex;	# Find the call site to mcount (return offset)
465c6cca2668a (Mike Frysinger          2010-08-06 03:26:24 -0400 173) my $mcount_adjust;	# Address adjustment to mcount offset
3a3d04aed05ad (Matt Fleming            2008-11-20 21:49:52 +0000 174) my $alignment;		# The .align value to use for $mcount_section
e58918ab9d4cd (Jim Radford             2008-11-20 19:48:39 -0800 175) my $section_type;	# Section header plus possible alignment command
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 176) 
b82a4045f7962 (Jan Kiszka              2010-01-11 11:31:44 +0100 177) if ($arch =~ /(x86(_64)?)|(i386)/) {
dce9d18adde74 (Steven Rostedt          2008-10-23 09:32:57 -0400 178)     if ($bits == 64) {
dce9d18adde74 (Steven Rostedt          2008-10-23 09:32:57 -0400 179) 	$arch = "x86_64";
dce9d18adde74 (Steven Rostedt          2008-10-23 09:32:57 -0400 180)     } else {
dce9d18adde74 (Steven Rostedt          2008-10-23 09:32:57 -0400 181) 	$arch = "i386";
dce9d18adde74 (Steven Rostedt          2008-10-23 09:32:57 -0400 182)     }
dce9d18adde74 (Steven Rostedt          2008-10-23 09:32:57 -0400 183) }
dce9d18adde74 (Steven Rostedt          2008-10-23 09:32:57 -0400 184) 
c204f7264c7de (Steven Rostedt          2008-11-20 15:07:34 -0500 185) #
c204f7264c7de (Steven Rostedt          2008-11-20 15:07:34 -0500 186) # We base the defaults off of i386, the other archs may
c204f7264c7de (Steven Rostedt          2008-11-20 15:07:34 -0500 187) # feel free to change them in the below if statements.
c204f7264c7de (Steven Rostedt          2008-11-20 15:07:34 -0500 188) #
306dcf47d28aa (Li Hong                 2009-10-28 13:06:19 +0800 189) $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\S+)";
306dcf47d28aa (Li Hong                 2009-10-28 13:06:19 +0800 190) $weak_regex = "^[0-9a-fA-F]+\\s+([wW])\\s+(\\S+)";
c204f7264c7de (Steven Rostedt          2008-11-20 15:07:34 -0500 191) $section_regex = "Disassembly of section\\s+(\\S+):";
be358af1191b1 (Steven Rostedt          2021-10-14 14:35:07 -0400 192) $function_regex = "^([0-9a-fA-F]+)\\s+<([^^]*?)>:";
f02b625d03415 (Jamie Iles              2013-11-05 10:42:09 +0000 193) $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s(mcount|__fentry__)\$";
e58918ab9d4cd (Jim Radford             2008-11-20 19:48:39 -0800 194) $section_type = '@progbits';
465c6cca2668a (Mike Frysinger          2010-08-06 03:26:24 -0400 195) $mcount_adjust = 0;
c204f7264c7de (Steven Rostedt          2008-11-20 15:07:34 -0500 196) $type = ".long";
c204f7264c7de (Steven Rostedt          2008-11-20 15:07:34 -0500 197) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 198) if ($arch eq "x86_64") {
f02b625d03415 (Jamie Iles              2013-11-05 10:42:09 +0000 199)     $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s(mcount|__fentry__)([+-]0x[0-9a-zA-Z]+)?\$";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 200)     $type = ".quad";
7d5222a6afa4e (Matt Fleming            2008-11-07 13:26:25 +0000 201)     $alignment = 8;
521ccb5c4aece (Martin Schwidefsky      2011-05-10 10:10:41 +0200 202)     $mcount_adjust = -1;
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 203) 
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 204)     # force flags for this arch
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 205)     $ld .= " -m elf_x86_64";
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 206)     $objdump .= " -M x86-64";
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 207)     $objcopy .= " -O elf64-x86-64";
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 208)     $cc .= " -m64";
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 209) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 210) } elsif ($arch eq "i386") {
7d5222a6afa4e (Matt Fleming            2008-11-07 13:26:25 +0000 211)     $alignment = 4;
521ccb5c4aece (Martin Schwidefsky      2011-05-10 10:10:41 +0200 212)     $mcount_adjust = -1;
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 213) 
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 214)     # force flags for this arch
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 215)     $ld .= " -m elf_i386";
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 216)     $objdump .= " -M i386";
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 217)     $objcopy .= " -O elf32-i386";
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 218)     $cc .= " -m32";
d74fcd1e4e884 (Steven Rostedt          2008-08-15 11:40:24 -0400 219) 
dfd9f7abc0fb6 (Heiko Carstens          2009-06-12 10:26:44 +0200 220) } elsif ($arch eq "s390" && $bits == 64) {
e6d60b368b45b (Heiko Carstens          2015-01-09 13:08:28 +0100 221)     if ($cc =~ /-DCC_USING_HOTPATCH/) {
e6d60b368b45b (Heiko Carstens          2015-01-09 13:08:28 +0100 222) 	$mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*c0 04 00 00 00 00\\s*brcl\\s*0,[0-9a-f]+ <([^\+]*)>\$";
e6d60b368b45b (Heiko Carstens          2015-01-09 13:08:28 +0100 223) 	$mcount_adjust = 0;
e6d60b368b45b (Heiko Carstens          2015-01-09 13:08:28 +0100 224)     }
dfd9f7abc0fb6 (Heiko Carstens          2009-06-12 10:26:44 +0200 225)     $alignment = 8;
dfd9f7abc0fb6 (Heiko Carstens          2009-06-12 10:26:44 +0200 226)     $type = ".quad";
dfd9f7abc0fb6 (Heiko Carstens          2009-06-12 10:26:44 +0200 227)     $ld .= " -m elf64_s390";
dfd9f7abc0fb6 (Heiko Carstens          2009-06-12 10:26:44 +0200 228)     $cc .= " -m64";
dfd9f7abc0fb6 (Heiko Carstens          2009-06-12 10:26:44 +0200 229) 
0da85c09b44bf (Matt Fleming            2008-11-12 20:11:47 +0900 230) } elsif ($arch eq "sh") {
3a3d04aed05ad (Matt Fleming            2008-11-20 21:49:52 +0000 231)     $alignment = 2;
0da85c09b44bf (Matt Fleming            2008-11-12 20:11:47 +0900 232) 
0da85c09b44bf (Matt Fleming            2008-11-12 20:11:47 +0900 233)     # force flags for this arch
0da85c09b44bf (Matt Fleming            2008-11-12 20:11:47 +0900 234)     $ld .= " -m shlelf_linux";
93ca696376dd3 (Rong Chen               2021-02-12 20:52:41 -0800 235)     if ($endian eq "big") {
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 236) 	$objcopy .= " -O elf32-shbig-linux";
93ca696376dd3 (Rong Chen               2021-02-12 20:52:41 -0800 237)     } else {
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 238) 	$objcopy .= " -O elf32-sh-linux";
93ca696376dd3 (Rong Chen               2021-02-12 20:52:41 -0800 239)     }
0da85c09b44bf (Matt Fleming            2008-11-12 20:11:47 +0900 240) 
42e007d040015 (Steven Rostedt          2008-11-20 07:16:16 -0800 241) } elsif ($arch eq "powerpc") {
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 242)     my $ldemulation;
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 243) 
306dcf47d28aa (Li Hong                 2009-10-28 13:06:19 +0800 244)     $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\.?\\S+)";
2e50c4bef7751 (Ulrich Weigand          2016-01-12 23:14:22 +1100 245)     # See comment in the sparc64 section for why we use '\w'.
2e50c4bef7751 (Ulrich Weigand          2016-01-12 23:14:22 +1100 246)     $function_regex = "^([0-9a-fA-F]+)\\s+<(\\.?\\w*?)>:";
42e007d040015 (Steven Rostedt          2008-11-20 07:16:16 -0800 247)     $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s\\.?_mcount\$";
c204f7264c7de (Steven Rostedt          2008-11-20 15:07:34 -0500 248) 
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 249)     if ($endian eq "big") {
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 250) 	    $cc .= " -mbig-endian ";
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 251) 	    $ld .= " -EB ";
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 252) 	    $ldemulation = "ppc"
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 253)     } else {
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 254) 	    $cc .= " -mlittle-endian ";
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 255) 	    $ld .= " -EL ";
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 256) 	    $ldemulation = "lppc"
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 257)     }
42e007d040015 (Steven Rostedt          2008-11-20 07:16:16 -0800 258)     if ($bits == 64) {
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 259) 	$type = ".quad";
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 260) 	$cc .= " -m64 ";
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 261) 	$ld .= " -m elf64".$ldemulation." ";
1421dc6d48296 (Nicholas Piggin         2018-05-30 22:19:21 +1000 262)     } else {
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 263) 	$cc .= " -m32 ";
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 264) 	$ld .= " -m elf32".$ldemulation." ";
42e007d040015 (Steven Rostedt          2008-11-20 07:16:16 -0800 265)     }
42e007d040015 (Steven Rostedt          2008-11-20 07:16:16 -0800 266) 
e58918ab9d4cd (Jim Radford             2008-11-20 19:48:39 -0800 267) } elsif ($arch eq "arm") {
e58918ab9d4cd (Jim Radford             2008-11-20 19:48:39 -0800 268)     $alignment = 2;
e58918ab9d4cd (Jim Radford             2008-11-20 19:48:39 -0800 269)     $section_type = '%progbits';
72dc43a9eb123 (Rabin Vincent           2010-08-10 19:52:35 +0100 270)     $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_ARM_(CALL|PC24|THM_CALL)" .
3b6c223b1b97a (Rabin Vincent           2010-08-10 19:43:28 +0100 271) 			"\\s+(__gnu_mcount_nc|mcount)\$";
e58918ab9d4cd (Jim Radford             2008-11-20 19:48:39 -0800 272) 
af64d2aa872a1 (AKASHI Takahiro         2014-04-30 10:54:32 +0100 273) } elsif ($arch eq "arm64") {
af64d2aa872a1 (AKASHI Takahiro         2014-04-30 10:54:32 +0100 274)     $alignment = 3;
af64d2aa872a1 (AKASHI Takahiro         2014-04-30 10:54:32 +0100 275)     $section_type = '%progbits';
af64d2aa872a1 (AKASHI Takahiro         2014-04-30 10:54:32 +0100 276)     $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_AARCH64_CALL26\\s+_mcount\$";
af64d2aa872a1 (AKASHI Takahiro         2014-04-30 10:54:32 +0100 277)     $type = ".quad";
418071eb6adbf (Shaohua Li              2009-01-09 11:29:44 +0800 278) } elsif ($arch eq "ia64") {
418071eb6adbf (Shaohua Li              2009-01-09 11:29:44 +0800 279)     $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
418071eb6adbf (Shaohua Li              2009-01-09 11:29:44 +0800 280)     $type = "data8";
418071eb6adbf (Shaohua Li              2009-01-09 11:29:44 +0800 281) 
418071eb6adbf (Shaohua Li              2009-01-09 11:29:44 +0800 282)     if ($is_module eq "0") {
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 283) 	$cc .= " -mconstant-gp";
418071eb6adbf (Shaohua Li              2009-01-09 11:29:44 +0800 284)     }
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 285) } elsif ($arch eq "sparc64") {
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 286)     # In the objdump output there are giblets like:
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 287)     # 0000000000000000 <igmp_net_exit-0x18>:
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 288)     # As there's some data blobs that get emitted into the
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 289)     # text section before the first instructions and the first
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 290)     # real symbols.  We don't want to match that, so to combat
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 291)     # this we use '\w' so we'll match just plain symbol names,
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 292)     # and not those that also include hex offsets inside of the
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 293)     # '<>' brackets.  Actually the generic function_regex setting
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 294)     # could safely use this too.
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 295)     $function_regex = "^([0-9a-fA-F]+)\\s+<(\\w*?)>:";
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 296) 
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 297)     # Sparc64 calls '_mcount' instead of plain 'mcount'.
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 298)     $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 299) 
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 300)     $alignment = 8;
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 301)     $type = ".xword";
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 302)     $ld .= " -m elf64_sparc";
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 303)     $cc .= " -m64";
9be12f9b1c4fd (David S. Miller         2009-06-13 01:03:24 -0700 304)     $objcopy .= " -O elf64-sparc";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 305) } elsif ($arch eq "mips") {
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 306)     # To enable module support, we need to enable the -mlong-calls option
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 307)     # of gcc for module, after using this option, we can not get the real
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 308)     # offset of the calling to _mcount, but the offset of the lui
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 309)     # instruction or the addiu one. herein, we record the address of the
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 310)     # first one, and then we can replace this instruction by a branch
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 311)     # instruction to jump over the profiling function to filter the
08a7e621ff81d (Masahiro Yamada         2017-02-27 14:28:41 -0800 312)     # indicated functions, or switch back to the lui instruction to trace
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 313)     # them, which means dynamic tracing.
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 314)     #
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 315)     #       c:	3c030000 	lui	v1,0x0
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 316)     #			c: R_MIPS_HI16	_mcount
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 317)     #			c: R_MIPS_NONE	*ABS*
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 318)     #			c: R_MIPS_NONE	*ABS*
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 319)     #      10:	64630000 	daddiu	v1,v1,0
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 320)     #			10: R_MIPS_LO16	_mcount
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 321)     #			10: R_MIPS_NONE	*ABS*
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 322)     #			10: R_MIPS_NONE	*ABS*
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 323)     #      14:	03e0082d 	move	at,ra
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 324)     #      18:	0060f809 	jalr	v1
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 325)     #
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 326)     # for the kernel:
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 327)     #
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 328)     #     10:   03e0082d        move    at,ra
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 329)     #	  14:   0c000000        jal     0 <loongson_halt>
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 330)     #                    14: R_MIPS_26   _mcount
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 331)     #                    14: R_MIPS_NONE *ABS*
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 332)     #                    14: R_MIPS_NONE *ABS*
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 333)     #	 18:   00020021        nop
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 334)     if ($is_module eq "0") {
a484e54fae891 (David Daney             2010-07-09 14:52:05 -0700 335) 	    $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_26\\s+_mcount\$";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 336)     } else {
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 337) 	    $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 338)     }
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 339)     $objdump .= " -Melf-trad".$endian."mips ";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 340) 
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 341)     if ($endian eq "big") {
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 342) 	    $endian = " -EB ";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 343) 	    $ld .= " -melf".$bits."btsmip";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 344)     } else {
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 345) 	    $endian = " -EL ";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 346) 	    $ld .= " -melf".$bits."ltsmip";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 347)     }
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 348) 
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 349)     $cc .= " -mno-abicalls -fno-pic -mabi=" . $bits . $endian;
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 350)     $ld .= $endian;
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 351) 
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 352)     if ($bits == 64) {
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 353) 	    $function_regex =
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 354) 		"^([0-9a-fA-F]+)\\s+<(.|[^\$]L.*?|\$[^L].*?|[^\$][^L].*?)>:";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 355) 	    $type = ".dword";
538f19526e40c (Wu Zhangjin             2009-11-20 20:34:32 +0800 356)     }
7d241ff0567b9 (Michal Simek            2009-12-10 14:15:44 +0100 357) } elsif ($arch eq "microblaze") {
7d241ff0567b9 (Michal Simek            2009-12-10 14:15:44 +0100 358)     # Microblaze calls '_mcount' instead of plain 'mcount'.
7d241ff0567b9 (Michal Simek            2009-12-10 14:15:44 +0100 359)     $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
a1d2a6b4cee85 (Alan Kao                2018-02-13 13:13:16 +0800 360) } elsif ($arch eq "riscv") {
a1d2a6b4cee85 (Alan Kao                2018-02-13 13:13:16 +0800 361)     $function_regex = "^([0-9a-fA-F]+)\\s+<([^.0-9][0-9a-zA-Z_\\.]+)>:";
7ce0477150307 (Nathan Chancellor       2021-03-25 15:38:06 -0700 362)     $mcount_regex = "^\\s*([0-9a-fA-F]+):\\sR_RISCV_CALL(_PLT)?\\s_?mcount\$";
a1d2a6b4cee85 (Alan Kao                2018-02-13 13:13:16 +0800 363)     $type = ".quad";
a1d2a6b4cee85 (Alan Kao                2018-02-13 13:13:16 +0800 364)     $alignment = 2;
fbf58a52ac088 (Zong Li                 2018-08-15 10:57:16 +0800 365) } elsif ($arch eq "nds32") {
fbf58a52ac088 (Zong Li                 2018-08-15 10:57:16 +0800 366)     $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_NDS32_HI20_RELA\\s+_mcount\$";
fbf58a52ac088 (Zong Li                 2018-08-15 10:57:16 +0800 367)     $alignment = 2;
28bb030f93334 (Guo Ren                 2019-03-01 08:50:36 +0800 368) } elsif ($arch eq "csky") {
28bb030f93334 (Guo Ren                 2019-03-01 08:50:36 +0800 369)     $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_CKCORE_PCREL_JSR_IMM26BY2\\s+_mcount\$";
28bb030f93334 (Guo Ren                 2019-03-01 08:50:36 +0800 370)     $alignment = 2;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 371) } else {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 372)     die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 373) }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 374) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 375) my $text_found = 0;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 376) my $read_function = 0;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 377) my $opened = 0;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 378) my $mcount_section = "__mcount_loc";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 379) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 380) my $dirname;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 381) my $filename;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 382) my $prefix;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 383) my $ext;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 384) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 385) if ($inputfile =~ m,^(.*)/([^/]*)$,) {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 386)     $dirname = $1;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 387)     $filename = $2;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 388) } else {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 389)     $dirname = ".";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 390)     $filename = $inputfile;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 391) }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 392) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 393) if ($filename =~ m,^(.*)(\.\S),) {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 394)     $prefix = $1;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 395)     $ext = $2;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 396) } else {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 397)     $prefix = $filename;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 398)     $ext = "";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 399) }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 400) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 401) my $mcount_s = $dirname . "/.tmp_mc_" . $prefix . ".s";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 402) my $mcount_o = $dirname . "/.tmp_mc_" . $prefix . ".o";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 403) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 404) #
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 405) # Step 1: find all the local (static functions) and weak symbols.
306dcf47d28aa (Li Hong                 2009-10-28 13:06:19 +0800 406) #         't' is local, 'w/W' is weak
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 407) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 408) open (IN, "$nm $inputfile|") || die "error running $nm";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 409) while (<IN>) {
306dcf47d28aa (Li Hong                 2009-10-28 13:06:19 +0800 410)     if (/$local_regex/) {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 411) 	$locals{$1} = 1;
306dcf47d28aa (Li Hong                 2009-10-28 13:06:19 +0800 412)     } elsif (/$weak_regex/) {
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 413) 	$weak{$2} = $1;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 414)     }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 415) }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 416) close(IN);
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 417) 
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 418) my @offsets;		# Array of offsets of mcount callers
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 419) my $ref_func;		# reference function to use for offsets
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 420) my $offset = 0;		# offset of ref_func to section beginning
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 421) 
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 422) ##
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 423) # update_funcs - print out the current mcount callers
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 424) #
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 425) #  Go through the list of offsets to callers and write them to
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 426) #  the output file in a format that can be read by an assembler.
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 427) #
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 428) sub update_funcs
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 429) {
6092858c60f16 (Li Hong                 2009-10-28 13:07:03 +0800 430)     return unless ($ref_func and @offsets);
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 431) 
c4b8ac2c1aee1 (Li Hong                 2009-10-28 13:07:43 +0800 432)     # Sanity check on weak function. A weak function may be overwritten by
c4b8ac2c1aee1 (Li Hong                 2009-10-28 13:07:43 +0800 433)     # another function of the same name, making all these offsets incorrect.
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 434)     if (defined $weak{$ref_func}) {
c4b8ac2c1aee1 (Li Hong                 2009-10-28 13:07:43 +0800 435) 	die "$inputfile: ERROR: referencing weak function" .
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 436) 	    " $ref_func for mcount\n";
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 437)     }
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 438) 
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 439)     # is this function static? If so, note this fact.
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 440)     if (defined $locals{$ref_func}) {
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 441) 	$convert{$ref_func} = 1;
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 442)     }
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 443) 
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 444)     # Loop through all the mcount caller offsets and print a reference
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 445)     # to the caller based from the ref_func.
dc4f8845ee2ca (Wolfram Sang            2010-01-05 19:27:51 +0100 446)     if (!$opened) {
dc4f8845ee2ca (Wolfram Sang            2010-01-05 19:27:51 +0100 447) 	open(FILE, ">$mcount_s") || die "can't create $mcount_s\n";
dc4f8845ee2ca (Wolfram Sang            2010-01-05 19:27:51 +0100 448) 	$opened = 1;
dc4f8845ee2ca (Wolfram Sang            2010-01-05 19:27:51 +0100 449) 	print FILE "\t.section $mcount_section,\"a\",$section_type\n";
dc4f8845ee2ca (Wolfram Sang            2010-01-05 19:27:51 +0100 450) 	print FILE "\t.align $alignment\n" if (defined($alignment));
dc4f8845ee2ca (Wolfram Sang            2010-01-05 19:27:51 +0100 451)     }
dc4f8845ee2ca (Wolfram Sang            2010-01-05 19:27:51 +0100 452)     foreach my $cur_offset (@offsets) {
dc4f8845ee2ca (Wolfram Sang            2010-01-05 19:27:51 +0100 453) 	printf FILE "\t%s %s + %d\n", $type, $ref_func, $cur_offset - $offset;
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 454)     }
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 455) }
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 456) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 457) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 458) # Step 2: find the sections and mcount call sites
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 459) #
77a88274dc1a2 (Masahiro Yamada         2021-04-30 10:56:27 +0900 460) open(IN, "LC_ALL=C $objdump -hdr $inputfile|") || die "error running $objdump";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 461) 
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 462) my $text;
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 463) 
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 464) 
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 465) # read headers first
b43f70933e775 (Steven Rostedt          2009-01-16 23:18:31 -0500 466) my $read_headers = 1;
b43f70933e775 (Steven Rostedt          2009-01-16 23:18:31 -0500 467) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 468) while (<IN>) {
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 469) 
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 470)     if ($read_headers && /$mcount_section/) {
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 471) 	#
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 472) 	# Somehow the make process can execute this script on an
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 473) 	# object twice. If it does, we would duplicate the mcount
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 474) 	# section and it will cause the function tracer self test
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 475) 	# to fail. Check if the mcount section exists, and if it does,
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 476) 	# warn and exit.
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 477) 	#
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 478) 	print STDERR "ERROR: $mcount_section already in $inputfile\n" .
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 479) 	    "\tThis may be an indication that your build is corrupted.\n" .
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 480) 	    "\tDelete $inputfile and try again. If the same object file\n" .
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 481) 	    "\tstill causes an issue, then disable CONFIG_DYNAMIC_FTRACE.\n";
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 482) 	exit(-1);
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 483)     }
db24c7dcf42f7 (Li Hong                 2009-10-28 13:05:23 +0800 484) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 485)     # is it a section?
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 486)     if (/$section_regex/) {
b43f70933e775 (Steven Rostedt          2009-01-16 23:18:31 -0500 487) 	$read_headers = 0;
34698bcbdf7b0 (Steven Rostedt          2008-10-23 09:32:58 -0400 488) 
34698bcbdf7b0 (Steven Rostedt          2008-10-23 09:32:58 -0400 489) 	# Only record text sections that we know are safe
dfaa9e2c5707b (Wolfram Sang            2010-01-05 21:41:22 +0100 490) 	$read_function = defined($text_sections{$1});
9c8e2f6d3d361 (Joe Lawrence            2018-11-20 15:19:18 -0500 491) 	if (!$read_function) {
9c8e2f6d3d361 (Joe Lawrence            2018-11-20 15:19:18 -0500 492) 	    foreach my $prefix (keys %text_section_prefixes) {
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 493) 		if (substr($1, 0, length $prefix) eq $prefix) {
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 494) 		    $read_function = 1;
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 495) 		    last;
2cf3af7aa6df0 (Steven Rostedt (VMware) 2021-03-22 17:45:22 -0400 496) 		}
9c8e2f6d3d361 (Joe Lawrence            2018-11-20 15:19:18 -0500 497) 	    }
9c8e2f6d3d361 (Joe Lawrence            2018-11-20 15:19:18 -0500 498) 	}
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 499) 	# print out any recorded offsets
6092858c60f16 (Li Hong                 2009-10-28 13:07:03 +0800 500) 	update_funcs();
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 501) 
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 502) 	# reset all markers and arrays
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 503) 	$text_found = 0;
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 504) 	undef($ref_func);
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 505) 	undef(@offsets);
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 506) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 507)     # section found, now is this a start of a function?
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 508)     } elsif ($read_function && /$function_regex/) {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 509) 	$text_found = 1;
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 510) 	$text = $2;
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 511) 
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 512) 	# if this is either a local function or a weak function
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 513) 	# keep looking for functions that are global that
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 514) 	# we can use safely.
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 515) 	if (!defined($locals{$text}) && !defined($weak{$text})) {
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 516) 	    $ref_func = $text;
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 517) 	    $read_function = 0;
bd171d5ffc5cb (Matt Fleming            2009-07-23 17:16:15 +0100 518) 	    $offset = hex $1;
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 519) 	} else {
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 520) 	    # if we already have a function, and this is weak, skip it
3f6e968ef4e1d (Steven Rostedt          2009-08-05 22:00:14 -0400 521) 	    if (!defined($ref_func) && !defined($weak{$text}) &&
3f6e968ef4e1d (Steven Rostedt          2009-08-05 22:00:14 -0400 522) 		 # PPC64 can have symbols that start with .L and
3f6e968ef4e1d (Steven Rostedt          2009-08-05 22:00:14 -0400 523) 		 # gcc considers these special. Don't use them!
3f6e968ef4e1d (Steven Rostedt          2009-08-05 22:00:14 -0400 524) 		 $text !~ /^\.L/) {
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 525) 		$ref_func = $text;
bd171d5ffc5cb (Matt Fleming            2009-07-23 17:16:15 +0100 526) 		$offset = hex $1;
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 527) 	    }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 528) 	}
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 529)     }
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 530)     # is this a call site to mcount? If so, record it to print later
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 531)     if ($text_found && /$mcount_regex/) {
465c6cca2668a (Mike Frysinger          2010-08-06 03:26:24 -0400 532) 	push(@offsets, (hex $1) + $mcount_adjust);
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 533)     }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 534) }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 535) 
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 536) # dump out anymore offsets that may have been found
6092858c60f16 (Li Hong                 2009-10-28 13:07:03 +0800 537) update_funcs();
8feff1cacc29e (Steven Rostedt          2008-08-20 10:07:35 -0400 538) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 539) # If we did not find any mcount callers, we are done (do nothing).
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 540) if (!$opened) {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 541)     exit(0);
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 542) }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 543) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 544) close(FILE);
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 545) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 546) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 547) # Step 3: Compile the file that holds the list of call sites to mcount.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 548) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 549) `$cc -o $mcount_o -c $mcount_s`;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 550) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 551) my @converts = keys %convert;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 552) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 553) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 554) # Step 4: Do we have sections that started with local functions?
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 555) #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 556) if ($#converts >= 0) {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 557)     my $globallist = "";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 558)     my $locallist = "";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 559) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 560)     foreach my $con (@converts) {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 561) 	$globallist .= " --globalize-symbol $con";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 562) 	$locallist .= " --localize-symbol $con";
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 563)     }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 564) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 565)     my $globalobj = $dirname . "/.tmp_gl_" . $filename;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 566)     my $globalmix = $dirname . "/.tmp_mx_" . $filename;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 567) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 568)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 569)     # Step 5: set up each local function as a global
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 570)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 571)     `$objcopy $globallist $inputfile $globalobj`;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 572) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 573)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 574)     # Step 6: Link the global version to our list.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 575)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 576)     `$ld -r $globalobj $mcount_o -o $globalmix`;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 577) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 578)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 579)     # Step 7: Convert the local functions back into local symbols
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 580)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 581)     `$objcopy $locallist $globalmix $inputfile`;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 582) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 583)     # Remove the temp files
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 584)     `$rm $globalobj $globalmix`;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 585) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 586) } else {
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 587) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 588)     my $mix = $dirname . "/.tmp_mx_" . $filename;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 589) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 590)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 591)     # Step 8: Link the object with our list of call sites object.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 592)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 593)     `$ld -r $inputfile $mcount_o -o $mix`;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 594) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 595)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 596)     # Step 9: Move the result back to the original object.
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 597)     #
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 598)     `$mv $mix $inputfile`;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 599) }
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 600) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 601) # Clean up the temp files
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 602) `$rm $mcount_o $mcount_s`;
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 603) 
8da3821ba5634 (Steven Rostedt          2008-08-14 15:45:07 -0400 604) exit(0);
b700fc3a63f16 (Steven Rostedt (VMware) 2021-03-22 17:47:37 -0400 605) 
b700fc3a63f16 (Steven Rostedt (VMware) 2021-03-22 17:47:37 -0400 606) # vim: softtabstop=4