Hi, can you explain what those switches mean? I'm looking in the LD documentation and there is no mention of these. -----Original Message----- From: David Brown [mailto:david.brown@xxxxxxxxxxxx] Sent: Friday, April 16, 2021 11:49 AM To: David Sherman <DSherman@xxxxxxxxxxxxxxx>; gcc-help@xxxxxxxxxxx Subject: Re: Removing unused code/variables 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?