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.

  • TI Thinks Resolved

Compiler/CCSTUDIO: Section, Memory, Compiler and Linker

Expert 1390 points

Replies: 1

Views: 134

Part Number: CCSTUDIO

Tool/software: TI C/C++ Compiler

Hi, I'm reading TMS320C6000 Assembly language tools User Guide according to this link: https://e2e.ti.com/support/processors/f/791/t/59430

I'm reading Chapter 2, and it says:

Several assembler directives allow you to associate various portions of code and data with the appropriate sections.」

I've only written C, and I'm with little experience on reading assembly code.

Q1: I didn't recall any directive in .asm file that I read before. Is dividing file into sections by using directives necessary or depending on Compiler?

I know that C programming language has by nature sections concept, e,g, variables outside any function are global, inside are local, and Compiler can take advantage of this for dividing sections. Therefore there is no need of programmer using directives in C source file.

Q2: Is my conclusion, as to last sentence, correct?

The user guide also says:

The linker has two main functions related to sections. First, the linker uses the sections in object files as building blocks; it combines input sections (when more than one file is being linked) to create output sections in an executable output module. Second, the linker chooses memory addresses for the output sections.

Two linker directives support these functions:

    • The MEMORY directive allows you to define the memory map of a target system. You can name portions of memory and specify their starting addresses and their lengths.

    • The SECTIONS directive tells the linker how to combine input sections into output sections and where to place these output sections in memory.

Q3: I didn't see "SECTIONS directive tells the linker how to combine input sections into output sections" in my linker command file.

7.4.9 Define an Entry Point (--entry_point Option) from User Guide

The memory address at which a program begins executing is called the entry point. When a loader loads a program into target memory , the program counter (PC) must be initialized to the entry point; the PC then points to the beginning of the program. The linker can assign one of four values to the entry point. These values are listed below in the order in which the linker tries to use them. If you use one of the first three values, it must be an external symbol in the symbol table.

    • The value specified by the --entry_point option. The syntax is: --entry_point= global_symbol where global_symbol defines the entry point and must be defined as an external symbol of the input files.

    • The value of symbol _c_int00 (if present). The _c_int00 symbol must be the entry point if you are linking code produced by the C compiler.

    • The value of symbol _main (if present)

    • 0 (default value)

Q4: The Linker options "-e Entry" is not described by user guide.

  • I do not recommend trying to learn how to program in assembly by reading the Assembly Languages Tools User's Guide (or ALT).  Instead, write very small C files that contain one variable definition, or one very small function.  When you build them, use the option --src_interlist.  This causes the compiler to keep, rather than delete, the auto-generated assembly code.  The file has the same name as the source file, with the extension changed to .asm.  Inspect this file.  Ignore all the directives that begin .dw.  Those directives are how debug information is encoded.  You'll never need to write those by hand.  For all the other directives, look them up in the ALT.  For the instructions, look those up in the relevant CPU user's guide.  

    Andy Lin94
    I know that C programming language has by nature sections concept, e,g, variables outside any function are global, inside are local, and Compiler can take advantage of this for dividing sections. Therefore there is no need of programmer using directives in C source file.

    You are mixing up two different concepts.  In C, there is the concept of variable scope.  A variable written outside of any function is global by default.  If you use the keyword static, then it is available throughout that file, but not the rest of the program.  A variable written inside a function is local to that function.  A section, on the other hand, is an entirely different concept.  In assembly, and in the linker, code and data are organized into sections.  A good introduction to sections is in the first part of the article Linker Command File Primer.

    Regarding the entry point ... The entry point is a field in the file header of the final executable file created by the linker.  This is how a loader knows where to begin execution of the program.  In many embedded systems, there is no loader.  In such systems, the entry point is less important.  The argument of the entry point option is a symbol.  The address corresponding with this symbol is encoded into the entry point field of the executable file header.

    Thanks and regards,

    -George


    TI C/C++ Compiler Forum Moderator
    Please click This Resolved My Issue on the best reply to your question
    The CCS Youtube Channel
     has short how-to videos
    The 
    Compiler Wiki answers most common questions
    Track an issue with SDOWP. Enter your bug id in the Search box.

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.