If compiler can "assemble " the used / working stuff, why it could not be modified to delete unused function?
The linker produces a list of discarded things, including function names , so this could be used to edit source files for specific cases. A completely general solution is impossible because of the macro preprocessor - the source code seen by the compiler may not correspond at all to the original input file.
If I want to keep old code for a bit I put it inside #ifdef OLD ... #endif. That guarantees it won't bloat the object code and is easy to tidy up later.