cancel
Showing results for 
Search instead for 
Did you mean: 

GCC _ Selective Function Compile?

tmall
Associate II
Posted on March 30, 2010 at 22:07

GCC _ Selective Function Compile?

#stm32
4 REPLIES 4
Posted on May 17, 2011 at 13:45

A Library is a special type of object file that specifically allows only certain parts to be extracted;

But the normal object file has to be linked in toto.

 

Some more advanced Linkers do have the facility to spot & remove unused functions; but this can be tricky - eg, if functions are called via pointers...

damh
Associate II
Posted on May 17, 2011 at 13:45

The old way is:

- The linker includes every file complete, in which at least one symbol is used.

- static unused functions does not get into the objectfile, so they won't appear in the programm

=> Best way in this case is to split files to be as small as possible (often one function per file).

gcc supports a new way, that does this splitting automatically. This won't function with assembler files, but in c-files it seems to be ok.

mdeneen2
Associate II
Posted on May 17, 2011 at 13:45

The following is GCC specific...

You can do this in two ways:

1.   Place every function in its own C source file.  The compiler will generate a .o file for each .c file, and the linker will discard any unused objects.

2.  Compile with the -ffunction-sections option, which will place each function in its own section.  Then when linking, use ''-Wl,--gc-sections'' to tell the linker to discard unused sections.

Check the GCC manual for -ffunction-sections and -fdata-sections.

tmall
Associate II
Posted on May 17, 2011 at 13:45

Greetings:

    First I wish to thank those that took the time to reply to my post here!

    I decided to followup to inform others of the solution which works well for me. In my case the difference in program size is dramatic. My un-optimized (for debugging) program code size had grown to over 82K and dropped to <32K once the unused functions were removed!

    I use the CrossWorks IDE from Rowley. Rowley's support group replied to me in another forum and pointed me to a build option named ''Enable Unused Symbol Removal'' which they have provided within the project ''Build Options'' section in CrossWorks. This apparently implements the GCC compiler options needed for removal of the unused function code.

    This option proved very significant for the project I am working on which has many imported files.

Best Regards,

Tom Alldread