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.

Compiler/Linker : section header in relocatable executable file is misaligned and cause CCS to crash

Team,

Could you please look at the following issue?
Compiler and CCS version will be added to the post.

Thanks and best regards,

Anthony

Loading symbols from the output of a relocatable link step crashes CCS 5:

This example is derived from a more complex one that doesn't actually attempt to load symbols from an unrelocated file but exhibits the same problem.

I have the following C file (hello.c):

c_int00() {
   volatile int x = 0;
   for (;;) x ++;
}

I compile it with: cl6x -c -mv6600 hello.c

I link it with: lnk6x -r -mv6600 hello.lnk

where hello.lnk contains:

hello.obj
-o hello.out
MEMORY {
   MEM: origin = 0x800000 length = 0x01000
}

SECTIONS {
   .text:   > MEM
}

This gives me two relocatable outputs: hello.obj and hello.out.

In CCS5 connected to an EVM6678L, I connect to core #0 and select hello.obj with Run/Load/Load Symbols.
This is accepted and behaves as I would expect.

If I do exactly the same thing with hello.out, CCS is _immediately_ blown away (the process is terminated) without any error report.

This is the simplest example I can make of the problem which actually appears when the output from a link step generating relocatable output is relocated by a separate program (which generates applications that successfully execute when loaded over Ethernet). That program is not involved in the example above.

If I use the relocatable output from the linker as input to another link step that generates executable output, loading the symbols starts to work again.

I conclude that the linker is generating something wrong when creating relocatable output that gets corrected when it later generates executable output.


A further observation: after linking the relocatable linker output to form an executable, I note
that the section headers are misaligned (at offset 0xaca from the start of the file).

This appears to break the alignment rule from:
http://www.sco.com/developers/gabi/2003-12-17/ch4.intro.html#file_format

"All data structures that the object file format defines follow the ``natural'' size and alignment guidelines for the relevant class. If necessary, data structures contain explicit padding to ensure 8-byte alignment for 8-byte objects, 4-byte alignment for 4-byte objects, to force structure sizes to a multiple of 4 or 8, and so forth. Data also have suitable alignment from the beginning of the file. Thus, for example, a structure containing an Elf32_Addr member will be aligned on a 4-byte boundary within the file. "

Section headers contain Elf32_Addr members, and so should be aligned on a 4-byte boundary (which 0xaca isn't).

  • More info:
    CCS  Version: 5.3.0.00090 - TMS320C6x C/C++ Compiler v7.3.4

  • AnBer said:
    CCS is _immediately_ blown away (the process is terminated) without any error report

    Whether or not there's something wrong with the linker, it is a distinct bug in CCS that it crashes on that input.

  • Ok, I will as well make a post on the CCS forum regarding the crash.

    Is it possible on you side to check if there is a Linker bug regarding this misaligned section header?

    Thanks in advance,

    Anthony

  • To clarify, I was not claiming that the misaligned data in object files are causing the CCS crash. From the experiments I have done, it appears there is a 50/50 chance that the areas will be misaligned in any working executables; the linker is simply ignoring the requirement of the ELF standard, but the tools do not seem to be affected (one of my tools had been built on the assumption that the standard was being followed and this sent me down a rabbit hole for a while with it appearing that incorrect code had been generated).

    There are two separate issues:

    1. the linker is not aligning data in object files correctly; and
    2. the ELF symbol tables from files generated by the linker with the relocatable option crash CCS5.

    Peter

  • From the last post, I assumed there was some other forum thread where this issue was originally raised.  I could only find an offhand reference to "getting the debugger to load symbol tables without blowing up" in this post. Is there such a thread?

  • As far as I know there isn't another thread.

    I had been chasing my tail after hitting problems that I originally though were errors in my generated object files.

    First I hit an alignment problem, but this turned out to be a side-effect of the misalignment of section headers in TI-generated object files.

    Then I hit the problem with the relocatable output of a TI linking step blowing away CCS5.

    It seems to be taking an inordinate time to get any sort of statement from TI about the issue. If I knew what was causing CCS to object to loading
    the symbol tables from the TI-generated object file, I would be able to correct the problem and more forward. As it is, I'm stuck on this.

  • Peter Robertson said:
    First I hit an alignment problem, but this turned out to be a side-effect of the misalignment of section headers in TI-generated object files.



    For the misalignement of section headers in object file could you please attach the test case (.c, .obj, .out files) to this forum post?
    Also could clarify how you can check that there is an alignement issue of the header? Do you look directly in the .out file? What do you use to do that?


    Peter Robertson said:
    Then I hit the problem with the relocatable output of a TI linking step blowing away CCS5

    I will create a new entry in the CCS forum for this. In you original question you mention that loading the hello.obj is ok but loading hello.out crash CCS so I assume that with the above test case the isse can be reproduced (so I will point this new post to this one in order for the CCS team to get the test case).

    EDITED: here is the CCS forum post : http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/t/239437.aspx

    Anthony

  • I tried to attach a file but the process deleted everything I had already typed! In any case, the one-line file is so trivial it's not worth attaching.

    First I must correct an error in your summary of one of the issues. You say 'In you original question you mention that loading the hello.obj is ok but loading hello.out crash CCS'.

    This is inaccurate. What I said was loading the symbols of the relocatable output crashes CCS5 (Run/Load/Add symbols...).

    This is the more important issue as it is now preventing progress on my project.

    To demonstrate the alignment problem, try this:

    Take the following one-line C file (hello.c):

    void main() {}

    Compile it with: cl6x  -mv6600 hello.c

    Link it with:    lnk6x -mv6600 -r hello.obj

    Dump the resulting output file a.out:

    File size 2011 (0x000007db) bytes
    00000000: 464c457f 00010101 00000000 00000000 008c0001 00000001 00000000 00000533  ELF                        3   
    00000020: 00000533 00000000 00200034 00280000 00100011 00000000 00000003 00000004 3       4     (                 
    00000040: 00000005 00000006 00000007 00000000 00000000 00000000 00000000 00000000                                 
    00000060: 008ca362 00000000 00000000 00000000 00000000 00000000 00000000 00000000 b                               
    00000080: 000000bc 00000003 01040000 6c6c6568 00632e6f 00000000 00000000 00000004             hello.c             
    000000a0: 5c3a4602 42204954 31204755 534d5400 43303233 43207836 72706d6f 6f737365  F:\TI BUG 1 TMS320C6x Compresso
    000000c0: 43502072 2e377620 20342e33 79706f43 68676972 63282074 39312029 322d3639 r PC v7.3.4 Copyright (c) 1996-2
    000000e0: 20323130 61786554 6e492073 75727473 746e656d 6e492073 70726f63 7461726f 012 Texas Instruments Incorporat
    00000100: 01006465 0000bf02 69616d00 0000006e 00040000 01060000 8f020101 69616d00 ed       main                mai
    00000120: 6568006e 2e6f6c6c 06010063 6c6c6568 00632e6f 00010e01 00000003 00000100 n hello.c   hello.c             
    00000140: 00000034 001e0003 01040000 000d7900 01010101 00000000 00010000 6c6c6568 4            y              hell
    00000160: 00632e6f 00000000 00020500 05000000 02060d0d 01010001 03011101 11061008 o.c                             
    00000180: 13011201 25081b0b 0b408b08 2e020000 03130101 12011108 3a0b3901 3f0b3b0b        %  @    .         9 : ; ?
    000001a0: 810a400c 40830840 0b408408 860b4085 40870840 0b40880b 940c408e 00000b40  @  @  @  @  @  @  @  @  @  @   
    000001c0: 01818803 89011100 00000c40 00001700 00000300 bc000000 84000000 6d000000         @                      m
    000001e0: 006e6961 00000000 0000001c 00000003 00040000 00000000 00000000 00000004 ain                             
    00000200: 00000000 00000000 00002c41 00495400 00002501 694c0500 72656b6e 0a080800         A,   TI  %    Linker    
    00000220: 80050c04 02820a02 02028402 9002028e 02960302 00001801 78366300 00696261                          c6xabi
    00000240: 00000d01 060a0400 12010a01 00000002 00000000 00000000 00000000 00000000                                 
    00000260: 00000001 00000000 00000000 00020003 00000011 00000000 00000000 00030003                                 
    00000280: 0000001d 00000000 00000000 00040003 00000029 00000000 00000000 00050003                 )               
    000002a0: 00000037 00000000 00000000 00060003 00000047 00000000 00000000 00070003 7               G               
    000002c0: 00000056 00000000 00000000 fff10204 0000005e 00000000 00000000 00020203 V               ^               
    000002e0: 00000011 00000000 00000000 00030203 0000001d 00000000 00000000 00040203                                 
    00000300: 00000029 00000000 00000000 00050203 00000047 00000000 00000000 00070203 )               G               
    00000320: 00000037 00000000 00000000 00060203 00000064 00000000 00000000 00020212 7               d               
    00000340: 00000006 00000b01 00000014 00000a01 00000018 00000801 0000001c 00000801                                 
    00000360: 0000008e 00000801 00000092 00000801 000000b9 00000801 0000002b 00000801                         +       
    00000380: 00000006 00000901 00000006 00000901 00000010 00000801 00000001 00000000                                 
    000003a0: 00000000 00000000 00000000 00000000 2e000000 74786574 6c65683a 6f2e6f6c                    .text:hello.o
    000003c0: 2e006a62 75626564 6e695f67 2e006f66 75626564 696c5f67 2e00656e 75626564 bj .debug_info .debug_line .debu
    000003e0: 62615f67 76657262 65642e00 5f677562 6e627570 73656d61 65642e00 5f677562 g_abbrev .debug_pubnames .debug_
    00000400: 6e617261 00736567 36303630 00303130 7865742e 616d0074 00006e69 49545f5f aranges 0606010 .text main  __TI
    00000420: 2e57445f 75626564 6e695f67 682e6f66 6f6c6c65 372e632e 37396237 37343332 _DW.debug_info.hello.c.77b972347
    00000440: 63343637 62343862 64306431 39333864 66356566 00303966 7865742e 65683a74 764cb84b1d0dd839fe5ff90 .text:he
    00000460: 2e6f6c6c 006a626f 6265642e 695f6775 006f666e 6265642e 6c5f6775 00656e69 llo.obj .debug_info .debug_line
    00000480: 6265642e 615f6775 65726262 642e0076 67756265 6275705f 656d616e 642e0073 .debug_abbrev .debug_pubnames .d
    000004a0: 67756265 6172615f 7365676e 36632e00 69626178 7474612e 75626972 00736574 ebug_aranges .c6xabi.attributes
    000004c0: 6d79732e 00626174 6c65722e 6265642e 695f6775 006f666e 6c65722e 6265642e .symtab .rel.debug_info .rel.deb
    000004e0: 6c5f6775 00656e69 6c65722e 6265642e 705f6775 616e6275 0073656d 6c65722e ug_line .rel.debug_pubnames .rel
    00000500: 6265642e 615f6775 676e6172 2e007365 732e4954 69746365 662e6e6f 7367616c .debug_aranges .TI.section.flags
    00000520: 74732e00 62617472 68732e00 74727473   006261
                                                  00       00000000 00000000 00000000  .strtab .shstrtab              
    00000540: 00000000 00000000 00000000 00000000 00000000 00000000 01000000 11000000                                 
    00000560: 00000000 00000000 34000000 18000000 09000000 00000000 00000000 04000000            4                    
    00000580: 3d000000 01000000 06000000 00000000 60000000 20000000 00000000 00000000    =               `            
    000005a0: 20000000 00000000 4d000000 01000000 00000000 00000002 80000000 c0000000            M                    
    000005c0: 00000000 00000000 01000000 00000000 59000000 01000000 00000000 00000002                    Y            
    000005e0: 40000000 38000001 00000000 00000000 01000000 00000000 65000000 01000000    @   8                   e    
    00000600: 00000000 00000002 78000000 55000001 00000000 00000000 01000000 00000000            x   U                
    00000620: 73000000 01000000 00000000 00000002 cd000000 1b000001 00000000 00000000    s                            
    00000640: 01000000 00000000 83000000 01000000 00000000 00000002 e8000000 20000001                                 
    00000660: 00000000 00000000 01000000 00000000 92000000 03000000 00700000 00000000                           p     

    The offset of the section headers from the start of the file is the ninth word of the file (00000533). This is not word aligned as required by the EFL definition.

    Looking at offset 533 we see an otherwise valid section header (first is all zero, second refers to symbol 1, etc).

    It appears that the compiler is failing to pad the size of the string table to ensure the alignment of the following areas. You can see that the alignment of the section headers depends on the size of the string table by changing the function name to 'main2'. This generates an output file where the section header offset is 534.

    Peter

  • I've submitted this as defect report SDSCM00046177.