develooper Front page | perl.perl5.porters | Postings from November 2008

Re: [perl #60574] sv_upgrade() loses 64-bit alignment, causing SIGBUS on sparc

Thread Previous | Thread Next
Nicholas Clark
November 16, 2008 09:15
Re: [perl #60574] sv_upgrade() loses 64-bit alignment, causing SIGBUS on sparc
Message ID:
On Sun, Nov 16, 2008 at 04:16:14AM -0800, Niko Tyni wrote:

> As seen in <>, calling sv_chop() or otherwise
> upgrading an SV can result in an unaligned 64-bit access on the sparc
> architecture.

> Calling the SvGROW() macro afterwards will cast sv->sv_any to an XPV
> pointer, which should be 64-bit aligned according to __alignof__().
> With -O2, gcc will compile the code using a doubleword load instruction
> (ldd) that fails with a SIGBUS if the 64-bit alignment has been lost.

> However, it seems to me that this is a more general problem that should
> be fixed by making sv_upgrade() somehow retain the alignment of the
> existing SV. 

Yes, it's a more general problem.

> The instruction that causes the bus error is a double-word load (ldd)
> during the first comparison. The compiler (gcc -O2) is using the
> double-word instruction to load both xpv_cur and xpv_len in one go.

> Quoting Julien Cristau in the Debian bug:
> > __alignof__(XPV) is 8, so gcc is allowed to assume that any XPV is
> > 64-bit aligned, as far as I can tell.  xpv_cur's offset is 8, so it
> > should also be 64-bit aligned.

What is __alignof__(XPVIV) and sizeof(XPVIV) on the same system?

>     cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'

I see that -fno-strict-aliasing is on. That might prove relevant in my reply
to your reply.
Nicholas Clark

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About