简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM