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.

Dead code elimination depends on ramfuncs pragma?

Hello,

I am a C28x software developer and I noticed something related to
dead code elimination.

I commented out a function calling from my code (the function
definition remained) and the size of the out file decreased and the
function disappeared from the map file. This is what I expected.
This function was a RAM run function and there is a pragma at the
file beginning:

    #pragma CODE_SECTION(StateMachine_XYZ, "ramfuncs");

When I commented out this pragma line too, the out file size was
bigger again and the function name showed up again in map file
(the function definition was still in the code). The pragma and the
function definition was in the same file as the (commented out)
funcion calling.

I thought if a function is not referenced should be removed from
executable code. Why depends the removing of unreferenced
function on ramfuncs pragma? Is this a glitch in dead code removing
method or is the normal behavior?

I use CCSv10, TI v20.2.5.LTS.

  • For a function to be automatically removed, it needs to be in a section on its own.  The is normally accomplished by building with the option --gen_func_subsections.  In your specific case, you did a similar thing with #pragma CODE_SECTION.  When the #pragma is removed, this function gets combined with others in a section named .text, and it cannot be automatically removed.

    For more details on this option and #pragma, please search for them in the C28x compiler manual.

    Thanks and regards,

    -George

  • I have played around with ramfuncs pragma and I tried the --gen_func_subsections compiler flag too and the situation was exactly what you described. Thank you for the demystification, George!