The GNU linker has a garbage collector of ELF sections. This garbage collector can remove all ELF sections which are not used by the program.
To remove unused functions, it is necessary to tell the compiler gcc to put each function in a separate .text section.
To do this, you must use the following option:
m6811-elf-gcc -Os -ffunction-sections ....
Then, at link time, you can pass the following option:
-Wl,--gc-sections
The linker will garbage collect all unused functions and remove them.
> This way, I can use just a few functions each from various libraries > (gcc included, third party, and my own), but have my compiled program > not be HUGE.
Yes but take care that if there is a reference to a function somewhere, it can drag (import) many others and the GC will do nothing (due to the initial function being referenced).
|