Static functions

Thiago Macieira thiago.macieira at kdemail.net
Mon Feb 16 15:37:49 GMT 2004


Dirk Mueller wrote:
>> I was assuming that if anyone wanted to not to export a symbol, that
>> he'd also know that the symbol has to be defined in the same file.
>
>No, it doesn't *have* to be defined in the same file. Only if you use
> weird constructs (anonymous namespaces, static in namespaces). Better
> don't do that.

Hmm... I meant "export from a compilation unit". You're referring to 
"export form a library".

Does anyone know if those protected and hidden symbols get removed from 
the library's export symbols when linking/stripping is done? My earlier 
tests indicated that those symbols stayed in the symbol table, but I 
hadn't stripped the library.

Oh, what the hell. Let me try it myself:
$ cat > test.cpp
int v5 __attribute__((visibility("hidden")));
int v6 __attribute__((visibility("protected")));
int v7 __attribute__((visibility("internal")));

main()
{ }

$ gcc -s -o test test.cpp
$ nm test
nm: test: no symbols
$ readelf -s test | grep 'v[567]$'

$ gcc -s -rdynamic -o test test.cpp
$ readelf -s test | grep 'v[567]$'
     2: 080497f0     4 OBJECT  GLOBAL PROTECTED   22 v6

$ gcc -s -shared -o test.so test.cpp
$ readelf -s test.so | grep 'v[567]$'
    22: 00001728     4 OBJECT  GLOBAL PROTECTED   19 v6

So the answer is "yes". (Protected means "exported, but can't be 
overriden")
-- 
  Thiago Macieira  -  Registered Linux user #65028
   thiago (AT) macieira (DOT) info
    ICQ UIN: 1967141   PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040216/c3621087/attachment.sig>


More information about the kde-core-devel mailing list