[Ns-developers] GCC 4 -fvisibility=hidden

Gustavo Carneiro gjcarneiro at gmail.com
Sun Jan 25 11:51:07 PST 2009

2009/1/25 Mathieu Lacage <mathieu.lacage at sophia.inria.fr>

> On Sun, 2009-01-25 at 19:29 +0000, Gustavo Carneiro wrote:
> >         1) a large fraction of performance-sensitive code is also
> >         'public' so
> >         you can't mark it 'hidden' so, you lose all the performance
> >         gain of this
> >         marking (there are 3 big items: the packet.h, simulator.h and
> >         object.h
> >         code).
> >
> > IIRC, I think what GTK+ and friends are doing these days is actually
> > maintain a duplicate set of symbols.  For each API function, it is
> > declared as both a hidden and public, and Gtk+ itself ends up calling
> > only the hidden symbols, bypassing the GOT indirection, although a
> > public version of the function symbol is also exported.
> It's been a while since I did not look at this, so how do they do it ?

They generate gtkalias.h and gtkaliasdef.c from gtk.symbols.

gtk.symbols contains:

gtkalias.h contains:
extern __typeof (gtk_window_unfullscreen) IA__gtk_window_unfullscreen
#define gtk_window_unfullscreen IA__gtk_window_unfullscreen

gtkaliasdef.c contains:
#undef gtk_window_unfullscreen
extern __typeof (gtk_window_unfullscreen) gtk_window_unfullscreen
__attribute((alias("IA__gtk_window_unfullscreen"), visibility("default")));

gtkwindow.c contains:
#include "gtkalias.h"
gtk_window_unfullscreen (GtkWindow *window)

The gtk_window_unfullscreen definition in gtkwindow.c expands (because of a
#define) to IA__gtk_window_unfullscreen, which was previously declared with
hidden visibility.  gtkaliasdef.c provides an alias symbol to
IA__gtk_window_unfullscreen called gtk_window_unfullscreen with public
visibility.  But internally gtk+'s own code only ends up calling the
functions with private visibility and no GOT lookups.

Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert

More information about the Ns-developers mailing list