]> sourceware.org Git - libabigail.git/commitdiff
ctf-reader: Fix array size representation
authorGuillermo E. Martinez via Libabigail <libabigail@sourceware.org>
Thu, 17 Nov 2022 03:43:05 +0000 (21:43 -0600)
committerDodji Seketeli <dodji@redhat.com>
Wed, 30 Nov 2022 09:49:22 +0000 (10:49 +0100)
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:

<array-type-def dimensions='1' ... size-in-bits='infinite' ...>
    <subrange length='infinite' type-id='type-id-3' .../>
</array-type-def>

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 <guillermo.e.martinez@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-ctf-reader.cc
tests/data/Makefile.am
tests/data/test-read-ctf/test-array-size.abi [new file with mode: 0644]
tests/data/test-read-ctf/test-array-size.c [new file with mode: 0644]
tests/data/test-read-ctf/test-array-size.o [new file with mode: 0644]
tests/data/test-read-ctf/test9.o.abi
tests/test-read-ctf.cc

index b4b957d243e818e7f220fb32c47b67c0e968bf28..e0b8bfb1d4ceee27f33212ca37c4e36c7e23dda5 100644 (file)
@@ -1194,7 +1194,7 @@ build_array_ctf_range(reader *rdr, ctf_dict_t *dic,
   upper_bound.set_unsigned(nelems > 0 ? nelems - 1 : 0U);
 
   /* for VLAs number of array elements is 0 */
-  if (upper_bound.get_unsigned_value() == 0)
+  if (upper_bound.get_unsigned_value() == 0 && nelems == 0)
     is_infinite = true;
 
   subrange.reset(new array_type_def::subrange_type(rdr->env(),
index d04ecf3f94d4996156251ef9aa84c4f86610f5fb..e994aff3d05b94a814607a3e6cf8a4302167bd9c 100644 (file)
@@ -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 (file)
index 0000000..3fbc65b
--- /dev/null
@@ -0,0 +1,23 @@
+<abi-corpus version='2.1' path='data/test-read-ctf/test-array-size.o'>
+  <elf-variable-symbols>
+    <elf-symbol name='bar' size='1' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+    <elf-symbol name='baz' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+    <elf-symbol name='foo' size='2' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+  </elf-variable-symbols>
+  <abi-instr address-size='64' language='LANG_C'>
+    <type-decl name='char' size-in-bits='8' id='type-id-1'/>
+    <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='8' id='type-id-2'>
+      <subrange length='1' type-id='type-id-3' id='type-id-4'/>
+    </array-type-def>
+    <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='16' id='type-id-5'>
+      <subrange length='2' type-id='type-id-3' id='type-id-6'/>
+    </array-type-def>
+    <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='infinite' id='type-id-7'>
+      <subrange length='infinite' type-id='type-id-3' id='type-id-8'/>
+    </array-type-def>
+    <type-decl name='unsigned long int' size-in-bits='64' id='type-id-3'/>
+    <var-decl name='bar' type-id='type-id-2' mangled-name='bar' visibility='default' elf-symbol-id='bar'/>
+    <var-decl name='baz' type-id='type-id-7' mangled-name='baz' visibility='default' elf-symbol-id='baz'/>
+    <var-decl name='foo' type-id='type-id-5' mangled-name='foo' visibility='default' elf-symbol-id='foo'/>
+  </abi-instr>
+</abi-corpus>
diff --git a/tests/data/test-read-ctf/test-array-size.c b/tests/data/test-read-ctf/test-array-size.c
new file mode 100644 (file)
index 0000000..fe2f3fe
--- /dev/null
@@ -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-read-ctf/test-array-size.o
new file mode 100644 (file)
index 0000000..8e4d8b1
Binary files /dev/null and b/tests/data/test-read-ctf/test-array-size.o differ
index 9f5a74662101c79668d196ee1703dbecf0cfe441..5c89f82148360c452d94aec95c41c743665d001e 100644 (file)
@@ -7,8 +7,8 @@
     <array-type-def dimensions='1' type-id='type-id-2' size-in-bits='448' alignment-in-bits='64' id='type-id-3'>
       <subrange length='7' type-id='type-id-4' id='type-id-5'/>
     </array-type-def>
-    <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='infinite' id='type-id-6'>
-      <subrange length='infinite' type-id='type-id-4' id='type-id-7'/>
+    <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='8' id='type-id-6'>
+      <subrange length='1' type-id='type-id-4' id='type-id-7'/>
     </array-type-def>
     <type-decl name='double' size-in-bits='64' id='type-id-8'/>
     <array-type-def dimensions='2' type-id='type-id-8' size-in-bits='960' id='type-id-9'>
index f3d461181e8da24b01c4b693f281082b251aa3fc..236ccbf2771a0074bdc7671c1a2922adb91d755c 100644 (file)
@@ -381,6 +381,15 @@ static InOutSpec in_out_specs[] =
     "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}
 };
This page took 0.041979 seconds and 5 git commands to generate.