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.

Compiler/66AK2G12: How can a program find the start and end of .text and .const sections?

Part Number: 66AK2G12

Tool/software: TI C/C++ Compiler

I have a very occasional crash in my TI-RTOS system and I can see a rogue memset() call involved.  The call itself is made by third party code and while I'm trying to get the sources, for the moment I want to protect against this.  I have added code to memset to identify "out of bounds" writes.  The .text and .const sections are out of bounds.  Today I am looking at the map file produced by the TMS320C6x Linker PC v8.1.0 and extracting these addresses by hand, then recompiling.  I could automate the recompile process using a script, but I'd first rather ask: 

Can you suggest a way for the compiler and linker to fill in these addresses themselves?  Eventually I need to fill in a variable with the start and size or end of the .text and .const sections.

  • There are two steps.  First, in the linker command file, create symbols that hold the address and size of the desired sections.  Second, in the C code, use those symbols to check for out of range accesses.  

    To learn how to create the symbols, see the section titled Address and Dimension Operators  in the C6000 assembly tools manual.  Note you need to capture run addresses, and not load addresses.  To understand how to use those symbols in C code, see the section titled Using Linker Symbols in C/C++ Applications  in the same manual.

    Thanks and regards,

    -George

  • This isn't yet working for me. I see that you provided the link to the user guide for v8.3.x. I'm now using 8.2.2. Is it possible that this matters? I doubt it.
    While constructs like this work:
    func_sym=UART_open+100; // function name.
    Constructs like this do not: (undefined symbol ".text" used in expression)
    func_sym=.text;
    It seems that .text and .const are not symbols.
    Address and Dimension Operators like RUN_END() similarly tell me that .text is not a symbol.

    Can you suggest a way to convert a section name to a symbol?
  • Chuck Peplinski said:
    I see that you provided the link to the user guide for v8.3.x. I'm now using 8.2.2. Is it possible that this matters?

    No.

    Chuck Peplinski said:
    It seems that .text and .const are not symbols.

    They are symbols.  Just not symbols you can access from C/C++ code.  In assembly code, and in the linker command file, symbol names can contain a ".", the dot character.  In C/C++ symbols, a "." is not allowed.  

    Chuck Peplinski said:
    Can you suggest a way to convert a section name to a symbol?

    Linker command files can #include C header files.  So, in a header file included by both C and the linker command file, you can write something like ...

    #define TEXT_START text_start

    In the linker command file, you would have something like ...

        .text > RAM, RUN_START(TEXT_START)

    In your C code, use TEXT_START as a C symbol.

    Thanks and regards,

    -George

  • Now it is resolved.  The command 

    .text > RAM, RUN_START(text_start)

    goes inside the SECTIONS region.

    Then the C code must :

        extern far unsigned int text_start;

    and the value I want (the start of the text region) is &text_start.