Compiler wastes memory by initializing const global array of class objects with a pinit function instead of putting data in .const

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Implement
    • Priority: Not Prioritized

      The attached C++ file has these lines ...

      const cPARA_INFO pg6[] = {
      //----------------------------------------------------------------------------------
      // DEF, MinL, MinH ,MaxL  , MaxH,           Type    | Attr (all Paras in P5 Gp is 32 bits)
      //---------------------------------------------------------------------------------- 
      cPARA_INFO(   0,0x0000,0X0000,0xff3f,0xFFFF,  0x6000 ,Para_Func_NULL,((int*)&PR_Homing) ),     // P6-00
      cPARA_INFO(   0,0x0000,0X8000,0xffff,0x7FFF,  0x2000 ,Para_Func_NULL,((int*)&PR_Homing)+2),    // P6-01
      cPARA_INFO(   0,0x0000,0X0000,0xffff,0xFFFF,  0x6000 ,Para_Func_P6_02_3,((int*)PR_Point)   ),  // P6-02
      cPARA_INFO(   0,0x0000,0X8000,0xffff,0x7FFF,  0x2000 ,Para_Func_P6_02_3,((int*)PR_Point)+ 2),  // P6-03
      cPARA_INFO(   0,0x0000,0X0000,0xffff,0xFFFF,  0x6000 ,Para_Func_P6_04_5,((int*)PR_Point)+ 4),  // P6-04
      /* and so on */
      

      Note it is const. The length of this array is important. Make it shorter, and the problem disappears.

      Use a very old version 3.07 of the compiler. Build it ...

      % cl2000 -@options.txt file.cpp
      

      Inspect the assembly file. This array begins ...

      	.sect	".econst"
      	.align	2
      _pg6:
      	.field  	0,32			; _pg6[0]._DEF @ 0
      	.field  	0,16			; _pg6[0]._MIN @ 32
      	.field  	0,16			; _pg6[0]._MAX @ 48
      	.field  	-193,16			; _pg6[0]._NUM @ 64
      	.field  	-1,16			; _pg6[0]._DEN @ 80
      	.field  	24576,16			; _pg6[0]._TYP @ 96
      

      The entire array is initialized with this entry in the .econst section.

      Build it again with version 22.6.0.LTS. Inspect the assembly file to see ...

      _pg6:	.usect	".ebss:_pg6",900,0,1
      	.clink ".ebss:_pg6"
      

      Even though pg6 is const, it is in the .ebss section. It gets initialized by a large function, the address of which is added to the .pinit section. This method requires much more memory, and it does not allow pg6 to be allocated to flash.

            Assignee:
            TI User
            Reporter:
            TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Connection: Intermediate to External PROD System
                EXTSYNC-3626 - Compiler wastes memory by initializ...
                SYNCHRONIZED
                • Last Sync Date: