title: How to wrap functions with the `--wrap` option correctly?
body: <p>The man page of gcc 6.3 says:</p>
  
  <pre><code>--wrap=symbol
             Use a wrapper function for symbol.  Any undefined reference to
             symbol will be resolved to "__wrap_symbol".  Any undefined
             reference to "__real_symbol" will be resolved to symbol.
             ...
             If you link other code with this file using --wrap malloc, then all
             calls to "malloc" will call the function "__wrap_malloc" instead.
             The call to "__real_malloc" in "__wrap_malloc" will call the real
             "malloc" function.
  </code></pre>
  
  <p>So I created a simple example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int foo() {
      printf("foo\n");
      return 0;
  }
  
  int __wrap_foo() {
      printf("wrap foo\n");
      return 0;
  }
  
  int main () {
      printf("foo:");foo();
      printf("wrapfoo:");__wrap_foo();
      printf("realfoo:");__real_foo();
      return 0;
  }
  </code></pre>
  
  <p>And compiled it with:</p>
  
  <pre><code>gcc main.c -Wl,--wrap=foo -o main
  </code></pre>
  
  <p>This gave me a warning:</p>
  
  <pre><code>main.c:18:21: warning: implicit declaration of function ‘__real_foo’ [-Wimplicit-function-declaration]
    printf("realfoo:");__real_foo();
                       ^~~~~~~~~~
  </code></pre>
  
  <p>Well going on. Now I would suggest an output like this:</p>
  
  <pre><code>foo:wrap foo
  wrapfoo:wrap foo
  realfoo:foo
  </code></pre>
  
  <p>Instead I get this:</p>
  
  <pre><code>foo:foo
  wrapfoo:wrap foo
  realfoo:foo
  </code></pre>
  
  <p>I hope the thing is clear. I am confused about the warning. Normally the <code>__real</code> function should be linked by the linker to <code>foo()</code>. Furthermore a call to <code>foo()</code> should be linked to <code>__wrap_foo</code>. But the output showes, that <code>foo()</code> is being executed instead.</p>
  
  <p>How to use <code>--wrap</code> correctly?</p>