Hi,

> I believe that you need to use a few options to force gcc to do this. 
> Try the linker option that goes something like --gc-sections. This tells 
> the linker to garbage collect unused sections. If you use some functions 
> but not others, you can try telling the compiler to make a new section 
> for each function, something like -ffunction-sections.

i tried -Os and
--retain-symbols-file -gfull --gc-sections -fdata-sections -ffunction-sections
-fssa-dce -dead_strip nichts
but these options do have no effect.
If i call only the linker with that options some are reported as unknown or
cause warnings/errors (and no output file in case of an error).

So i converted every *.c file, execept main.c, to a library:

msp430-ar -rcs libi2c.a ../i2c.o
msp430-ar -rcs libmmc.a ../mmc.o
...

msp430-gcc -mmcu=msp430x169 -o aout.elf ../main.o -Wl,-Map=aout.map--cref -L. 
-lflag -li2c -lmmc ...

and the result is:

> msp430-size aout.elf
before:
   text    data     bss     dec     hex filename
  19476      36    1596   21108    5274 aout.elf

after:
   text    data     bss     dec     hex filename
  17192      28     564   17784    4578 aout.elf

so this works!
I also tested without the unused mmc code:

before:
   text    data     bss     dec     hex filename
  17572      30     568   18170    46fa aout.elf

after:
   text    data     bss     dec     hex filename
  17192      28     564   17784    4578 aout.elf

which shows that unused variables and functions from used
files do not get linked!
It seems this is the only way to remove dead (unused) code.

Now i'm looking for a makefile which does this (conversion to libraries
and linking that libs) automatically.
Can someone give a link to such an example makefile?

Regards,

Rolf


-------------------------------------------------------------------------------------------
> >i thought that only used code gets linked but i added some MMC/SDC
> >code to a project and although that code is unused now and has not ISRs 
> >and gets compiled+linked without a warning it gets linked:
> >
> >without MMC/SDC code:
> > msp430-size  aout.elf
> >   text    data     bss     dec     hex filename
> >  20114      30     568   20712    50e8 aout.elf
> >
> >with MMC/SDC code (only linked, not used):
> >   text    data     bss     dec     hex filename
> >  22044      36    1596   23676    5c7c aout.elf
> >
> >How can i force not linking unused code?
> >
> >Regards,
> >
> >Rolf


Reply via email to