Skip to contentSkip to conversation

dead code removal

DISCUSSION Jim Reekes 4 participants 4 messages Nov 25, 1999 – Dec 18, 1999

lore
Share & tools
lore

Jim Reekes

author
#0 lore raw

I have a little program that contains a routine DummyFunc() which is never reference in the code. Building this single source file in any way I've tried results in a binary which contains DummyFunc(). Using nm and objdump, as far as I can determine GCC 2.95 does not dead-code strip. (which I find amazing!). So I have two questions.

Am I missing something and GCC actually does dead-code stripping?

- or -

How can I find unused/unreferenced symbols in my code so that I can bury the dead code manually?

Jim

P.S. I have always compared programming to ditch digging, and now I'm convinced.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#1 lore raw

That kind of stripping can not be done by the compiler. It could theoretically be done by the linker, and there MIGHT be a linker option to give the warnings you want - what if another object file in your program called DummyFunc? Or worse, what if a shared library expected DummyFunc to be available?

Quoted 11 lines · Jim Reekes

I have a little program that contains a routine DummyFunc() which is never reference in the code. Building this single source file in any way I've tried results in a binary which contains DummyFunc(). Using nm and objdump, as far as I can determine GCC 2.95 does not dead-code strip. (which I find amazing!). So I have two questions.

Am I missing something and GCC actually does dead-code stripping?

- or -

Quoted 9 lines

How can I find unused/unreferenced symbols in my code so that I can bury the dead code manually?

Jim

P.S. I have always compared programming to ditch digging, and now I'm convinced.

Dan

/--------------------------------\ /--------------------------------\

|       Daniel Jacobowitz        |__|        SCS Class of 2002       |
|   Debian GNU/Linux Developer    __    Carnegie Mellon University   |
|         [email protected]         |  |       [email protected]      |
\--------------------------------/  \--------------------------------/

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#2 lore raw
Quoted 7 lines · Daniel Jacobowitz

That kind of stripping can not be done by the compiler. It could theoretically be done by the linker, and there MIGHT be a linker option to give the warnings you want - what if another object file in your program called DummyFunc? Or worse, what if a shared library expected DummyFunc to be available?

In principle it can be if the function is marked static (so the compiler knows it will never link outside the module.) Does anyone know if GCC does remove the code in this case?

Quoted 24 lines · Jim Reekes
Quoted 11 lines

I have a little program that contains a routine DummyFunc() which is never reference in the code. Building this single source file in any way I've tried results in a binary which contains DummyFunc(). Using nm and objdump, as far as I can determine GCC 2.95 does not dead-code strip. (which I find amazing!). So I have two questions.

Am I missing something and GCC actually does dead-code stripping?

- or -

Quoted 9 lines

How can I find unused/unreferenced symbols in my code so that I can bury the dead code manually?

Jim

P.S. I have always compared programming to ditch digging, and now I'm convinced.

Quoted 8 lines

Dan

/--------------------------------\ /--------------------------------\

|       Daniel Jacobowitz        |__|        SCS Class of 2002       |
|   Debian GNU/Linux Developer    __    Carnegie Mellon University   |
|         [email protected]         |  |       [email protected]      |
\--------------------------------/  \--------------------------------/

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#3 lore raw
Quoted 3 lines · On 25-Nov-99 Jeffrey Karl Lassahn wrote:

In principle it can be if the function is marked static (so the compiler knows it will never link outside the module.) Does anyone know if GCC does remove the code in this case?

No, only if its inline. Just because the compiler can't see a reference, it doesn't mean one isn't there - inline assember may refer to the static function.

Basically, you need the linker to strip dead functions, because nothing else has enough information to do it right.

J

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/