From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by sourceware.org (Postfix) with ESMTPS id 7A2713858D20 for ; Wed, 30 Nov 2022 09:58:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A2713858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=seketeli.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=seketeli.org Received: (Authenticated sender: dodji@seketeli.org) by mail.gandi.net (Postfix) with ESMTPSA id 4C9191BF20B; Wed, 30 Nov 2022 09:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seketeli.org; s=gm1; t=1669802302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MhXNuvpsfZJZI7lWfZpMleabfo9e5+Q8GTt/5sPW44E=; b=jxKku0Lvl/2Fb03rI8fL+le0niDQMXR94hwEowGOgM6k4rFqMQtnJFZM2/q3f3aPPeHM8r dilbTSzwgWkJAAAjdFX+zN0EqndQgVy6PqRpVbOv3RKwrhsEt9H/cZcJxUpI2/99BTUEl9 RDF8/SdASxSwAzFrksZDjBwBjK6ux1a/EdGHAfI+fpv3PZWzgWSOxHYX7cZmJ5QJlfaYkY xUYo7Ml97aFw5hi3BGsFKtGzxbKzrgvQd67IDMNpQMlmPqr7+ottKeQEMnM+fbrXPiS9LQ YrwfYf/aZ0htKxybp4d5mzPJBGf4oDHMivPq23SLDiWAlg/w46POIUJRjwH5EA== Received: by localhost (Postfix, from userid 1000) id 67687581C59; Wed, 30 Nov 2022 10:58:21 +0100 (CET) From: Dodji Seketeli To: "Guillermo E. Martinez via Libabigail" Cc: "Guillermo E. Martinez" Subject: Re: [PATCH 5/5] ctf-front-end: Fix array size representation Organization: Me, myself and I References: <20221117034305.184864-1-guillermo.e.martinez@oracle.com> <20221117034305.184864-6-guillermo.e.martinez@oracle.com> X-Operating-System: Fedora 38 X-URL: http://www.seketeli.net/~dodji Date: Wed, 30 Nov 2022 10:58:21 +0100 In-Reply-To: <20221117034305.184864-6-guillermo.e.martinez@oracle.com> (Guillermo E. Martinez via Libabigail's message of "Wed, 16 Nov 2022 21:43:05 -0600") Message-ID: <878rjsojb6.fsf@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_SHORT,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello Guillermo, "Guillermo E. Martinez via Libabigail" a =C3=A9crit: > Array with a single element is represented as infinite array. > > > > Hmmh, actually I think it's a little bit more involved than that. This case is for "variable length arrays", for instance, defined as: int a[]; There is also an extension known as "zero-length arrays", supported by GCC and various other compilers since forever: https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html. It's an extension because strictly speaking an array can't have a zero size in C. I see the "zero-length array" as another way to specify a variable length array in the context of the "flexible array member" idiom: https://en.wikipedia.org/wiki/Flexible_array_member. Those were standardized in C99, by the way. So, it's those types of array that are represented in the libabigail IR as being of "non known size". The IR uses the "infinite" keyword, similarly to what DWARF does. I have thus updated the introductory paragraphs of the commit log according= ly. > > * src/abg-ctf-reader.cc (build_array_ctf_range): Use > * tests/data/Makefile.am: Add new test. > `upper_bound' and number of elements to indicate infinite > array size. > * tests/data/test-read-ctf/test-array-size.abi: New test. > * tests/data/test-read-ctf/test-array-size.c: Likewise. > * tests/data/test-read-ctf/test-array-size.o: Likewise. > * tests/test-read-ctf.cc: Update testsuite. > > Signed-off-by: Guillermo E. Martinez The patch otherwise looks good to me. Please find below what was actually applied to the master repository. [...] Cheers, >From 77ae31417697dde8d3119e042dafd7dddb9538e1 Mon Sep 17 00:00:00 2001 From: "Guillermo E. Martinez via Libabigail" Date: Wed, 16 Nov 2022 21:43:05 -0600 Subject: [PATCH] ctf-reader: Fix array size representation A variable length array (VLA), or a flexible array member (with its size set to zero to recognize such cases) is represented in the libabigail IR as an array with "non-finite" length. This is a way to say that the length of the array is not statically known. The ABIXML array-type-def element looks like: The patch teaches the ctf-reader to correctly set the size of the array for VLAs. * src/abg-ctf-reader.cc (build_array_ctf_range): Use * tests/data/Makefile.am: Add new test. `upper_bound' and number of elements to indicate infinite array size. * tests/data/test-read-ctf/test-array-size.abi: New test. * tests/data/test-read-ctf/test-array-size.c: Likewise. * tests/data/test-read-ctf/test-array-size.o: Likewise. * tests/test-read-ctf.cc: Update testsuite. Signed-off-by: Guillermo E. Martinez Signed-off-by: Dodji Seketeli --- src/abg-ctf-reader.cc | 2 +- tests/data/Makefile.am | 3 +++ tests/data/test-read-ctf/test-array-size.abi | 23 +++++++++++++++++++ tests/data/test-read-ctf/test-array-size.c | 4 ++++ tests/data/test-read-ctf/test-array-size.o | Bin 0 -> 1432 bytes tests/data/test-read-ctf/test9.o.abi | 4 ++-- tests/test-read-ctf.cc | 9 ++++++++ 7 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 tests/data/test-read-ctf/test-array-size.abi create mode 100644 tests/data/test-read-ctf/test-array-size.c create mode 100644 tests/data/test-read-ctf/test-array-size.o diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc index b4b957d2..e0b8bfb1 100644 --- a/src/abg-ctf-reader.cc +++ b/src/abg-ctf-reader.cc @@ -1194,7 +1194,7 @@ build_array_ctf_range(reader *rdr, ctf_dict_t *dic, upper_bound.set_unsigned(nelems > 0 ? nelems - 1 : 0U); =20 /* for VLAs number of array elements is 0 */ - if (upper_bound.get_unsigned_value() =3D=3D 0) + if (upper_bound.get_unsigned_value() =3D=3D 0 && nelems =3D=3D 0) is_infinite =3D true; =20 subrange.reset(new array_type_def::subrange_type(rdr->env(), diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index d04ecf3f..e994aff3 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -716,6 +716,9 @@ test-read-ctf/test-const-array.o \ test-read-ctf/test-array-mdimension.abi \ test-read-ctf/test-array-mdimension.c \ test-read-ctf/test-array-mdimension.o \ +test-read-ctf/test-array-size.abi \ +test-read-ctf/test-array-size.c \ +test-read-ctf/test-array-size.o \ \ test-annotate/test0.abi \ test-annotate/test1.abi \ diff --git a/tests/data/test-read-ctf/test-array-size.abi b/tests/data/test= -read-ctf/test-array-size.abi new file mode 100644 index 00000000..3fbc65b6 --- /dev/null +++ b/tests/data/test-read-ctf/test-array-size.abi @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-ctf/test-array-size.c b/tests/data/test-r= ead-ctf/test-array-size.c new file mode 100644 index 00000000..fe2f3fef --- /dev/null +++ b/tests/data/test-read-ctf/test-array-size.c @@ -0,0 +1,4 @@ +/* gcc -gctf -c test-array-size.c -o test-array-size.o */ +char foo[2]; +char bar[1]; +char baz[0]; diff --git a/tests/data/test-read-ctf/test-array-size.o b/tests/data/test-r= ead-ctf/test-array-size.o new file mode 100644 index 0000000000000000000000000000000000000000..8e4d8b147bcf9ae2fcfe3d6f2ca= ca05868f6b341 GIT binary patch literal 1432 zcmbVM&2G~`5T29}elMj5kU+vnNVEd4op7QDWT}Em2ysK=3D!eQ-f6AQ<#?5!I20*}Ev zaN!Yn3~ulW@B%QOvzx3};lfDc`R1E%Ry$)SA78wFxic7$wE;b+O=3Del5?>ifubTFYC zbe(?x7_KW1HxjzZ7=3DFii%<(h3W*@R&V!zCOj~$x8VAOz70}q|K&j|4KsGEI2Ehd{(Myke8ZHs)|ysr1FBId9_ec+NNz( z)iNto)YMs2iS!^vNodbuHVl$uE@1h>nkr4uk#U zH*XJu@lz3tIGDtf$#@(;3-;CWRMq)Hm0A`D-3`0l1q`ttZsIuy->@@l1Cu**+EOo~ zKBQlNdL$=3D%?7Q98R~5U*+lIHfJ^!xZ@t%5y9fZA6-8GVE+J%-WM_sSt+#;=3D(ngq5- zB5fKHyg7bU3oL>}S!pGB^svz~`(W}}c_vQlir1yv-ZlO=3D!CaWpd~54tk~QiByAR7g zU;xhFOJW6H^!p!i9pCrA`rUVqqx}9STR7+vJlGPi!Aoh(8gTgCy7tKkAG;)D+i&Bc z!@1HgR^XCbw6B=3DE!fwAeEB|Wx{d-|ou0iJaqW;tLFOB$`(b<0d=3DfJ@Gy9fWy9C{y# UWBypXT-(-vZu;Lly?}oIUzApI#Q*>R literal 0 HcmV?d00001 diff --git a/tests/data/test-read-ctf/test9.o.abi b/tests/data/test-read-ct= f/test9.o.abi index 9f5a7466..5c89f821 100644 --- a/tests/data/test-read-ctf/test9.o.abi +++ b/tests/data/test-read-ctf/test9.o.abi @@ -7,8 +7,8 @@ - - + + diff --git a/tests/test-read-ctf.cc b/tests/test-read-ctf.cc index f3d46118..236ccbf2 100644 --- a/tests/test-read-ctf.cc +++ b/tests/test-read-ctf.cc @@ -381,6 +381,15 @@ static InOutSpec in_out_specs[] =3D "output/test-read-ctf/test-array-mdimension.abi", "--ctf", }, + { + "data/test-read-ctf/test-array-size.o", + "", + "", + SEQUENCE_TYPE_ID_STYLE, + "data/test-read-ctf/test-array-size.abi", + "output/test-read-ctf/test-array-size.abi", + "--ctf", + }, // This should be the last entry. {NULL, NULL, NULL, SEQUENCE_TYPE_ID_STYLE, NULL, NULL, NULL} }; --=20 2.38.1 --=20 Dodji