richard_damon wrote on Monday, July 22, 2013:
First, in most cases a linker will remove function that are not called anyway, meaning the INCLUDE_ macros can all be set to 1 without any effect on the code size. I think GCC is the only tool chain that won’t do that by default, but it can be requested to remove unused functions using the command line options.
I am not sure this would be generally true! The “Standard Model” for compiling projects has been that each source file generates a single object file with a single module which is included in the resulting executable, with any modules needed from library files to satisfy unmet references. You often needed to be careful with the order the libraries were specified so that libraries that fulfilled requests from other libraries were listed later in the list, as the linker did just a single pass through the object files/libraries.
To implement the exclusion of unused functions, first the complier needs to break up the object file to have a module for each function within it, as the linker can not include just part of a module. The linker then needs to scan the object files multiple times to find all referenced symbols (or at least record all defined symbols and go back to get the needed modules.) While this capability is very common on “big machine” compilers, I am not as sure it is universal with the sometimes older base compliers found on many of the smaller processors (and smaller processors are where you most need to worry about code space consumption).
If FreeRTOS was compiled into a library, this wouldn’t be as much of a problem, as library modules have implemented this sort of functionality, but the dependance in FreeRTOS to FreeRTOSConfig.h, which is generally a PROJECT file, makes this not as convenient.