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.

How to retain a function which is not used in the code?

I want to retain a function but eliminate all other unused function from my code. I am using CCS code gen tools version 4.4.2.

I have tried the following options

  1. #pragma RETAIN(func_name); Compiler throws an error indicating unrecognized pragma
  2. #pragma FUNC_EXT_CALLED(func_name); With this also, function is removed.
  3. --retain=func_name in the linker command file. This does not work with TI COFF output. I had to change compilation to EABI format and even after that the function was removed.

How to force linker to keep a function even if it is not used?

Thanks,
Sumeer

  • Hi Sumeer,

    Have you tried locating the function in its own section and then retaining this section within the linker, e.g.:

    In code:

    #pragma CODE_SECTION(MyFunc, ".myFuncSection")

    In Linkfer.cmd:

    --retain="*(.myFuncSection)"

    Regards, Tony

  • I am getting the error

    error: --retain=*(.myFuncSection) not supported when producing TI-COFF output
       files

  • hi,

    I face the same issue when compiling a cortexM3 application.

    here is the function  I want to keep

    // force the code in internal memory- function will be called by its address

    #pragma CODE_SECTION(ISR_EncFunction, ".iva_enc_int");

    // so need to keep the function otherwise it will be swept

    #pragma FUNC_EXT_CALLED(ISR_EncFunction);

    void ISR_EncFunction()

    and here is the build options;(CGT 4.9)

    "C:/TI/CCS/ccsv5/tools/compiler/tms470_4.9.5/bin/cl470" -mv7M3 --abi=eabi -me -O2 --opt_for_speed=2 -g --include_path="C:/TI/CCS/ccsv5/tools/compiler/tms470_4.9.5/include" --include_path="M/libComap4/modules/codecs/ivahd_h264encoder/release_1.0/client/test/inc" --include_path="MlibComap4/modules/codecs/ivahd_h264encoder/release_1.0/inc" --include_path="M:/libComap4/modules/codecs/ivahd_h264encoder/release_1.0/inc/import" --define="OMAP4" --define=_SLAVEM3_ --define="xdc_target_types__= ti/targets/std.h" --define="xdc_target_name__= TMS470" --undefine="A9_HOST_FILE_IO" --diag_warning=225 --enum_type=packed --signed_chars --auto_inline=200 --preproc_with_compile --preproc_dependency="H264EncRmanConfig.pp"

     

    Is it a known issue?

    what are the possible workarounds?

    regards

  • Please see the section titled Unused Section Elimination in this document.   -George