More symbol export stuff -- GCC Visibility patch

Karl Vogel karl.vogel at seagha.com
Mon Jul 19 12:43:54 CEST 2004


On 19 Jul 2004, you wrote in gmane.comp.kde.devel.optimize:

> On Sunday 18 July 2004 22:59, Karl Vogel wrote:
>> While playing with this symbol stuff.. I noticed that other libs were
>> also exporting way more than needed.
>> 
>> For instance... libkateinterfaces has exports for all the private
>> methods & private slots of all the classes it implements. 
>> 
>> I was able to reduce the symbols by manually adding an attribute to
>> the private parts (source parts.. not the other kind :-) ... ie.
>> 
>> #define HIDE  __attribute__((visibility ("hidden"))
>> 
>> and then..
>> 
>>   private:
>>      void methodX() HIDE;
> 
> It's already available in KDE, called KDE_NO_EXPORT, see
> kdelibs/kdecore/kdemacros.h 
> 
> But I guess it's far from used enough at the moment.

The gcc patch on http://www.nedprod.com/programs/gccvisibility.html 
allows you to have the visibility=hidden as a default, so that you need 
to explicitly tag classes/functions that need to be exported.

[quote]
In your header files, wherever you want an interface or API made public 
outside the current DSO, place __attribute__ ((visibility("default")))  
in struct, class and function declarations you wish to make public (it's 
easier if you define a macro as this). You don't need to specify it in 
the definition. Now alter your make system to pass -fvisibility=hidden  
to each call of GCC compiling a source file.
[/quote]

The page also mentions that the patch has been submitted for inclusion 
in GCC V3.5. So it might be interesting to add a configure check for 
this visibility commandline flag and to start using KDE_EXPORT on public 
interfaces (as defined in kdemacros.h).


I'm going to test drive that patch on qt-copy, since QT already has the 
necessary QT_EXPORT's in-place.


NOTE: this not only benefits filesize but also enables GCC to generate 
more efficient code. (no indirect jumps through PLT to local functions)

instead of this:

        popl    %ebx
        addl    $_GLOBAL_OFFSET_TABLE_+[.-.L3], %ebx
        pushl   8(%ebp)
        call    _ZN6MyTest5helloEi at PLT

with corresponding PLT section :

00000414 <_ZN6MyTest5helloEi at plt>:
 414:   ff a3 0c 00 00 00       jmp    *0xc(%ebx)
 41a:   68 00 00 00 00          push   $0x0
 41f:   e9 e0 ff ff ff          jmp    404 <_init+0x18>



you get this:
        call    _ZN6MyTest5helloEi


Since all KDE applications use kdeinit, they are all implemented as a 
shared library, so they are all using the first form!!



More information about the Kde-optimize mailing list