Re: [HACKERS] SerializedSnapshotData alignment - Mailing list pgsql-hackers

From Noah Misch
Subject Re: [HACKERS] SerializedSnapshotData alignment
Date
Msg-id 20170302040220.GA1646858@tornado.leadboat.com
Whole thread Raw
In response to Re: [HACKERS] SerializedSnapshotData alignment  (Thomas Munro <thomas.munro@enterprisedb.com>)
List 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@leadboat.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.



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: [HACKERS] PATCH: two slab-like memory allocators
Next
From: Kyotaro HORIGUCHI
Date:
Subject: Re: [HACKERS] \h tab-completion