Re: [PATCH] Generic dead function optimisation

From: Graham Stoney (
Date: Tue Apr 25 2000 - 19:21:34 EST

Hi Stefan,

Stefan Monnier writes:
> In the same spirit, I think gcc should automatically get rid of `static'
> functions which are not called in the file. This should be part of
> the normal "dead-code elimination".
> This does not involve the linker at all. It doesn't catch as many cases
> as `-ffunction-sections -Wl,--gc-sections' which also works with globally-dead
> functions, but has its own advantages.

I agree entirely. gcc-2.95.2 will optimise away unused static functions if you
specifiy -finline-functions (perhaps via -O3), but there is no easy way to ask
it to do this without also inlining stuff you haven't otherwise asked it to.
Hence, the net effect is to increase code size because of all the inline
expansions rather than reduce it. Reducing the -finline-limit- can probably
mitigate this effect somewhat, but the optimal value is likely to be
application dependent and I haven't tried tuning it for the Linux kernel.

I think it would be really nice if -Os (optimise for space) performed obvious
unused static function elimination; currently it does not.

This is one reason I tried harder to get -ffunction-sections working.


Graham Stoney
Principal Hardware/Software Engineer
Canon Information Systems Research Australia
Ph: +61 2 9805 2909  Fax: +61 2 9805 2929

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to Please read the FAQ at

This archive was generated by hypermail 2b29 : Sun Apr 30 2000 - 21:00:10 EST