On Wed, 29 Jul 2026 at 22:07, "Tristan Partin" <[email protected]> wrote:
> The counted_by[0] compiler attribute is fairly new. It was added in GCC 
> 15 and Clang 18. It has been used fairly extensively in the Linux 
> kernel[0].
>
> To summarize the benefits of the attribute:
>
> - Runtime bounds checking with -DFORTIFY_SOURCE=3 and -fsanitize-bounds
> - Accurate reporting of __builtin_dynamic_object_size()
>
> While we don't use __builtin_dynamic_object_size(), I think the runtime 
> bounds checking improvements are easily worth the little bit of effort 
> to add the attribute in various locations and review the code. I think 
> it will improve things for buildfarm animals using ASan due to expanded 
> coverage.
>
> Adding this attribute to the codebase was previously proposed back in 
> 2024[1], but the thread never got any traction. I figured that I would 
> try again, but bring some patches this time. I figured that I would 
> start small, and then after people agree that it has value, I can look 
> into adding the attribute in many more places.
>
> [0]: 
> https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-counted_005fby
> [1]: 
> https://people.kernel.org/gustavoars/how-to-use-the-new-counted_by-attribute-in-c-and-linux
> [2]: 
> https://www.postgresql.org/message-id/me3p282mb3166210cde36bd485b703bf6b6...@me3p282mb3166.ausp282.prod.outlook.com
>

+1 for this idea.

> -- 
> Tristan Partin
> PostgreSQL Contributors Team
> AWS (https://aws.amazon.com)

-- 
Regards,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.


Reply via email to