title: how to get the address of an asm function in c
body: <p>I have an asm file (I'm using gas) and a c file. My asm file contains a function, something like this</p>
  
  <pre><code>.global myfunc
  .type myfunc, @function
  
  myfunc:
     pusha
     .
     .
     .
  </code></pre>
  
  <p>now I want to get the address of the label myfunc from my c file, so I've wrote</p>
  
  <pre><code>extern uintptr_t _myfunc asm("myfunc");
  </code></pre>
  
  <p>my program links without problems, but when I execute my program the variable _myfunc doesn't contain the right address.</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>maybe it's useful to know that this piece of code is part of a bare-metal program</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>using a function prototype solved the problem</p>
  
  <pre><code>void function() asm("myfunc");
  
  uintptr_t _myfunc = (uintptr_t)&amp;myfunc;
  </code></pre>