2010-03-30 01:07 PM
GCC _ Selective Function Compile?
#stm322011-05-17 04:45 AM
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...
2011-05-17 04:45 AM
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.2011-05-17 04:45 AM
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.2011-05-17 04:45 AM
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