[PATCH] operf: prefer _stext over _text as the kernel address range start

Michael Petlan <[email protected]>
Newsgroups gmane.linux.oprofile
Message-ID <alpine.LRH.2.20.1603311910410.7107@Rudolf-RHEL-7>
In newer kernels, _stext is the right pseudo-symbol for marking the
start address of the kernel address range. The older _text symbol is
rather architecture specific.

With this patch, the _stext symbol is preferred (if found). In case
_stext is not there (an older kernel), _text is accepted like before.
---
  pe_profiling/operf.cpp | 19 ++++++++++++++++++-
  1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/pe_profiling/operf.cpp b/pe_profiling/operf.cpp
index 5585b34..06a0ea3 100644
--- a/pe_profiling/operf.cpp
+++ b/pe_profiling/operf.cpp
@@ -87,8 +87,9 @@ bool track_new_forks;


  #define DEFAULT_OPERF_OUTFILE "operf.data"
-#define KERN_ADDR_SPACE_START_SYMBOL  "_text"
+#define KERN_ADDR_SPACE_START_SYMBOL  "_stext"
  #define KERN_ADDR_SPACE_END_SYMBOL    "_etext"
+#define KERN_ADDR_SPACE_START_SYMBOL_OBSOLETE  "_text"

  static operf_record * operfRecord = NULL;
  static char * app_name_SAVE = NULL;
@@ -1141,6 +1142,22 @@ static bool _process_kallsyms(void)
  		iss >> type;
  		iss >> name;

+		/* accept _text as the start symbol only in case there is no _stext
+		 * because _stext has higher priority
+		*/
+		if (start_addr_str.empty()) {
+			if (strncmp(name.c_str(), KERN_ADDR_SPACE_START_SYMBOL_OBSOLETE,
+					strlen(name.c_str())) == 0) {
+				/* found the symbol for the start of the kernel
+				 * address space.
+				*/
+				start_addr_str.assign(address_str);
+			}
+		}
+
+		/* if _stext is found, it will overwrite the _text if it has been
+		 * already found
+		*/
  		if (strncmp(name.c_str(), KERN_ADDR_SPACE_START_SYMBOL,
  			    strlen(name.c_str())) == 0) {
  			/* found the symbol for the start of the kernel
-- 
1.8.3.1


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.