Re: How to test Postgres for any unaligned memory accesses? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: How to test Postgres for any unaligned memory accesses?
Date
Msg-id 1312608.1619186109@sss.pgh.pa.us
Whole thread Raw
In response to How to test Postgres for any unaligned memory accesses?  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
Responses Re: How to test Postgres for any unaligned memory accesses?  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
List pgsql-hackers
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> writes:
> I'm trying to test Postgres code for any unaligned memory accesses. I
> used a hack shown at [1] and put it in exec_simple_query, then I'm
> seeing a SIGBUS error from SplitIdentifierString's strncpy, see [2].

Regardless of Postgres' policy about alignment safety, glibc sees
no reason to avoid unaligned accesses on x86 hardware.  If you want
to test this sort of thing on hardware that's not actually alignment
picky, you have to enlist the toolchain's help.

> I'm not sure this is the right way. I would like to know whether there
> is a standard way of testing Postgres code for any unaligned memory
> accesses. Thanks. Any help would be appreciated.

Per c.h, late-model compilers have options for this:

 * Testing can be done with "-fsanitize=alignment -fsanitize-trap=alignment"
 * on clang, or "-fsanitize=alignment -fno-sanitize-recover=alignment" on gcc.

We have at least one buildfarm member using the former.  I have no idea
how water-tight these checks are though.  They don't seem to cause very
much slowdown, which is suspicious :-(

            regards, tom lane



pgsql-hackers by date:

Previous
From: "osumi.takamichi@fujitsu.com"
Date:
Subject: RE: Truncate in synchronous logical replication failed
Next
From: "osumi.takamichi@fujitsu.com"
Date:
Subject: RE: Forget close an open relation in ReorderBufferProcessTXN()