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

Dead code

µVision2 V2.14
Compiler : C51 V6.14
Target : 87C591

In my software, functions are not called. Which is the option of compilation which allows not to generate code for these functions?
Even by using for the optimization of the code the level 1 " Dead codes elimination ", code is generated for the uncalled functions.

Parents
  • Also be aware that uncalled functions are essentially new "roots" in the call tree generated during data overlay analysis. This means that the parameter and auto data allocated to them (assuming a non-reentrant model) will not be overlaid -- that is, permanently occupying otherwise unused RAM. This is especially troublesome when using the small memory model.

Reply
  • Also be aware that uncalled functions are essentially new "roots" in the call tree generated during data overlay analysis. This means that the parameter and auto data allocated to them (assuming a non-reentrant model) will not be overlaid -- that is, permanently occupying otherwise unused RAM. This is especially troublesome when using the small memory model.

Children
  • Unfortunately, a linker option to remove unreference, relocatable code is not available. This is true even though this option is as safe as removing unreferenced, "one function per file" code. That option they do support. By the sheer number of questions on this topic, you would think they would implement it.

  • ". By the sheer number of questions on this topic, you would think they would implement it"

    On that basis, I think they'd have to allow initialisers with _at_ definitions first... ;-)

    (although that question hasn't actually been asked for a while now...)

  • This is true even though this option is as safe as removing unreferenced, "one function per file" code. That option they do support.

    Actually, we don't support that. Our linker (lika hopefully every other linker on the planet) is smart enough that is doesn't include library MODULES (not functions) that you don't reference.

    There is no option that excludes functions that are no referenced.

    It is just that the linker doesn't include modules that are unreferences (because the functions in them are unreferenced).

    Jon

  • "Our linker (lika hopefully every other linker on the planet) is smart enough that is doesn't include library MODULES (not functions) that you don't reference."

    Absolutely! that is, after all, the whole point of a Library


  • IMO, It would still be valuable to be able to remove uncalled functions, even if other functions in the same module were referenced.

    A library is just a list of object files. Dead code elimination should work the same whether I build a lib or list a string of .obj's for the link.

    Why is the dead code there? The project's not done yet, and that code will be live eventually. Perhaps it will be called soon. And for doing incremental testing, I'd sometimes like to be able to just comment routines out. If I do that, though, the uncalled functions become new roots of the overlay tree and the linker becomes unhappy over all the extra data space that's now "consumed" by the dead code. If the function disappeared entirely, the overlayer wouldn't get so concerned. Even if the warning is "harmless", it's good practice to avoid all build warnings so that the "harmless" ones don't bury real ones in a wall of text. Since the point of tools is to make your life easier instead of harder, avoiding these warnings and the code/data bloat shouldn't require lots of hacking around with OVERLAY directives and re-organization of your project structure every time you comment or uncomment a function call.

    Please add this option to the feature request list. I'd suggest you need perhaps three levels: the current style; a "warnings only" where the linker merely notes that the code has been removed to nag you into getting to the final code yet without adding to the "program size" counters; and a silent option where the code disappears without any warning.