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!

  • Hi Paul,

    Apologies for the delayed response, i am discussing this with compiler expert once, i will provide you updates as soon as possible.

    --
    Thanks & regards,
    Jagadish.

  • Unfortunately, I am unable to reproduce ...

    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

    I think I can reproduce it with less than your entire project.  But I still need more than is typical for a test case.

    1. For the source file appBlk.cpp, please follow the directions in the article How to Submit a Compiler Test Case.  That results in a preprocessed source file.
    2. Please capture the log of a complete build in a text file.  Please capture all the commands as the system sees them, i.e. after all build variables are evaluated.
    3. Please send the linker command file.

    Put all 3 files in a zip and attach it to your next post.

    Thanks and regards,

    -George

  • Hi George,

    I've reduced the project to the minimum which replicates the issue. Removed all IP (though the company name still appears as the namespace and headers).

    Within the zip are two further zips of the build, including console_output.txt which is a copy-paste of the build output.

    Release_working.zip is with optimisation set to 4

    Release_notworking.zip is with optimisation set to off (the only difference)

    2477.Test.zip

    Hope that helps.

    Thanks, Paul.

  • Thank you for the test case.  I am able to reproduce the same behavior.  While you see the problem in the linker, it starts with an error in the compiler. I filed the issue EXT_EP-12701 to have this investigated.  You are welcome to follow it with that link.

    When I build the C++ code, I see the problem when building with --opt_level=1 or lower.  You see the problem with --opt_level=3 or lower.  I cannot reproduce that detail of the behavior.  

    For a workaround ... Build the source file that defines the problem appBlock structure with --opt_level=4.  In the CCS project, right click on the name of the source file and choose Show Build Settings.  It is just like changing the build options for the project.  But the option settings only apply to that file.

    Thanks and regards,

    -George

  • Thanks George,

    I can confirm the work-around works... I can debug (more easily) again! 

    Thanks,

    Paul.