Re: [arm-gnu] Image size reduction with linker optimization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [arm-gnu] Image size reduction with linker optimization



On Thu, 2009-02-05 at 11:02 -0500, Daniel Jacobowitz wrote:
> On Thu, Feb 05, 2009 at 07:41:59AM -0800, Michael Downing wrote:
> > I am developing a program using CodeSourcery Lite and the ST drivers for
> > the STM32 family.  I am calling only a few functions in the ST driver
> > files, and yet I see ALL of the functions of those files included,
> > whether they are called or not.  I want to minimize my image size by
> > getting rid of this unused code.

I have the same scenario and thought I'd give your following suggestion
a try.

> * Link with --gc-sections.  This will only help.

With this alone, I get infinitely small code that unfortunately doesn't
run.  For some reason the linker thought it was cool to remove *all*
text, bss and data sections.

Discarded input sections

 .text          0x00000000        0x0 ./obj/stm32f10x_adc.o
 .data          0x00000000        0x0 ./obj/stm32f10x_adc.o
 .bss           0x00000000        0x0 ./obj/stm32f10x_adc.o

Compiling with -Os yields the best code size optimisation as expected,
but still includes unused functions.

	text	bss	data
-O0	59496	1324	10156
-O2	29272	1324	10156
-Os	24598	1324	10156

-O3 increased text, bss and data above that for -O2, also as expected.

Optimisations caused a heap of warnings to be generated by the ST FWLib,
as in;

../../FWLib/library/src/stm32f10x_tim.c:368: warning: dereferencing
type-punned pointer will break strict-aliasing rules

Adding -fno-strict-aliasing ignored the warning, but is this a good
idea?  Or should ST be changing their FWLib source?

Cheers,
James.