"Error: attempt to move .org backwards" using Xtensa XCC, GCC works fine

625 views Asked by At

Here is a minimal reproducible example:

/*
 * Example for Xtensa xt-xcc compiler "error: attempt to move .org backwards".
 */

struct k_dict
{
    char *m_name_dict;
    char *p_name_dict;
    union
    {
        float f_value;
        int i_value;
        char* s_value;
    };
};

struct k_mode
{
    const char*  m_name;
          int    p_number;
    const struct k_dict *p;
    const struct k_dict pars[];
};

struct k_dict P1[] =
{
    {.m_name_dict="M1", .p_name_dict="P1", .s_value="string"},
    {.m_name_dict="M2", .p_name_dict="P2", .i_value=5       },
    {.m_name_dict="M3", .p_name_dict="P3", .f_value=48.0    }
};

struct k_mode mode_default =
{
    .m_name   = "default",
    .p_number = 1,
    .p        = P1,
    .pars =
    {
        {.m_name_dict = "m", .p_name_dict="p", .s_value="s"}
    }
};


int main( int argc, char **argv )
{
    return 0;
}

Compiling this using Tensilica Xtensa xt-xcc compiler gives assembler error:

"xt-xcc" -c -g -O0 -std=c11 -fmessage-length=0 -DPROC_hifi3_tv_car_5 -DCONFIG_hifi3_tv_car_5 --xtensa-system=hifi3_tv_car_5/config --xtensa-core=hifi3_tv_car_5 --xtensa-params= "\"HelloWorld/main.c\"" -o "\"HelloWorld/bin/hifi3_tv_car_5/Debug/main.o\"" 
/Temp/cc0s#6c7c.a32040: Assembler messages:
/Temp/cc0s#6c7c.a32040:39: Error: attempt to move .org backwards
xt-xcc ERROR: XtensaTools/bin/xt-as.exe returned non-zero status 1   

Where could this come from?

Note: GCC works fine.

2

There are 2 answers

0
Danijel On BEST ANSWER

Seems like C11 is not supported by xt-xcc, even there is no warning reported by the compiler when the -std=c11 flag is added.

From the Xtensa manual: "Support for the C11 standard can be enabled with the -std=c11 option only with the Clang front end. (...) Starting with the RG-2017.7 release, XCC includes an alternative compiler front end based on Clang version 3.4 from the LLVM project. In future versions, the Clang front end will replace GCC. The Clang front end is selected by using the -clang compiler option."

Using Clang the above code compiles fine.

2
jcmvbkbc On

The issue comes from the code generated for initialization of mode_default:

        .data
        .org 0x0
        .align  16
        .global mode_default
        .type   mode_default, @object
        .size   mode_default, 12
mode_default:   # 0x0
        .long   .L_g_7
        # offset 4
        .long   1
        .long   P1 +0
        .long   .L_g_8
        .long   .L_g_9
        .long   .L_g_10
        # end of initialization for mode_default
        .org 0x10

and it looks like a bug in the compiler. Interestingly, I observe the same issue with both xt-xcc and xt-xcc -clang.