title: GCC alias attribute for C++ member functions
body: <p>I am running into a portability issue on Linux due to a type change in a system header.  The siginfo_t type was changed from a named struct (struct siginfo) to an unnamed struct.  For me this changed between RHEL6 and RHEL7.</p>
  
  <p>We use <a href="http://www.cs.wustl.edu/~schmidt/ACE.html" rel="nofollow">ACE</a> in a few places and they have siginfo_t in a few publicly exposed interfaces.  The result is that code compiled on RHEL7 will not link against a library that was built on RHEL6.  For the time being, I need to support this.</p>
  
  <p>In RHEL6, one problem function is typed as:</p>
  
  <pre><code>ACE_Event_Handler::handle_signal(int, siginfo*, ucontext*) 
  </code></pre>
  
  <p>In RHEL7, it looks like this:</p>
  
  <pre><code>ACE_Event_Handler::handle_signal(int, siginfo_t*, ucontext*) 
  </code></pre>
  
  <p>These get mangled into different symbols resulting in either a failure during linking or a symbol lookup failure at runtime.</p>
  
  <p>A relatively simple solution is to use a function alias.  However, I do not want to modify the header file.  I'm struggling a bit because this is a virtual member function.</p>
  
  <p>I tried doing this in Event_Handler.cpp on a version of ACE built on RHEL7:</p>
  
  <pre><code>struct siginfo;
  ACE_Event_Handler::handle_signal(int, siginfo*, ucontext*)
  __attribute__((
    alias("_ZN17ACE_Event_Handler13handle_signalEiP9siginfo_tP8ucontext")
  ));
  </code></pre>
  
  <p>With this, GCC complains that the function was not declared.  I was ultimately able to make this work, but only with this ugly hack:</p>
  
  <pre><code>extern "C" int _ZN17ACE_Event_Handler13handle_signalEiP7siginfoP8ucontext()
  __attribute__((
    alias("_ZN17ACE_Event_Handler13handle_signalEiP9siginfo_tP8ucontext")
  ));
  </code></pre>
  
  <p>The 'extern "C"' is needed to prevent re-mangling the mangled name.</p>
  
  <p>Is there a more elegant way to accomplish this without running into compiler complaints?</p>