Re: SerializedSnapshotData alignment

From: Noah Misch <noah(at)leadboat(dot)com>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Rahila Syed <rahilasyed90(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SerializedSnapshotData alignment
Date: 2017-03-02 04:02:20
Message-ID: 20170302040220.GA1646858@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Feb 27, 2017 at 03:08:35PM +1300, Thomas Munro wrote:
> On Mon, Feb 27, 2017 at 2:18 PM, Noah Misch <noah(at)leadboat(dot)com> wrote:
> > I wondered the same thing; if nothing else, why don't protosciurus and
> > castoroides fail the same way? They do use older compilers, "Sun C 5.10
> > SunOS_sparc 2009/06/03" and gcc 3.4.3. I have "Sun C 5.12 SunOS_sparc
> > 2011/11/16" and gcc 4.9.2, both of which are alignment-sensitive in several
> > configurations, according to the attached test program. However, in a 32-bit
> > build with this Sun C, I don't get alignment-related bus errors. (Those
> > animals build 64-bit, so this isn't the full story.)
>
> It's been a while but I seem to recall that Sun C defaulted to a
> -xmemalign setting that tolerated misaligned reads in 32 bit builds,
> but used a different default on 64 bit builds. "Solaris Application
> Programming" 5.8.5 seems to confirm this: "For 32-bit applications,
> since Sun Studio 9, the default is for the compiler to assume 8-byte
> alignment and to trap and correct any misaligned data accesses. For
> 64-bit applications, the compiler assumes 8-byte alignment, but the
> application will SIGBUS on a misaligned access."
>
> Yet castoroides seems to be building with -m64, so that's not the
> explanation. Could it be correctly aligned by coincidence?

Coincidental alignment was it. ps_snapshot_data has offset 16 in a 64-bit
build and offset 12 in a 32-bit build, so it is well-aligned in 64-bit only.
I was building a 32-bit PostgreSQL; when I build a 64-bit PostgreSQL, I no
longer get the SIGBUS.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro HORIGUCHI 2017-03-02 04:36:22 Re: \h tab-completion
Previous Message Tomas Vondra 2017-03-02 03:47:13 Re: PATCH: two slab-like memory allocators