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.

TI ARM compiler 5.2.2 issue with data alignment?

Hi,


I have something I suppose to be a compiler issue.

We are using TI ARM CGT v5.2.2 on a DM814x with CCS v6.1.0.00104 with a Makefile based project.

The code is like this:

void foo()
{
    // ...
    unsigned short int values[] = { 1, 0 };
    bar(values);
    // ...
}

What the compiler generates to initialize the "values" array looks like this:

ldr   r12 [pc, #0x860]
ldr   r12, [r12]
str   r12, [sp, #0x18]

At PC+0x860 is the address to the location where the constants { 1, 0 } are located in the binary.

Unfortunately this address is not 4-byte aligned, probably because it's an array of 16 bit values.

Hence the processor throws a data fault exception when executing ldr r12, [r12] because of address misalignment.

In my opinion the compiler should not assume the data to be 4-byte-aligned since it is an array of 16 bit values. So I wonder if this is a compiler bug.

Am I right?

Is there any workaround without manipulating the source code? (I don't want to scan our code which has been developed for years using TI's DSPs for more situations like this ...)

Thanks.

BR, Lars

  • Lars Beikirch said:
    I wonder if this is a compiler bug.

    I suspect it is.  I filed SDSCM00052892 in the SDOWP system to have this investigated.  You are welcome to follow it with the SDOWP link below in my signature.  

    Thanks and regards,

    -George

  • Hi George,


    thanks for filing the issue.

    Is there any workaround by a compiler/linker option e.g. to align all consts at 4 byte borders?

    Best regards,

    Lars

  • Unfortunately, the bug has not been investigated yet.  A workaround may be found at that time.

    Thanks and regards,

    -George

  • I cannot reproduce this. Please show us your exact command-line options. These are most easily seen in the build console window.
  • I'm going to make some guesses. DM814x has a Cortex-A8, which supports unaligned data accesses. The compiler allows unaligned data accesses by default, so if you compile with -mv7A8, you'll get code which does a 32-bit load and a 32-bit write very much like the snippet you show. This should work just fine, unless unaligned accesses have somehow been disabled in the hardware. In that case, you'll need to add the compiler option --unaligned_access=off to reflect the hardware settings. If you have a situation other than described, I'll need a bit more information to analyze this further.
  • Yes, we are compiling with -mv7A8. The full compiler options are:

    "C:\ti\ccsv6\tools\compiler\ti-cgt-arm_5.2.2\bin\armcl" --display_error_number --diag_warning=225 --gcc -mv7A8 -pds1844 -g -pds515 -pds145 -pds169 -pds179 -pds190 -q --code_state=32 --fp_mode=strict --endian=little --neon --float_support=vfpv3 -pdse225 "--asm_directory=ARM_Debug" --abi=eabi "--define=__GNUC__" "--define=CHIP_DM8148" "--define=TI_CCS" "--define=dm8148" "--define=_LITTLE_ENDIAN" "--define=_DEBUG" "--define=xdc_target_name__=A8Fnv" "--define=xdc_target_types__=ti/targets/arm/elf/std.h" "--define=enum=enum __attribute__((unpacked))" "--define=__TI_EABI__" -I="C:/ti/bios_6_35_06_56/packages" -I="C:/ti/bios_6_35_06_56/packages/ti/bios/include" -I="C:/ti/ccsv6/tools/compiler/ti-cgt-arm_5.2.2/include" -I="C:/ti/xdctools_3_25_06_96/packages" -ppd=ARM_Debug\foo.d -ppa --output_file=ARM_Debug\foo.obj ..\foo.cpp

    In the ARMv7-A Architecture Reference Manual I read about a "System Control Register" (SCTLR) which supports enabling or disabling unalignment check for LDR etc. (Chapters A3.2.1, B4.1.130).

    Unfortunately I was not able to find anything about that in the DM814x manuals. Is there any way to control unalignment check in the DM814x? (Either by SW or HW?)

    Using --unaligned_access=off is a cumbersome workaround since it generates a memcpy() function call instead of a simple LDR + STR. :-(

    Best regards,

    Lars

  • I'm sorry, I'm not an ARM expert; I don't know how to manipulate the hardware settings for unaligned access. You are better off asking that in an ARM-specific forum.

    If you want to use LDR instead of memcpy, you either need to enable unaligned access in hardware, or add extra alignment to the object. For instance:

    unsigned short int __attribute__((aligned(__alignof__(int)))) values[] = { 1, 0 } ;
  • Archaeologist said:
    I'm sorry, I'm not an ARM expert; I don't know how to manipulate the hardware settings for unaligned access. You are better off asking that in an ARM-specific forum.


    Ok, I'll try, thanks.


    Archaeologist said:
    If you want to use LDR instead of memcpy, you either need to enable unaligned access in hardware, or add extra alignment to the object. For instance:

    unsigned short int __attribute__((aligned(__alignof__(int)))) values[] = { 1, 0 } ;

    Well, actually I'm not keen on scanning thousands of lines of legacy and third party code for situations like this. Is there any option e.g. to align all objects to a certain boundary?

    BR, Lars