Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scope.c cause an unaligned access exception. #13498

Closed
p5pRT opened this issue Dec 28, 2013 · 24 comments
Closed

scope.c cause an unaligned access exception. #13498

p5pRT opened this issue Dec 28, 2013 · 24 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 28, 2013

Migrated from rt.perl.org#120888 (status was 'resolved')

Searchable as RT120888$

@p5pRT
Copy link
Author

p5pRT commented Dec 28, 2013

From nullnilaki@gmail.com

Created by nullnilaki@gmail.com

I am using Netbsd/alpha.
perl cause an unaligned access exception.

Core was generated by `perl'.
Program terminated with signal 10, Bus error.
#0 0x00000001601795c8 in Perl_leave_scope (my_perl=0x160505000,
base=<optimized out>) at scope.c​:1217
1217 *(I8*)ARG0_PTR = (I8)(uv >> 8);

Taking a picture
http​://p.twipple.jp/Rh2K4
http​://twitpic.com/dqa7uh

Perl Info

Flags:
    category=core
    severity=critical

Site configuration information for perl 5.18.1:

Configured by naruaki at Sat Dec 28 11:15:19 UTC 2013.

Summary of my perl5 (revision 5 version 18 subversion 1) configuration:

  Platform:
    osname=netbsd, osvers=6.1.2, archname=alpha-netbsd-thread-multi
    uname='netbsd 6.1.2 netbsd 6.1.2 (generic-$revision: 1.343 $) #13:
sat dec 7 08:25:52 jst 2013
naruaki@netbsd:usrnetbsd_6_1_2obj.alphasysarchalphacompilegeneric
alpha '
    config_args='-sde -Duseshrplib -Duseithreads -Uusemymalloc'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-O2 -mieee -g -pthread -I/usr/include
-fno-strict-aliasing -pipe -I/usr/pkg/include',
    optimize='-O2 -mieee -g  -pthread  -I/usr/include',
    cppflags='-O2 -mieee -g -pthread -I/usr/include
-fno-strict-aliasing -pipe -I/usr/pkg/include'
    ccversion='', gccversion='4.5.3', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-Wl,-rpath,/usr/pkg/lib -L/usr/pkg/lib'
    libpth=/lib /usr/lib /usr/pkg/lib
    libs=-lm -lcrypt -lpthread
    perllibs=-lm -lcrypt -lpthread
    libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
-Wl,-R/usr/pkg/lib/perl5/5.18.0/alpha-netbsd-thread-multi/CORE'
    cccdlflags='-DPIC -fPIC ', lddlflags='-shared  -L/usr/pkg/lib'

Locally applied patches:



@INC for perl 5.18.1:
    /usr/pkg/lib/perl5/site_perl/5.18.0/alpha-netbsd-thread-multi
    /usr/pkg/lib/perl5/site_perl/5.18.0
    /usr/pkg/lib/perl5/vendor_perl/5.18.0/alpha-netbsd-thread-multi
    /usr/pkg/lib/perl5/vendor_perl/5.18.0
    /usr/pkg/lib/perl5/5.18.0/alpha-netbsd-thread-multi
    /usr/pkg/lib/perl5/5.18.0
    .


Environment for perl 5.18.1:
    HOME=/home/naruaki
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/naruaki/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R7/bin:/usr/X11R6/bin:/usr/pkg/bin:/usr/pkg/sbin:/usr/games:/usr/local/bin:/usr/local/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/sh

@p5pRT
Copy link
Author

p5pRT commented Dec 28, 2013

From @demerphq

You need to provide us a replication script.

On 28 December 2013 14​:05, æ±�å¯�å��æ�� <perlbug-followup@​perl.org> wrote​:

# New Ticket Created by ����
# Please include the string​: [perl #120888]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=120888 >

This is a bug report for perl from nullnilaki@​gmail.com,
generated with the help of perlbug 1.39 running under perl 5.18.1.

-----------------------------------------------------------------
[Please describe your issue here]
I am using Netbsd/alpha.
perl cause an unaligned access exception.

Core was generated by `perl'.
Program terminated with signal 10, Bus error.
#0 0x00000001601795c8 in Perl_leave_scope (my_perl=0x160505000,
base=<optimized out>) at scope.c​:1217
1217 *(I8*)ARG0_PTR = (I8)(uv >> 8);

Taking a picture
http​://p.twipple.jp/Rh2K4
http​://twitpic.com/dqa7uh

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=core
severity=critical
---
Site configuration information for perl 5.18.1​:

Configured by naruaki at Sat Dec 28 11​:15​:19 UTC 2013.

Summary of my perl5 (revision 5 version 18 subversion 1) configuration​:

Platform​:
osname=netbsd, osvers=6.1.2, archname=alpha-netbsd-thread-multi
uname='netbsd 6.1.2 netbsd 6.1.2 (generic-$revision​: 1.343 $) #13​:
sat dec 7 08​:25​:52 jst 2013
naruaki@​netbsd​:usrnetbsd_6_1_2obj.alphasysarchalphacompilegeneric
alpha '
config_args='-sde -Duseshrplib -Duseithreads -Uusemymalloc'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cc', ccflags ='-O2 -mieee -g -pthread -I/usr/include
-fno-strict-aliasing -pipe -I/usr/pkg/include',
optimize='-O2 -mieee -g -pthread -I/usr/include',
cppflags='-O2 -mieee -g -pthread -I/usr/include
-fno-strict-aliasing -pipe -I/usr/pkg/include'
ccversion='', gccversion='4.5.3', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='cc', ldflags ='-Wl,-rpath,/usr/pkg/lib -L/usr/pkg/lib'
libpth=/lib /usr/lib /usr/pkg/lib
libs=-lm -lcrypt -lpthread
perllibs=-lm -lcrypt -lpthread
libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
-Wl,-R/usr/pkg/lib/perl5/5.18.0/alpha-netbsd-thread-multi/CORE'
cccdlflags='-DPIC -fPIC ', lddlflags='-shared -L/usr/pkg/lib'

Locally applied patches​:

---
@​INC for perl 5.18.1​:
/usr/pkg/lib/perl5/site_perl/5.18.0/alpha-netbsd-thread-multi
/usr/pkg/lib/perl5/site_perl/5.18.0
/usr/pkg/lib/perl5/vendor_perl/5.18.0/alpha-netbsd-thread-multi
/usr/pkg/lib/perl5/vendor_perl/5.18.0
/usr/pkg/lib/perl5/5.18.0/alpha-netbsd-thread-multi
/usr/pkg/lib/perl5/5.18.0
.

---
Environment for perl 5.18.1​:
HOME=/home/naruaki
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/naruaki/bin​:/bin​:/sbin​:/usr/bin​:/usr/sbin​:/usr/X11R7/bin​:/usr/X11R6/bin​:/usr/pkg/bin​:/usr/pkg/sbin​:/usr/games​:/usr/local/bin​:/usr/local/sbin
PERL_BADLANG (unset)
SHELL=/bin/sh

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Dec 28, 2013

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Dec 29, 2013

From @jkeenan

On 12/28/13 8​:05 AM, æ±�å¯�å��æ�� wrote​:

# New Ticket Created by ����
# Please include the string​: [perl #120888]
# in the subject line of all future correspondence about this issue.
#<URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=120888>

This is a bug report for perl from nullnilaki@​gmail.com,
generated with the help of perlbug 1.39 running under perl 5.18.1.

-----------------------------------------------------------------
[Please describe your issue here]
I am using Netbsd/alpha.
perl cause an unaligned access exception.

Core was generated by `perl'.
Program terminated with signal 10, Bus error.
#0 0x00000001601795c8 in Perl_leave_scope (my_perl=0x160505000,
base=<optimized out>) at scope.c​:1217
1217 *(I8*)ARG0_PTR = (I8)(uv>> 8);

Taking a picture
http​://p.twipple.jp/Rh2K4
http​://twitpic.com/dqa7uh

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=core
severity=critical
---
Site configuration information for perl 5.18.1​:

Configured by naruaki at Sat Dec 28 11​:15​:19 UTC 2013.

Summary of my perl5 (revision 5 version 18 subversion 1) configuration​:

Platform​:
osname=netbsd, osvers=6.1.2, archname=alpha-netbsd-thread-multi
uname='netbsd 6.1.2 netbsd 6.1.2 (generic-$revision​: 1.343 $) #13​:
sat dec 7 08​:25​:52 jst 2013
naruaki@​netbsd​:usrnetbsd_6_1_2obj.alphasysarchalphacompilegeneric
alpha '
config_args='-sde -Duseshrplib -Duseithreads -Uusemymalloc'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cc', ccflags ='-O2 -mieee -g -pthread -I/usr/include
-fno-strict-aliasing -pipe -I/usr/pkg/include',
optimize='-O2 -mieee -g -pthread -I/usr/include',
cppflags='-O2 -mieee -g -pthread -I/usr/include
-fno-strict-aliasing -pipe -I/usr/pkg/include'
ccversion='', gccversion='4.5.3', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='cc', ldflags ='-Wl,-rpath,/usr/pkg/lib -L/usr/pkg/lib'
libpth=/lib /usr/lib /usr/pkg/lib
libs=-lm -lcrypt -lpthread
perllibs=-lm -lcrypt -lpthread
libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
-Wl,-R/usr/pkg/lib/perl5/5.18.0/alpha-netbsd-thread-multi/CORE'
cccdlflags='-DPIC -fPIC ', lddlflags='-shared -L/usr/pkg/lib'

Locally applied patches​:

---
@​INC for perl 5.18.1​:
/usr/pkg/lib/perl5/site_perl/5.18.0/alpha-netbsd-thread-multi
/usr/pkg/lib/perl5/site_perl/5.18.0
/usr/pkg/lib/perl5/vendor_perl/5.18.0/alpha-netbsd-thread-multi
/usr/pkg/lib/perl5/vendor_perl/5.18.0
/usr/pkg/lib/perl5/5.18.0/alpha-netbsd-thread-multi
/usr/pkg/lib/perl5/5.18.0
.

---
Environment for perl 5.18.1​:
HOME=/home/naruaki
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/naruaki/bin​:/bin​:/sbin​:/usr/bin​:/usr/sbin​:/usr/X11R7/bin​:/usr/X11R6/bin​:/usr/pkg/bin​:/usr/pkg/sbin​:/usr/games​:/usr/local/bin​:/usr/local/sbin
PERL_BADLANG (unset)
SHELL=/bin/sh

Did you encounter this problem while trying to build or test perl 5.18
(i.e., during 'make' or 'make test')?

Or did you encounter this problem while running a perl program after
having built and installed perl?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

From @iabyn

On Sat, Dec 28, 2013 at 05​:05​:33AM -0800, æ±�å¯�å��æ�� wrote​:

Core was generated by `perl'.
Program terminated with signal 10, Bus error.
#0 0x00000001601795c8 in Perl_leave_scope (my_perl=0x160505000,
base=<optimized out>) at scope.c​:1217
1217 *(I8*)ARG0_PTR = (I8)(uv >> 8);

I don't understand why this would cause an alignment error; it's casting a
pointer to be a pointer to a signed char (1 byte), then writing to it.
More or less by definition, writing a byte shouldn't give alignment
errors.

Can you show the output of the following commands please, run in the
directory where you're trying to build 5.18.1​:

  grep I8TYPE config.h
  grep I8SIZE config.h

--
A major Starfleet emergency breaks out near the Enterprise, but
fortunately some other ships in the area are able to deal with it to
everyone's satisfaction.
  -- Things That Never Happen in "Star Trek" #13

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

From perl@profvince.com

On 12/30/13 12​:25, Dave Mitchell wrote​:

On Sat, Dec 28, 2013 at 05​:05​:33AM -0800, æ±�å¯�å��æ�� wrote​:

Core was generated by `perl'.
Program terminated with signal 10, Bus error.
#0 0x00000001601795c8 in Perl_leave_scope (my_perl=0x160505000,
base=<optimized out>) at scope.c​:1217
1217 *(I8*)ARG0_PTR = (I8)(uv >> 8);
I don't understand why this would cause an alignment error; it's casting a
pointer to be a pointer to a signed char (1 byte), then writing to it.
More or less by definition, writing a byte shouldn't give alignment
errors.

It can happen on alpha or ppc architectures if ARG0_PTR is not aligned
on 4 or 8 bytes boundaries, like for this :

  int n;
  char *p = &n;
  char *q = p + 1;
  *q = 123; /* boom */

But I don't understand why ARG0_PTR wouldn't have such alignment here.

Vincent

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

From @craigberry

On Mon, Dec 30, 2013 at 6​:19 AM, Vincent Pit <perl@​profvince.com> wrote​:

On 12/30/13 12​:25, Dave Mitchell wrote​:

On Sat, Dec 28, 2013 at 05​:05​:33AM -0800, æ±�å¯�å��æ�� wrote​:

Core was generated by `perl'.
Program terminated with signal 10, Bus error.
#0 0x00000001601795c8 in Perl_leave_scope (my_perl=0x160505000,
base=<optimized out>) at scope.c​:1217
1217 *(I8*)ARG0_PTR = (I8)(uv >> 8);

I don't understand why this would cause an alignment error; it's casting a
pointer to be a pointer to a signed char (1 byte), then writing to it.
More or less by definition, writing a byte shouldn't give alignment
errors.

It can happen on alpha or ppc architectures if ARG0_PTR is not aligned on 4
or 8 bytes boundaries, like for this :

int n;
char \*p = &n;
char \*q = p \+ 1;
\*q = 123; /\* boom \*/

But I don't understand why ARG0_PTR wouldn't have such alignment here.

Isn't it more likely it's the "(I8)(uv >> 8)" rather than anything to
do with ARG0_PTR? I think the optimizer might decide to step over the
first byte and grab the second one, i.e., why shift if the end result
is going to be the same as pulling bits 8-15 directly out of a 64-bit
value. But of course the compiler should know better than to do that
if it's going to generate an unaligned access.

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

From @iabyn

On Mon, Dec 30, 2013 at 01​:19​:24PM +0100, Vincent Pit wrote​:

On 12/30/13 12​:25, Dave Mitchell wrote​:

On Sat, Dec 28, 2013 at 05​:05​:33AM -0800, æ±�å¯�å��æ�� wrote​:

Core was generated by `perl'.
Program terminated with signal 10, Bus error.
#0 0x00000001601795c8 in Perl_leave_scope (my_perl=0x160505000,
base=<optimized out>) at scope.c​:1217
1217 *(I8*)ARG0_PTR = (I8)(uv >> 8);
I don't understand why this would cause an alignment error; it's casting a
pointer to be a pointer to a signed char (1 byte), then writing to it.
More or less by definition, writing a byte shouldn't give alignment
errors.

It can happen on alpha or ppc architectures if ARG0_PTR is not
aligned on 4 or 8 bytes boundaries, like for this :

int n;
char \*p = &n;
char \*q = p \+ 1;
\*q = 123; /\* boom \*/

You seem to be implying that a char* pointer needs to be aligned on a 4/8
byte boundary. Unless I'm misunderstanding you, that makes no sense.
I'd expect your code above to overwrite one of the bytes that make up the
storage for the integer n.

--
I before E. Except when it isn't.

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

From @craigberry

On Sat, Dec 28, 2013 at 10​:29 PM, æ±�å¯�å��æ�� <nullnilaki@​gmail.com> wrote​:

I think this problem disadvantage isobviously the loss of performance
on alpha (and IA64? and amd64?).

Please look at the
Intel 64 and IA-32 Architectures Software Developer�s Manual Combined
Volumes​:1, 2A, 2B, 2C, 3A, 3B, and 3C
and read section 4.1.1 Alignment of Words, Doublewords, Quadwords,
and Double Quadwords.

I managed to find this at
<http​://flint.cs.yale.edu/cs422/doc/24547012.pdf> and the section you
reference starts on page 72. It's talking about IA-32 and doesn't
seem directly relevant. Yes, alignment faults are bad, worse on some
architectures than others. But C programs must sometimes deal with
data one byte at a time and the compiler should be generating
instructions to produce aligned access in this case.

----------------------------------------
$ perl -Mre=debug -e "/just|another|perl|hacker/"
pid 388 (perl)​: unaligned access​: va=0x16050fcee pc=0x1601895c4
ra=0x160189124 sp=0x1ffffd0f0 op=ldl
pid 388 (perl)​: unaligned access​: va=0x16050fcee pc=0x1601895d0
ra=0x160189124 sp=0x1ffffd0f0 op=stl

If "va" means virtual address, then 0x16050fcee is an even number but
not a multiple of 4 or 8 and thus word (16-bit) aligned, but not
longword (32-bit) or quadword (64-bit) aligned. I don't really know
Alpha assembler but I'm pretty sure stl and ldl store and load
longwords. So we have longword instructions operating on a
word-aligned address; that does sound like an alignment fault.

The Alpha assembly tutorial at
<http​://www.cs.cmu.edu/afs/cs/academic/class/15213-f98/doc/alpha-guide.pdf>,
in sections 2.6 and 2.6.1 (starting on page 7) seems to indicate that
byte-level operations can be done entirely using quadword-aligned
memory accesses. So I think the real question is why isn't gcc doing
that for the relevant line in scope.c?

For the original poster​:

Can you post verbose compiler version output?

Can you report your Alpha system or processor model?

Does turning off optimizations with -Doptimize=-O0 make the problem go away?

Does adding -mcpu=XXXX to your compiler flags make any difference,
where XXXX matches the exact version of Alpha cpu your system has
(options at <http​://gcc.gnu.org/onlinedocs/gcc/DEC-Alpha-Options.html>)?

Do you know enough C to write a small C program that reproduces the
alignment error? It should just need that single line from scope.c
and enough declarations to get things set up.

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2013

From @bulk88

On Mon Dec 30 13​:51​:54 2013, craig.a.berry@​gmail.com wrote​:

On Sat, Dec 28, 2013 at 10​:29 PM, æ±�å¯�å��æ�� <nullnilaki@​gmail.com> wrote​:

I think this problem disadvantage isobviously the loss of performance
on alpha (and IA64? and amd64?).

Please look at the
Intel 64 and IA-32 Architectures Software Developer�s Manual Combined
Volumes​:1, 2A, 2B, 2C, 3A, 3B, and 3C
and read section 4.1.1 Alignment of Words, Doublewords, Quadwords,
and Double Quadwords.

I managed to find this at
<http​://flint.cs.yale.edu/cs422/doc/24547012.pdf> and the section you
reference starts on page 72. It's talking about IA-32 and doesn't
seem directly relevant. Yes, alignment faults are bad, worse on some
architectures than others. But C programs must sometimes deal with
data one byte at a time and the compiler should be generating
instructions to produce aligned access in this case.

http​://books.google.com/books?id=GumAeql5KPkC&lpg=PP1&dq=intitle%3Aalpha%20assembler%20risc&pg=SA4-PA6#v=onepage&q&f=false

If I read that correctly, "natural alignment" is the requirement, so by byte access should unalign fault.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Dec 31, 2013

From greg@blekko.com

On Mon, Dec 30, 2013 at 03​:51​:37PM -0600, Craig A. Berry wrote​:

The Alpha assembly tutorial at
<http​://www.cs.cmu.edu/afs/cs/academic/class/15213-f98/doc/alpha-guide.pdf>,
in sections 2.6 and 2.6.1 (starting on page 7) seems to indicate that
byte-level operations can be done entirely using quadword-aligned
memory accesses.

That's because Alpha didn't originally have byte load/stores... they
were faked with word loads and masks, etc. Real byte loads/stores were
added later, but I'm not surprised that the manuals still contain lots
of artifacts from the pre-byte days.

Alphas under Linux have a kernel software fixup for unaligned
loads/stores that would make the program work but with potentially
bad perf; but apparently netbsd doesn't do that.

The things you ask for are the right ones to diagnose. I agree that it
seems that ARG0_PTR is not arriving with good alignment.

-- greg

@p5pRT
Copy link
Author

p5pRT commented Dec 31, 2013

From @craigberry

On Mon, Dec 30, 2013 at 7​:03 PM, Greg Lindahl <greg@​blekko.com> wrote​:

On Mon, Dec 30, 2013 at 03​:51​:37PM -0600, Craig A. Berry wrote​:

The Alpha assembly tutorial at
<http​://www.cs.cmu.edu/afs/cs/academic/class/15213-f98/doc/alpha-guide.pdf>,
in sections 2.6 and 2.6.1 (starting on page 7) seems to indicate that
byte-level operations can be done entirely using quadword-aligned
memory accesses.

That's because Alpha didn't originally have byte load/stores... they
were faked with word loads and masks, etc. Real byte loads/stores were
added later, but I'm not surprised that the manuals still contain lots
of artifacts from the pre-byte days.

Right. That's why I want to see detailed compiler version info and/or
get a build attempted targeting the specific Alpha architecture of the
machine where we're seeing the alignment faults.

Alphas under Linux have a kernel software fixup for unaligned
loads/stores that would make the program work but with potentially
bad perf; but apparently netbsd doesn't do that.

It looks like netbsd by default does the fix-ups but also warns. You
can independently enable or disable the fix-ups and the warnings​:

<http​://www.netbsd.org/ports/alpha/faq.html#unaligned>.

The things you ask for are the right ones to diagnose. I agree that it
seems that ARG0_PTR is not arriving with good alignment.

-- greg

@p5pRT
Copy link
Author

p5pRT commented Dec 31, 2013

From @iabyn

On Mon, Dec 30, 2013 at 05​:03​:34PM -0800, Greg Lindahl wrote​:

On Mon, Dec 30, 2013 at 03​:51​:37PM -0600, Craig A. Berry wrote​:

The Alpha assembly tutorial at
<http​://www.cs.cmu.edu/afs/cs/academic/class/15213-f98/doc/alpha-guide.pdf>,
in sections 2.6 and 2.6.1 (starting on page 7) seems to indicate that
byte-level operations can be done entirely using quadword-aligned
memory accesses.

That's because Alpha didn't originally have byte load/stores... they
were faked with word loads and masks, etc. Real byte loads/stores were
added later, but I'm not surprised that the manuals still contain lots
of artifacts from the pre-byte days.

Alphas under Linux have a kernel software fixup for unaligned
loads/stores that would make the program work but with potentially
bad perf; but apparently netbsd doesn't do that.

The things you ask for are the right ones to diagnose. I agree that it
seems that ARG0_PTR is not arriving with good alignment.

I still don''t follow this. ARG0_PTR is being used to read a single byte.
This should never cause an alignment error; even if the underlying h/w
doesn't support byte reads, the compiler should convert something like

  char c = *((char *)p)

into something like

  int i = *((int *)i(p & ~7);
  char c = shift_and_mask(i);

--
Little fly, thy summer's play my thoughtless hand
has terminated with extreme prejudice.
  (with apologies to William Blake)

@p5pRT
Copy link
Author

p5pRT commented Dec 31, 2013

From @craigberry

On Tue, Dec 31, 2013 at 6​:14 AM, Dave Mitchell <davem@​iabyn.com> wrote​:

On Mon, Dec 30, 2013 at 05​:03​:34PM -0800, Greg Lindahl wrote​:

On Mon, Dec 30, 2013 at 03​:51​:37PM -0600, Craig A. Berry wrote​:

The things you ask for are the right ones to diagnose. I agree that it
seems that ARG0_PTR is not arriving with good alignment.

I still don''t follow this. ARG0_PTR is being used to read a single byte.

I think mentioning ARG0_PTR (the target of the assignment) is a red
herring. It translates to arg0.any_ptr, a union member, which is by
definition at the beginning of a union. If the compiler can't put
unions and structs on naturally aligned boundaries, all bets are off
and there would be lots more alignment faults anywhere and everywhere.
I think the source of the assignment is more likely where the trouble
is.

This should never cause an alignment error; even if the underlying h/w
doesn't support byte reads, the compiler should convert something....

Exactly, but for some reason it doesn't look like this compiler is
doing what it should in this one case. I really don't think Perl is
at fault, but it's hard to say for sure without pinning down a bit
further what exactly is going wrong.

To anyone with gcc/NetBSD/Alpha handy, please try running the
following and let us know if you get an alignment fault​:

$ cat > checkalign.c
#include <stdio.h>

typedef union any ANY;
union any {
  void* any_ptr;
  unsigned int any_int;
  unsigned char any_char;
};

int main() {
  ANY arg0;
  int tmp = 0xdeadbeef;
  arg0.any_ptr = &tmp;
  unsigned long long int uv = 0x4200;

  *(char*)arg0.any_ptr = (char)(uv >> 8);

  printf("tmp is 0x%x\n", tmp);
}
<CTRL-D>
$ cc -O2 -o checkalign checkalign.c
$ ./checkalign
tmp is 0xdeadbe42

@p5pRT
Copy link
Author

p5pRT commented Dec 31, 2013

From nullnilaki@gmail.com

Thank you for your mail!

This problem was caused by compiler's bug.
-ftree-ter option makes wrong binary.
I'm sorry to have caused you trouble.
Please close this topic.


$ perl -Mre=debug -e "/just|another|perl|hacker/"
Compiling REx "just|another|perl|hacker"
Final program​:
  1​: TRIEC-EXACT[ahjp] (15)
  <just>
  <another>
  <perl>
  <hacker>
  15​: END (0)
stclass AHOCORASICKC-EXACT[ahjp] minlen 4
Freeing REx​: "just|another|perl|hacker"


# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
Target​: alpha--netbsd
Configured with​:
/usr/src2/tools/gcc/../../external/gpl3/gcc/dist/configure
--target=alpha--netbsd --enable-long-long --enable-threads
--with-bugurl=http​://www.NetBSD.org/Misc/send-pr.html
--with-pkgversion='NetBSD nb2 20111202' --enable-__cxa_atexit
--with-mpc=/var/obj/mknative/alpha/usr/src2/destdir.alpha/usr
--with-mpfr=/var/obj/mknative/alpha/usr/src2/destdir.alpha/usr
--with-gmp=/var/obj/mknative/alpha/usr/src2/destdir.alpha/usr
--enable-tls --disable-multilib --disable-symvers
--disable-libstdcxx-pch --build=x86_64-unknown-netbsd5.99.56
--host=alpha--netbsd
Thread model​: posix
gcc version 4.5.3 (NetBSD nb2 20110806)


AlphaStation DS15, 1000MHz
8192 byte page size, 1 processor.
total memory = 512 MB
(2880 KB reserved for PROM, 509 MB used by NetBSD)
avail memory = 490 MB
timecounter​: Timecounters tick every 0.976 msec
mainbus0 (root)
cpu0 at mainbus0​: ID 0 (primary), 21264C-6
cpu0​: Architecture extensions​: 0x1307<PAT,MVI,CIX,FIX,BWX>


That's very nice of you!
--
Naruaki Etomi / nullnilaki@​gmail.com

@p5pRT
Copy link
Author

p5pRT commented Dec 31, 2013

From @jkeenan

On Tue Dec 31 14​:53​:53 2013, nullnilaki@​gmail.com wrote​:

Thank you for your mail!

This problem was caused by compiler's bug.
-ftree-ter option makes wrong binary.
I'm sorry to have caused you trouble.
Please close this topic.

Closed per request from original poster.

@p5pRT p5pRT closed this as completed Dec 31, 2013
@p5pRT
Copy link
Author

p5pRT commented Dec 31, 2013

@jkeenan - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant