http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28896

--- Comment #9 from Larry Baker <baker at usgs dot gov> 2012-08-09 02:06:27 UTC 
---
(In reply to comment #6)
> Fixed in 4.8.

Andreas,

My application uses a 4.6.1+ compiler from Code Sourcery for ColdFire uClinux
(no longer being sponsored by Freescale).  So, I have been working with those
sources for the moment.

I encounter two gcc ICEs when I request -mcpu=5208
-fstack-limit-symbol=_stack_start:

• With    -msep-data: internal compiler error: in gen_reg_rtx, at emit-rtl.c
• Without -msep-data: internal compiler error: in extract_insn, at recog.c

Your fix of bug target 53834/28896 fixes the second ICE, by requiring at least
-mcpu=68020.  However, it did not cure the first ICE.

I traced the second ICE to the -fPIC flag, which is implied by -msep-data.  The
simplest function, junk.c:

void junk() {}

will demonstrate the ICE, which occurs in cc1.  The simplest cc1 command that
will cause the ICE is:

$ /usr/local/gcc-4.6-2011.09/libexec/gcc/m68k-uclinux/4.6.1/cc1 -mcpu=68020
-fPIC -fstack-limit-symbol=_stack_start -o junk.s junk.c

I put a breakpoint at fancy_abort.  Here is the backtrace as far the function
prologue code being generated to check the stack pointer in
m68k_expand_prologue() at m68k.c:1078:

#0  fancy_abort (file=0x10064a588
"/Users/baker/Desktop/Software/gcc/gcc-4.6-2011.09/gcc/emit-rtl.c", line=883,
function=0x10064a865 "gen_reg_rtx") at
/Users/baker/Desktop/Software/gcc/gcc-4.6-2011.09/gcc/diagnostic.c:893
#1  0x00000001001fdbb8 in gen_reg_rtx (mode=SImode) at
/Users/baker/Desktop/Software/gcc/gcc-4.6-2011.09/gcc/emit-rtl.c:883
#2  0x00000001000ea32a in gen_movsi (operand0=0x1418dd2c0,
operand1=0x1418a9b50) at m68k.md:913
#3  0x000000010021ae03 in emit_move_insn_1 (x=0x1418dd2c0, y=0x1418a9b50) at
/Users/baker/Desktop/Software/gcc/gcc-4.6-2011.09/gcc/expr.c:3311
#4  0x000000010021b2c8 in emit_move_insn (x=0x1418dd2c0, y=0x1418a9b50) at
/Users/baker/Desktop/Software/gcc/gcc-4.6-2011.09/gcc/expr.c:3420
#5  0x0000000100561c98 in m68k_expand_prologue () at
/Users/baker/Desktop/Software/gcc/gcc-4.6-2011.09/gcc/config/m68k/m68k.c:1078
:

The ICE occurs because of the -fPIC conditional code surrounding m68k.md:913:

  else if (flag_pic && !TARGET_PCREL && symbolic_operand (operands[1], SImode))
    {
      /* The source is an address which requires PIC relocation.
         Call legitimize_pic_address with the source, mode, and a relocation
         register (a new pseudo, or the final destination if reload_in_progress
         is set).   Then fall through normally */
      rtx temp = reload_in_progress ? operands[0] : gen_reg_rtx (Pmode);
      operands[1] = legitimize_pic_address (operands[1], SImode, temp);
    }

I see the same code in the current gcc source tree.

>From my reading of the comments, it is preferable to allocate a new pseudo
register.  If that is not possible, the destination register is used.  I
believe the bug is caused by the insufficient test for whether a pseudo
register can be allocated.

I fixed the test to use can_create_pseudo_p():

/*    rtx temp = reload_in_progress ? operands[0] : gen_reg_rtx (Pmode); */
      rtx temp = can_create_pseudo_p() ? gen_reg_rtx (Pmode) : operands[0];

That cures the ICE caused by -fPIC -fstack-limit-symbol=_stack_start.

However, I think the generated code is wrong.  The reason is that the stack
check code relies on %a5 being valid, but that code is executed before the
prologue code which sets up %a5 to point to the GLOBAL_OFFSET_TABLE (see
below).

Here's my results:

$ /usr/local/gcc-4.6-2011.09/libexec/gcc/m68k-uclinux/4.6.1/cc1 -mcpu=68020
-fPIC -fstack-limit-symbol=_stack_start -o junk.s junk.c

$ cat junk.s
#NO_APP
    .file    "junk.c"
    .text
    .align    2
    .globl    junk
    .type    junk, @function
junk:
    move.l _stack_start@GOT(%a5),%d0
    addq.l #4,%d0
    cmp.l %sp,%d0
    traphi
    link.w %fp,#0
    lea (%pc, _GLOBAL_OFFSET_TABLE_@GOTPC), %a5
    unlk %fp
    rts
    .size    junk, .-junk
    .ident    "GCC: (GNU) 4.6.1"
    .section    .note.GNU-stack,"",@progbits

Without -fPIC, I get:

$ /usr/local/gcc-4.6-2011.09/libexec/gcc/m68k-uclinux/4.6.1/cc1 -mcpu=68020
-fstack-limit-symbol=_stack_start -o junk.s junk.c

$ cat junk.s
#NO_APP
    .file    "junk.c"
    .text
    .align    2
    .globl    junk
    .type    junk, @function
junk:
    move.l #_stack_start,%d0
    addq.l #4,%d0
    cmp.l %sp,%d0
    traphi
    link.w %fp,#0
    unlk %fp
    rts
    .size    junk, .-junk
    .ident    "GCC: (GNU) 4.6.1"
    .section    .note.GNU-stack,"",@progbits

Next I will look for the prologue code which sets up %a5 for -fPIC code (in
m68k_expand_prologue() in m68k.c?).

Larry Baker

Reply via email to