here is some C++ test code:
__attribute__((visibility("hidden"))) void foo()
{
int fd = fopen("data1", "rb");
printf ("%d", fd);
}
And all other code don’t call function ‘foo’ and function ‘fopen’
Then I use gcc option -ffunction-sections to compile the code to a so file.
As I think, the function foo symbol and foo binary code has’t inlcuded in the so file.
But The problem is, I think the symbol ‘fopen’ should not be symbol table.
ps:I can make sure that only function ‘foo’ has use ‘fopen’.
And it actually is not, when I use command nm, I found ‘U’ type symbol of ‘fopen’.
How is the gcc work?
And has gcc other compile option to found that, symbol ‘fopen’ is not use, and remove ‘fopen’ symbol.
The problem is, that the compiler does not know, wheter the symbols are used later.
You can tell at compile time that you gave him the whole program, so that if your program isnt calling the function, nobody would.
The compiling option is
-fwhole-program.