Re: Add counted_by attribute

From: Tomas Vondra <tomas(at)vondra(dot)me>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>, Tristan Partin <tristan(at)partin(dot)io>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Japin Li <japinli(at)hotmail(dot)com>
Subject: Re: Add counted_by attribute
Date: 2026-11-27 17:04:24
Message-ID: dbc0e211-6ef5-4699-9d6a-930d2da2286c@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11/26/26 11:50, Peter Eisentraut wrote:
> On 02.11.26 11:49, Peter Eisentraut wrote:
>> On 06.10.26 22:41, Tristan Partin wrote:
>>> On Mon Oct 5, 2026 at 7:52 PM UTC, Peter Eisentraut wrote:
>>>> Ok, all the infrastructure is in place now.  I'm working through the
>>>> attribute additions now.
>>>>
>>>> One thing to think about is that adding these attributes to server
>>>> header files would also affect extensions.  I think we might want to do
>>>> some research about that.  Like, is the normal API to fill in the
>>>> structure yourself, or are there wrapper functions that are
>>>> mandatory to
>>>> use?  I'm going to park that for the moment and work through the
>>>> attribute additions in .c files first.
>>>
>>> I have to think that extensions testing with
>>> -fsanitize=bounds/_FORTIFY_SOURCE=3 is pretty rare. In any case, I did
>>> some analysis (grepping and reading) on the list of structs exposed in
>>> header files against 9 popular extensions (not in contrib), and I didn't
>>> find any potential issues.
>>
>> Ok, I studies this a bit, too, and I think it's ok.  I have committed
>> the rest of this, and added a note in the commit message about this.
> Since we committed these, clang with -fsanitize=bounds has been failing.
>  (CI only runs with gcc.)
>
> The problem is that clang rejects things like
>
>     memcpy(&p->a[0], ...);
>
> when the associated count is 0.  It's debatable whether this is correct,
> but in any case clang behaves inconsistently about it, and I have filed
> a bug: https://github.com/llvm/llvm-project/issues/236753 .  But there
> hasn't been any response in a while, so I'm suggesting we go ahead with
> a workaround.  In this case, we can just write
>
>     memcpy(p->a, ...);
>
> which is simpler anyway.
>
> With the attached patch, I get a clean pass on clang -fsanitize=bounds.

I apologize,

I independently discovered this issue (with UBSan) today while working
on some memory-safety fixes, convinced myself it's right to adjust the
parallelCurrentXids accesses and pushed the fix.

I intended to ping this thread (I even linked it in the commit message)
after the commit, but now I realize Peter already posted virtually the
same fix I pushed. Obviously, his authorship is not mentioned in the
commit :-( Sorry about that, I should have checked before.

I think we agree the change is correct, but I feel quite silly.

:-(

--
Tomas Vondra

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-11-27 17:18:56 Re: Add counted_by attribute
Previous Message Zsolt Parragi 2026-11-27 16:23:19 Re: What is up on BF member kestrel?