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.

TMS570LC4357: Linker creating uninitialised section when optimisation less than 4 (Whole Programme)

Part Number: TMS570LC4357
Other Parts Discussed in Thread: ARM-CGT

Tool/software:

Using ARM-CGT v20.2.7LTS

I have a defined region in flash I want to place some data. I have a struct defined in a header, then instantiated in a .cpp, wrapped in a SET_DATA_SECTION()

appBlk.cpp:

#pragma SET_DATA_SECTION(".appblk")
#pragma RETAIN
const AppBlk ApplicationBlock{NEO_MAGIC_NUMBER,
(uint32_t)&_app_start,
(uint32_t)&_app_end,
(uint32_t)&_c_int00,
(uint32_t)&_appblk_crc,
(uint32_t)&_app_crc};
#pragma SET_DATA_SECTION()

in the linker command file, I have a memory region and section:

MEMORY
{
. . . 
APPBLK (R) : origin=APP_BLK_LOC length=APP_BLK_SIZE vfill = 0xffffffff
FLASH0 (RX) : origin=APP_LOC length=(FLASH0_SIZE - APP_LOC) vfill = 0xffffffff
FLASH1 (RX) : origin=FLASH1_LOC length=FLASH1_SIZE vfill = 0xffffffff

 . . . 

.appblk palign(8), fill = 0xffffffff : {} LOAD = APPBLK, LOAD_START(_appblk_start), LOAD_END(_appblk_end), crc_table(_appblk_crc, algorithm=TMS570_CRC64_ISO)

. . .

When compiled with optimsation level 4, this works perfectly

.map:

MEMORY CONFIGURATION

name origin length used unused attr fill
---------------------- -------- --------- -------- -------- ---- --------
VECTORS 00000000 00000040 00000000 00000040 X (ffffffff)
BOOT 00000040 0001ffc0 00000000 0001ffc0 R (ffffffff)
APPBLK 00020000 00000100 00000080 00000080 R (ffffffff)
FLASH0 00020100 001dff00 00025788 001ba778 R X (ffffffff)
FLASH1 00200000 00200000 00000000 00200000 R X (ffffffff)

. . . 


SEGMENT ALLOCATION MAP

run origin load origin length init length attrs members
---------- ----------- ---------- ----------- ----- -------
00020000 00020000 00000080 00000080 r--
00020000 00020000 00000080 00000080 r-- .appblk
00020120 00020120 00025768 00025768 r-x
00020120 00020120 00000030 00000030 r-x .intvecs
00020150 00020150 00022df0 00022df0 r-x .text

. . . 

SECTION ALLOCATION MAP

output attributes/
section page origin length input sections
-------- ---- ---------- ---------- ----------------
.appblk 0 00020000 00000080
00020000 00000080 AppBlk.obj (.appblk)

when I compile for debug, with optimisation off or up to 3, I get the following error:

warning #99922: app.out: accessing the raw data of section ".appblk" which is uninitialized according to its section attributes; changes to raw data may be lost

.map:

MEMORY CONFIGURATION

name origin length used unused attr fill
---------------------- -------- --------- -------- -------- ---- --------
VECTORS 00000000 00000040 00000000 00000040 X (ffffffff)
BOOT 00000040 0001ffc0 00000000 0001ffc0 R (ffffffff)
APPBLK 00020000 00000100 00000080 00000080 R (ffffffff)
FLASH0 00020100 001dff00 0002ea24 001b14dc R X (ffffffff)
FLASH1 00200000 00200000 00000000 00200000 R X (ffffffff)

. . . 


SEGMENT ALLOCATION MAP

run origin load origin length init length attrs members
---------- ----------- ---------- ----------- ----- -------
00020000 00020000 00000080 00000000 rw-
00020000 00020000 00000080 00000000 rw- .appblk
00020120 00020120 0002ea04 0002ea04 r-x
00020120 00020120 00000030 00000030 r-x .intvecs
00020150 00020150 0002a208 0002a208 r-x .text

. . .

SECTION ALLOCATION MAP

output attributes/
section page origin length input sections
-------- ---- ---------- ---------- ----------------
.appblk 0 00020000 00000080 UNINITIALIZED
00020000 00000080 AppBlk.obj (.appblk)

For some reason the memory region switches from read-only to read-write, and the section is empty. I assume it's expecting to be populated on start-up with a copy.

How do I force that to be a read-only section so the data is placed there by the linker? I just can't figure it out!