Re: How to test Postgres for any unaligned memory accesses?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: How to test Postgres for any unaligned memory accesses?
Date: 2021-04-23 13:55:09
Message-ID: 1312608.1619186109@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message osumi.takamichi@fujitsu.com 2021-04-23 14:33:53 RE: Forget close an open relation in ReorderBufferProcessTXN()
Previous Message osumi.takamichi@fujitsu.com 2021-04-23 13:48:37 RE: Truncate in synchronous logical replication failed