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.

Specifying variable placement in the Linker Sections, how?

Hello,

  I am trying to order the placement of variables within a section without having to define a new section for each variable.  So, in two source files there are variables placed in the .sysmem section.  During the build process, the variable Variable01 is placed before Variable02, but I really want Variable02to be placed at the beginning of the section no matter what.

    #pragma DATA_SECTION (Variable02,  ".sysmem"); 
    #pragma DATA_SECTION (Variable01,  ".sysmem");

In the SECTIONS area of the Linker Directives I can use the following:

SECTIONS
{
    ...
    .sysmem : { Variable02_Src_File.obj Variable01_Src_File.obj } > RAM /* DYNAMIC MEMORY ALLOCATION AREA */
    ...
}

But since there is executable code in this files the executable code goes into those sections too which is not what I want, only these two variables.  I have tried something like:

SECTIONS
{
    ...
    .sysmem       : { *(.sysmem); Variable02= .; Variable01= .; } > RAM
    ...
}

Which is declaring two variables within the section, so during the build it fails since there are now two instantiations of each variable.  So, that does not work.  I supposed I could try moving each of these variables into one common file and declare one variable before another until the ordering is correct, but I am afraid that would break down the road.  Does anyone know how to accomplish this?

Regards,

Mark

  • It looks like you are using CCS (which I do not). However, in IAR, there is a mechanism to specify link address in the source code at the compiler stage of the build process. You might check the compiler user's guide to see if something similar exists.

    #define ALWAYS_ALLOCATE __root
    #define DO_NOT_INITIALIZE __no_init
    
    ALWAYS_ALLOCATE DO_NOT_INITIALIZE unsigned int Variable02 @ 0x3200;
    ALWAYS_ALLOCATE DO_NOT_INITIALIZE unsigned int Variable01 @ 0x3202;
    

    Just make sure to carve out a section in the linker file for the variable placement.

  • While researching another problem I came across the pragma directive "LOCATION" which states:

    "The compiler supports the ability to specify the run-time address of a variable at the source level. This can

    be accomplished with the LOCATION pragma or attribute. Location support is only available in EABI"

    with the code syntax of 

    #pragma LOCATION( x , address );
    int x;

    I have not tried this yet, but I think this should do it.

    Regards,

    Mark

**Attention** This is a public forum