Peter Jansen wrote:
Hi Ivan,



The  bigger  code problem in your case is caused by GCC4 inlining
some functions by default. For example, an non-static inline
function, that is  used  only  a  single  time  (such  as  init_SPI
in your case), is included  in the object file twice (the function
itself and its inline call).  If  you specify the
-ffunction-sections attribute (and use the -gc-sections linker
switch), the code size will be less than using GCC v3.

If  you  don't want to use the -ffunction-sections, you either need
to disable  inlining  completely  (-fno-inline),  or  tweak  the
maximum inlined  function  size  (-finline-limit=x),  that  is
more  precise.

Thanks, the fno-inline works and reduces the code.


Of course, the best way is to correct your code! Functions and data that are not exported from a module should always be declared "static". That way the compiler will inline single-use functions and omit the non-inline version entirely. This will give the compiler the best chance to make the code smaller and faster.

With gcc 4.3, it is also possible to compile and link all your source code on a single line and use the "-combine" and "-fwhole-program" options. This lets the compiler know that it has full information about all code, and will give inter-module inter-function optimisation. It can make debugging a little inconvenient, of course, as with any powerful optimisation.


Reply via email to