title: Wrapping a function
body: <p>As mentioned <a href="https://stackoverflow.com/questions/46444052/how-to-wrap-functions-with-the-wrap-option-correctly">here</a>, we can wrap a function using the <code>-Wl,--wrap</code> switch.
  Consider the following program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void __wrap_f()
  {
          puts("wrapped");
  }
  
  void f()
  {
          puts("original");
  }
  
  int main(void)
  {
          f();
  }
  </code></pre>
  
  <p>The program was written to <code>a.c</code> and compiled as <code>gcc -Wl,--wrap=f a.c</code>. When I run the executable (using <code>./a.out</code>), I get <code>original</code> as the output.</p>
  
  <p>My expectation was that on invoking <code>f()</code>, the wrapped version would be called and the program would print <code>wrapped</code>. Please let me know what I am missing here.</p>
  
  <p>GCC version: 9.1.0</p>