I was suprised to know that GCC failed to remove the dead codes from my program. Here’s an example:
kunil@cerpelai:~/Temp$ vi test.c
#include
void unusedFunction(void) {
printf(“This is a dead code\n”);
}
int main(void) {
printf(“Hello world\n”);
return 0;
}
kunil@cerpelai:~/Temp$ gcc -Os test.c -o test.elf
If you take a look carefully on the ELF binary, you can see that GCC still includes the “unusedFunction()”, although nothing refers to it.
kunil@cerpelai:~/Temp$ objdump -d test.elf
test.elf: file format elf32-i386
….
080483c4
….
080483e9
….
So I was wondering if there’s something wrong with GCC (or GNU-ld), or should I add something to remove it.
(more…)