On 16/04/2021 15:47, David Sherman wrote: > We are using NXP's MCUXpresso to target ARM, and it uses gcc. We > have a large project with several different configurations. The > underlying library code gets compiled into libs and linked into the > main application, and the main application has all the switches to > enable or disable features. Despite using -Os, many chunks of code > are still present, as are static variables, even though they never > get used. We have tried turning on link time optimization, but it > appears to have no effect. Some static variables are optimized away, > but many remain. We have even tried making them part of their own > section and using different linker directives that don't have that > section specified, but they get linked in anyway. > > Short of changing the project to one large project that excludes > certain source files that aren't needed, is there a nice way to > remove them? > Have you tried enabling "-ffunction-sections", "-fdata-sections" and "-Wl,--gc-sections" for linking?