Domanda

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:

È stato utile?

Soluzione

You're looking at the .o file, but that's the input to the linker, not the output. The .o file will contain all the functions, the linker should not emit unused ones into the linked output. It doesn't edit the .o files though.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top