Re: Detecting pointer misalignment (was Re: pgsql: Implementation of subscripting for jsonb)

From: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Alexander Korotkov <akorotkov(at)postgresql(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Detecting pointer misalignment (was Re: pgsql: Implementation of subscripting for jsonb)
Date: 2021-02-09 00:34:27
Message-ID: CAPpHfdvh+QrbBCo=uY=_fHK8w7yKr=Q4KGAtp=3tzp62SjODrA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Hi, Tom!

Thank you for taking care of this.

On Mon, Feb 8, 2021 at 3:47 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> [ redirecting to -hackers ]
>
> Alexander Korotkov <aekorotkov(at)gmail(dot)com> writes:
> >> BTW, I managed to reproduce the issue by compiling with CFLAGS="-O0
> >> -fsanitize=alignment -fsanitize-trap=alignment" and the patch
> >> attached.
> >> I can propose the following to catch such issues earlier. We could
> >> finish (wrap attribute with macro and apply it to other places with
> >> misalignment access if any) and apply the attached patch and make
> >> commitfest.cputube.org check patches with CFLAGS="-O0
> >> -fsanitize=alignment -fsanitize-trap=alignment". What do you think?
>
> > The revised patch is attached. The attribute is wrapped into
> > pg_attribute_no_sanitize_alignment() macro. I've checked it works for
> > me with gcc-10 and clang-11.
>
> I found some time to experiment with this today. It is really nice
> to be able to detect these problems without using obsolete hardware.
> However, I have a few issues:
>
> * Why do you recommend -O0? Seems to me we want to test the code
> as we'd normally use it, ie typically -O2.

My idea was that with -O0 we can see some unaligned accesses, which
would be optimized away with -O2. I mean with -O2 we might completely
skip accessing some pointer, which would be accessed in -O0. However,
this situation is probably very rare.

> * I think the right place to run such a check is in some buildfarm
> animals. The cfbot only sees portions of what goes into our tree.

Could we have both cfbot + buildfarm animals?

------
Regards,
Alexander Korotkov

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2021-02-09 00:35:01 Re: Detecting pointer misalignment (was Re: pgsql: Implementation of subscripting for jsonb)
Previous Message Peter Geoghegan 2021-02-08 23:21:17 pgsql: Correct pgstattuple B-Tree page comments.

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2021-02-09 00:35:01 Re: Detecting pointer misalignment (was Re: pgsql: Implementation of subscripting for jsonb)
Previous Message Greg Nancarrow 2021-02-09 00:17:14 Re: Libpq support to connect to standby server as priority