public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [V2][PATCH 0/3] New attribute "counted_by" to annotate bounds for C99 FAM(PR108896)
@ 2023-08-04 19:44 Qing Zhao
  2023-08-04 19:44 ` [V2][PATCH 1/3] Provide counted_by attribute to flexible array member field (PR108896) Qing Zhao
                   ` (4 more replies)
  0 siblings, 5 replies; 33+ messages in thread
From: Qing Zhao @ 2023-08-04 19:44 UTC (permalink / raw)
  To: joseph, richard.guenther, jakub, gcc-patches
  Cc: keescook, siddhesh, uecker, isanbard, Qing Zhao

Hi,

This is the 2nd version of the patch, per our discussion based on the
review comments for the 1st version, the major changes in this version
are:

1. change the name "element_count" to "counted_by";
2. change the parameter for the attribute from a STRING to an
Identifier;
3. Add logic and testing cases to handle anonymous structure/unions;
4. Clarify documentation to permit the situation when the allocation
size is larger than what's specified by "counted_by", at the same time,
it's user's error if allocation size is smaller than what's specified by
"counted_by";
5. Add a complete testing case for using counted_by attribute in
__builtin_dynamic_object_size when there is mismatch between the
allocation size and the value of "counted_by", the expecting behavior
for each case and the explanation on why in the comments. 

As discussed, I plan to add two more separate patch sets after this initial
patch set is approved and committed.

set 1. A new warning option and a new sanitizer option for the user error
       when the allocation size is smaller than the value of "counted_by".
set 2. An improvement to __builtin_dynamic_object_size  for the following
       case:

struct A
{
size_t foo;
int array[] __attribute__((counted_by (foo)));
};

extern struct fix * alloc_buf ();

int main ()
{
struct fix *p = alloc_buf ();
__builtin_object_size(p->array, 0) == sizeof(struct A) + p->foo * sizeof(int);
  /* with the current algorithm, it’s UNKNOWN */ 
__builtin_object_size(p->array, 2) == sizeof(struct A) + p->foo * sizeof(int);
  /* with the current algorithm, it’s UNKNOWN */
}

Bootstrapped and regression tested on both aarch64 and X86, no issue.

Please see more details on the description of this work on:

https://gcc.gnu.org/pipermail/gcc-patches/2023-May/619708.html

Okay for committing?

thanks.

Qing

Qing Zhao (3):
  Provide counted_by attribute to flexible array member field (PR108896)
  Use the counted_by atribute info in builtin object size [PR108896]
  Use the counted_by attribute information in bound sanitizer[PR108896]

 gcc/c-family/c-attribs.cc                     |  54 ++++-
 gcc/c-family/c-common.cc                      |  13 ++
 gcc/c-family/c-common.h                       |   1 +
 gcc/c-family/c-ubsan.cc                       |  16 ++
 gcc/c/c-decl.cc                               |  79 +++++--
 gcc/doc/extend.texi                           |  73 +++++++
 .../gcc.dg/flex-array-counted-by-2.c          |  74 +++++++
 .../gcc.dg/flex-array-counted-by-3.c          | 197 ++++++++++++++++++
 gcc/testsuite/gcc.dg/flex-array-counted-by.c  |  40 ++++
 .../ubsan/flex-array-counted-by-bounds-2.c    |  27 +++
 .../ubsan/flex-array-counted-by-bounds.c      |  46 ++++
 gcc/tree-object-size.cc                       |  37 +++-
 gcc/tree.cc                                   | 133 ++++++++++++
 gcc/tree.h                                    |  15 ++
 14 files changed, 780 insertions(+), 25 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by-2.c
 create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by-3.c
 create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by.c
 create mode 100644 gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds-2.c
 create mode 100644 gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds.c

-- 
2.31.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2023-08-17 16:54 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-04 19:44 [V2][PATCH 0/3] New attribute "counted_by" to annotate bounds for C99 FAM(PR108896) Qing Zhao
2023-08-04 19:44 ` [V2][PATCH 1/3] Provide counted_by attribute to flexible array member field (PR108896) Qing Zhao
2023-08-04 19:44 ` [V2][PATCH 2/3] Use the counted_by atribute info in builtin object size [PR108896] Qing Zhao
2023-08-04 19:44 ` [V2][PATCH 3/3] Use the counted_by attribute information in bound sanitizer[PR108896] Qing Zhao
2023-08-07 16:16 ` [V2][PATCH 0/3] New attribute "counted_by" to annotate bounds for C99 FAM(PR108896) Kees Cook
2023-08-07 16:33   ` Qing Zhao
2023-08-09 19:17     ` Kees Cook
2023-08-08 14:54   ` Martin Uecker
2023-08-08 16:18     ` Michael Matz
2023-08-08 19:58     ` Kees Cook
2023-08-09 16:05     ` Qing Zhao
2023-08-09 16:21       ` Michael Matz
2023-08-09 20:10         ` Qing Zhao
2023-08-10  6:58           ` Martin Uecker
2023-08-10 13:59             ` Qing Zhao
2023-08-10 14:38               ` Martin Uecker
2023-08-10 14:42                 ` Jakub Jelinek
2023-08-10 14:47                   ` Martin Uecker
2023-08-10 14:58                     ` Siddhesh Poyarekar
2023-08-10 15:18                       ` Martin Uecker
2023-08-10 16:28                         ` Qing Zhao
2023-08-10 16:30                         ` Siddhesh Poyarekar
2023-08-10 16:39                           ` Jakub Jelinek
2023-08-10 17:06                             ` Siddhesh Poyarekar
2023-08-16 21:42                               ` Qing Zhao
2023-08-10 18:18                             ` Qing Zhao
2023-08-10 14:02             ` Michael Matz
2023-08-10 13:54           ` Michael Matz
2023-08-09 20:34     ` Qing Zhao
2023-08-17  5:31 ` Kees Cook
2023-08-17  6:38   ` Kees Cook
2023-08-17 13:44     ` Qing Zhao
2023-08-17 16:54       ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).