[Bug c/59679] New: gcc version 4.7.3 and gcc version 4.5.3 cause an unaligned access exception on NetBSD/Alpha

2014-01-04 Thread nullnilaki at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679

Bug ID: 59679
   Summary: gcc version 4.7.3 and gcc version 4.5.3 cause an
unaligned access exception on NetBSD/Alpha
   Product: gcc
   Version: 4.7.3
Status: UNCONFIRMED
  Severity: critical
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: nullnilaki at gmail dot com

Using gcc4.7.3 and gcc4.5.3 to compile a Perl v5.18.1.
Perl cause an unaligned access exception.


Please read the perl-bug
https://rt.perl.org/Public/Bug/Display.html?id=120888



gcc4.5 and gcc4.7 cause this problem.
(I can not compile gcc4.6 and gcc4.8 but I think gcc4.6 and gcc4.8 has some 
kind of similar bug.)



This problem was caused by compiler's bug. -ftree-ter option makes wrong
binary. 



-O2 version.

(gdb) break scope.c:1217
No source file named scope.c.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (scope.c:1217) pending.
(gdb) r perl.pl
Starting program: /usr/pkg/bin/perl perl.pl
[Switching to LWP 1]

Breakpoint 1, Perl_leave_scope (my_perl=0x160505000, base=) at 
scope.c:1217
1217*(I8*)ARG0_PTR = (I8)(uv >> 8);
(gdb) list
1212
1213case SAVEt_I16: /* I16 reference */
1214*(I16*)ARG0_PTR = (I16)(uv >> 8);
1215break;
1216case SAVEt_I8:  /* I8 reference */
1217*(I8*)ARG0_PTR = (I8)(uv >> 8);
1218break;
1219case SAVEt_DESTRUCTOR:
1220(*arg1.any_dptr)(ARG0_PTR);
1221break;
(gdb) x/10i $pc
=> 0x1601795c0 : extbl   t5,0x1,t5
   0x1601795c4 : ldl t0,0(s1)
   0x1601795c8 : andnot  t0,0xff,t0
   0x1601795cc : or  t5,t0,t5
   0x1601795d0 : stl t5,0(s1)
   0x1601795d4 : ldl t3,48(s0)
   0x1601795d8 : ldl t0,152(s0)
   0x1601795dc : br  0x160178800 

   0x1601795e0 : mov s0,a0
   0x1601795e4 : ldq t12,-24984(gp)
(gdb) p uv
$1 = 2574
(gdb) ptype uv
type = long unsigned int
(gdb) ptype I8
type = signed char
(gdb) print /a uv
$2 = 0xa0e
(gdb) p arg0
$1 = {any_ptr = 0x1605104ee, any_i32 = 1615922414, any_iv = 5910889710, any_uv 
= 5910889710, any_long = 5910889710, any_bool = 238, 
  any_dptr = 0x1605104ee, any_dxptr = 0x1605104ee}
(gdb) p &arg0
Address requested for identifier "arg0" which is in register $s1
(gdb) n
pid 436 (perl): unaligned access: va=0x1605104ee pc=0x1601795c4 ra=0x160179124 
sp=0x1c698 op=ldl
pid 436 (perl): unaligned access: va=0x1605104ee pc=0x1601795d0 ra=0x160179124 
sp=0x1c698 op=stl
1218break;
1218break;
(gdb) p uv
$1 = 

---

-O2 -fno-tree-ter version.

(gdb) break scope.c:1217
No source file named scope.c.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (scope.c:1217) pending.
(gdb) r perl.pl
Starting program: /usr/pkg/bin/perl perl.pl
[Switching to LWP 1]

Breakpoint 1, Perl_leave_scope (my_perl=0x160505000, base=) at 
scope.c:1217
1217*(I8*)ARG0_PTR = (I8)(uv >> 8);
(gdb) x/10i $pc
=> 0x160177df0 : extbl   t5,0x1,t5
   0x160177df4 : ldq_u   t0,0(s1)
   0x160177df8 : insbl   t5,s1,t5
   0x160177dfc : mskbl   t0,s1,t0
   0x160177e00 : or  t5,t0,t5
   0x160177e04 : stq_u   t5,0(s1)
   0x160177e08 : ldl t3,48(s0)
   0x160177e0c : ldl t0,152(s0)
   0x160177e10 : br  0x160177020 

   0x160177e14 : unop
(gdb) p uv
$1 = 2574
(gdb) ptype uv
type = long unsigned int
(gdb) ptype I8
type = signed char
(gdb) print /a uv
$2 = 0xa0e
(gdb) p arg0
$1 = {any_ptr = 0x1605104ee, any_i32 = 1615922414, any_iv = 5910889710, any_uv 
= 5910889710, any_long = 5910889710, any_bool = 238, 
  any_dptr = 0x1605104ee, any_dxptr = 0x1605104ee}
(gdb) n
1218break;


[Bug target/59679] gcc version 4.7.3 and gcc version 4.5.3 cause an unaligned access exception on NetBSD/Alpha

2014-01-05 Thread nullnilaki at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679

--- Comment #2 from nullnilaki at gmail dot com ---
Created attachment 31576
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31576&action=edit
perl.h

perl.h


[Bug target/59679] gcc version 4.7.3 and gcc version 4.5.3 cause an unaligned access exception on NetBSD/Alpha

2014-01-05 Thread nullnilaki at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679

--- Comment #3 from nullnilaki at gmail dot com ---
Created attachment 31577
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31577&action=edit
scope.c

scope.c


[Bug target/59679] gcc version 4.7.3 and gcc version 4.5.3 cause an unaligned access exception on NetBSD/Alpha

2014-01-05 Thread nullnilaki at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679

--- Comment #4 from nullnilaki at gmail dot com ---
(In reply to Andrew Pinski from comment #1)
> This looks more like a bug in perl sources.  Can you attach the preprocessed
> source for scope.c?
> 
> The big question is how is ARG0_PTR defined?  GCC must be assuming the
> alignment is 64bits for some reason.  This needs the preprocessed source to
> see why the alignment is being done incorrectly.  Maybe ARG0_PTR was
> assigned from a long long pointer. 
> 
> In C, once you assign it to a pointer of bigger alignment and it is not
> aligned, the code is undefined.

Thank you for your reply!

ARG0_PTR is defined in scope.c.
#define ARG0_PTR arg0.any_ptr

and

any_ptr is defined in perl.h.

union any {
void*   any_ptr;
I32 any_i32;
IV  any_iv;
UV  any_uv;
longany_long;
boolany_bool;
void(*any_dptr) (void*);
void(*any_dxptr) (pTHX_ void*);
};


[Bug target/59679] gcc version 4.7.3 and gcc version 4.5.3 cause an unaligned access exception on NetBSD/Alpha

2014-01-06 Thread nullnilaki at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679

--- Comment #6 from nullnilaki at gmail dot com ---
(In reply to Andrew Pinski from comment #5)
> This is still not the preprocessed source.  We need the preprocessed source
> and the exact options you used to compile the source and the exact options
> used to configure gcc with.

Thank you for your reply!
>We need the preprocessed source...
I made a mistake.
Sorry...
--
Compile option.

[*] /usr/pkgsrc/lang/perl5/work/.wrapper/bin/cc
/usr/pkgsrc/lang/perl5/work/.wrapper/bin/cc -c -DPERL_CORE -O2 -mieee -pthread
-I/usr/include -fno-strict-aliasing -pipe -
I/usr/pkg/include -std=c89 -O2 -mieee -pthread -I/usr/include -Wall -ansi -W
-Wextra -Wdeclaration-after-statement -Wendif-labels -Wc++-compat
-Wwrite-strings -DPIC -fPIC
 scope.c
WARNING: [transform-gcc] passing unknown option -mieee
WARNING: [transform-gcc] passing unknown option -std=c89
WARNING: [transform-gcc] passing unknown option -mieee
WARNING: [transform-gcc] passing unknown option -ansi
WARNING: [transform-gcc] passing unknown option -Wdeclaration-after-statement
WARNING: [transform-gcc] passing unknown option -Wendif-labels
WARNING: [transform-gcc] passing unknown option -Wc++-compat
<.> /usr/pkgsrc/lang/perl5/work/.gcc/bin/gcc -c -DPERL_CORE -O2 -mieee -pthread
-fno-strict-aliasing -pipe -I/usr/pkgsrc/lang/perl5/work/.buildlink/include
-std=c89 -O2 -
mieee -pthread -Wall -ansi -W -Wextra -Wdeclaration-after-statement
-Wendif-labels -Wc++-compat -Wwrite-strings -DPIC -fPIC scope.c
-L/usr/pkgsrc/lang/perl5/work/.buildli
nk/lib

--


[Bug target/59679] gcc version 4.7.3 and gcc version 4.5.3 cause an unaligned access exception on NetBSD/Alpha

2014-01-06 Thread nullnilaki at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679

--- Comment #8 from nullnilaki at gmail dot com ---
Created attachment 31757
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31757&action=edit
preprocess scope.c(NO.2)

preprocess scope.c(This source is very large. Please concatenate files.)


[Bug target/59679] gcc version 4.7.3 and gcc version 4.5.3 cause an unaligned access exception on NetBSD/Alpha

2014-01-06 Thread nullnilaki at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679

--- Comment #9 from nullnilaki at gmail dot com ---
Created attachment 31758
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31758&action=edit
preprocess scope.c(NO.3)

preprocess scope.c(This source is very large. Please concatenate files.)


[Bug target/59679] gcc version 4.7.3 and gcc version 4.5.3 cause an unaligned access exception on NetBSD/Alpha

2014-01-06 Thread nullnilaki at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679

--- Comment #7 from nullnilaki at gmail dot com ---
Created attachment 31756
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31756&action=edit
preprocess scope.c(NO.1)

preprocess scope.c(This source is very large. Please concatenate files.)