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.

Is that possible to extract the binary code of a symbol from the genereated ELF file even though the size is 0 in the symbol table?

Other Parts Discussed in Thread: TMS320C6747

I'm a user of CCS 5.0.3 with the compiler tool 7.1.2, I compiled my DSP TMS320C6747 C code to target file in ELF format. I have a requirement to extract the binary code of a symbol (for example, a global function or a global variable). However, I found that the size field of all the symbols in the symbol table of the gerated file are 0, which means the size is 0 or unknown refer to the ELF file specification. I prefer some of values mean unknown. So is that possible to extract the binary code eventhough the size field is 0? Or is there some options for compiler that can cause the size field to be non-zero value?

Thanks for your answer in advance.

  • I'm not sure what you mean.  Please show me a small example of a symbol with size 0.  

    Thanks and regards,

    -George

  • Hi , thanks for your reply first. I'm sorry that I need to correct a mistake that I made in my previous post. The exact code generation tool version of CCS 5.0.3 is 7.2.1 instead of 7.1.2. But anyway,  it's not so related to this topic. 

    Here is a small example of a symbol with size 0. I created a CCS project in CCS 5.0.3, created a main.c file, then wrote such a piece of code.

    #include <c6x.h>
    #include <stdio.h>
    
    void initC6747() {
    	printf("initC6747 invoked!\n");
    }
    
    int main() {
    	initC6747();
    }
    

    and compiled it in default DEBUG mode to generate an ELF file, the generated file name is ElfTest.out.

    Then I use the readelf tool (a default tool in Linux) to parse the information of ElfTest.out by:

    readelf -a ElfTest.out > ElfTest.out_debug.txt

    In the file ElfTest.out_debug, I found the symbol items of global function main and initC6747 in the symbol table:

       Num:    Value  Size Type    Bind   Vis      Ndx Name
      ......
      1220: 00805e20     0 FUNC    GLOBAL HIDDEN     1 initC6747
      1221: 00805e40     0 FUNC    GLOBAL HIDDEN     1 main
      ......

    However, both of the sizes are showed 0! So is that possible if I want to extract the binary code of initC6747() and main() from the generated ELF file ElfTest.out?

    For convenience, the mentioned CCS project, generated ELF file and the readelf parse result are attached below:

    The CCS project file: 4643.ElfTest.zip

    The generated ELF file: 0535.ElfTest_out.zip

    The readelf parse result: 7607.ElfTest.out_debug.zip

    Thank you very much.

  • In TI tools symbol size is meaningful only for data symbols.

    I tried to see if this is also true of the gcc compiler.  On a Linux machine I performed a native build with gcc.  That ELF file did show a size for the functions initC6747 and main, but no other functions.  I'm not sure where that size is coming from.  I think it is notable that most functions did not have a size even under gcc.

    The main point is that, for functions, you cannot rely on finding a size associated with the symbol.

    What overarching problem are you trying to solve?  I'm sure there is a way to do it.

    Thanks and regards,

    -George

  • Hi , thanks for your answer first. I wondered why the symbol size is meaningful only for data symbols, but not for functions.

    I tested a C code with a global variable (int globalVar;) in the code generation tool v7.2.1, and found the size of both function and global variable is 0, but when I moved to the code generation tool v7.4.4, the global variable size is 4 as you mentioned. However the function size is still 0.

    I tested this C code using gcc under a linux platform both on x86 and ARMv11 machine, the generated ELF file show the size of the functions, but not for some functions that are automatically added by gcc itself. I performed objdump to disassemble the generated ELF, and found the function size is equal to the number of bytes of the machine code of that function. So I believe the function size can be determined after compilation and linkage, because the function size can be counted by its machine code bytes. I don't know why TI tools didn't do that.

    Is there disassembler tools like objdump for TI DSP C6747? If there is, probably I can count the function size from the result of the disassembler.

    I want to analyze the memory layout change of the ELF file that compared with before and after adding/deleting/modifying few functions.

  • Hi,

    Try to dump also the dwarf debug info (readelf --debug-dump).

    You should find enties fo type "DW_TAG_subprogram", followed by the function name (DW_AT_name) and the low/high program counter (DW_AT_low_pc and DW_AT_high_pc).

    It seem to me that the high program counter (end of function code) point to the next location after the return branch instruction.

  • Shan Wang said:
    I want to analyze the memory layout change of the ELF file that compared with before and after adding/deleting/modifying few functions.

    One way to do that is to look at the linker map file.  This file is created when you use the linker option --map_file=filename.

    Another way to do it ... Adapt the technique in this wiki article.  That allows you to see the changes in an Excel spreadsheet.

    Thanks and regards,

    -George