This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Redundant code removal

While I was trying to fit an application in a limited space I noticed that the compiler/linker does not appear to remove functions that are uncalled across C files.

I have a number of C files that are common to a number of applications but not all of these functions are called by all applications.

If I comment out these functions the application will then reduce in size, so I am pretty sure the linker is not removing these (or at least part of these) unused functions. This is regardless of the optimisation level I have set for the compiler.

Ideally I want the compiler/linker to remove these functions automatically.

I have trawled through the options on armlink but I cant seem to find what I want.

I am pretty sure I am missing something obvious. So can anyone explain how I achieve this?

Thanks

Parents
  • I have a number of C files that are common to a number of applications but not all of these functions are called by all applications.

    And apparently those files each contain more than one separately useful function. Sorry, but that's just not the right way to build a library. Particularly not if you're going to try and re-use that library of routines for real, so it'll be used with more than one version of one compiler.

    Yes, some tool chains can be convinced to break open individual compiled source files and use only poart of them. But it's not a good plan to rely on that feature being available everywhere.

    The whole idea of a library, as apposed to just compiling a few big fat object files with your whole set of utility function in there, is that it really does take those many object files, and you need a way of handling them efficiently. The linker picks from the library what it needs. No more, no less.

    In the case at hand, one considerable advantage is that you would get the size reduction on every build, not just the last one in a long sequence of complete re-builds --- how will you ever build "official" program images if every re-compile may produce a different one?

Reply
  • I have a number of C files that are common to a number of applications but not all of these functions are called by all applications.

    And apparently those files each contain more than one separately useful function. Sorry, but that's just not the right way to build a library. Particularly not if you're going to try and re-use that library of routines for real, so it'll be used with more than one version of one compiler.

    Yes, some tool chains can be convinced to break open individual compiled source files and use only poart of them. But it's not a good plan to rely on that feature being available everywhere.

    The whole idea of a library, as apposed to just compiling a few big fat object files with your whole set of utility function in there, is that it really does take those many object files, and you need a way of handling them efficiently. The linker picks from the library what it needs. No more, no less.

    In the case at hand, one considerable advantage is that you would get the size reduction on every build, not just the last one in a long sequence of complete re-builds --- how will you ever build "official" program images if every re-compile may produce a different one?

Children