C++ AVR big code size & excess unused symbols in build file
If using GCC (AVR-GCC), the following options can be helpful
Compiler:
-fdata-sections -ffunction-sections
Linker:
-Wl,--gc-sections

Additional explanation:
The above options work together as follows
-ffunction-sections and -fdata-sections -- these put each function or data item into its own section in the output file (i.e. object file coming out of compiler). At this stage it's too soon to say whether we can garbage collect anything, only when linking will there be enough information to make that decision, hence the linker option below
-Wl,--gc-sections  -- figures out if there are &quot;sections&quot; that are never used and removes them (&quot;garbage-collection&quot;)...
Reference: the documentation

Also, examining the .map file is a way to deduce how much individual functions/methods or static data items are contributing to the total size