Other Parts Discussed in Thread: SYSCONFIG, , C2000WARE
Tool/software:
I defined a variable
static uint16_t myvar = 0;
I needed this variable to be in the shared ram (RAM_GS)
So I added a user section in Sysconfig named LOCAL_RAM_GS, giving this line in the CMD file
LOCAL_RAM_GS { } > RAM_GS
and added a pragma to the variable declaration, so it looks like this.
#pragma DATA_SECTION( myvar, "LOCAL_RAM_GS" ) static bq_size_t myvar = 0;
All fine and good until I started to get ITRAP exceptions.
I used the debugger to find that the first byte of a ramfunction in another module had been overwritten with a zero (ITRAP0).
My findings:
The linker allocates 1 byte for this variable, acording to these snippets from the map file
GLOBAL SYMBOLS: SORTED ALPHABETICALLY BY Name
page address name
---- ------- ----
0 00011774 foo_readData 00091204
0 00011770 foo_sendData 00091200
0 00088c0d bar_sendData
zoo.obj
Run/Load
Value Binding Name (Section)
-------- -------- ---------------
0009017d global Isr_IpcFlag0 (.text:retain)
0001176f local LOCAL_RAM_GS (LOCAL_RAM_GS)
00015980 local other_var (.bss)
...
0001176f local myvar (LOCAL_RAM_GS)
LINKER GENERATED COPY TABLES
__TI_cinit_table @ 0009432c records: 6, size/record: 4, table size: 24
.data: load addr=00093e10, load size=00000500 bytes, run addr=00015992, run size=00002d61 bytes, compression=lzss
LOCAL_RAM_GS: load addr=00094316, load size=00000005 bytes, run addr=0001176f, run size=00000001 bytes, compression=copy
...
binit @ 00094348 records: 4, size/record: 6, table size: 26
...
FOO_OBJ_TO_RAM: load addr=00091200, load size=0000010a, run addr=00011770, run size=0000010a, compression=none
...
So `myvar` should be placed at 0x0001176f and have length 1
and `foo_sendData` should be placed at 0x00011770
The reason why `foo_sendData` is being overwritten I found in the actual copy table read from memory using the debugger.

looking at the load address i find

switching to 32 bit, as that is how `__TI_auto_init` reads it

first word is the idx for `TI_Handler_Table` and this idx points to the `__TI_decompress_none`
Second word is the count, passed to `memcpy` by `__TI_decompress_none`. And here I find a "2", and not a 1 as indicated in the map file.
This means that `__TI_decompress_none`->`memcpy` will write to address 0x0001176f and 0x00011770
0x00011770 being the first byte of the foo_sendData function.
I tried changing the config of the user section., but in Sysconfig I can only find an option to enable .align(2), and as I understand the linker manual i need to use .palign(2), to ensure enough memory is allocated for this case.
In a very short term solution, I see that if I set the .align(2) attribute it will place the `myvar` with a hole after it. But that is probably only the case because the chuck coming after `myvar`is also aligned. In other words, this is a very temporary solution.
Please advise.
Edit:
Almost forgot tool versions used:
Code Composer Studio Version: 12.8.1.00005