[PATCH 02/11] ftrace: dynamic ftrace process only text section

Steven Rostedt
2008-10-22T18:55:11Z

[-- Attachment #1: ftrace-record-only-text.patch --]
[-- Type: text/plain, Size: 2198 bytes --]

The text section stays in memory without ever leaving. With the exception
of modules, but modules know how to handle that case. With the dynamic
ftrace tracer, we need to make sure that it does not try to modify code
that no longer exists. The only safe section is .text.

This patch changes the recordmcount script to only record the mcount calls
in the .text sections.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
scripts/recordmcount.pl | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

Index: linux-compile.git/scripts/recordmcount.pl
===================================================================
--- linux-compile.git.orig/scripts/recordmcount.pl 2008-10-22 11:45:59.000000000 -0400
+++ linux-compile.git/scripts/recordmcount.pl 2008-10-22 11:46:33.000000000 -0400
@@ -109,6 +109,11 @@ if ($#ARGV < 6) {
my ($arch, $bits, $objdump, $objcopy, $cc,
$ld, $nm, $rm, $mv, $inputfile) = @ARGV;

+# Acceptible sections to record.
+my %text_sections = (
+ ".text" => 1,
+);
+
$objdump = "objdump" if ((length $objdump) == 0);
$objcopy = "objcopy" if ((length $objcopy) == 0);
$cc = "gcc" if ((length $cc) == 0);
@@ -139,7 +144,7 @@ if ($arch eq "x86") {
}

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";
@@ -151,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";
@@ -298,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);

--