Skip to content

Commit 63c1a97

Browse files
joe-lawrencegregkh
authored andcommitted
scripts/recordmcount.{c,pl}: support -ffunction-sections .text.* section names
commit 9c8e2f6d3d361439cc6744a094f1c15681b55269 upstream. When building with -ffunction-sections, the compiler will place each function into its own ELF section, prefixed with ".text". For example, a simple test module with functions test_module_do_work() and test_module_wq_func(): % objdump --section-headers test_module.o | awk '/\.text/{print $2}' .text .text.test_module_do_work .text.test_module_wq_func .init.text .exit.text Adjust the recordmcount scripts to look for ".text" as a section name prefix. This will ensure that those functions will be included in the __mcount_loc relocations: % objdump --reloc --section __mcount_loc test_module.o OFFSET TYPE VALUE 0000000000000000 R_X86_64_64 .text.test_module_do_work 0000000000000008 R_X86_64_64 .text.test_module_wq_func 0000000000000010 R_X86_64_64 .init.text Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Joe Lawrence <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]> Cc: Manoj Gupta <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 18968aa commit 63c1a97

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: scripts/recordmcount.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static uint32_t (*w2)(uint16_t);
415415
static int
416416
is_mcounted_section_name(char const *const txtname)
417417
{
418-
return strcmp(".text", txtname) == 0 ||
418+
return strncmp(".text", txtname, 5) == 0 ||
419419
strcmp(".init.text", txtname) == 0 ||
420420
strcmp(".ref.text", txtname) == 0 ||
421421
strcmp(".sched.text", txtname) == 0 ||

Diff for: scripts/recordmcount.pl

+13
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
".text.unlikely" => 1,
143143
);
144144

145+
# Acceptable section-prefixes to record.
146+
my %text_section_prefixes = (
147+
".text." => 1,
148+
);
149+
145150
# Note: we are nice to C-programmers here, thus we skip the '||='-idiom.
146151
$objdump = 'objdump' if (!$objdump);
147152
$objcopy = 'objcopy' if (!$objcopy);
@@ -507,6 +512,14 @@ sub update_funcs
507512

508513
# Only record text sections that we know are safe
509514
$read_function = defined($text_sections{$1});
515+
if (!$read_function) {
516+
foreach my $prefix (keys %text_section_prefixes) {
517+
if (substr($1, 0, length $prefix) eq $prefix) {
518+
$read_function = 1;
519+
last;
520+
}
521+
}
522+
}
510523
# print out any recorded offsets
511524
update_funcs();
512525

0 commit comments

Comments
 (0)