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.

Linker inits const variables in cinit

Hello,

I am using the TMS470 Linker PC v4.9.0 for linking the project.

My problem is, that the linker places const (section .osconst)  - data into ROM, but it does not show in the output file.
Looking at the MAP file, I've seen that this particular section is going to be initialized via cinit. I placed an excerpt and the bottom of this message.

As it is shown in the linker generated copy tables, the section .osconst is stated there. This table now tries to copy RLE compressed data from ROM to ROM, which is not going to work in my opinion.
Using the section .osconst as input section for .text is currently the only solution for my problem.

My questions is, why this section is initialized by cinit? Is there a way to disable this for this particular section?

Thanks, Erich

MAP-FILE:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

******************************************************************************
                  TMS470 Linker PC v4.9.0                      
******************************************************************************
>> Linked Mon Jul 02 10:33:12 2012

OUTPUT FILE NAME:   <MMU-SCM_DEBUGGING.out>
ENTRY POINT SYMBOL: "_c_int00"  address: 00047c68


MEMORY CONFIGURATION

         name            origin    length      used     unused   attr    fill
----------------------  --------  ---------  --------  --------  ----  --------
  JMPVECTORS            00000000   00000020  00000018  00000008     X
  HEADER                00020000   00000080  00000008  00000078  R   
  VECTORS               00020080   00000200  000001a4  0000005c  R  X
  DSW                   00020280   0015fd70  00040940  0011f430  R  X
  PRESENCEFLAG          0017fff0   00000010  00000008  00000008  R   
  FLASH3                00180000   00080000  00000000  00080000  R  X
  STACKS                08000000   00001000  00000000  00001000  RW  
  RAM                   08001000   0003efff  00010918  0002e6e7  RW  


SEGMENT ALLOCATION MAP

run origin  load origin   length   init length attrs members
----------  ----------- ---------- ----------- ----- -------
00000000    00000000    00000018   00000018    r-x
  00000000    00000000    00000018   00000018    r-x .jmpvectors
00020000    00020000    00000008   00000008    r--
  00020000    00020000    00000008   00000008    r-- .APPLHEADER
00020080    00020080    000001a4   000001a4    r-x
  00020080    00020080    00000004   00000004    r-x .osresetvect
  00020084    00020084    00000018   00000018    r-x .osarmvect
  0002009c    0002009c    00000188   00000188    r-- .osvtable
00020280    00020280    000399b8   000399b8    r-x
  00020280    00020280    0000094c   0000094c    r-- .osconfig
  00020bcc    00020bcc    00027cb8   00027cb8    r-x .text
  00048884    00048884    000113b4   000113b4    r-- .const
00059c38    00059c38    00000a60   00000a60    rw-
  00059c38    00059c38    00000a60   00000a60    rw- .osconst
0005a698    0005a698    00006524   00006524    r-x
  0005a698    0005a698    00005eb0   00005eb0    r-x .oscode
  00060548    00060548    00000670   00000670    r-- .cinit
  00060bb8    00060bb8    00000004   00000004    r-- .APPLTRAILER
0017fff0    0017fff0    00000008   00000008    r--
  0017fff0    0017fff0    00000008   00000008    r-- .PRESENCEFLAG
08001000    08001000    00007888   00007888    rw-
  08001000    08001000    00007888   00007888    rw- .data
08009000    08009000    00009090   00009090    rw-
  08009000    08009000    00009090   00009090    rw- .bss
 
 
LINKER GENERATED COPY TABLES

__TI_cinit_table @ 00060ba0 records: 3, size/record: 8, table size: 24
    .osconst: load addr=00060548, load size=00000489 bytes, run addr=00059c38, run size=00000a60 bytes, compression=rle
    .data: load addr=000609d8, load size=000001a1 bytes, run addr=08001000, run size=00007888 bytes, compression=rle
    .bss: load addr=00060b80, load size=00000018 bytes, run addr=08009000, run size=00009090 bytes, compression=rle

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

LINKER COMMAND FILE:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/****************************************************************************************/
#define STARTUP_STACK_SIZE           0x00001000
#define RAM_SIZE                     0x0003FFFF

/****************************************************************************************/
/* SPECIFY THE SYSTEM MEMORY MAP for PSFC61 */                                     
/****************************************************************************************/
MEMORY
{
    /* BANK 0 */
    JMPVECTORS   (X)  : origin=0x00000000 length=0x00000020  /* Dummy JMPVECTORS section can be removed if FBL is integrated */
    HEADER       (R)  : origin=0x00020000 length=0x00000080  /* */
    VECTORS      (RX) : origin=0x00020080 length=0x00000200  /* Interrupt Vectors are placed here */
    DSW          (RX) : origin=0x00020280 length=0x0015FD70  /* Application space for driving software */
    PRESENCEFLAG (R)  : origin=0x0017FFF0 length=0x00000010  /* Last 16 Byte are for the presence flag and MASK. Needed by the FBL */
    
    
    /* BANK 1 */            
    FLASH3       (RX)    : origin=0x00180000 length=0x00080000
    
    /* TCM RAM */  
    STACKS       (RW) : origin=0x08000000                  length=STARTUP_STACK_SIZE  /* Stacks used by ... */
    RAM          (RW) : origin=START(STACKS)+SIZE(STACKS)  length=(RAM_SIZE - SIZE(STACKS))
}

/****************************************************************************************/


/****************************************************************************************/
/* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY                                          */
/****************************************************************************************/
SECTIONS
{
/* ROM */

    .jmpvectors   : {} > JMPVECTORS    /* Substitude FBL */

    .APPLHEADER   : {} > HEADER
    
    GROUP (VECTORS) :
    {
        .osresetvect  /* INTERRUPT VECTORS for RESET   */
        .osarmvect    /* INTERRUPT VECTORS for ARM     */
        .osvtable     /* INTERRUPT VECTORS for VIM     */
    } load=VECTORS

    .osconfig   : {} > 0x00020280         

    .text       : { } > DSW
    .osconst    : { } > DSW
    .const      : { } > DSW
          
    GROUP(APPLICATION) : palign(4)
    {
        .oscode
        .cinit       
        .pinit
        .APPLTRAILER       
    } > DSW
    
    
    .PRESENCEFLAG  : palign(4) {} > PRESENCEFLAG   /* This is the presence flag the FBL normaly writes. For using it with the debugger we place it here */
    
/* END ROM */

/* RAM */

    .stack   : {
                    _StackUSER_  = .+ (SIZE(STACKS) - (256+128+128+128+128));
                    _StackFIQ_   = _StackUSER_  + 128;
                    _StackIRQ_   = _StackFIQ_   + 256;
                    _StackABORT_ = _StackIRQ_   + 128;
                    _StackUND_   = _StackABORT_ + 128;
                    _StackSUPER_ = _StackUND_   + 128;
               } > STACKS       /* SOFTWARE SYSTEM STACK            */

    .bss     : {
                 #include "..\GenData\BSW\osobjs.inc"
                 *(.osstack)
                 *(.bss)
               } > RAM         /* GLOBAL & STATIC VARS              */
               
    .data    : {
                 #include "..\GenData\BSW\osobjs_init.inc"
                 *(.data)
               } > RAM        /* INITIALIZED DATA              */               
/* END RAM */


}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • Erich,

    .cinit section is used for initializing global variables with initial values. The problem here is that compiler/linker does not recognize the data in your .osconst section as read-only constants. You need to define all data in .osconst section as constant. You can add "const " in front of all your data definitions. If you use EABI library, you need also add "--retain="*(.osconst)" before memory definition.

    Thanks and regards,

    Zhaohong

  • Thank you for your answer.

    After checking again all variables I've put into the section ".osconst", there was only 1 variable which did not have the qualifier "const" set. After doing so, there was no ".cinit" any more.

    I think a linker warning would be suitable for such things, telling the user, that there is a variable (including variable name)  with no const qualifier put into ROM.

    BR,
    Erich

  • Hello,

    I am having the same problem in my EVM. I am trying to place some .const tables in specific obj files in another const section named .extconst via my linker file.

    I am using following line to place them...

    .extconst > DDR3_0 { command_table.obj (.const) }

    this line places the const parts of this file to extconst section, it is correctly loaded to memory but cinit initializes the section. Also in simulator this is not happening, only in evm.

    I also tried (NOINIT) with the section but that doesn't work either.

    I also add --retain="*(.extconst)" to the beginning of my linker file.

    If I don't put that line into my linker file, those tables are loaded into internal ram and don't be initialized after cinit.

    How can I tell the compiler not to initialize my section?