Skip to main content
davedave95
Associate III
February 9, 2017
Question

SPC5 studio project problems when compiling with -Os

  • February 9, 2017
  • 7 replies
  • 3133 views
Posted on February 09, 2017 at 17:10

When compiling a SPC5 studio generated demo program with -Os to optimize on size, the resulting code stalls during initialisation. in eirqInit() the loop

  while (eirqconf[i].eirqNumber != -1) {

never terminates when the eirqconf[] table has no entries except for the terminator record where irq is set to -1

  const eirq_config eirqconf[]={

    {-1,0,0,0,NULL}

  };

Is this a known issue, can anyone reproduce?

    This topic has been closed for replies.

    7 replies

    Erwan YVIN
    ST Employee
    February 9, 2017
    Posted on February 09, 2017 at 17:26

    Hello Gert ,

    could you confirm your test application tested ?

    Do you use ppc-freevlvle-eabi or hightec gcc ?

    i will check with my board.

    to debug this issue , you should focus your assembly code not C code.

    you should add --save-temps and check your .s file 

          Best Regards

                       

                         Erwan

    davedave95
    Associate III
    February 9, 2017
    Posted on February 09, 2017 at 17:29

    Using the ppc-freevle-eabi 4.9.2 compiler. I'm currently trying to reproduce by generating a minimal example function which shows the same behaviour.

    davedave95
    Associate III
    February 9, 2017
    Posted on February 09, 2017 at 17:48

    Minimal snippet to reproduce.

    The following never terminates:

    #include <stdint.h>

    volatile int store1, store2;

    int8_t fs[] = { -1 };

    void bug(void)

    {

            uint8_t i = 0;

            while (fs[i] != -1) {

                    uint8_t v = (uint8_t)fs[i];

                    store2 = v;

                    store1 = fs[i];

                    i++;

            }

    }

    However, removing the line 'store1 = fs[i]' or 'store2 = v' will change the behaviour so that the loop terminates.

    Assembly:

      0:   70 e0 e0 00     e_lis   r7,0

       4:   70 c0 e0 00     e_lis   r6,0

       8:   71 20 00 00     e_li    r9,0

       c:   1c e7 00 00     e_add16i r7,r7,0

      10:   1c c6 00 00     e_add16i r6,r6,0

      14:   7d 47 48 ae     lbzx    r10,r7,r9

      18:   7d 48 07 74     extsb   r8,r10

      1c:   18 28 ac ff     e_cmpi  cr1,r8,-1

      20:   7a 16 00 18     e_beq   cr1,38 <bug+0x38>

      24:   75 4a 06 3f     e_rlwinm r10,r10,0,24,31

      28:   19 29 80 01     e_addi  r9,r9,1

      2c:   55 46 00 00     e_stw   r10,0(r6)

      30:   75 29 06 3f     e_rlwinm r9,r9,0,24,31

      34:   79 ff ff e0     e_b     14 <bug+0x14>

      38:   00 04           se_blr
    davedave95
    Associate III
    February 9, 2017
    Posted on February 09, 2017 at 20:10

    And even simpler code:

    void boom(int a, int b)

    {

            printd('%d %d\n', a, b);

    }

    int8_t fs = -1;

    void bug(void)

    {

            if (fs != -1) {

                    boom((uint8_t)fs, fs);

            }

    }

    resulting in

    bug:

    .LFB2:

            .loc 1 15 0

            .cfi_startproc

            .loc 1 16 0

            e_lis %r9,.LANCHOR0@ha

            e_lbz %r3,.LANCHOR0@l(%r9)

            se_extsb %r4

            e_cmpi %cr1,%r4,-1

            e_beq %cr1,.L2

            .loc 1 17 0

            se_extzb %r3

            .loc 1 19 0

            .loc 1 17 0

            e_b boom
    Erwan YVIN
    ST Employee
    February 28, 2017
    Posted on February 28, 2017 at 11:35

    Hello Gert ,

    i have tried this code on SPC560D

    uint8_t bugmessage[] = 'Bug!!!
    
    ';
    int8_t fs = -1;
    void bug(void) {
     if (fs != -1) {
     sd_lld_write(&SD1, bugmessage,
     (uint16_t)(sizeof(bugmessage)/ sizeof(bugmessage[0])));
     }
     }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    No bug happenned

    Which SPC56 Family do you use ?

    Best regards

    Erwan

    davedave95
    Associate III
    February 9, 2017
    Posted on February 09, 2017 at 21:34

    Sorry to keep spamming my own topic, but things are getting more and more weird. The following snippet shows wrong behaviour with -O2, but not with -Os:

    signed char fs = -1;

    void boom(int a)

    {

            printd('boom %d %d\n', (int)fs, (int)a);

    }

    void bug(void)

    {

            if (fs != -1) {

                    boom((unsigned char)fs);

            }

    }

    The expression in the 'if' is handled as if it is true, and the output of the program is

    boom 1 255

    The beaviour of the program is not stable: if 'signed char fs' is declared volatile, it behaves as expected.

    I feel that the integer promotion in the if expression seems to mess up, but I can't get my finger around it.

    I found some references about ppc being kind of special considering the 'char' type, which is unsigned by default instead of signed on this architecture, although I'm not sure if that is relevant for this case.

    Erwan YVIN
    ST Employee
    February 10, 2017
    Posted on February 10, 2017 at 10:35

    Hello Gert ,

    It seems to be a compiler issue.

    i am contacting thecompiler team.

    for your information, It is not the last version of the compiler

    you can try with the last version 10/12/2016 from NXP website

    https://community.nxp.com/docs/DOC-333045

    by updating ,c:\SPC5Studio\eclipse\plugins\com.st.tools.spc5.tools.gnu.gcc.ppcvle.win32_1.0.0.201611101103

    anyway, you can force

    __attribute__((optimize('-O0'))) 
    �?
    �?�?�?�?�?

    I have created a ticket for this issue.

    Best regards

    Erwan

    davedave95
    Associate III
    February 10, 2017
    Posted on February 10, 2017 at 10:55

    Thank you for the confirmation. I will try the updated compiler when possible - the NXP site is not available at this moment:

    We are unable to complete your software download request at this time due to a system outage. Please try your download at a later time. We apologize for the inconvenience.

    It has been like this for a few days already, unfortunately.

    Erwan YVIN
    ST Employee
    February 14, 2017
    Posted on February 14, 2017 at 14:37

    Hello Giert ,

    i will contact NXP-Freescale

    The gcc source code are not available anymore

    use some special attribute to disable compiler optimization.

    __attribute__((optimize('-O0'))) 
    
    Best regards
     
     Erwan

    davedave95
    Associate III
    May 3, 2017
    Posted on May 03, 2017 at 08:50

    Hello Erwan,

    Is there any news on this issue?

    Do you know of any party offering a PPC VLC toolchain with commercial support?

    Erwan YVIN
    ST Employee
    May 4, 2017
    Posted on May 04, 2017 at 09:55

    Hello Gert ,

    I have no news about that.

    you can use hightec gcc

    http://www.st.com/en/development-tools/spc5-htcomp-nltl.html

     

    By SPC5Studio , you have 30 days free.

      Best Regards

                     Erwan