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.

AM2634-Q1: Unused code compiling issue

Part Number: AM2634-Q1

Tool/software:

Hi Champ,

When some code be assigned to once section. through #pragma clang section,  even the code is never called (that means  unused code) will be linked and assigned to that section.

you can refer to below example,  unused function testfunc1 in main.c be linked and be assigned to" .BSW_CODE_SECTION" section.

I attached the example project which i used here.

gpio_led_blink_am263x-cc_r5fss0-0_nortos_ti-arm-clang.rar

May i know if there have any complier option can discard the unused code under this situation?

  • May i know if there have any complier option can discard the unused code under this situation?

    There is no compiler option.  But I do have a source level workaround to suggest.

    Remove the #pragma clang statements. 

    Write a macro similar to ...

    // CSN : Code Section Name
    #define CSN(fn) __attribute__((section(".BSW_CODE_SECTION." #fn)))

    Just before the definition of every function, write ...

    CSN(function_name_here)

    That causes this function to be in its own section with the section name .BSW_CODE_SECTION.function_name_here.  Because each function is in a separate section, the linker can remove the ones that are never called.

    Thanks and regards,

    -George