Bharath Rupireddy <bharath.rupireddyforpostg...@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


Reply via email to