title: Strange behaviour while wrapping abort() system call
body: <p>I need, to write unitary tests, to wrap the abort() system call.</p>
  
  <p>Here is a snippet of code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;assert.h&gt;
  
  extern void __real_abort(void);
  extern void * __real_malloc(int c);
  extern void __real_free(void *);
  
  
  void __wrap_abort(void)
  {
      printf("=== Abort called !=== \n");
  }   
  
  void * __wrap_malloc(int s)
  {
      void *p = __real_malloc(s);
      printf("allocated %d bytes @%p\n",s, (void *)p);
      return p;
  }
  
  void __wrap_free(void *p)
  {
      printf("freeing @%p\n",(void *)p);
      return __real_free((void *)p);
  }
  
  
  int main(int ac, char **av)
  {
      char *p = NULL;
      printf("pre malloc: p=%p\n",p);
      p = malloc(40);
      printf("post malloc p=%p\n",p);
  
      printf("pre abort\n");
      //abort();
      printf("post abort\n");
  
      printf("pre free\n");
      free(p);
      printf("post free\n");
      return -1;
  }
  </code></pre>
  
  <p>Then i compile this using the following command line :</p>
  
  <pre><code>gcc -Wl,--wrap=abort,--wrap=free,--wrap=malloc -ggdb -o test test.c
  </code></pre>
  
  <p>Running it give the following output:</p>
  
  <pre><code>$ ./test
  pre malloc: p=(nil)
  allocated 40 bytes @0xd06010
  post malloc p=0xd06010
  pre abort
  post abort
  pre free
  freeing @0xd06010
  post free
  </code></pre>
  
  <p>So everything is fine.
  Now let's test the same code but with abort() call uncommented:</p>
  
  <pre><code>$ ./test
  pre malloc: p=(nil)
  allocated 40 bytes @0x1bf2010
  post malloc p=0x1bf2010
  pre abort
  === Abort called !=== 
  Segmentation fault (core dumped)
  </code></pre>
  
  <p>I don't really understand why i get a segmentation fault while mocking abort() syscall... 
  Every advice is welcome !</p>
  
  <p>I run Debian GNU/Linux 8.5 on an x86_64 kernel. Machine is a Core i7 based laptop.</p>