Ibraim Ganiev
Ibraim Ganiev

Reputation: 9390

Why hidden symbols are still added to DSO

user@pc ~/hiddensymbols
% cat main.cpp 
__attribute__((visibility ("hidden"))) int f_b1(void){
return 21 ;
}

__attribute__((visibility ("hidden"))) int f_b3(void){
return f_b1() ;
}                                                                                                                                    user@pc ~/hiddensymbols
 % g++ -shared main.cpp
user@pc ~/hiddensymbols
 % nm -C ./a.out       
.............
000000000000055a t f_b1()
0000000000000565 t f_b3()

I wonder, what was the point in leaving these two symbols in DSO? I understand that dynamic linker can't use them, but then why they are added to some hidden symbol table? What was the purpose of this?

Upvotes: 0

Views: 572

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136256

When the linker emits an object file it records the name and the address of each symbol, regardless of its visibility (in .symtab section which you can dump with readelf --symbols <elf-file> ). It is used for debugging to display symbol names even if no debug information is available. During normal execution this section is not loaded/mapped into the address space.

Hidden symbols cannot be used to resolve symbols from other object files, just like symbols marked with static keyword. You can strip them out with strip utility if necessary.

Upvotes: 2

Related Questions