Advertisement
yichun

patch for stap-symbols.h CU

Dec 18th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.52 KB | None | 0 0
  1. diff --git a/buildrun.cxx b/buildrun.cxx
  2. index 14043adbb..629a6d5d0 100644
  3. --- a/buildrun.cxx
  4. +++ b/buildrun.cxx
  5. @@ -607,7 +607,9 @@ compile_pass (systemtap_session& s)
  6.        objname[objname.size()-1] = 'o'; // now objname
  7.        o << " " + objname;
  8.      }
  9. -  o << endl;
  10. +  o << " stap_symbols.o" << endl;
  11. +
  12. +  o << s.tmpdir << "/stap_symbols.o: $(STAPCONF_HEADER)" << endl;
  13.  
  14.    // add all stapconf dependencies
  15.    string translated = s.translated_source;
  16. diff --git a/runtime/sym.h b/runtime/sym.h
  17. index 990500083..92075814f 100644
  18. --- a/runtime/sym.h
  19. +++ b/runtime/sym.h
  20. @@ -133,13 +133,13 @@ struct _stp_module {
  21.  };
  22.  
  23.  /* Defined by translator-generated stap-symbols.h. */
  24. -static struct _stp_module *_stp_modules [];
  25. -static const unsigned _stp_num_modules;
  26. +extern struct _stp_module *_stp_modules [];
  27. +extern const unsigned _stp_num_modules;
  28.  
  29.  /* Used in the unwinder to special case unwinding through kretprobes. */
  30.  /* Initialized through translator (stap-symbols.h) relative to kernel */
  31.  /* load address, fixup by transport symbols _stp_do_relocation */
  32. -static unsigned long _stp_kretprobe_trampoline;
  33. +extern unsigned long _stp_kretprobe_trampoline;
  34.  
  35.  static unsigned long _stp_kmodule_relocate (const char *module,
  36.                         const char *section,
  37. @@ -154,10 +154,10 @@ static void _stp_kmodule_update_address(const char* module,
  38.  
  39.  #if (defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)) \
  40.      || defined(STP_NEED_LINE_DATA)
  41. -static struct _stp_module _stp_module_self;
  42. -static struct _stp_section _stp_module_self_sections[];
  43. -static struct _stp_symbol _stp_module_self_symbols_0[];
  44. -static struct _stp_symbol _stp_module_self_symbols_1[];
  45. +extern struct _stp_module _stp_module_self;
  46. +extern struct _stp_section _stp_module_self_sections[];
  47. +extern struct _stp_symbol _stp_module_self_symbols_0[];
  48. +extern struct _stp_symbol _stp_module_self_symbols_1[];
  49.  #endif /* defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)
  50.            || defined(STP_NEED_LINE_DATA) */
  51.  #endif /* _STP_SYM_H_ */
  52. diff --git a/translate.cxx b/translate.cxx
  53. index f5a73eca9..cabcad55a 100644
  54. --- a/translate.cxx
  55. +++ b/translate.cxx
  56. @@ -7610,12 +7610,15 @@ prepare_symbol_data (systemtap_session& s)
  57.  void
  58.  emit_symbol_data (systemtap_session& s)
  59.  {
  60. -  string symfile = "stap-symbols.h";
  61. -
  62. -  s.op->newline() << "#include " << lex_cast_qstring (symfile);
  63. +  string symfile = "stap_symbols.c";
  64.  
  65.    ofstream kallsyms_out ((s.tmpdir + "/" + symfile).c_str());
  66.  
  67. +  kallsyms_out << "#include <linux/module.h>\n"
  68. +    "#include <linux/kernel.h>\n"
  69. +    "#include <sym.h>\n"
  70. +    "#include \"stap_common.h\"\n";
  71. +
  72.    vector<pair<string,unsigned> > seclist;
  73.    map<unsigned, addrmap_t> addrmap;
  74.    unwindsym_dump_context ctx = { s, kallsyms_out,
  75. @@ -7712,13 +7715,13 @@ void
  76.  self_unwind_declarations(unwindsym_dump_context *ctx)
  77.  {
  78.    ctx->output << "static uint8_t _stp_module_self_eh_frame [] = {0,};\n";
  79. -  ctx->output << "static struct _stp_symbol _stp_module_self_symbols_0[] = {{0},};\n";
  80. -  ctx->output << "static struct _stp_symbol _stp_module_self_symbols_1[] = {{0},};\n";
  81. -  ctx->output << "static struct _stp_section _stp_module_self_sections[] = {\n";
  82. +  ctx->output << "struct _stp_symbol _stp_module_self_symbols_0[] = {{0},};\n";
  83. +  ctx->output << "struct _stp_symbol _stp_module_self_symbols_1[] = {{0},};\n";
  84. +  ctx->output << "struct _stp_section _stp_module_self_sections[] = {\n";
  85.    ctx->output << "{.name = \".symtab\", .symbols = _stp_module_self_symbols_0, .num_symbols = 0},\n";
  86.    ctx->output << "{.name = \".text\", .symbols = _stp_module_self_symbols_1, .num_symbols = 0},\n";
  87.    ctx->output << "};\n";
  88. -  ctx->output << "static struct _stp_module _stp_module_self = {\n";
  89. +  ctx->output << "struct _stp_module _stp_module_self = {\n";
  90.    ctx->output << ".name = \"stap_self_tmp_value\",\n";
  91.    ctx->output << ".path = \"stap_self_tmp_value\",\n";
  92.    ctx->output << ".num_sections = 2,\n";
  93. @@ -7751,16 +7754,16 @@ emit_symbol_data_done (unwindsym_dump_context *ctx, systemtap_session& s)
  94.    // Print out a definition of the runtime's _stp_modules[] globals.
  95.    ctx->output << "\n";
  96.    self_unwind_declarations(ctx);
  97. -   ctx->output << "static struct _stp_module *_stp_modules [] = {\n";
  98. +   ctx->output << "struct _stp_module *_stp_modules [] = {\n";
  99.    for (unsigned i=0; i<ctx->stp_module_index; i++)
  100.      {
  101.        ctx->output << "& _stp_module_" << i << ",\n";
  102.      }
  103.    ctx->output << "& _stp_module_self,\n";
  104.    ctx->output << "};\n";
  105. -  ctx->output << "static const unsigned _stp_num_modules = ARRAY_SIZE(_stp_modules);\n";
  106. +  ctx->output << "const unsigned _stp_num_modules = ARRAY_SIZE(_stp_modules);\n";
  107.  
  108. -  ctx->output << "static unsigned long _stp_kretprobe_trampoline = ";
  109. +  ctx->output << "unsigned long _stp_kretprobe_trampoline = ";
  110.    // Special case for -1, which is invalid in hex if host width > target width.
  111.    if (ctx->stp_kretprobe_trampoline_addr == (unsigned long) -1)
  112.      ctx->output << "-1;\n";
  113. @@ -7860,8 +7863,11 @@ int
  114.  translate_pass (systemtap_session& s)
  115.  {
  116.    int rc = 0;
  117. +  string comm_hdr_file = s.tmpdir + "/stap_common.h";
  118.  
  119.    s.op = new translator_output (s.translated_source);
  120. +  s.op->new_common_header (comm_hdr_file);
  121. +
  122.    // additional outputs might be found in s.auxiliary_outputs
  123.    c_unparser cup (& s);
  124.    s.up = & cup;
  125. @@ -7929,31 +7935,45 @@ translate_pass (systemtap_session& s)
  126.               << "__attribute__ ((section (\"" << STAP_PRIVILEGE_SECTION <<"\")))"
  127.               << " = STP_PRIVILEGE;";
  128.  
  129. -      s.op->newline() << "#ifndef MAXNESTING";
  130. -      s.op->newline() << "#define MAXNESTING " << nesting;
  131. -      s.op->newline() << "#endif";
  132. +      s.op->newline() << "#include \"stap_common.h\"";
  133. +
  134. +      s.op->hdr->newline() << "#ifndef MAXNESTING";
  135. +      s.op->hdr->newline() << "#define MAXNESTING " << nesting;
  136. +      s.op->hdr->newline() << "#endif";
  137.  
  138.        // Generated macros specifying how much storage is required for
  139.        // regexp subexpressions. (TODOXXX Skip when there are no DFAs?)
  140. -      s.op->newline() << "#define STAPREGEX_MAX_MAP " << s.dfa_maxmap;
  141. -      s.op->newline() << "#define STAPREGEX_MAX_TAG " << s.dfa_maxtag;
  142. +      s.op->hdr->newline() << "#define STAPREGEX_MAX_MAP " << s.dfa_maxmap;
  143. +      s.op->hdr->newline() << "#define STAPREGEX_MAX_TAG " << s.dfa_maxtag;
  144.  
  145. -      s.op->newline() << "#define STP_SKIP_BADVARS " << (s.skip_badvars ? 1 : 0);
  146. +      s.op->hdr->newline() << "#define STP_SKIP_BADVARS " << (s.skip_badvars ? 1 : 0);
  147.  
  148.        if (s.bulk_mode)
  149. -     s.op->newline() << "#define STP_BULKMODE";
  150. +     s.op->hdr->newline() << "#define STP_BULKMODE";
  151.  
  152.        if (s.timing || s.monitor)
  153. -   s.op->newline() << "#define STP_TIMING";
  154. +   s.op->hdr->newline() << "#define STP_TIMING";
  155.  
  156.        if (s.need_unwind)
  157. -   s.op->newline() << "#define STP_NEED_UNWIND_DATA 1";
  158. +   s.op->hdr->newline() << "#define STP_NEED_UNWIND_DATA 1";
  159.  
  160.        if (s.need_lines)
  161. -        s.op->newline() << "#define STP_NEED_LINE_DATA 1";
  162. +        s.op->hdr->newline() << "#define STP_NEED_LINE_DATA 1";
  163.  
  164.        // Emit the total number of probes (not regarding merged probe handlers)
  165. -      s.op->newline() << "#define STP_PROBE_COUNT " << s.probes.size();
  166. +      s.op->hdr->newline() << "#define STP_PROBE_COUNT " << s.probes.size();
  167. +
  168. +      s.op->hdr->newline() << "#if (defined(__arm__) || defined(__i386__) "
  169. +        "|| defined(__x86_64__) || defined(__powerpc64__)) "
  170. +        "|| defined (__s390x__) || defined(__aarch64__) || defined(__mips__)\n"
  171. +        "#ifdef STP_NEED_UNWIND_DATA\n"
  172. +        "#ifndef STP_USE_DWARF_UNWINDER\n"
  173. +        "#define STP_USE_DWARF_UNWINDER\n"
  174. +        "#endif\n"
  175. +        "#endif\n"
  176. +        "#endif";
  177. +
  178. +      s.op->hdr->close ();
  179.  
  180.        // Emit systemtap_module_refresh() prototype so we can reference it
  181.        s.op->newline() << "static void systemtap_module_refresh (const char* modname);";
  182. diff --git a/translator-output.cxx b/translator-output.cxx
  183. index a28d6f8d1..370fe8124 100644
  184. --- a/translator-output.cxx
  185. +++ b/translator-output.cxx
  186. @@ -15,7 +15,7 @@
  187.  using namespace std;
  188.  
  189.  translator_output::translator_output (ostream& f):
  190. -  buf(0), o2 (0), o (f), tablevel (0), trailer_p(false)
  191. +  buf(0), o2 (0), o (f), tablevel (0), trailer_p(false), hdr (NULL)
  192.  {
  193.  }
  194.  
  195. @@ -26,11 +26,33 @@ translator_output::translator_output (const string& filename, size_t bufsize):
  196.    o (*o2),
  197.    tablevel (0),
  198.    filename (filename),
  199. -  trailer_p (false)
  200. +  trailer_p (false),
  201. +  hdr (NULL)
  202.  {
  203.    o2->rdbuf()->pubsetbuf(buf, bufsize);
  204.  }
  205.  
  206. +
  207. +void
  208. +translator_output::new_common_header (ostream& f)
  209. +{
  210. +  if (hdr)
  211. +    delete hdr;
  212. +
  213. +  hdr = new translator_output (f);
  214. +}
  215. +
  216. +
  217. +void
  218. +translator_output::new_common_header (const string& filename, size_t bufsize)
  219. +{
  220. +  if (hdr)
  221. +    delete hdr;
  222. +
  223. +  hdr = new translator_output (filename, bufsize);
  224. +}
  225. +
  226. +
  227.  void
  228.  translator_output::close()
  229.  {
  230. diff --git a/translator-output.h b/translator-output.h
  231. index f7a108642..0ca59aca6 100644
  232. --- a/translator-output.h
  233. +++ b/translator-output.h
  234. @@ -27,10 +27,15 @@ public:
  235.    std::string filename;
  236.    bool trailer_p; // is this file to be linked before or after main generated source file
  237.  
  238. +  translator_output* hdr;
  239. +
  240.    translator_output (std::ostream& file);
  241.    translator_output (const std::string& filename, size_t bufsize = 8192);
  242.    ~translator_output ();
  243.  
  244. +  void new_common_header (std::ostream& file);
  245. +  void new_common_header (const std::string& filename, size_t bufsize = 8192);
  246. +
  247.    void close ();
  248.    
  249.    std::ostream& newline (int indent = 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement