I am trying to remove unused functions (having no calls made to them) in my code which is built on x86 / Linux using gcc/g++. I use below options as I read from the gcc manual:
CCFLAGS = -ffunction-sections -fdata-sections -Wl,--gc-sections,--print-gc-sections
Make command output does show some unused sections removed messages as below:
/usr/bin/ld: Removing unused section '.text._ZN14myclass30myunusedfuncEPPNS_8device_sE' in file './myproject/x86-linux/release/file1.o'
But just to make sure, I tried to find if that symbol was present in the *.o object file, so when I do:
strings --all -f file1.o|grep myunusedfunc
I see output as below
myproject/x86-linux/debug/file1.o: [] myclass::myunusedfunc()
myproject/x86-linux/debug/file1.o: myunusedfunc
myproject/x86-linux/debug/file1.o: _ZN14myclass30myunusedfuncEPPNS_8device_sE
myproject/x86-linux/debug/file1.o: .rel.text._ZN14myclass30myunusedfuncEPPNS_8device_sE
myproject/x86-linux/debug/file1.o: _ZN14myclass30myunusedfuncEPPNS_8device_sE
What's going on?
Have the unused functions really been removed by these gcc/ld options: