summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillermo E. Martinez <guillermo.e.martinez@oracle.com>2022-04-29 09:05:19 -0500
committerDodji Seketeli <dodji@redhat.com>2022-05-02 17:51:04 +0200
commit9054dbf9e2d1d0df09d02b07bf3aac6bf0f5bced (patch)
tree3d066bc9d87f8f10aca6c6f77183e70947809fe8
parenttools-utils: `entry_of_file_with_name' returns incorrect result (diff)
downloadlibabigail-9054dbf9e2d1d0df09d02b07bf3aac6bf0f5bced.tar.gz
libabigail-9054dbf9e2d1d0df09d02b07bf3aac6bf0f5bced.tar.bz2
libabigail-9054dbf9e2d1d0df09d02b07bf3aac6bf0f5bced.tar.xz
ctf-reader: Fix multiple var-decl in anonymous struct/uninons
This patch avoids multiple inclusion of `var-decl' node for the same field in anonymous struct/union declaration in the abixml, e.g: struct uprobe_task { union { struct { unsigned long vaddr; }; struct { int dup_xol_work; }; }; }; Three `var-decl' nodes are written in abixml file, expected a single one: <var-decl name='dup_xol_work' .../> * src/abg-ctf-reader.cc (process_ctf_sou_members): Remove CTF_MN_RECURSE flag. * tests/data/Makefile.am: Add new input test files. * tests/data/test-read-ctf/test-anonymous-fields.c: New test file. * tests/data/test-read-ctf/test-anonymous-fields.o: New expected test output. * tests/data/test-read-ctf/test-anonymous-fields.o.abi: Likewise. * tests/test-read-ctf.cc: Add new test. Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
-rw-r--r--src/abg-ctf-reader.cc2
-rw-r--r--tests/data/Makefile.am3
-rw-r--r--tests/data/test-read-ctf/test-anonymous-fields.c18
-rw-r--r--tests/data/test-read-ctf/test-anonymous-fields.obin0 -> 1408 bytes
-rw-r--r--tests/data/test-read-ctf/test-anonymous-fields.o.abi33
-rw-r--r--tests/test-read-ctf.cc8
6 files changed, 63 insertions, 1 deletions
diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
index f8cdf6be..2c6839cb 100644
--- a/src/abg-ctf-reader.cc
+++ b/src/abg-ctf-reader.cc
@@ -350,7 +350,7 @@ process_ctf_sou_members(read_context *ctxt,
350 while ((member_size = ctf_member_next(ctf_dictionary, ctf_type, 350 while ((member_size = ctf_member_next(ctf_dictionary, ctf_type,
351 &member_next, &member_name, 351 &member_next, &member_name,
352 &member_ctf_type, 352 &member_ctf_type,
353 CTF_MN_RECURSE)) >= 0) 353 0 /* flags */)) >= 0)
354 { 354 {
355 ctf_membinfo_t membinfo; 355 ctf_membinfo_t membinfo;
356 356
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index 8f71fcbf..ee23aff6 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -669,6 +669,9 @@ test-read-ctf/test-list-struct.abi \
669test-read-ctf/test-callback2.c \ 669test-read-ctf/test-callback2.c \
670test-read-ctf/test-callback2.o \ 670test-read-ctf/test-callback2.o \
671test-read-ctf/test-callback2.abi \ 671test-read-ctf/test-callback2.abi \
672test-read-ctf/test-anonymous-fields.c \
673test-read-ctf/test-anonymous-fields.o \
674test-read-ctf/test-anonymous-fields.o.abi \
672\ 675\
673test-annotate/test0.abi \ 676test-annotate/test0.abi \
674test-annotate/test1.abi \ 677test-annotate/test1.abi \
diff --git a/tests/data/test-read-ctf/test-anonymous-fields.c b/tests/data/test-read-ctf/test-anonymous-fields.c
new file mode 100644
index 00000000..25c21047
--- /dev/null
+++ b/tests/data/test-read-ctf/test-anonymous-fields.c
@@ -0,0 +1,18 @@
1/*
2 * test single var-decl in anonymous struct/union
3 * gcc -gctf -c tests/data/test-read- ctf/test-anonymous-fields.c \
4 * -o tests/data/test-read-ctf/test-anonymous-fields.o
5*/
6struct uprobe_task {
7 union {
8 struct {
9 unsigned long vaddr;
10 };
11
12 struct {
13 int dup_xol_work;
14 };
15 };
16};
17
18struct uprobe_task t;
diff --git a/tests/data/test-read-ctf/test-anonymous-fields.o b/tests/data/test-read-ctf/test-anonymous-fields.o
new file mode 100644
index 00000000..452a8122
--- /dev/null
+++ b/tests/data/test-read-ctf/test-anonymous-fields.o
Binary files differ
diff --git a/tests/data/test-read-ctf/test-anonymous-fields.o.abi b/tests/data/test-read-ctf/test-anonymous-fields.o.abi
new file mode 100644
index 00000000..0419c29c
--- /dev/null
+++ b/tests/data/test-read-ctf/test-anonymous-fields.o.abi
@@ -0,0 +1,33 @@
1<abi-corpus version='2.1' path='data/test-read-ctf/test-anonymous-fields.o'>
2 <elf-variable-symbols>
3 <elf-symbol name='t' size='8' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
4 </elf-variable-symbols>
5 <abi-instr address-size='64' language='LANG_C'>
6 <class-decl name='' size-in-bits='64' alignment-in-bits='64' is-struct='yes' is-anonymous='yes' visibility='default' id='type-id-1'>
7 <data-member access='public' layout-offset-in-bits='0'>
8 <var-decl name='vaddr' type-id='type-id-2' visibility='default'/>
9 </data-member>
10 </class-decl>
11 <class-decl name='' size-in-bits='32' alignment-in-bits='32' is-struct='yes' is-anonymous='yes' visibility='default' id='type-id-3'>
12 <data-member access='public' layout-offset-in-bits='0'>
13 <var-decl name='dup_xol_work' type-id='type-id-4' visibility='default'/>
14 </data-member>
15 </class-decl>
16 <class-decl name='uprobe_task' size-in-bits='64' alignment-in-bits='64' is-struct='yes' visibility='default' id='type-id-5'>
17 <data-member access='public' layout-offset-in-bits='0'>
18 <var-decl name='' type-id='type-id-6' visibility='default'/>
19 </data-member>
20 </class-decl>
21 <type-decl name='int' size-in-bits='32' alignment-in-bits='32' id='type-id-4'/>
22 <union-decl name='' size-in-bits='64' is-anonymous='yes' visibility='default' id='type-id-6'>
23 <data-member access='public'>
24 <var-decl name='' type-id='type-id-1' visibility='default'/>
25 </data-member>
26 <data-member access='public'>
27 <var-decl name='' type-id='type-id-3' visibility='default'/>
28 </data-member>
29 </union-decl>
30 <type-decl name='unsigned long int' size-in-bits='64' alignment-in-bits='64' id='type-id-2'/>
31 <var-decl name='t' type-id='type-id-5' mangled-name='t' visibility='default'/>
32 </abi-instr>
33</abi-corpus>
diff --git a/tests/test-read-ctf.cc b/tests/test-read-ctf.cc
index 8ed8ac1a..fdf49e90 100644
--- a/tests/test-read-ctf.cc
+++ b/tests/test-read-ctf.cc
@@ -213,6 +213,14 @@ static InOutSpec in_out_specs[] =
213 "output/test-read-ctf/test-dynamic-array.o.abi" 213 "output/test-read-ctf/test-dynamic-array.o.abi"
214 }, 214 },
215 { 215 {
216 "data/test-read-ctf/test-anonymous-fields.o",
217 "",
218 "",
219 SEQUENCE_TYPE_ID_STYLE,
220 "data/test-read-ctf/test-anonymous-fields.o.abi",
221 "output/test-read-ctf/test-anonymous-fields.o.abi"
222 },
223 {
216 "data/test-read-common/PR27700/test-PR27700.o", 224 "data/test-read-common/PR27700/test-PR27700.o",
217 "", 225 "",
218 "data/test-read-common/PR27700/pub-incdir", 226 "data/test-read-common/PR27700/pub-incdir",