AM263P4: tiarmclang linker automatic splitting behavior

Part Number: AM263P4
Other Parts Discussed in Thread: SYSCONFIG

I want to use the TI linker split feature to distribute certain sections across multiple memory ranges. More specifically, the .text and .data sections are too large to fit into the reserved OCRAM memory range for my core and I want to split them so they use TCMA and TCMB memories first, before spilling into OCRAM.

The way I tried to achive this is by enabling "Split Across Memories" in SysConfig and adding all three memory ranges there, for both .data and .text. The resulting linker command file snippet looks like this:

    GROUP  :   {
    .text : {
    } align(8)
    .rodata : {
    } align(8)
    } >> R5F_TCMA | R5F_TCMB | OCRAM


    GROUP  :   {
    .data : {
    } align(8)
    } >> R5F_TCMA | R5F_TCMB | OCRAM

Sadly, this leads to the linker not only splitting among the three memory ranges, but also interleaving each section with each other. See this linker map file for a good visualization:

SEGMENT ALLOCATION MAP

run origin  load origin   length   init length attrs members
----------  ----------- ---------- ----------- ----- -------
00000000    00000000    00008000   00008000    r-x
  00000000    00000000    00000040   00000040    r-x .vectors
  00000040    00000040    00007fc0   00007fc0    r-x .text.1
00080118    00080118    00000008   00000008    rw-
  00080118    00080118    00000008   00000008    rw- .data.1
00080120    00080120    00007ee0   00007ee0    r-x
  00080120    00080120    00007ee0   00007ee0    r-x .text.2
70100000    70100000    0000e670   00000000    rw-
  70100000    70100000    00002670   00000000    rw- .bss
  70102670    70102670    00008000   00000000    rw- .sysmem
  7010a670    7010a670    00004000   00000000    rw- .stack
7010e670    7010e670    000014c8   000014c8    r-x
  7010e670    7010e670    00000be0   00000be0    r-x .text.hwi
  7010f250    7010f250    00000438   00000438    r-x .text.cache
  7010f688    7010f688    00000298   00000298    r-x .text.mpu
  7010f920    7010f920    000001a0   000001a0    r-x .text.boot
  7010fac0    7010fac0    00000010   00000010    r-x .text:abort
  7010fad0    7010fad0    00000053   00000053    r-- .metadata
  7010fb28    7010fb28    00000010   00000010    r-- .init_array
7010fb38    7010fb38    00001400   00000000    rw-
  7010fb38    7010fb38    00000100   00000000    rw- .irqstack
  7010fc38    7010fc38    00000100   00000000    rw- .fiqstack
  7010fd38    7010fd38    00001000   00000000    rw- .svcstack
  70110d38    70110d38    00000100   00000000    rw- .abortstack
  70110e38    70110e38    00000100   00000000    rw- .undefinedstack
70110f38    70110f38    00000008   00000008    rw-
  70110f38    70110f38    00000008   00000008    rw- .data.2
70110f40    70110f40    0000d984   0000d984    r-x
  70110f40    70110f40    0000d984   0000d984    r-x .text.3
7011e8c8    7011e8c8    00000008   00000008    rw-
  7011e8c8    7011e8c8    00000008   00000008    rw- .data.3
7011e8d0    7011e8d0    00000026   00000026    r-x
  7011e8d0    7011e8d0    00000026   00000026    r-x .text.4
7011e8f8    7011e8f8    00000008   00000008    rw-
  7011e8f8    7011e8f8    00000008   00000008    rw- .data.4
7011e900    7011e900    00000092   00000092    r-x
  7011e900    7011e900    00000092   00000092    r-x .text.5
7011e998    7011e998    00000008   00000008    rw-
  7011e998    7011e998    00000008   00000008    rw- .data.5
7011e9a0    7011e9a0    00000074   00000074    r-x
  7011e9a0    7011e9a0    00000074   00000074    r-x .text.6
7011ea18    7011ea18    00000008   00000008    rw-
  7011ea18    7011ea18    00000008   00000008    rw- .data.6
7011ea20    7011ea20    000002b6   000002b6    r-x
  7011ea20    7011ea20    000002b6   000002b6    r-x .text.7
7011ecd8    7011ecd8    00000008   00000008    rw-
  7011ecd8    7011ecd8    00000008   00000008    rw- .data.7
7011ece0    7011ece0    00000006   00000006    r-x
  7011ece0    7011ece0    00000006   00000006    r-x .text.8
7011ece8    7011ece8    00000008   00000008    rw-
  7011ece8    7011ece8    00000008   00000008    rw- .data.8
7011ecf0    7011ecf0    00000004   00000004    r-x
  7011ecf0    7011ecf0    00000004   00000004    r-x .text.9
7011ecf8    7011ecf8    00000008   00000008    rw-
  7011ecf8    7011ecf8    00000008   00000008    rw- .data.9
7011ed00    7011ed00    00000004   00000004    r-x
  7011ed00    7011ed00    00000004   00000004    r-x .text.10
7011ed08    7011ed08    00000008   00000008    rw-
  7011ed08    7011ed08    00000008   00000008    rw- .data.10
7011ed10    7011ed10    00000004   00000004    r-x
  7011ed10    7011ed10    00000004   00000004    r-x .text.11
7011ed18    7011ed18    00000008   00000008    rw-
  7011ed18    7011ed18    00000008   00000008    rw- .data.11
7011ed20    7011ed20    00000004   00000004    r-x
  7011ed20    7011ed20    00000004   00000004    r-x .text.12
7011ed28    7011ed28    00000008   00000008    rw-
  7011ed28    7011ed28    00000008   00000008    rw- .data.12
7011ed30    7011ed30    00000004   00000004    r-x
  7011ed30    7011ed30    00000004   00000004    r-x .text.13
7011ed38    7011ed38    00000008   00000008    rw-
  7011ed38    7011ed38    00000008   00000008    rw- .data.13
7011ed40    7011ed40    00000004   00000004    r-x
  7011ed40    7011ed40    00000004   00000004    r-x .text.14
7011ed48    7011ed48    00000008   00000008    rw-
  7011ed48    7011ed48    00000008   00000008    rw- .data.14
7011ed50    7011ed50    00000004   00000004    r-x
  7011ed50    7011ed50    00000004   00000004    r-x .text.15
7011ed58    7011ed58    00000008   00000008    rw-
  7011ed58    7011ed58    00000008   00000008    rw- .data.15
7011ed60    7011ed60    00000004   00000004    r-x
  7011ed60    7011ed60    00000004   00000004    r-x .text.16
7011ed68    7011ed68    00000008   00000008    rw-
  7011ed68    7011ed68    00000008   00000008    rw- .data.16
7011ed70    7011ed70    00000004   00000004    r-x
  7011ed70    7011ed70    00000004   00000004    r-x .text.17
7011ed78    7011ed78    00000008   00000008    rw-
  7011ed78    7011ed78    00000008   00000008    rw- .data.17
7011ed80    7011ed80    00000004   00000004    r-x
  7011ed80    7011ed80    00000004   00000004    r-x .text.18
7011ed88    7011ed88    00000008   00000008    rw-
  7011ed88    7011ed88    00000008   00000008    rw- .data.18
7011ed90    7011ed90    00000004   00000004    r-x
  7011ed90    7011ed90    00000004   00000004    r-x .text.19
7011ed98    7011ed98    00000008   00000008    rw-
  7011ed98    7011ed98    00000008   00000008    rw- .data.19
7011eda0    7011eda0    00000004   00000004    r-x
  7011eda0    7011eda0    00000004   00000004    r-x .text.20
7011eda8    7011eda8    00000008   00000008    rw-
  7011eda8    7011eda8    00000008   00000008    rw- .data.20
7011edb0    7011edb0    00000004   00000004    r-x
  7011edb0    7011edb0    00000004   00000004    r-x .text.21
7011edb8    7011edb8    00000008   00000008    rw-
  7011edb8    7011edb8    00000008   00000008    rw- .data.21
7011edc0    7011edc0    00000004   00000004    r-x
  7011edc0    7011edc0    00000004   00000004    r-x .text.22
7011edc8    7011edc8    00000008   00000008    rw-
  7011edc8    7011edc8    00000008   00000008    rw- .data.22
7011edd0    7011edd0    00000004   00000004    r-x
  7011edd0    7011edd0    00000004   00000004    r-x .text.23
7011edd8    7011edd8    00000008   00000008    rw-
  7011edd8    7011edd8    00000008   00000008    rw- .data.23
7011ede0    7011ede0    00000004   00000004    r-x
  7011ede0    7011ede0    00000004   00000004    r-x .text.24
7011ede8    7011ede8    00000008   00000008    rw-
  7011ede8    7011ede8    00000008   00000008    rw- .data.24
7011edf0    7011edf0    00000004   00000004    r-x
  7011edf0    7011edf0    00000004   00000004    r-x .text.25
7011edf8    7011edf8    00000008   00000008    rw-
  7011edf8    7011edf8    00000008   00000008    rw- .data.25
7011ee00    7011ee00    00000004   00000004    r-x
  7011ee00    7011ee00    00000004   00000004    r-x .text.26
7011ee08    7011ee08    00000008   00000008    rw-
  7011ee08    7011ee08    00000008   00000008    rw- .data.26
7011ee10    7011ee10    00000004   00000004    r-x
  7011ee10    7011ee10    00000004   00000004    r-x .text.27
7011ee18    7011ee18    00000008   00000008    rw-
  7011ee18    7011ee18    00000008   00000008    rw- .data.27
7011ee20    7011ee20    00000004   00000004    r-x
  7011ee20    7011ee20    00000004   00000004    r-x .text.28
7011ee28    7011ee28    00000008   00000008    rw-
  7011ee28    7011ee28    00000008   00000008    rw- .data.28
7011ee30    7011ee30    00000002   00000002    r-x
  7011ee30    7011ee30    00000002   00000002    r-x .text.29
7011ee38    7011ee38    00000008   00000008    rw-
  7011ee38    7011ee38    00000008   00000008    rw- .data.29
7011ee40    7011ee40    00000002   00000002    r-x
  7011ee40    7011ee40    00000002   00000002    r-x .text.30
7011ee48    7011ee48    00000008   00000008    rw-
  7011ee48    7011ee48    00000008   00000008    rw- .data.30
7011ee50    7011ee50    00000002   00000002    r-x
  7011ee50    7011ee50    00000002   00000002    r-x .text.31
7011ee58    7011ee58    00000008   00000008    rw-
  7011ee58    7011ee58    00000008   00000008    rw- .data.31
7011ee60    7011ee60    00000002   00000002    r-x
  7011ee60    7011ee60    00000002   00000002    r-x .text.32
7011ee68    7011ee68    00000008   00000008    rw-
  7011ee68    7011ee68    00000008   00000008    rw- .data.32
7011ee70    7011ee70    00000002   00000002    r-x
  7011ee70    7011ee70    00000002   00000002    r-x .text.33
7011ee78    7011ee78    00000008   00000008    rw-
  7011ee78    7011ee78    00000008   00000008    rw- .data.33
7011ee80    7011ee80    00004d1e   00004d1e    r--
  7011ee80    7011ee80    00004d1e   00004d1e    r-- .rodata
70123ba0    70123ba0    0000119d   0000119d    rw-
  70123ba0    70123ba0    0000119d   0000119d    rw- .data.34
70130000    70130000    0000cd70   0000cd70    r-x
  70130000    70130000    0000cd70   0000cd70    r-x .text.safety
7013cd70    7013cd70    00000008   00000008    rw-
  7013cd70    7013cd70    00000008   00000008    rw- .data.safety
7013cd78    7013cd78    00001458   00001458    r--
  7013cd78    7013cd78    00001458   00001458    r-- .rodata.safety
702f0100    702f0100    000002a4   00000000    rw-
  702f0100    702f0100    000002a4   00000000    rw- .noinit

This is undesirable as our bootloader's ELF parser currently can't handle such a huge amount of ELF segments.

Is there a way to keep the desired "split among memories" functionality without invoking the adverse "interleave each section with each other" effect?

  • Hi Nicholas,

    A general rule of thumb, Its better to split the code, where you need fastest execution like ISR, control loop, high memeory movement code in TCM first,then in OCRAm.

    The way you are doing it now, would be inefficient way to do the same.

    Further answer to your question:

    Option 1: Separate the sections into independent split directives (no GROUP)

    Remove the GROUP wrapper and give each section its own split directive. This way .text fills TCMA → TCMB → OCRAM independently of .data:

    SECTIONS
    {
    .text : {} >> R5F_TCMA | R5F_TCMB | OCRAM
    .rodata : {} >> R5F_TCMA | R5F_TCMB | OCRAM
    .data : {} >> R5F_TCMA | R5F_TCMB | OCRAM
    }
    

    Without the GROUP, the linker won't interleave the sections with each other—each section is split independently across the memory list. The sections will still be split into pieces (.text.1, .text.2, etc.), but .data pieces won't be interspersed between .text pieces.

    In SysConfig, this means unchecking "Group Section" and configuring each output section as its own entry with "Split Across Memories" enabled.

    Option 2: Use Smart Placement annotations

    TI's Smart Placement feature lets you annotate functions/data with placement priorities, channeling them into dedicated output sections with their own memory hierarchies [2][3]:

    SECTIONS
    {
        .TI.local   : {} >> R5F_TCMA | R5F_TCMB | MSRAM
        .TI.onchip  : {} >> MSRAM | FLASH
        .TI.offchip : {} > FLASH
    }

    This approach fills R5F_TCMA completely before spilling to R5F_TCMB, then to MSRAM—exactly the priority-based behavior you want [3]. You'd annotate your functions/data to control which tier they land in.

  • Thanks for getting back to me on short notice, this enabled me to push option 1 as a stopgap measure yesterday and solved my immediate issue! Agree that manual annotation is the way to go instead of relying on the linker splitting the sections in whatever order it processes them.

    Marking this as resolved for now, but might come back to you with follow-up questions in a new thread.