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 configure linker to remove and list unused function identified in source code?

Hi all,

This applies to other TI processor/compiler.

My intention is to identify and remove unused function in the source code. Looking in the manual TMS320C6000 Optimizing Compiler v7.6 User's Guide (SPRU187V):

Table 2-31. Link-Time Optimization Options

--unused_section_elimination[=off|on]
Eliminates sections that are not needed in the executable module. Default is on.

Not clear about the meaning of "sections". It includes for instance one function among other functions in a object file? Or it is a section of linker file?

Comparing the map file with on and off for --unused_section_elimination give me a rough idea.

In order tool chains I am able to remove and list the unused functions in the source code during linkage. 

Eg:.

Deleting Unused Functions
myFunctionUnused in foo.o deleted (regained 44 bytes)

  • Moved this thread over TI Compiler forum for appropriate response. Thank you.
  • Lucas Santos said:
    My intention is to identify and remove unused function in the source code.

    I presume you use the newer ELF based EABI, and not the older COFF ABI.  In that case, the tools remove unused functions automatically.  There is no need to do it yourself.  That said, if you really want to pursue this, here is one way to go about it.

    Build normally, without using --unused_section_elimination.  Then use ofd6x to collect the names of all the functions in the final linked executable.  Something like this ...

    %> ofd6x --func_info final.out > used_functions.csv

    The option --func_info causes ofd6x to emit information on all the functions found in the executable.  It looks similar to this ...

    "memccpy","memccpy.c",0x0000fb20,0x0000fb80,96
    "memcpy","memcpy64.asm",0x0000f500,0x0000f598,152
    "memset","memset.c",0x0000eae0,0x0000ebac,204
    ...

    The format is a .csv (comma separated values) file that you can load into a spreadsheet program like Excel.  You only care about the first column, the name of the function.

    Then build again, but use --unused_section_elimination=off.  Use ofd6x to collect the names of the functions, but name the output file all_functions.csv.  The difference between the files used_functions.csv and all_functions.csv are functions which are never called.

    Thanks and regards,

    -George

  • Thanks Raja and George,

    I´ve checked and the compile support ELF based EABI. Also, it removes unused functions automatically. Since it does automatically, I was not confident if it is doing correctly.
    I missed an output of the list of identified unused functions for verification purpose. It could be a new feature for next releases.

    But, using the ofd6x --func_info like you proposed, I am able to get this list.

    No more questions, thanks indeed.

    Regards,

    Lucas / Hirata