This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix for hardcoded symbol "_stext"


Hi all,

here is a draft for the problem on the hardcoded symbol "_stext".
It replaces the string by a macro and defines it in a headerfile accessible for runtime and compilation components.


greetings
Alex
>From 8e992fadbba06b0bba6d369bfac25da0022e98c2 Mon Sep 17 00:00:00 2001
From: Alexander Lochmann <alexander.lochmann@tu-dortmund.de>
Date: Wed, 26 Sep 2012 21:29:05 +0200
Subject: [PATCH] Replaced all hardcoded _stext by marco KERNEL_RELOC_SYMBOL
 and placed it's own headerfile

---
 dwflpp.cxx                         |    3 ++-
 runtime/sym.c                      |    5 +++--
 runtime/transport/symbols.c        |   13 +++++++------
 runtime/transport/transport_msgs.h |    2 +-
 staprun/staprun.c                  |    9 ++-------
 tapsets.cxx                        |    7 ++++---
 translate.cxx                      |   15 ++++++++-------
 7 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/dwflpp.cxx b/dwflpp.cxx
index 5e27577..68cf61f 100644
--- a/dwflpp.cxx
+++ b/dwflpp.cxx
@@ -23,6 +23,7 @@
 #include "hash.h"
 #include "rpm_finder.h"
 #include "setupdwfl.h"
+#include "runtime/k_syms.h"
 
 #include <cstdlib>
 #include <algorithm>
@@ -2116,7 +2117,7 @@ dwflpp::emit_address (struct obstack *pool, Dwarf_Addr address)
           // elfutils' way of telling us that this is a relocatable kernel address, which we
           // need to treat the same way here as dwarf_query::add_probe_point does: _stext.
           address -= sess.sym_stext;
-          secname = "_stext";
+          secname = KERNEL_RELOC_SYMBOL;
           // Note we "cache" the result here through a static because the
           // kernel will never move after being loaded (unlike modules and
           // user-space dynamic share libraries).
diff --git a/runtime/sym.c b/runtime/sym.c
index 4fce3b7..2d66357 100644
--- a/runtime/sym.c
+++ b/runtime/sym.c
@@ -15,6 +15,7 @@
 #include "sym.h"
 #include "vma.c"
 #include "stp_string.c"
+#include "k_syms.h"
 #include <asm/uaccess.h>
 
 #ifdef STAPCONF_PROBE_KERNEL
@@ -342,9 +343,9 @@ static int _stp_module_check(void)
           /* notes end address */
           if (!strcmp(m->name, "kernel")) {
               notes_addr = _stp_kmodule_relocate("kernel",
-                  "_stext", m->build_id_offset);
+                  KERNEL_RELOC_SYMBOL, m->build_id_offset);
               base_addr = _stp_kmodule_relocate("kernel",
-                  "_stext", 0);
+                  KERNEL_RELOC_SYMBOL, 0);
           } else {
               notes_addr = m->notes_sect + m->build_id_offset;
               base_addr = m->notes_sect;
diff --git a/runtime/transport/symbols.c b/runtime/transport/symbols.c
index 9930bde..63f3c18 100644
--- a/runtime/transport/symbols.c
+++ b/runtime/transport/symbols.c
@@ -12,6 +12,7 @@
 #ifndef _STP_SYMBOLS_C_
 #define _STP_SYMBOLS_C_
 #include "../sym.h"
+#include "../k_syms.h"
 
 
 static void systemtap_module_refresh (void);
@@ -59,19 +60,19 @@ static void _stp_do_relocation(const char __user *buf, size_t count)
 
   /* Detect actual kernel load address. */
   if (!strcmp ("kernel", msg.module)
-      && !strcmp ("_stext", msg.reloc)) {
+      && !strcmp (KERNEL_RELOC_SYMBOL, msg.reloc)) {
       if (msg.address == 0) {
       #ifdef CONFIG_KALLSYMS
-	    dbug_sym(1,"asking kernel for _stext load address");
-	    msg.address = kallsyms_lookup_name("_stext");
+	    dbug_sym(1,"asking kernel for "KERNEL_RELOC_SYMBOL" load address");
+	    msg.address = kallsyms_lookup_name(KERNEL_RELOC_SYMBOL);
 	    if (msg.address == 0) {
-	    _stp_warn("kallsyms_lookup_name() does not returned a suitable load address for _stext");
+	    _stp_warn("kallsyms_lookup_name() does not returned a suitable load address for "KERNEL_RELOC_SYMBOL);
 	} else {
-	    dbug_sym(1, "found kernel _stext load address: 0x%lx\n",
+	    dbug_sym(1, "found kernel "KERNEL_RELOC_SYMBOL" load address: 0x%lx\n",
              (unsigned long) msg.address);
 	}
      #else
-	_stp_warn("No load address for symbol _stext given. Stap will not be able to relocate the probe points!");
+	_stp_warn("No load address for symbol "KERNEL_RELOC_SYMBOL" given. Stap will not be able to relocate the probe points!");
      #endif
     }
     if (_stp_kretprobe_trampoline != (unsigned long) -1)
diff --git a/runtime/transport/transport_msgs.h b/runtime/transport/transport_msgs.h
index d1ba20f..6fd12b1 100644
--- a/runtime/transport/transport_msgs.h
+++ b/runtime/transport/transport_msgs.h
@@ -62,7 +62,7 @@ enum
 	    into the module).  */
 	STP_READY,
 	/** Send by staprun at startup to notify module of where the kernel
-	    (_stext) and all other modules are loaded.  */
+	    (KERNEL_RELOC_SYMBOL) and all other modules are loaded.  */
         STP_RELOCATION,
 	/** Never used.  deprecated STP_TRANSPORT_VERSION == 1 **/
 	STP_BUF_INFO,
diff --git a/staprun/staprun.c b/staprun/staprun.c
index 5508393..05aecd9 100644
--- a/staprun/staprun.c
+++ b/staprun/staprun.c
@@ -23,6 +23,7 @@
 #define _BSD_SOURCE
 #include "staprun.h"
 #include "../privilege.h"
+#include "../runtime/k_syms.h"
 #include <string.h>
 #include <sys/uio.h>
 #include <glob.h>
@@ -473,12 +474,6 @@ int send_a_relocation (const char* module, const char* reloc, unsigned long long
 }
 
 
-#ifdef __powerpc64__
-#define KERNEL_RELOC_SYMBOL ".__start"
-#else
-#define KERNEL_RELOC_SYMBOL "_stext"
-#endif
-
 int send_relocation_kernel ()
 {
   FILE* kallsyms;
@@ -510,7 +505,7 @@ int send_relocation_kernel ()
 		  && !strcmp(line + pos, KERNEL_RELOC_SYMBOL "\n"))
                 {
                   /* NB: even on ppc, we use the _stext relocation name. */
-                  rc = send_a_relocation ("kernel", "_stext", address);
+                  rc = send_a_relocation ("kernel", KERNEL_RELOC_SYMBOL, address);
 		  if (rc != 0)
 		    break;
 
diff --git a/tapsets.cxx b/tapsets.cxx
index 65e6974..0ebe33e 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -22,6 +22,7 @@
 #include "hash.h"
 #include "dwflpp.h"
 #include "setupdwfl.h"
+#include "runtime/k_syms.h"
 #include <gelf.h>
 
 #include "sdt_types.h"
@@ -1206,7 +1207,7 @@ dwarf_query::add_probe_point(const string& dw_funcname,
     {
       // PR 4224: adapt to relocatable kernel by subtracting the _stext address here.
       reloc_addr = addr - sess.sym_stext;
-      reloc_section = "_stext"; // a message to runtime's _stp_module_relocate
+      reloc_section = KERNEL_RELOC_SYMBOL; // a message to runtime's _stp_module_relocate
     }
 
   if (! bad)
@@ -2037,7 +2038,7 @@ query_module (Dwfl_Module *mod,
           if (! q->sess.sym_kprobes_text_end)
             q->sess.sym_kprobes_text_end = lookup_symbol_address (mod, "__kprobes_text_end");
           if (! q->sess.sym_stext)
-            q->sess.sym_stext = lookup_symbol_address (mod, "_stext");
+            q->sess.sym_stext = lookup_symbol_address (mod, KERNEL_RELOC_SYMBOL);
         }
 
       // We either have a wildcard or an unresolved library
@@ -7093,7 +7094,7 @@ module_info::get_symtab(dwarf_query *q)
                 sym_table->lookup_symbol_address("__kprobes_text_start");
               sess.sym_kprobes_text_end =
                 sym_table->lookup_symbol_address("__kprobes_text_end");
-              sess.sym_stext = sym_table->lookup_symbol_address("_stext");
+              sess.sym_stext = sym_table->lookup_symbol_address(KERNEL_RELOC_SYMBOL);
             }
         }
     }
diff --git a/translate.cxx b/translate.cxx
index dd09d44..23eb9da 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -19,6 +19,7 @@
 #include "setupdwfl.h"
 #include "task_finder.h"
 #include "dwflpp.h"
+#include "runtime/k_syms.h"
 
 #include <cstdlib>
 #include <iostream>
@@ -5617,7 +5618,7 @@ dump_section_list (Dwfl_Module *m,
     {
       // kernel or shared library (ET_DYN).
       string secname;
-      secname = (modname == "kernel") ? "_stext" : ".dynamic";
+      secname = (modname == "kernel") ? KERNEL_RELOC_SYMBOL : ".dynamic";
       unsigned size = end - start;
       c->seclist.push_back (make_pair (secname, size));
       return DWARF_CB_OK;
@@ -5727,7 +5728,7 @@ dump_symbol_tables (Dwfl_Module *m,
 	      // there may have been no kernel probes set.  We could
 	      // use tapsets.cxx:lookup_symbol_address(), but then
 	      // we're already iterating over the same data here...
-	      if (! strcmp(name, "_stext"))
+	      if (! strcmp(name, KERNEL_RELOC_SYMBOL))
 		{
 		  int ki;
 		  extra_offset = sym_addr;
@@ -5736,7 +5737,7 @@ dump_symbol_tables (Dwfl_Module *m,
 			       ki >= 0);
 
 		  if (c->session.verbose > 2)
-		    clog << _F("Found kernel _stext extra offset %#" PRIx64,
+		    clog << _F("Found kernel "KERNEL_RELOC_SYMBOL" extra offset %#" PRIx64,
 			       extra_offset) << endl;
 
 		  if (! c->session.need_symbols
@@ -5836,7 +5837,7 @@ dump_symbol_tables (Dwfl_Module *m,
 		      && sym.st_shndx == SHN_ABS)
 		    continue;
 
-                  secname = "_stext";
+                  secname = KERNEL_RELOC_SYMBOL;
                   // NB: don't subtract session.sym_stext, which could be
                   // inconveniently NULL. Instead, sym_addr will get
                   // compensated later via extra_offset.
@@ -6017,7 +6018,7 @@ dump_unwindsym_cxt (Dwfl_Module *m,
 
       string secname = c->seclist[secidx].first;
       Dwarf_Addr extra_offset;
-      extra_offset = (secname == "_stext") ? c->stext_offset : 0;
+      extra_offset = (secname == KERNEL_RELOC_SYMBOL) ? c->stext_offset : 0;
 
       // Only include symbols if they will be used
       if (c->session.need_symbols)
@@ -6043,7 +6044,7 @@ dump_unwindsym_cxt (Dwfl_Module *m,
 
       /* For now output debug_frame index only in "magic" sections. */
       if (secname == ".dynamic" || secname == ".absolute"
-	  || secname == ".text" || secname == "_stext")
+	  || secname == ".text" || secname == KERNEL_RELOC_SYMBOL)
 	{
 	  if (debug_frame_hdr != NULL && debug_frame_hdr_len > 0)
 	    {
@@ -6090,7 +6091,7 @@ dump_unwindsym_cxt (Dwfl_Module *m,
       /* For now output debug_frame index only in "magic" sections. */
       string secname = c->seclist[secidx].first;
       if (debug_frame_hdr && (secname == ".dynamic" || secname == ".absolute"
-			      || secname == ".text" || secname == "_stext"))
+			      || secname == ".text" || secname == KERNEL_RELOC_SYMBOL))
 	{
 	  c->output << "#if defined(STP_USE_DWARF_UNWINDER)"
 		    << " && defined(STP_NEED_UNWIND_DATA)\n";
-- 
1.7.9.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]