diff mbox series

ctf-reader: Fix multiple var-decl in anonymous struct/uninons

Message ID 20211216052007.374822-1-guillermo.e.martinez@oracle.com
State New
Headers show
Series ctf-reader: Fix multiple var-decl in anonymous struct/uninons | expand

Commit Message

Guillermo E. Martinez Dec. 16, 2021, 5:20 a.m. UTC
Hello libabigail team,

This patch fix multiple `var-decl' node  in anonymous struct/uninons in
ctf-reader.

Comments will be appreciated.

Thanks in advanced!,
Guillermo

This patch avoid 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>
---
 src/abg-ctf-reader.cc                         |   2 +-
 .../test-read-ctf/test-anonymous-fields.c     |  19 ++++++++++
 .../test-read-ctf/test-anonymous-fields.o     | Bin 0 -> 1408 bytes
 .../test-read-ctf/test-anonymous-fields.o.abi |  33 ++++++++++++++++++
 tests/test-read-ctf.cc                        |   8 +++++
 5 files changed, 61 insertions(+), 1 deletion(-)
 create mode 100644 tests/data/test-read-ctf/test-anonymous-fields.c
 create mode 100644 tests/data/test-read-ctf/test-anonymous-fields.o
 create mode 100644 tests/data/test-read-ctf/test-anonymous-fields.o.abi
diff mbox series

Patch

diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
index fbf6baef..8151bfbb 100644
--- a/src/abg-ctf-reader.cc
+++ b/src/abg-ctf-reader.cc
@@ -321,7 +321,7 @@  process_ctf_sou_members(read_context *ctxt,
   while ((member_size = ctf_member_next(ctf_dictionary, ctf_type,
                                         &member_next, &member_name,
                                         &member_ctf_type,
-                                        CTF_MN_RECURSE)) >= 0)
+                                        0 /* flags */)) >= 0)
     {
       ctf_membinfo_t membinfo;
 
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..be97bfa3
--- /dev/null
+++ b/tests/data/test-read-ctf/test-anonymous-fields.c
@@ -0,0 +1,19 @@ 
+/*
+ * test single var-decl in anonymous struct/union
+ * gcc -gctf -c tests/data/test-read- ctf/test-anonymous-fields.c \
+ *    -o tests/data/test-read-ctf/test-anonymous-fields.o
+*/
+struct uprobe_task {
+ union {
+  struct {
+   unsigned long vaddr;
+  };
+
+  struct {
+   int dup_xol_work;
+  };
+ };
+};
+
+struct 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 0000000000000000000000000000000000000000..452a8122c5cf4fa8fb81772bdfd824dfa92954ce
GIT binary patch
literal 1408
zcmbVL&5qMB5S}ch{9Raa;YXlwVi$<h_JGhHP^1;?3L$PBQRO7wZqy{MVh5TN55bii
zFS1X7cmtjRUI1niyR}TYFw%Iw`DVVUJxV{leDi8A2*6qZFJPNl7T{uUi<2HEa09Nx
zuOFjL<@vS+Mu^F;8o!D03;JjDG5Ry(gvszX?^5rrJ_Dek<{o3>6T?#<&Ao4O!gmHd
zCL9_W>K~BKnwiz7m+*XyPP5#e%Tz68y$IV{6^mNrVNq-N!1KHTLV3HIuVp#^D4Qj;
zt45|`uDM!*hWK1oB2K%si)F*JQpBps;<8A2S}b@`M(s-JM(`@uLTMG}T=O1ANaj(d
z&xVZGvhFI`s_3i`Wv*BTaB_Tn6ds(seRmj6XKcbI;cPOSPSL{yv0jO$s6?%Kd5G6H
zI{<nMDsYd%1##8_le_z{H8)ay1V4Yf9AVn^KF|gS+w6~?745ja24JeIG*2<=W{Bq&
zX|dM8Xc@p#rGVig@Q@X~2v{w(VEBwkX`U@jzNlM<yT^Cy&R*lc<2_W;TkUsf2PGDG
z(cjxctP{80$RJ3D@Ym_<A7KaW@L&4Pe$6C5e~P?6lUfrx&@!*+r7*=F;wIGW*jLl|
z#Nh~9y^Ti>=eB;c4KBH(_cd}?(CPo~+IOS(@8!Rr+I($4$B?IH=rz-4^|u|~-#wL1
Yjh?;_*ZgPgV{w;0Gy3<g7_qPa16<>NRR910

literal 0
HcmV?d00001

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 @@ 
+<abi-corpus version='2.1' path='data/test-read-ctf/test-anonymous-fields.o'>
+  <elf-variable-symbols>
+    <elf-symbol name='t' size='8' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+  </elf-variable-symbols>
+  <abi-instr address-size='64' language='LANG_C'>
+    <class-decl name='' size-in-bits='64' alignment-in-bits='64' is-struct='yes' is-anonymous='yes' visibility='default' id='type-id-1'>
+      <data-member access='public' layout-offset-in-bits='0'>
+        <var-decl name='vaddr' type-id='type-id-2' visibility='default'/>
+      </data-member>
+    </class-decl>
+    <class-decl name='' size-in-bits='32' alignment-in-bits='32' is-struct='yes' is-anonymous='yes' visibility='default' id='type-id-3'>
+      <data-member access='public' layout-offset-in-bits='0'>
+        <var-decl name='dup_xol_work' type-id='type-id-4' visibility='default'/>
+      </data-member>
+    </class-decl>
+    <class-decl name='uprobe_task' size-in-bits='64' alignment-in-bits='64' is-struct='yes' visibility='default' id='type-id-5'>
+      <data-member access='public' layout-offset-in-bits='0'>
+        <var-decl name='' type-id='type-id-6' visibility='default'/>
+      </data-member>
+    </class-decl>
+    <type-decl name='int' size-in-bits='32' alignment-in-bits='32' id='type-id-4'/>
+    <union-decl name='' size-in-bits='64' is-anonymous='yes' visibility='default' id='type-id-6'>
+      <data-member access='public'>
+        <var-decl name='' type-id='type-id-1' visibility='default'/>
+      </data-member>
+      <data-member access='public'>
+        <var-decl name='' type-id='type-id-3' visibility='default'/>
+      </data-member>
+    </union-decl>
+    <type-decl name='unsigned long int' size-in-bits='64' alignment-in-bits='64' id='type-id-2'/>
+    <var-decl name='t' type-id='type-id-5' mangled-name='t' visibility='default'/>
+  </abi-instr>
+</abi-corpus>
diff --git a/tests/test-read-ctf.cc b/tests/test-read-ctf.cc
index b448ddc5..4b11cca6 100644
--- a/tests/test-read-ctf.cc
+++ b/tests/test-read-ctf.cc
@@ -212,6 +212,14 @@  static InOutSpec in_out_specs[] =
     "data/test-read-ctf/test-dynamic-array.o.abi",
     "output/test-read-ctf/test-dynamic-array.o.abi"
   },
+  {
+    "data/test-read-ctf/test-anonymous-fields.o",
+    "",
+    "",
+    SEQUENCE_TYPE_ID_STYLE,
+    "data/test-read-ctf/test-anonymous-fields.o.abi",
+    "output/test-read-ctf/test-anonymous-fields.o.abi"
+  },
   {
     "data/test-read-common/PR27700/test-PR27700.o",
     "",