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.

TMS320F28379D: Linker Adds Unused Code

Part Number: TMS320F28379D

Greetings,

I have a project which imports a folder which contains a lot of different things.  The project uses a subset of those things.  On a recent build, the linker ran out of room in the flash.  Upon investigation, I realized that code which is not being used was being added to the output.  I have looked for a linker option which prevents this, but I am unable to find anything.  Would you please steer me to the correct setting?

Thank you,

Ed

  • OK.  It's a compiler switch to put everything in a separate subsection.  But this is only part of the problem.  I have found that by excluding the unused parts from the build, I get even more space back.  Is this because constructors and destructors are still added even if nothing else in the object is used?

    Thank you,

    Ed

  • by excluding the unused parts from the build, I get even more space back.

    Let's say you have one source file named never_used.cpp.  It contains the implementation of some member functions for a class.  The main program never creates an instance of this class.  Thus, none of these functions are ever called.  Even so, the fact that you build never_used.cpp and include never_used.obj in the final link means those member functions appear in the program, taking up memory.  I cannot reproduce this behavior.  

    My guess is you are doing something similar, but there is a difference or two.  And one of those differences might be the cause.  What are you doing that is different?

    Thanks and regards,

    -George

  • Hi George,

    First, from the map file, I made a note of the amount of free flash.

    Next, in the project Properties, under Build->C2000 Compiler->Advanced Options->Runtime Model Options, I changed "Place each function in a separate subsection (--gen_func_subsections, -mo)" to "on".  The project was built and the map file examined.  The functions in never_used.cpp were gone, and the amount of free flash had increased.

    Finally, in Project Explorer, I navigated to never_used.cpp, right clicked, and selected "Exclude from Build".  The project was built again, and the map file inspected.  The amount of free flash had increased again.  This lead me to think that the constructors and destructors had been removed.  I neglected to examine that part of the map file.

    So I just duplicated it again with the file not excluded, and I do see it reflected in the .cinit and .pinit sections and some code in the .text area.  When I excluded the file again, it was nowhere in the map file.

    So I think I have answered my own question.  Agreed?

    Thank you,

    Ed

  • I can show you one example of what might be happening.

    Suppose you define a class with a non-trivial constructor ...

    /* These lines typically in header file */
    class ntc {
       ntc(/* arguments here */);
    };
    
    /* These lines typically in a C++ file */
    ntc::ntc(/* arguments here */)
    {
        /* non-trivial code here */
    }

    And, you define an global instance of this class ...

    ntc global_instance(/* arguments here */);

    Suppose further the main part of your program never refers to global_instance, or uses this class in any way.

    If the build includes the C++ source file(s) that define this constructor and global_instance, that causes all the code and data shown here to be part of the build.  If you exclude those same C++ source file(s) from the build, that same code and data is not part of the build.

    I suspect your code does something along these lines.

    Thanks and regards,

    -George

  • This class is instantiated globally.  But it differs in the sense that it has a base class and no arguments or code.  That being said, the base class constructor does some assignments.

    ntc::ntc()
    : ntc_base_class()
    {
    // No code.
    }

    Thanks,

    Ed