pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexander Korotkov <aekorotkov@gmail.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Alexander Korotkov <akorotkov@postgresql.org>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Detecting pointer misalignment (was Re: pgsql: Implementation of subscripting for jsonb)
Date: Sun, 07 Feb 2021 19:47:37 -0500
Message-ID: <475514.1612745257@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPpHfdu8Jh0tySa50Zhkyg6gMvi2pQFdHAMiF+UkZNqsDLwTQw@mail.gmail.com>
References: <E1l6Jjn-0000kp-75@gemulon.postgresql.org>
	<37bb56a0-391d-759d-771b-9c1d8c15a84b@iki.fi>
	<3293925.1612163110@sss.pgh.pa.us>
	<CAPpHfdsne3=T=fMNU45PtxdhSL_J2PjLTeS8rwKnJzUR4YNd4w@mail.gmail.com>
	<CAPpHfdu8Jh0tySa50Zhkyg6gMvi2pQFdHAMiF+UkZNqsDLwTQw@mail.gmail.com>

[ redirecting to -hackers ]

Alexander Korotkov <aekorotkov@gmail.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.

* -fsanitize-trap=alignment seems to be a clang-ism; gcc won't take it.
However, after some experimenting I found that "-fno-sanitize-recover=all"
(or "-fno-sanitize-recover=alignment" if you prefer) produces roughly
equivalent results on gcc.

* Both clang and gcc seem to be happy with the same spelling of the
function attribute, which is fortunate.  However, I seriously doubt
that bare "#ifdef __GNUC__" is going to be good enough.  At the very
least there's going to need to be a compiler version test in there,
and we might end up needing to get the configure script involved.

* 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.

			regards, tom lane





view thread (15+ messages)  latest in thread

Message-ID: <475514.1612745257@sss.pgh.pa.us>
Permalink:  ../475514.1612745257@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/475514.1612745257@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, aekorotkov@gmail.com, hlinnaka@iki.fi, akorotkov@postgresql.org, pgsql-hackers@lists.postgresql.org
  Subject: Re: Detecting pointer misalignment (was Re: pgsql: Implementation of subscripting for jsonb)
  In-Reply-To: <475514.1612745257@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox