This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F28335: Unused function when compiling/linking libraries ( .libs )

Part Number: TMS320F28335

Tool/software: TI C/C++ Compiler

I have a question regarding the usage of the Flash28335_API_V210.lib and rts2800_fpu32.lib libraries that are being used on one of our programs. What happens with library functions that aren’t called by the program? Do those functions get linked and built into the image or are they left out of the final image? 

C2000 compiler toolchain V5.2.1 is being used with CCS V3.3

Thanks!

  • It is close, but not quite precise, to say: Functions in a library which are not called are left out of the final image.

    It is precise to say: Files (not functions) in a library which define no symbols used by the main application code (whether direct or indirect), are left out of the final image.  Consider an example.  Suppose a library file contains two functions:

    int is_called()    { /* code here */ }
    int never_called() { /* code here */ }

    Suppose the main application code calls is_called, but not never_called.  Then the entire file is brought into the link.  Other features of the linker, under circumstances not described here, may later remove never_called.  But, restricting the discussion to what comes in from a library, both functions come in.

    Thanks and regards,

    -George

  • Yes, thanks for the clarification; that makes sense.

    Would you please explain further the features of the linker that will remove unused functions from within a library file that has used functions such as your example from above?

    Thanks!
  • The linker removes the function never_called if that source file is built with the option --gen_func_subsections.  The C2000 compiler manual describes the option --gen_func_subsections.  This description includes a library example similar to the one I give in the previous post.

    Thanks and regards,

    -George

  • The linker operates on sections, not functions. The linker can and does eliminate unused sections. If an unused function is in a section by itself, it can be eliminated by the linker. If the unused function is in the same section as a needed function, the linker must include that section, thereby dragging in the unused function.