On 30.07.26 00:07, Tristan Partin 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.
I think this is a good idea.
Maybe you could produce an intentionally broken piece of code that would
illustrate what kinds of reports one might hope to get from this.