hppa64-linux gcc bug
Hi Folks,
We think we found a "heisenbug" which has been bothering us for the past couple of weeks during hppa64-linux developement:create_proc_entry() "works" when a printk() is added and otherwise passes garbage as the "parent" argument when calling proc_register().
We need some help in fixing the compiler though.
We haven't had a chance to talk to linuxcare (toolchain support for hppa*-linux provider) yet since Alan Modra is in .au. Though this seems like a "generic" hppa bug to me, I doubt it's in the currently published hppa2.0-hpux toolchain.
[ Note : hppa64-linux tool chain isn't fully merged up with the
FSF developement trees and can be viewed at:
http://puffin.external.hp.com/cgi-bin/cvsview/
OR
ftp puffin.external.hp.com:/pub/parisc/cvs/*-latest.tar.gz
]
Here's the IRC transcript from John Marvin ([email protected]):
<jsm> There is definitely at least one bug in the 64 bit compiler. The code it
generates for create_proc_entry is garbage. That could be just one manifestation of the heisenbug.
...
<jsm> If you guys want to attempt it, look at how "parent" is handled. It
stores r24 at -30 off of the ap (ret1), if it has to call xlate_proc_name that is OK, but when it calls proc_register it is calling it with -30 off of the new ret1.
<jsm> i.e. the new ap which is -10 off of the new sp, not the original one. <jsm> It actually does ldo -10(sp),ret1, then ldo -40(ret1),r19, then ldd
10(r19),r26.
<jsm> but the effect is the same. I'll write it up when I get into work if you
guys don't beat me to it.
Let me extract the generic.s output that jsm talks about above:
0000000000000000 <create_proc_entry>:
0: 0f c2 12 c1 std rp,-10(sr0,sp) 4: 37 de 02 00 ldo 100(sp),sp [ new_sp == orig_sp + 0x100 ] ... 24: 73 b8 3f a1 std r24,-30(ret1) [ "parent" input parm ] ... 2c: 53 b3 3f a1 ldd -30(ret1),r19 [ if (!parent && ...) ] 30: 9e 66 22 68 cmpb,*= r6,r19,16c <create_proc_entry+0x16c> 34: db 23 0b f0 extrd,u r25,63,16,r3
...
94: e8 00 a0 00 call 9c <create_proc_entry+0x9c>
94: R_PARISC_PCREL22F memcpy
98: 37 dd 3f e1 ldo -10(sp),ret1
...
d8: 37 dd 3f e1 ldo -10(sp),ret1 dc: 37 b3 3f 81 ldo -40(ret1),r19 e0: 08 06 02 59 copy r6,r25 e4: e8 00 a0 00 call ec <create_proc_entry+0xec>
e4: R_PARISC_PCREL22F proc_register
e8: 52 7a 00 20 ldd 10(r19),r26
Recall "parent" input parm was stored at -0x30(orig_ret1). And now we are effectively trying to reload from -0x40(new_sp). That would be ok if orig_ret1 == -0x10(new_sp).
But it doesn't: orig_ret1 == -0x100-0x10(new_sp)
So either "parent" is getting stored to the wrong relative stack location or is getting reloaded from the wrong one.
Kudos to John - good catch!
The following is available via anon ftp from hpisp747:pub/heisenbug/
o generic.gcc: hppa64-linux-gcc command line to compile generic.c
o *.S are generic.gcc output w/-S added
o *.s files are "hppa64-linux-objdump -rD" output
o '*.prt.*' files have a printk() statement added to create_proc_entry() and proc_mkdir() to compare the code generation.
thanks,
grant
ps. Right now, I'm pretty sure I don't want to know why gcc
doesn't just issue "ldo -100+0x30(sp),r26" instead of fooling around w/ret1 (arg ptr).
Quoted 1 line · Grant Grundler
The following is available via anon ftp from hpisp747:pub/heisenbug/
Can you turn this into a real URL please?
Signature · 1 line
Linuxcare. Support for the Revolution.
Quoted 5 lines · Alan Modra
Quoted 1 line · Grant Grundler
The following is available via anon ftp from hpisp747:pub/heisenbug/
Can you turn this into a real URL please?
Alan (and others),
My bad...I had in fact scp'd the files to
ftp://puffin.external.hp.com/pub/parisc/debug/
I just blanked out and forgot to list that as well in the email.
aplogies,
grant
Grant Grundler
Unix Systems Enablement Lab
+1.408.447.7253
I've checked in a fix for the arg_pointer problem on pa64 that should fix the problem you found with create_proc_entry (and probably elsewhere in the kernel too). It's not the ideal fix, as I ran into other problems trying to eliminate the arg_pointer completely, and it's taken up a large lump of my time already.
Alan Modra
Signature · 1 line
Linuxcare. Support for the Revolution.
Quoted 4 lines · Grant Grundler
Though this seems like a "generic" hppa bug to me, I doubt it's in the currently published hppa2.0-hpux toolchain.
[ Note : hppa64-linux tool chain isn't fully merged up with the
The bug manifests itself on today's CVS gcc from sourceware. .../configure --host=i686-linux --target=hppa64-linux
Maybe one of the gcc maintainers can clue me in to where I should be looking for a problem from the following.
Extract from generic.c.17.sched
[snip, nothing changes reg:DI 29 (ARG_POINTER_REGNUM)]
(insn 4 23 9 (set (reg:DI 66)
(plus:DI (reg:DI 29 %r29)
(const_int -64 [0xffffffc0]))) 166 {fixuns_truncdfdi2+2} (nil)
(nil))[snip, nothing changes reg:DI 66, but reg:DI 29 gets set before a number
of function calls, including this one. ]
(insn 199 203 204 (set (reg:DI 26 %r26)
(mem/f:DI (plus:DI (reg:DI 66)
(const_int 16 [0x10])) 0)) 123 {movstrsi_internal+11} (insn_list 194 (nil))
(expr_list:REG_DEAD (reg:DI 66)
(nil)))(call_insn 204 199 206 (parallel[
(set (reg:DI 28 %r28)
(call (mem:SI (symbol_ref/v:DI ("@proc_register")) 0)
(const_int 64 [0x40])))
(clobber (reg:SI 2 %r2))
(use (const_int 0 [0x0]))
] ) 272 {call_value_internal_symref} (insn_list 194 (insn_list 203 (insn_list 199 (insn_list 201 (nil)))))
(expr_list:REG_DEAD (reg:DI 26 %r26)
(expr_list:REG_DEAD (reg:DI 25 %r25)
(expr_list:REG_DEAD (reg:DI 27 %r27)
(expr_list:REG_DEAD (reg:DI 29 %r29)
(expr_list:REG_UNUSED (reg:DI 28 %r28)
(expr_list:REG_UNUSED (reg:SI 2 %r2)
(expr_list:REG_EH_REGION (const_int 0 [0x0])
(nil))))))))
(expr_list (use (reg:DI 29 %r29))
(expr_list (use (reg:DI 4 %r4))
(expr_list (use (reg:DI 27 %r27))
(expr_list (use (reg:DI 25 %r25))
(expr_list (use (reg:DI 26 %r26))
(nil)))))))Now the corresponding rtl from generic.c.18.lreg
[snip a number of places like the following insn where reg:DI 29
(ARG_POINTER_REGNUM) is set for function calls. How is it that gcc doesn't see this register has been trashed?]
(insn 203 201 239 (set (reg:DI 29 %r29)
(plus:DI (reg:DI 30 %r30)
(const_int -16 [0xfffffff0]))) 166 {fixuns_truncdfdi2+2} (nil)
(nil))(insn 239 203 199 (set (reg:DI 66)
(plus:DI (reg:DI 29 %r29)
(const_int -64 [0xffffffc0]))) 166 {fixuns_truncdfdi2+2} (nil)
(expr_list:REG_EQUIV (plus:DI (reg:DI 29 %r29)
(const_int -64 [0xffffffc0]))
(nil)))(insn 199 239 204 (set (reg:DI 26 %r26)
(mem/f:DI (plus:DI (reg:DI 66)
(const_int 16 [0x10])) 0)) 123 {movstrsi_internal+11} (insn_list 194 (nil))
(expr_list:REG_DEAD (reg:DI 66)
(nil)))(call_insn 204 199 206 (parallel[
(set (reg:DI 28 %r28)
(call (mem:SI (symbol_ref/v:DI ("@proc_register")) 0)
(const_int 64 [0x40])))
(clobber (reg:SI 2 %r2))
(use (const_int 0 [0x0]))
] ) 272 {call_value_internal_symref} (insn_list 194 (insn_list 203 (insn_list 199 (insn_list 201 (nil)))))
(expr_list:REG_DEAD (reg:DI 26 %r26)
(expr_list:REG_DEAD (reg:DI 25 %r25)
(expr_list:REG_DEAD (reg:DI 27 %r27)
(expr_list:REG_DEAD (reg:DI 29 %r29)
(expr_list:REG_UNUSED (reg:DI 28 %r28)
(expr_list:REG_UNUSED (reg:SI 2 %r2)
(expr_list:REG_EH_REGION (const_int 0 [0x0])
(nil))))))))
(expr_list (use (reg:DI 29 %r29))
(expr_list (use (reg:DI 4 %r4))
(expr_list (use (reg:DI 27 %r27))
(expr_list (use (reg:DI 25 %r25))
(expr_list (use (reg:DI 26 %r26))
(nil)))))))Signature · 1 line
Linuxcare. Support for the Revolution.
Quoted 9 lines · Alan Modra
Quoted 4 lines · Grant Grundler
Though this seems like a "generic" hppa bug to me, I doubt it's in the currently published hppa2.0-hpux toolchain.
[ Note : hppa64-linux tool chain isn't fully merged up with the
The bug manifests itself on today's CVS gcc from sourceware. .../configure --host=i686-linux --target=hppa64-linux
Errm, how embarrassing. Instead of "today's CVS gcc" I configured from the puffin gcc tree. Alert readers probably can see that from the hppa64-linux target I used above. Trying again, this time using the right gcc source with --target=hppa64-hpux11 is even worse though. The same sort of bug exhibits itself in proc_symlink, _and_ I get a segmentation fault.
Alan Modra
Signature · 1 line
Linuxcare. Support for the Revolution.
[parisc-linux] testcase for hppa64 gcc bug
Here is a distilled testcase for the hppa64 bug reported in
http://gcc.gnu.org/ml/gcc-bugs/2000-10/msg00511.html
extern void abort(void);
char p;
int f1 (char **);
int f2 (char *, char **);
char *f3 (char *a, char *b)
{
char *c = 0;
if (f1 (&b) != 0)
goto out;
/* hppa64 passes bogus value for b */
f2 (b, &c);
out:
return c;
}
int f1 (char **x)
{
if (*x != &p)
abort ();
return 0;
}
int f2 (char *a, char **b)
{
if (a != &p)
abort ();
*b += 1;
return 0;
}
int main (void)
{
if (f3 (0, &p) != (char *) 0 + 1)
abort ();
return 0;
}
Signature · 1 line
Linuxcare. Support for the Revolution.
Re: testcase for hppa64 gcc bug
Quoted 5 lines · Alan Modra
char *f3 (char *a, char *b)
{
char *c = 0;if (f1 (&b) != 0)
Quoted 8 lines
goto out;/* hppa64 passes bogus value for b */
f2 (b, &c);out:
return c;
}
I think I know what's going on here. The root of the problem is that pa-64.h defines an ARG_POINTER_REGNUM that isn't a fixed reg, and isn't eliminable. The arg_pointer isn't even a call-saved reg. That breaks a number of places in the compiler.
So I went down the path of trying to fix things properly by defining ELIMINABLE_REGS and so on, but I ended in a maze of twisty little passages labelled "Unrecognizable instruction", like this one:
/src/parisc/gcc/gcc/libgcc2.c: In function `__moddi3':
/src/parisc/gcc/gcc/libgcc2.c:601: Unrecognizable insn:
(insn 1289 209 1298 (set (reg:SI 50 %fr22)
(subreg:SI (plus:DI (reg:DI 30 %r30)
(const_int -272 [0xfffffef0])) 0)) -1 (nil)
(nil))/src/parisc/gcc/gcc/libgcc2.c:601: Internal compiler error in extract_insn, at recog.c:2134
Anyway, this hack seems to fix it for me.
* rtl.h (ARG_POINTER_INVARIANT): Define as 1 if undef.
* rtlanal.c (rtx_unstable_p): Qualify arg_pointer_rtx match with ARG_POINTER_INVARIANT.
(rtx_varies_p): Likewise.
(rtx_addr_can_trap_p): Likewise.
* local-alloc.c (function_invariant_p): Likewise.
* loop.c (loop_invariant_p): Likewise.
* tm.texi (ARG_POINTER_INVARIANT): Describe.
Alan Modra
Signature · 129 lines
Linuxcare. Support for the Revolution.
Index: gcc/local-alloc.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/local-alloc.c,v
retrieving revision 1.72
diff -u -p -r1.72 local-alloc.c
--- gcc/local-alloc.c 2000/10/23 18:42:52 1.72
+++ gcc/local-alloc.c 2000/10/30 03:57:35
@@ -780,10 +780,12 @@ function_invariant_p (x)
{
if (CONSTANT_P (x))
return 1;
- if (x == frame_pointer_rtx || x == arg_pointer_rtx)
+ if (x == frame_pointer_rtx
+ || (ARG_POINTER_INVARIANT && x == arg_pointer_rtx))
return 1;
if (GET_CODE (x) == PLUS
- && (XEXP (x, 0) == frame_pointer_rtx || XEXP (x, 0) == arg_pointer_rtx)
+ && (XEXP (x, 0) == frame_pointer_rtx
+ || (ARG_POINTER_INVARIANT && XEXP (x, 0) == arg_pointer_rtx))
&& CONSTANT_P (XEXP (x, 1)))
return 1;
return 0;
Index: gcc/loop.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/loop.c,v
retrieving revision 1.293
diff -u -p -r1.293 loop.c
--- gcc/loop.c 2000/10/21 12:12:07 1.293
+++ gcc/loop.c 2000/10/30 03:58:24
@@ -3038,7 +3038,7 @@ loop_invariant_p (loop, x)
since the reg might be set by initialization within the loop. */
if ((x == frame_pointer_rtx || x == hard_frame_pointer_rtx
- || x == arg_pointer_rtx)
+ || (ARG_POINTER_INVARIANT && x == arg_pointer_rtx))
&& ! current_function_has_nonlocal_goto)
return 1;
Index: gcc/rtl.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/rtl.h,v
retrieving revision 1.228
diff -u -p -r1.228 rtl.h
--- gcc/rtl.h 2000/10/16 16:24:54 1.228
+++ gcc/rtl.h 2000/10/30 04:03:31
@@ -1504,6 +1504,10 @@ extern rtx global_rtl[GR_MAX];
#define hard_frame_pointer_rtx (global_rtl[GR_HARD_FRAME_POINTER])
#define arg_pointer_rtx (global_rtl[GR_ARG_POINTER])
+#ifndef ARG_POINTER_INVARIANT
+#define ARG_POINTER_INVARIANT 1
+#endif
+
extern rtx pic_offset_table_rtx;
extern rtx struct_value_rtx;
extern rtx struct_value_incoming_rtx;
Index: gcc/rtlanal.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/rtlanal.c,v
retrieving revision 1.74
diff -u -p -r1.74 rtlanal.c
--- gcc/rtlanal.c 2000/10/24 23:01:11 1.74
+++ gcc/rtlanal.c 2000/10/30 04:03:51
@@ -71,7 +71,8 @@ rtx_unstable_p (x)
case REG:
/* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
- || x == arg_pointer_rtx || RTX_UNCHANGING_P (x))
+ || (ARG_POINTER_INVARIANT && x == arg_pointer_rtx)
+ || RTX_UNCHANGING_P (x))
return 0;
#ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
/* ??? When call-clobbered, the value is stable modulo the restore
@@ -144,7 +145,7 @@ rtx_varies_p (x)
eliminated the frame and/or arg pointer and are using it
for pseudos. */
if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
- || x == arg_pointer_rtx)
+ || (ARG_POINTER_INVARIANT && x == arg_pointer_rtx))
return 0;
#ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
/* ??? When call-clobbered, the value is stable modulo the restore
@@ -209,7 +210,8 @@ rtx_addr_can_trap_p (x)
case REG:
/* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
- || x == stack_pointer_rtx || x == arg_pointer_rtx);
+ || (ARG_POINTER_INVARIANT && x == arg_pointer_rtx)
+ || x == stack_pointer_rtx);
case CONST:
return rtx_addr_can_trap_p (XEXP (x, 0));
Index: gcc/tm.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tm.texi,v
retrieving revision 1.149
diff -u -p -r1.149 tm.texi
--- gcc/tm.texi 2000/10/18 17:51:54 1.149
+++ gcc/tm.texi 2000/10/30 04:06:49
@@ -2564,7 +2564,12 @@ register this is. On other machines, yo
wish for this purpose. If this is not the same register as the frame
pointer register, then you must mark it as a fixed register according to
@code{FIXED_REGISTERS}, or arrange to be able to eliminate it
-(@pxref{Elimination}).
+(@pxref{Elimination}), or clear ARG_POINTER_INVARIANT
+
+@findex ARG_POINTER_INVARIANT
+@item ARG_POINTER_INVARIANT
+ARG_POINTER_INVARIANT allows the compiler to assume that
+ARG_POINTER_REGNUM is unchanging over the life of a function.
@findex RETURN_ADDRESS_POINTER_REGNUM
@item RETURN_ADDRESS_POINTER_REGNUM
Index: gcc/config/pa/pa-64.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/pa/pa-64.h,v
retrieving revision 1.3
diff -u -p -r1.3 pa-64.h
--- gcc/config/pa/pa-64.h 2000/09/25 13:39:45 1.3
+++ gcc/config/pa/pa-64.h 2000/10/30 04:30:51
@@ -129,6 +129,7 @@ do { \
#undef ARGS_GROW_DOWNWARD
#undef ARG_POINTER_REGNUM
#define ARG_POINTER_REGNUM 29
+#define ARG_POINTER_INVARIANT 0
#undef STATIC_CHAIN_REGNUM
#define STATIC_CHAIN_REGNUM 31Re: testcase for hppa64 gcc bug
Quoted 20 lines
I think I know what's going on here. The root of the problem is that
pa-64.hdefines anARG_POINTER_REGNUMthat isn't a fixed reg, and isn't eliminable. Thearg_pointerisn't even a call-saved reg. That breaks a number of places in the compiler.So I went down the path of trying to fix things properly by defining
ELIMINABLE_REGSand so on, but I ended in a maze of twisty little passages labelled "Unrecognizable instruction", like this one:/src/parisc/gcc/gcc/libgcc2.c: In function `__moddi3':
/src/parisc/gcc/gcc/libgcc2.c:601: Unrecognizable insn:
(insn 1289 209 1298 (set (reg:SI 50 %fr22)(subreg:SI (plus:DI (reg:DI 30 %r30) (const_int -272 [0xfffffef0])) 0)) -1 (nil) (nil))/src/parisc/gcc/gcc/libgcc2.c:601: Internal compiler error in
extract_insn, at recog.c:2134Anyway, this hack seems to fix it for me.
Quoted 8 lines
*
rtl.h(ARG_POINTER_INVARIANT): Define as 1 if undef.
*rtlanal.c(rtx_unstable_p): Qualifyarg_pointer_rtxmatch withARG_POINTER_INVARIANT.
(rtx_varies_p): Likewise.
(rtx_addr_can_trap_p): Likewise.
*local-alloc.c(function_invariant_p): Likewise.
*loop.c(loop_invariant_p): Likewise.
* tm.texi (ARG_POINTER_INVARIANT): Describe.
I don't think this is the correct fix. Isn't r29 used for 128 bit return values?
Dave
Signature · 2 lines
J. David Anglin [email protected] National Research Council of Canada (613) 990-0752 (FAX: 952-6605)
Re: testcase for hppa64 gcc bug
Quoted 11 lines · John David Anglin
Quoted 8 lines
*
rtl.h(ARG_POINTER_INVARIANT): Define as 1 if undef.
*rtlanal.c(rtx_unstable_p): Qualifyarg_pointer_rtxmatch withARG_POINTER_INVARIANT.
(rtx_varies_p): Likewise.
(rtx_addr_can_trap_p): Likewise.
*local-alloc.c(function_invariant_p): Likewise.
*loop.c(loop_invariant_p): Likewise.
* tm.texi (ARG_POINTER_INVARIANT): Describe.I don't think this is the correct fix. Isn't r29 used for 128 bit return values?
Yes, r29 is used for 128 bit return values, but how is that relevant to use of r29 as the arg pointer?
I tried setting up ELIMINATE_REGS and so forth (see puffin CVS gcc/config/pa/pa-linux64.h) but that failed badly with what looked like, from a very cursory inspection, a use of r29 as a temporary reg being "eliminated" to r30+const. Oops.
Anyway, nothing in the above patch should make the situation worse. All it really does is let the compiler see places where arg_pointer changes, instead of blindly assuming that arg_pointer will not change. Take a peek at the .lreg rtl for the test case I posted.
Alan Modra
Signature · 1 line
Linuxcare. Support for the Revolution.
Re: testcase for hppa64 gcc bug
In reply to Alan ModraQuoted 9 lines
I think I know what's going on here. The root of the problem is that
pa-64.hdefines anARG_POINTER_REGNUMthat isn't a fixed reg, and isn't eliminable. Thearg_pointerisn't even a call-saved reg. That breaks a number of places in the compiler.So I went down the path of trying to fix things properly by defining
ELIMINABLE_REGSand so on, but I ended in a maze of twisty little passages labelled "Unrecognizable instruction", like this one:
Quoted 8 lines
/src/parisc/gcc/gcc/libgcc2.c: In function `__moddi3':
/src/parisc/gcc/gcc/libgcc2.c:601: Unrecognizable insn:
(insn 1289 209 1298 (set (reg:SI 50 %fr22)(subreg:SI (plus:DI (reg:DI 30 %r30) (const_int -272 [0xfffffef0])) 0)) -1 (nil) (nil))/src/parisc/gcc/gcc/libgcc2.c:601: Internal compiler error in
extract_insn, at recog.c:2134
I am making progress in trying to make the arg_pointer register eliminable. I have fixed the above problem. What was happening was that reload_as_needed was incorrectly trying to eliminate the return from millicode calls which is also register r29. I have figured out how to hide it from reload with unspec.
However, the compiler is now too good at eliminating the arg_pointer. At -O3, it completely eliminates the arg_pointer. However, as I read the ABI, the call must always set the arg_pointer before calls.
Dave
Signature · 2 lines
J. David Anglin [email protected] National Research Council of Canada (613) 990-0752 (FAX: 952-6605)