Lines Matching +full:0 +full:- +full:9 +full:a +full:- +full:f

2 # SPDX-License-Identifier: GPL-2.0-only
5 # recordmcount.pl - makes a section called __mcount_loc that holds
9 # What we want to end up with this is that each object file will have a
22 # functions in a section that has a call site to mcount, will have the
30 # The trick is to change the call offset referring the start of a section to
31 # referring a function symbol in this section. During the link step, 'ld' will
40 # call mcount (offset: 0x10)
44 # func2: (offset: 0x20)
50 # call mcount (offset: 0x30)
54 # offset from .sched.text. If we choose global symbol func2 as a reference and
58 # .quad func2 - 0x10
59 # .quad func2 + 0x10
66 # in this section. In such a case we have to select a local one. E.g. func1:
71 # call mcount (offset: 0x10)
76 # call mcount (offset: 0x20)
83 # an undefined reference to func1 or a wrong reference to another global
87 # a way to make tmp.o reference the local objects of the original object
89 # into a global symbol before linking tmp.o. Then after we link tmp.o
90 # we will only have a single symbol for func1 that is global.
91 # We can convert func1 back into a local symbol and we are done.
106 # 9) Move the result back to the original object.
112 my $P = $0;
128 exit(0);
145 # Acceptable section-prefixes to record.
150 # Note: we are nice to C-programmers here, thus we skip the '||='-idiom.
167 my $local_regex; # Match a local function (return function)
168 my $weak_regex; # Match a weak function (return function)
169 my $section_regex; # Find the start of a section
170 my $function_regex; # Find the name of a function
176 my $can_use_local = 0; # If we can use local function references
181 $print_warning = 0 if ( -f $quiet_recordmcount);
184 # check_objcopy - whether objcopy supports --globalize-symbols
186 # --globalize-symbols came out in 2.17, we must test the version
191 open (IN, "$objcopy --version |") or die "error running $objcopy";
222 $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\S+)";
223 $weak_regex = "^[0-9a-fA-F]+\\s+([wW])\\s+(\\S+)";
225 $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:";
226 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s(mcount|__fentry__)\$";
228 $mcount_adjust = 0;
232 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s(mcount|__fentry__)([+-]0x[0-9a-zA-Z]+)?\$";
235 $mcount_adjust = -1;
238 $ld .= " -m elf_x86_64";
239 $objdump .= " -M x86-64";
240 $objcopy .= " -O elf64-x86-64";
241 $cc .= " -m64";
245 $mcount_adjust = -1;
248 $ld .= " -m elf_i386";
249 $objdump .= " -M i386";
250 $objcopy .= " -O elf32-i386";
251 $cc .= " -m32";
254 if ($cc =~ /-DCC_USING_HOTPATCH/) {
255 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*c0 04 00 00 00 00\\s*brcl\\s*0,[0-9a-f]+ <([^\+]*)>\$";
256 $mcount_adjust = 0;
258 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_390_(PC|PLT)32DBL\\s+_mcount\\+0x2\$";
259 $mcount_adjust = -14;
263 $ld .= " -m elf64_s390";
264 $cc .= " -m64";
270 $ld .= " -m shlelf_linux";
271 $objcopy .= " -O elf32-sh-linux";
276 $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\.?\\S+)";
278 $function_regex = "^([0-9a-fA-F]+)\\s+<(\\.?\\w*?)>:";
279 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s\\.?_mcount\$";
282 $cc .= " -mbig-endian ";
283 $ld .= " -EB ";
286 $cc .= " -mlittle-endian ";
287 $ld .= " -EL ";
292 $cc .= " -m64 ";
293 $ld .= " -m elf64".$ldemulation." ";
295 $cc .= " -m32 ";
296 $ld .= " -m elf32".$ldemulation." ";
302 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_ARM_(CALL|PC24|THM_CALL)" .
308 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_AARCH64_CALL26\\s+_mcount\$";
311 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
314 if ($is_module eq "0") {
315 $cc .= " -mconstant-gp";
319 # 0000000000000000 <igmp_net_exit-0x18>:
327 $function_regex = "^([0-9a-fA-F]+)\\s+<(\\w*?)>:";
330 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
334 $ld .= " -m elf64_sparc";
335 $cc .= " -m64";
336 $objcopy .= " -O elf64-sparc";
338 # To enable module support, we need to enable the -mlong-calls option
342 # first one, and then we can replace this instruction by a branch
347 # c: 3c030000 lui v1,0x0
351 # 10: 64630000 daddiu v1,v1,0
361 # 14: 0c000000 jal 0 <loongson_halt>
366 if ($is_module eq "0") {
367 $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_26\\s+_mcount\$";
369 $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$";
371 $objdump .= " -Melf-trad".$endian."mips ";
374 $endian = " -EB ";
375 $ld .= " -melf".$bits."btsmip";
377 $endian = " -EL ";
378 $ld .= " -melf".$bits."ltsmip";
381 $cc .= " -mno-abicalls -fno-pic -mabi=" . $bits . $endian;
386 "^([0-9a-fA-F]+)\\s+<(.|[^\$]L.*?|\$[^L].*?|[^\$][^L].*?)>:";
391 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
393 $function_regex = "^([0-9a-fA-F]+)\\s+<([^.0-9][0-9a-zA-Z_\\.]+)>:";
394 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\sR_RISCV_CALL\\s_mcount\$";
398 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_NDS32_HI20_RELA\\s+_mcount\$";
401 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_CKCORE_PCREL_JSR_IMM26BY2\\s+_mcount\$";
407 my $text_found = 0;
408 my $read_function = 0;
409 my $opened = 0;
454 my $offset = 0; # offset of ref_func to section beginning
457 # update_funcs - print out the current mcount callers
460 # the output file in a format that can be read by an assembler.
466 # Sanity check on weak function. A weak function may be overwritten by
476 # only use locals if objcopy supports globalize-symbols
483 # Loop through all the mcount caller offsets and print a reference
488 print FILE "\t.section $mcount_section,\"a\",$section_type\n";
492 printf FILE "\t%s %s + %d\n", $type, $ref_func, $cur_offset - $offset;
499 open(IN, "LANG=C $objdump -hdr $inputfile|") || die "error running $objdump";
521 exit(-1);
524 # is it a section?
526 $read_headers = 0;
532 if (substr($1, 0, length $prefix) eq $prefix) {
542 $text_found = 0;
546 # section found, now is this a start of a function?
551 # if this is either a local function or a weak function
556 $read_function = 0;
559 # if we already have a function, and this is weak, skip it
569 # is this a call site to mcount? If so, record it to print later
580 exit(0);
588 `$cc -o $mcount_o -c $mcount_s`;
595 if ($#converts >= 0) {
600 $globallist .= " --globalize-symbol $con";
601 $locallist .= " --localize-symbol $con";
608 # Step 5: set up each local function as a global
615 `$ld -r $globalobj $mcount_o -o $globalmix`;
632 `$ld -r $inputfile $mcount_o -o $mix`;
635 # Step 9: Move the result back to the original object.
643 exit(0);