When attempting to use TI Clang v1.3.0-beta.1 to create a C++ example for a MSP430E301Y the program was failing to reach main, with the __TI_decompress_lzss() function suffering a hard fault when it attempted to write to flash.
The problem is that the .init_array section has been placed in a read/write section by the linker. As shown in the linker map file:
SEGMENT ALLOCATION MAP run origin load origin length init length attrs members ---------- ----------- ---------- ----------- ----- ------- 00000000 00000000 0002d44b 0002d44b r-x 00000000 00000000 00000208 00000208 r-- .intvecs 00000208 00000208 0002a9c2 0002a9c2 r-x .text 0002abd0 0002abd0 0000287b 0000287b r-- .rodata 0002d44c 0002d44c 00000008 00000000 rw- 0002d44c 0002d44c 00000008 00000000 rw- .init_array LINKER GENERATED COPY TABLES __TI_cinit_table @ 0002d4f8 records: 3, size/record: 8, table size: 24 .data: load addr=0002d458, load size=0000007b bytes, run addr=20031000, run size=00000e45 bytes, compression=lzss .init_array: load addr=0002d4d3, load size=0000000d bytes, run addr=0002d44c, run size=00000008 bytes, compression=lzss .bss: load addr=0002d4f0, load size=00000008 bytes, run addr=20031e48, run size=00000478 bytes, compression=zero_init
The linker command file was placing the .init_array section in flash (ROM) which matches the example given in 3.1. Source Files of the tiarmclang Getting Started Guide:
.init_array : > FLASH
The example is attached.
If the same example is used with the TI ARM v20.2.5 compiler then the .init_array section created by the linker is read-only, and thus can be placed in flash.
Is it a bug that the TI ARM Clang v1.3.0 linker creates the .init_array section as read/write, rather than read-only?