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/TMS320F28069: function not called will not not occupy space in the map file

Part Number: TMS320F28069

Tool/software: TI C/C++ Compiler

Hi,

we test with a project and inspect the final map file generated.

We find that there are some functions we wrote code in .c file but it's not called in main() or ISR(), so in the final map file it's not seen, which is okay.

Then we want it to be compiled and reside somewhere in map.

We add a .asm file.

In that file, we write 

LCR _func()// func() is the function that was not called but defined in a .c file.

Then we could find that this function will reside in the final map.

So my question is:

1. what's the correct way to make a uncalled function being compiled and linked to the final .out file?

2. Why I add LCR _func() could make this function being compiled and linked? Since in main(), there is no other code that will call "LCR _func()", so in theory this piece of code will not be executed, and thus _func() will not be called, so it should still not be found in .map file.

  • Hi Howard,

    Have you tried #pragma FUNC_EXT_CALLED ?

  • Refer to TI compiler documentation, section 6.10.14

    https://www.ti.com/lit/ug/spru514t/spru514t.pdf

  • Santosh,

    thanks.

    How about question 2:

    2. Why I add LCR _func() could make this function being compiled and linked? Since in main(), there is no other code that will call "LCR _func()", so in theory this piece of code will not be executed, and thus _func() will not be called, so it should still not be found in .map file.

  • Howard,

    I will need to check with Compiler Team. Is this EABI or COFF output format?

    In Assembly file, the post-link optimization can be controlled using comment statement NOPLINK/PLINK. Please refer to the compiler documentation for more details on it. 

  • Howard Zou said:
    1. what's the correct way to make a uncalled function being compiled and linked to the final .out file?

    Use #pragma RETAIN.  Please search for it in the C28x compiler manual.

    Howard Zou said:
    Why I add LCR _func() could make this function being compiled and linked?

    If no reference is made to _func, the linker removes the section which contains it.  I'm not sure why, but for some reason the linker does not remove the section which contains the instruction LCR _func.  That being the case, this reference to _func means it is also not removed.  I recommend you not worry much with this detail.  Just use #pragma RETAIN to solve your problem.

    Thanks and regards,

    -George

  • George,

    Santosh suggest using 

    #pragma FUNC_EXT_CALLED

    while you suggest using 

    #pragma RETAIN

    what's the difference and which exactly is suitable?

  • I'm not sure why, but for some reason the linker does not remove the section which contains the instruction LCR _func.  That being the case, this reference to _func means it is also not removed. 

    Is it that I wrote the code LCR _func in an .ASM file that make it not removed?

    I mean, all the code in .asm file will not be removed, no matter it's called or not by main, right?

  • Howard Zou said:

    Santosh suggest using 

    #pragma FUNC_EXT_CALLED

    while you suggest using 

    #pragma RETAIN

    what's the difference and which exactly is suitable?

    FUNC_EXT_CALLED only matters when program level optimization (--opt_level=3 or higher) is used.  It prevents the compiler from removing a function.

    RETAIN prevents the linker from removing a function.  This is what happens in your case.

    These two pragmas work independently.  When thinking through how they work, consider them one at a time.

    Thanks and regards,

    -George

  • Howard Zou said:
    Is it that I wrote the code LCR _func in an .ASM file that make it not removed?

    There is more to it than that.

    Howard Zou said:
    I mean, all the code in .asm file will not be removed, no matter it's called or not by main, right?

    Wrong.  Even code or data written in assembly is subject to being removed.

    I'm not sure why this particular bit of assembly code is not removed.  Since #pragma RETAIN solves your problem, I do not recommend considering this issue any further.

    Thanks and regards,

    -George