There are some functions which are never called. Not because they are not called under some logic but because they are never called from tree of main function. assuming:
int A()
{
if(...)
call F();
}
int B()
{
}
int C()
{
call B();
}
int D()
{
call A();
}
int F()
{
call A();
}
int main()
{
call D();
call F();
}
so in this example:
main ---> D
|
--> F
D ------> A
F -------> A
A -------> F
C -------> B
So in no way by running this application B and C have chance of being called. They are orphan. But it seems gcc/g++ do not remove orphan functions as I have checked:
program 1:
int main()
{
int a=4;
int b=3;
int c=a+b;
b=c-a;
a=c-b;
return 0;
}
running in command line:
g++ -std=c++11 test.cpp
md5sum a.out
I get:
546da269abddb8dcb3883527a362f769 a.out
Now by adding an orpan function (test), I get different executive file:
program 2:
int test()
{
}
int main()
{
int a=4;
int b=3;
int c=a+b;
b=c-a;
a=c-b;
return 0;
}
running in command line:
g++ -std=c++11 test.cpp
md5sum a.out
gives different hash:
64095263965d2d94ed2f305f99a2b25a a.out
It shows that this orphan function which will never be called in my program has influenced the compiled code. Is there any way to tell gcc/g++ to remove orphan functions?