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 specify a global variable to point to start and end of .text section?

Hi,

I need to set up a global variable in my program which point to start of '.text' section also another points to the end.  I found a Platform.xdc file, which it was commented as "File generated by platform wizard. DO NOT MODIFY". Could anybody please suggest a way to do this?

Thanks in advance

Sudeep

  • I recommend you set up a symbol in the link command file, and refer to it from C code.

    Your link command file probably sets up the .text section with a line like this ...

    .text > MEMORY_RANGE_NAME

    So, change it to this ...

    .text > MEMORY_RANGE_NAME, RUN_START(_text_start_sym)

    That will create a symbol named _text_start_sym.  The value of that symbol will be the address at which .text starts.

    To refer to this symbol in C code write "text_start_sym" if you are building with the older COFFABI.  If you are using the newer EABI, write "_text_start_sym" (don't drop the leading underscore).  For now, I presume you are using the older COFFABI.

    Do not refer to the symbol like this ...

    my_ptr = text_start_sym;

    That treats text_start_sym as if it were a normal C symbol.  That is, it will fetch the contents of the memory address labeled with text_start_sym.  Since text_start_sym is not a normal C symbol, that doesn't work.  You need the value associated with the symbol, i.e. its address.  Do this instead ...

    extern int text_start_sym;
    #define TEXT_START (&text_start_sym)
    ...
    my_ptr = TEXT_START;

    Thanks and regards,

    -George

  • Hi George,

    Thanks a lot for the reply. I checked the linker.cmd file and could see that it is generated in my build folder as a result of build. i.e configuration is also done as part of

    build. So it seems the editing of  'linker.cmd' is meaningless. Probably, there are mechanisms to override this way, which I am not sure about. On checking the linker.cmd

    file, it was pointing to another file 'arm_app_config_pe9_x.xdl' which actually contains the sections mapping.

    SECTIONS
    {

    .cio: load >> DDR

    GROUP: load > DDR
        {
            .bss:
            .neardata:
            .rodata:
        }
        xdc.meta: load >> DDR, type = COPY
        .text: load >> DDR

    etc.

    }

    Also, on the file's header it is written as "Do not modify this file; it is automatically generated from the template  * linkcmd.xdt in the ti.targets.elf package and will be overwritten.", which indicates there is a possibility to edit 'linkcmd.xdt' to insert a variable in linker.cmd. I am not sure how to do this and whether this is possible.

    Thanks

    Sudeep R K

  • Sudeep,

    You are right, if you're using BIOS6, the linker command file is auto generated based on your BIOS configuration file and RTSC platform. To achieve what you want, you need to add a custom linker command file to the project, and then exclude the .text from the BIOS generated file.

    Try adding the following line to your .cfg file:

    Program.sectionsExclude = "^\.text$";

    Then add a new linker command file to your project with the SECTIONS directive suggested by George:

    SECTIONS
    {
     .text: load > DDR, RUN_START(_text_start_sym)
    }

    Here are some additional references on this topic that might be helpful:

    http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/p/135424/487939.aspx#487939
    http://rtsc.eclipse.org/docs-tip/Memory_Management#User_Defined_Linker_Command_Files
    http://e2e.ti.com/support/embedded/bios/f/355/p/95695/333475.aspx#333475
    http://rtsc.eclipse.org/cdoc-tip/xdc/cfg/Program.html#sections.Exclude

  • Hi Aarti,

    Thanks a lot for replying. I tried to exclude the .text section as you had suggested(done in the .cfg file). It was found that '.text' section mapping is now

    excluded from 'dsp_app_config_p674_x.xdl' (which is where the Segments and sections are listed and file path of which is included in 'linker.cmd')

    SECTIONS

    {

     .cio:load >> DDR

     xdc.meta: load >> DDR, type = COPY

    .text:load >> DDR                           ----------now excluded

    }

    But, it is not possible to directly add anything here, since it is also automatically generated during build in my case. So, as per the documents you had shared,

    there is another way suggested. i.e to edit the '.xdt' file(template). In my case it is 'ti/targets/linkcmd.xdt'. When I edited it and build, I got the following errors

    warning: memory range not found : text.loadsegment on page 0

    error: no valid memory range(NULL) available for placement of ".text"

    error: placement fails for object ".text" size 0x453e0 (page 0)

    Any clue whether I have done anything terribly wrong?

    Thanks

    Sudeep R K

     

     

  • sudeep rk said:
    But, it is not possible to directly add anything here, since it is also automatically generated during build in my case.

    That is correct, you do not add the SECTIONS statement in the .xdl or BIOS generated linker.cmd files. You should create a new file (which will be your custom linker command file), add those SECTIONS lines I mentioned above, and save the file with .cmd extension (say mylink.cmd). Then add this file to your project. Now when you rebuild, it should link in this custom .cmd as well in addition to the BIOS linker.cmd and honor your section specification.

  • Hi Aarti,

    Thanks a lot for your reply. I tried it out and it worked.

    Thanks

    Sudeep R K