Re: pg_verify_checksums and -fno-strict-aliasing - Mailing list pgsql-hackers

From Andres Freund
Subject Re: pg_verify_checksums and -fno-strict-aliasing
Date
Msg-id 20180830220409.4zhdka6ibs66enbk@alap3.anarazel.de
Whole thread Raw
In response to Re: pg_verify_checksums and -fno-strict-aliasing  (Andres Freund <andres@anarazel.de>)
Responses Re: pg_verify_checksums and -fno-strict-aliasing
List pgsql-hackers
On 2018-08-30 14:46:06 -0700, Andres Freund wrote:
> Hi,
> 
> On 2018-08-30 17:19:28 -0400, Tom Lane wrote:
> > So, I've been fooling around trying to get it to work without
> > -fno-strict-aliasing, but with little luck so far.
> 
> The problem presumably is that pg_checksum_block() accesses the relevant
> fields as an uint32, whereas pg_checksum_page() accesses it as a
> PageHeader. That's an aliasing violation.  *One* cast from char* to
> either type is fine, it's accessing under both those types that's
> problematic.
> 
> One way to fix it would be to memcpy in/out the modified PageHeader, or
> just do offset math and memcpy to that offset.

It took me a bit to reproduce the issue (due to sheer stupidity on my
part: no, changing the flags passed to gcc to link pg_verify_checksums
doesn't do the trick), but the above indeed fixes the issue for me.

The attached is just for demonstration that the approach works.

Greetings,

Andres Freund

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: 10.5 but not 10.4: backend startup during reindex system: could not read block 0 in file "base/16400/..": read only 0 of 8192 bytes
Next
From: Tom Lane
Date:
Subject: Re: pg_verify_checksums and -fno-strict-aliasing