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.

The C6000 command line tools 7.3.1 linker creates an invalid COFF file.

Create a source file a.c with the following content:

void b();
#pragma CODE_SECTION(a, ".a")
void a() {volatile int a = 0; b();}

#pragma CODE_SECTION(b, ".b")
void b() {volatile int b = 0; a();}

void c_int00(int x)
{
    switch (x)
    {
    case   3: case   7: case  11: case  17: case  19:
    case  23: case  29: case  31: case  37: case  41:
    case  47: case  53: case  59: case  61: case  67:
    case  71: case  73: case  79: case  83: case  89:
    case 101: case 103: case 109: case 113: case 127:
    case 131: case 137: case 139: case 149: case 151:
        a(); break;
    case 307: case 311: case 317: case 331: case 337:
    case 347: case 349: case 353: case 359: case 367:
    case 373: case 379: case 383: case 389: case 397:
    case 401: case 409: case 419: case 421: case 431:
    case 433: case 439: case 449: case 457: case 461:
    case 463: case 467: case 479: case 487: case 491:
        b(); break;
    }
}

Create a linker command file a.cmd with the following content:

MEMORY
{
    RAM: o = 0x80000000 l = 0x10000
    DDR: o = 0xc0000000 l = 0x10000
}
SECTIONS
{
    .a:      load >> RAM
    .switch: load >> DDR
    .b:      load >> DDR
    .text:   load >> DDR
}

Invoke the C6000 compiler version 7.3.1 as follows:

cl6x -mv6400+ --symdebug:none -o a.c -z -ma.map a.cmd

Now, the map file produced looks as follows:

 output                                  attributes/
section   page    origin      length       input sections
--------  ----  ----------  ----------   ----------------
.a         0    80000000    00000040
                  80000000    00000020     a.obj (.a)
                  80000020    00000010     a.obj ($Tramp$S$$_b)
                  80000030    00000010     --HOLE-- [fill = 0]

.text      0    c0000000    00000580
                  c0000000    00000560     a.obj (.text)
                  c0000560    00000010     a.obj ($Tramp$S$$_a)
                  c0000570    00000010     --HOLE-- [fill = 0]

.b         0    c0000580    00000040
                  c0000580    00000020     a.obj (.b)
                  c00005a0    00000010     a.obj ($Tramp$S$$_a)
                  c00005b0    00000010     --HOLE-- [fill = 0]

.switch    0    c00005b0    0000002c
                  c00005b0    0000002c     a.obj (.switch:_c_int00)

It can be seen that section .b overlaps section .switch. This behavior is wrong for the linker, whose manual says that output sections do not overlap.

Moreover, the OFD dump of the produced a.out file shows:

    id name                      load addr  run addr    size align alloc
    -- ----                      ---------  --------    ---- ----- -----
     1 $build.attributes         0x00000000 0x00000000  0x27     1   N
     2 .a                        0x80000000 0x80000000  0x40    32   Y
     3 .switch                   0xc00005b0 0xc00005b0  0x2c     4   Y
     4 .b                        0xc0000580 0xc0000580  0x40    32   Y
     5 .text                     0xc0000000 0xc0000000 0x580    32   Y

The section .switch precedes the section .b. A program loader that processes section sequentially would load section .switch first, and then section.b. As a result section .b would destroy the first 16 bytes of section .switch.

The above indeeds happens when the file a.out is loaded onto a target or simulator memory via Code Composer Stdio.

This bug appears in cgtools 7.3.1. It did not manifest in earlier tools, because the trampolines generates were 32 bytes long.
In addition, the bug appears only when the automatic section split operator '>>' is used in the command file. The regular operator '>' or '=' produces a correct output file.
The problem is that the RTSC/XDC tools generate linker command files that use the '>>' operator, and the described bug manifests itself.