title: _stext and _etext in the 2.6 Linux kernel - why can't my kernel module link to them?
body: <p>I have a kernel module that needs to have access to the kernel's <code>_stext</code> and <code>_etext</code> symbols. For some reason, even though the kernel has definitions for these symbols (<code>/proc/kallsyms</code>), whenever I load my module I get</p>
  
  <pre><code>mymodule: Unknown symbol _etext (err 0)
  mymodule: Unknown symbol _stext (err 0)
  </code></pre>
  
  <p>I'm not running a tainted kernel, and everything else in the module seems to link ok. Are there module or license restrictions on linking to <code>_stext</code> and <code>_etext</code>? Is there a substitute definition in the kernel that I could use for the beginning and end of code memory? </p>
  
  <p>Update:</p>
  
  <p>I'm looking at the kernel source, and in <code>kallsyms.c</code>, there's this:</p>
  
  <pre><code>static int read_symbol_tr(const char *sym, unsigned long long addr)
  {
  size_t i;
  struct text_range *tr;
  
  for (i = 0; i &lt; ARRAY_SIZE(text_ranges); ++i) {
      tr = &amp;text_ranges[i];
  
      if (strcmp(sym, tr-&gt;stext) == 0) {
          tr-&gt;start = addr;
          return 0;
      } else if (strcmp(sym, tr-&gt;etext) == 0) {
          tr-&gt;end = addr;
          return 0;
      }
  }
  
  return 1;
  }
  </code></pre>
  
  <p>Does this mean that the <code>_etext</code> and <code>_stext</code> entries that I'm seeing the <code>/proc/kallsyms</code> are fake symbols that a kernel module can't actually link to?</p>