Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Qing Zhao via Gcc-patches
> On Aug 4, 2023, at 3:09 PM, Siddhesh Poyarekar wrote: > > On 2023-08-04 15:06, Qing Zhao wrote: >>> Yes, that's what I'm thinking. >>> > so `q` must be pointing to a single element. So you could deduce: > > 1. the minimum size of the whole object that q points to. You mean

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Siddhesh Poyarekar
On 2023-08-04 15:06, Qing Zhao wrote: Yes, that's what I'm thinking. so `q` must be pointing to a single element. So you could deduce: 1. the minimum size of the whole object that q points to. You mean that the TYPE will determine the minimum size of the whole object? (Does this include th

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Qing Zhao via Gcc-patches
> On Aug 4, 2023, at 12:36 PM, Siddhesh Poyarekar wrote: > > On 2023-08-04 11:27, Qing Zhao wrote: >>> On Aug 4, 2023, at 10:40 AM, Siddhesh Poyarekar wrote: >>> >>> On 2023-08-03 13:34, Qing Zhao wrote: One thing I need to point out first is, currently, even for regular fixed size

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Siddhesh Poyarekar
On 2023-08-04 11:27, Qing Zhao wrote: On Aug 4, 2023, at 10:40 AM, Siddhesh Poyarekar wrote: On 2023-08-03 13:34, Qing Zhao wrote: One thing I need to point out first is, currently, even for regular fixed size array in the structure, We have this same issue, for example: #define LENGTH 10

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Qing Zhao via Gcc-patches
> On Aug 4, 2023, at 10:42 AM, Siddhesh Poyarekar wrote: > > On 2023-08-04 10:40, Siddhesh Poyarekar wrote: >> On 2023-08-03 13:34, Qing Zhao wrote: >>> One thing I need to point out first is, currently, even for regular fixed >>> size array in the structure, >>> We have this same issue, for e

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Qing Zhao via Gcc-patches
> On Aug 4, 2023, at 10:40 AM, Siddhesh Poyarekar wrote: > > On 2023-08-03 13:34, Qing Zhao wrote: >> One thing I need to point out first is, currently, even for regular fixed >> size array in the structure, >> We have this same issue, for example: >> #define LENGTH 10 >> struct fix { >> siz

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Siddhesh Poyarekar
On 2023-08-04 10:40, Siddhesh Poyarekar wrote: On 2023-08-03 13:34, Qing Zhao wrote: One thing I need to point out first is, currently, even for regular fixed size array in the structure, We have this same issue, for example: #define LENGTH 10 struct fix {    size_t foo;    int array[LENGTH];

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Siddhesh Poyarekar
On 2023-08-03 13:34, Qing Zhao wrote: One thing I need to point out first is, currently, even for regular fixed size array in the structure, We have this same issue, for example: #define LENGTH 10 struct fix { size_t foo; int array[LENGTH]; }; … int main () { struct fix *p; p = al

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Qing Zhao via Gcc-patches
> On Aug 4, 2023, at 3:38 AM, Kees Cook wrote: > > On Thu, Aug 03, 2023 at 09:31:24PM +, Qing Zhao wrote: >> So, the basic question is: >> >> Given the following: >> >> struct fix { >> int others; >> int array[10]; >> } >> >> extern struct fix * alloc_buf (); >> >> int main () >> { >>

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Kees Cook via Gcc-patches
On Thu, Aug 03, 2023 at 09:31:24PM +, Qing Zhao wrote: > So, the basic question is: > > Given the following: > > struct fix { > int others; > int array[10]; > } > > extern struct fix * alloc_buf (); > > int main () > { > struct fix *p = alloc_buf (); > __builtin_object_size(p->array

Re: One question on the source code of tree-object-size.cc

2023-08-04 Thread Kees Cook via Gcc-patches
On Thu, Aug 03, 2023 at 07:55:54PM +, Qing Zhao wrote: > > > > On Aug 3, 2023, at 1:51 PM, Kees Cook wrote: > > > > On August 3, 2023 10:34:24 AM PDT, Qing Zhao wrote: > >> One thing I need to point out first is, currently, even for regular fixed > >> size array in the structure, > >> We

Re: One question on the source code of tree-object-size.cc

2023-08-03 Thread Qing Zhao via Gcc-patches
So, the basic question is: Given the following: struct fix { int others; int array[10]; } extern struct fix * alloc_buf (); int main () { struct fix *p = alloc_buf (); __builtin_object_size(p->array,0) == ? } Given p->array, can the compiler determine that p points to an object that ha

Re: One question on the source code of tree-object-size.cc

2023-08-03 Thread Qing Zhao via Gcc-patches
> On Aug 3, 2023, at 1:51 PM, Kees Cook wrote: > > On August 3, 2023 10:34:24 AM PDT, Qing Zhao wrote: >> One thing I need to point out first is, currently, even for regular fixed >> size array in the structure, >> We have this same issue, for example: >> >> #define LENGTH 10 >> >> struct f

Re: One question on the source code of tree-object-size.cc

2023-08-03 Thread Kees Cook via Gcc-patches
On August 3, 2023 10:34:24 AM PDT, Qing Zhao wrote: >One thing I need to point out first is, currently, even for regular fixed size >array in the structure, >We have this same issue, for example: > >#define LENGTH 10 > >struct fix { > size_t foo; > int array[LENGTH]; >}; > >… >int main () >{ >

Re: One question on the source code of tree-object-size.cc

2023-08-03 Thread Qing Zhao via Gcc-patches
One thing I need to point out first is, currently, even for regular fixed size array in the structure, We have this same issue, for example: #define LENGTH 10 struct fix { size_t foo; int array[LENGTH]; }; … int main () { struct fix *p; p = alloc_buf_more (); expect(__builtin_object_

Re: One question on the source code of tree-object-size.cc

2023-08-03 Thread Siddhesh Poyarekar
On 2023-08-03 12:43, Qing Zhao wrote: Surely we could emit that for __bdos(q->array, 0) though, couldn't we? For __bdos(q->array, 0), we only have the access info for the sub-object q->array, we can surely decide the size of the sub-object q->array, but we still cannot decide the whole objec

Re: One question on the source code of tree-object-size.cc

2023-08-03 Thread Qing Zhao via Gcc-patches
> On Aug 3, 2023, at 12:15 PM, Siddhesh Poyarekar wrote: > > On 2023-08-02 10:02, Qing Zhao wrote: >> /*when checking the observed access p->array, we only have info on the >> observed access, i.e, the TYPE_SIZE info from the access. We don't have >> info on the whole object. */ >>

Re: One question on the source code of tree-object-size.cc

2023-08-03 Thread Siddhesh Poyarekar
On 2023-08-02 10:02, Qing Zhao wrote: /*when checking the observed access p->array, we only have info on the observed access, i.e, the TYPE_SIZE info from the access. We don't have info on the whole object. */ expect(__builtin_dynamic_object_size(q->array, 1), q->foo * sizeof(int

Re: One question on the source code of tree-object-size.cc

2023-08-02 Thread Qing Zhao via Gcc-patches
Okay. This previous small example was used to show the correct behavior of __bos for Fixed arrays when the allocation size and the TYPE_SIZE are mismatched. Now we agreed on the correct behavior for each of the cases for the fixed array. Since the new “counted_by” attribute is mainly a comple

Re: One question on the source code of tree-object-size.cc

2023-08-01 Thread Siddhesh Poyarekar
On 2023-08-01 18:57, Kees Cook wrote: return p; } /* in the following function, malloc allocated less space than size of the struct fix. Then what's the correct behavior we expect the __builtin_object_size should have for the following? */ static struct fix * noinline alloc_buf_l

Re: One question on the source code of tree-object-size.cc

2023-08-01 Thread Siddhesh Poyarekar
On 2023-08-01 17:35, Qing Zhao wrote: typedef struct { int a; } A; size_t f() { A *p = malloc (1); return __builtin_object_size (p, 0); Correction, that should be __builtin_object_size (p->a, 0). Actually, it should be __builtin_object_size(p->a, 1). For __builtin_object_size(p->a,0)

Re: One question on the source code of tree-object-size.cc

2023-08-01 Thread Kees Cook via Gcc-patches
On Tue, Aug 01, 2023 at 09:35:30PM +, Qing Zhao wrote: > > > > On Jul 31, 2023, at 1:07 PM, Siddhesh Poyarekar wrote: > > > > On 2023-07-31 13:03, Siddhesh Poyarekar wrote: > >> On 2023-07-31 12:47, Qing Zhao wrote: > >>> Hi, Sid and Jakub, > >>> > >>> I have a question in the following so

Re: One question on the source code of tree-object-size.cc

2023-08-01 Thread Qing Zhao via Gcc-patches
> On Jul 31, 2023, at 1:07 PM, Siddhesh Poyarekar wrote: > > On 2023-07-31 13:03, Siddhesh Poyarekar wrote: >> On 2023-07-31 12:47, Qing Zhao wrote: >>> Hi, Sid and Jakub, >>> >>> I have a question in the following source portion of the routine >>> “addr_object_size” of gcc/tree-object-size.c

Re: One question on the source code of tree-object-size.cc

2023-07-31 Thread Qing Zhao via Gcc-patches
> On Jul 31, 2023, at 2:23 PM, Siddhesh Poyarekar wrote: > > On 2023-07-31 14:13, Qing Zhao wrote: >> Okay. I see. >> Then if the size info from the TYPE is smaller than the size info from the >> malloc, >> then based on the current code, we use the smaller one between these two, >> i.e, the

Re: One question on the source code of tree-object-size.cc

2023-07-31 Thread Siddhesh Poyarekar
On 2023-07-31 14:13, Qing Zhao wrote: Okay. I see. Then if the size info from the TYPE is smaller than the size info from the malloc, then based on the current code, we use the smaller one between these two, i.e, the size info from the TYPE. (Even for the OST_MAXIMUM). Is such behavior co

Re: One question on the source code of tree-object-size.cc

2023-07-31 Thread Qing Zhao via Gcc-patches
Hi, Sid, Thanks a lot. > On Jul 31, 2023, at 1:07 PM, Siddhesh Poyarekar wrote: > > On 2023-07-31 13:03, Siddhesh Poyarekar wrote: >> On 2023-07-31 12:47, Qing Zhao wrote: >>> Hi, Sid and Jakub, >>> >>> I have a question in the following source portion of the routine >>> “addr_object_size” of

Re: One question on the source code of tree-object-size.cc

2023-07-31 Thread Siddhesh Poyarekar
On 2023-07-31 13:03, Siddhesh Poyarekar wrote: On 2023-07-31 12:47, Qing Zhao wrote: Hi, Sid and Jakub, I have a question in the following source portion of the routine “addr_object_size” of gcc/tree-object-size.cc:   743   bytes = compute_object_offset (TREE_OPERAND (ptr, 0), var);   74

Re: One question on the source code of tree-object-size.cc

2023-07-31 Thread Siddhesh Poyarekar
On 2023-07-31 12:47, Qing Zhao wrote: Hi, Sid and Jakub, I have a question in the following source portion of the routine “addr_object_size” of gcc/tree-object-size.cc: 743 bytes = compute_object_offset (TREE_OPERAND (ptr, 0), var); 744 if (bytes != error_mark_node) 745

One question on the source code of tree-object-size.cc

2023-07-31 Thread Qing Zhao via Gcc-patches
Hi, Sid and Jakub, I have a question in the following source portion of the routine “addr_object_size” of gcc/tree-object-size.cc: 743 bytes = compute_object_offset (TREE_OPERAND (ptr, 0), var); 744 if (bytes != error_mark_node) 745 { 746 bytes = size_for_offset