public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix PR debug/105089
@ 2022-03-30 23:31 Indu Bhagat
  2022-03-30 23:31 ` [PATCH 1/3] ctfc: get rid of the static variable in ctf_list_add_ctf_vars () Indu Bhagat
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Indu Bhagat @ 2022-03-30 23:31 UTC (permalink / raw)
  To: gcc-patches

Hello,

This patch set fixes PR debug/105089.

[PS: The first patch in the series "ctfc: get rid of the static variable in
ctf_list_add_ctf_vars" is unrelated to the PR and is combined here only for
ease of review.]

As noted in the PR debug/105089, gcc is emitting two CTF variable records
where it sees an extern variable with declaration and definition in the same
compilation unit.

The CTF format format does not distinguish between the non-defining decl vs.
the defining decl, so the correct behaviour wrt the compiler generating the
type for such extern variables is to simply emit the type of the defining 
declaration.

Testing Notes:
-- bootstrapped and reg tested on x86_64 and aarch64
-- built binutils package with -gctf (with CTF-capable linker) on x86_64, no
   CTF errors reported.

Thanks,

Indu Bhagat (3):
  ctfc: get rid of the static variable in ctf_list_add_ctf_vars ()
  CTF for extern variable fix [PR105089]
  Refactor and update CTF testcases [PR105089]

 gcc/ctfc.cc                                   | 62 ++++++++++++++++++-
 gcc/ctfc.h                                    |  8 ++-
 gcc/ctfout.cc                                 | 28 ++++++---
 gcc/dwarf2ctf.cc                              | 18 +++++-
 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c  | 22 +++----
 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c  | 17 +++++
 .../gcc.dg/debug/ctf/ctf-variables-3.c        | 22 +++++++
 7 files changed, 147 insertions(+), 30 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-3.c

-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] ctfc: get rid of the static variable in ctf_list_add_ctf_vars ()
  2022-03-30 23:31 [PATCH 0/3] Fix PR debug/105089 Indu Bhagat
@ 2022-03-30 23:31 ` Indu Bhagat
  2022-03-30 23:31 ` [PATCH 2/3] CTF for extern variable fix [PR105089] Indu Bhagat
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Indu Bhagat @ 2022-03-30 23:31 UTC (permalink / raw)
  To: gcc-patches

2022-03-28  Indu Bhagat  <indu.bhagat@oracle.com>

gcc/ChangeLog:

	* ctfc.h (struct ctf_container): Introduce a new member.
	* ctfout.cc (ctf_list_add_ctf_vars): Use it instead of static
	  variable.
---
 gcc/ctfc.h    | 2 ++
 gcc/ctfout.cc | 4 +---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/ctfc.h b/gcc/ctfc.h
index 18c93c802a06..4ce756c728a7 100644
--- a/gcc/ctfc.h
+++ b/gcc/ctfc.h
@@ -301,6 +301,8 @@ typedef struct GTY (()) ctf_container
   /* List of pre-processed CTF Variables.  CTF requires that the variables
      appear in the sorted order of their names.  */
   ctf_dvdef_t ** GTY ((length ("0"))) ctfc_vars_list;
+  /* Count of pre-processed CTF Variables in the list.  */
+  uint64_t ctfc_vars_list_count;
   /* List of pre-processed CTF types.  CTF requires that a shared type must
      appear before the type that uses it.  For the compiler, this means types
      are emitted in sorted order of their type IDs.  */
diff --git a/gcc/ctfout.cc b/gcc/ctfout.cc
index a23d37758019..28a873b2027d 100644
--- a/gcc/ctfout.cc
+++ b/gcc/ctfout.cc
@@ -173,9 +173,7 @@ ctf_calc_num_vbytes (ctf_dtdef_ref ctftype)
 static void
 ctf_list_add_ctf_vars (ctf_container_ref ctfc, ctf_dvdef_ref var)
 {
-  /* FIXME - static may not fly with multiple CUs.  */
-  static int num_vars_added = 0;
-  ctfc->ctfc_vars_list[num_vars_added++] = var;
+  ctfc->ctfc_vars_list[ctfc->ctfc_vars_list_count++] = var;
 }
 
 /* Initialize the various sections and labels for CTF output.  */
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] CTF for extern variable fix [PR105089]
  2022-03-30 23:31 [PATCH 0/3] Fix PR debug/105089 Indu Bhagat
  2022-03-30 23:31 ` [PATCH 1/3] ctfc: get rid of the static variable in ctf_list_add_ctf_vars () Indu Bhagat
@ 2022-03-30 23:31 ` Indu Bhagat
  2022-03-30 23:31 ` [PATCH 3/3] Refactor and update CTF testcases [PR105089] Indu Bhagat
  2022-04-07 20:04 ` [PATCH 0/3] Fix PR debug/105089 Indu Bhagat
  3 siblings, 0 replies; 6+ messages in thread
From: Indu Bhagat @ 2022-03-30 23:31 UTC (permalink / raw)
  To: gcc-patches

The CTF format cannot differentiate between a non-defining extern
variable declaration vs. a defining variable declaration (unlike DWARF).
So, the correct behaviour wrt the compiler generating CTF for such
extern variables (i.e., when both the defining and non-defining decl
are present in the same CU) is to simply emit the CTF variable
correspoding to the defining declaration.

To carry out the above, following changes are introduced via the patch:

1. The CTF container (ctfc.h) now keeps track of the non-defining declarations
(by noting the DWARF attribute DW_AT_specification) in a new ctfc_ignore_vars
hashtable.  Such book-keeping is necessary because the CTF container should
not rely on the order of DWARF DIEs presented to it at generation time.

2. At the time of ctf_add_variable (), the DW_AT_specification DIE if present
is added in the ctfc_ignore_vars hashtable.  The CTF variable generation for
the defining declaration continues as normal.

3. If the ctf_add_variable () is asked to generate CTF variable for a DIE
present in the ctfc_ignore_vars, it skips generating CTF for it.

4. Recall that CTF variables are pre-processed before emission.  Till now, the
only pre-processing that was being done was to sort them in order of their
names.  Now an additional step is added:  If the CTF variable which
corresponds to the non-defining declaration is indeed present in the ctfc_vars
hashtable (because the corresponding DWARF DIE was encountered first by the
CTF generation engine), skip that CTF variable from output.

An important side effect of such a workflow above is that CTF for the C type
of the non-defining decl will remain in the CTF dictionary (and will be
emitted in the output section as well).  This type can, however, be pruned by
the link-time de-duplicator as usual, if deemed unused.

2022-03-30  Indu Bhagat  <indu.bhagat@oracle.com>

gcc/ChangeLog:

	PR debug/105089
	* ctfc.cc (ctf_dvd_ignore_insert): New function.
	(ctf_dvd_ignore_lookup): Likewise.
	(ctf_add_variable): Keep track of non-defining decl DIEs.
	(new_ctf_container): Initialize the new hash-table.
	(ctfc_delete_container): Empty hash-table.
	* ctfc.h (struct ctf_container): Add new hash-table.
	(ctf_dvd_ignore_lookup): New declaration.
	(ctf_add_variable): Add additional argument.
	* ctfout.cc (ctf_dvd_preprocess_cb): Skip adding CTF variable
	record for non-defining decl for which a defining decl exists
	in the same TU.
	(ctf_preprocess): Defer updating the number of global objts
	until here.
	(output_ctf_header): Use ctfc_vars_list_count as some CTF
	variables may not make it to the final output.
	(output_ctf_vars): Likewise.
	* dwarf2ctf.cc (gen_ctf_variable): Skip generating CTF variable
	if this is known to be a non-defining decl DIE.
---
 gcc/ctfc.cc      | 62 ++++++++++++++++++++++++++++++++++++++++++++++--
 gcc/ctfc.h       |  6 ++++-
 gcc/ctfout.cc    | 24 +++++++++++++------
 gcc/dwarf2ctf.cc | 18 ++++++++++++--
 4 files changed, 98 insertions(+), 12 deletions(-)

diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc
index 6fe44d2e8d49..f24e7bff9487 100644
--- a/gcc/ctfc.cc
+++ b/gcc/ctfc.cc
@@ -179,6 +179,40 @@ ctf_dvd_lookup (const ctf_container_ref ctfc, dw_die_ref die)
   return NULL;
 }
 
+/* Insert a dummy CTF variable into the list of variables to be ignored.  */
+
+static void
+ctf_dvd_ignore_insert (ctf_container_ref ctfc, ctf_dvdef_ref dvd)
+{
+  bool existed = false;
+  ctf_dvdef_ref entry = dvd;
+
+  ctf_dvdef_ref * item = ctfc->ctfc_ignore_vars->find_slot (entry, INSERT);
+  if (*item == NULL)
+     *item = dvd;
+  else
+    existed = true;
+  /* Duplicate variable records not expected to be inserted.  */
+  gcc_assert (!existed);
+}
+
+/* Lookup the dummy CTF variable given the DWARF die for the non-defining
+   decl to be ignored.  */
+
+bool
+ctf_dvd_ignore_lookup (const ctf_container_ref ctfc, dw_die_ref die)
+{
+  ctf_dvdef_t entry;
+  entry.dvd_key = die;
+
+  ctf_dvdef_ref * slot = ctfc->ctfc_ignore_vars->find_slot (&entry, NO_INSERT);
+
+  if (slot)
+    return true;
+
+  return false;
+}
+
 /* Append member definition to the list.  Member list is a singly-linked list
    with list start pointing to the head.  */
 
@@ -666,9 +700,10 @@ ctf_add_member_offset (ctf_container_ref ctfc, dw_die_ref sou,
 
 int
 ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_id_t ref,
-		  dw_die_ref die, unsigned int external_vis)
+		  dw_die_ref die, unsigned int external_vis,
+		  dw_die_ref die_var_decl)
 {
-  ctf_dvdef_ref dvd;
+  ctf_dvdef_ref dvd, dvd_ignore;
 
   gcc_assert (name);
 
@@ -680,6 +715,24 @@ ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_id_t ref,
       dvd->dvd_name = ctf_add_string (ctfc, name, &(dvd->dvd_name_offset));
       dvd->dvd_visibility = external_vis;
       dvd->dvd_type = ref;
+
+      /* If DW_AT_specification attribute exists, keep track of it as this is
+	 the non-defining declaration corresponding to the variable.  We will
+	 skip emitting CTF variable for such incomplete, non-defining
+	 declarations.
+	 There could be some non-defining declarations, however, for which a
+	 defining declaration does not show up in the same CU.  For such
+	 cases, the compiler continues to emit CTF variable record as
+	 usual.  */
+      if (die_var_decl)
+	{
+	  dvd_ignore = ggc_cleared_alloc<ctf_dvdef_t> ();
+	  dvd_ignore->dvd_key = die_var_decl;
+	  /* It's alright to leave other fields as zero.  No valid CTF
+	     variable will be added for these DW_TAG_variable DIEs.  */
+	  ctf_dvd_ignore_insert (ctfc, dvd_ignore);
+	}
+
       ctf_dvd_insert (ctfc, dvd);
 
       if (strcmp (name, ""))
@@ -900,6 +953,8 @@ new_ctf_container (void)
     = hash_table<ctfc_dtd_hasher>::create_ggc (100);
   tu_ctfc->ctfc_vars
     = hash_table<ctfc_dvd_hasher>::create_ggc (100);
+  tu_ctfc->ctfc_ignore_vars
+    = hash_table<ctfc_dvd_hasher>::create_ggc (10);
 
   return tu_ctfc;
 }
@@ -952,6 +1007,9 @@ ctfc_delete_container (ctf_container_ref ctfc)
       ctfc->ctfc_vars->empty ();
       ctfc->ctfc_types = NULL;
 
+      ctfc->ctfc_ignore_vars->empty ();
+      ctfc->ctfc_ignore_vars = NULL;
+
       ctfc_delete_strtab (&ctfc->ctfc_strtable);
       ctfc_delete_strtab (&ctfc->ctfc_aux_strtable);
       if (ctfc->ctfc_vars_list)
diff --git a/gcc/ctfc.h b/gcc/ctfc.h
index 4ce756c728a7..001e544ef083 100644
--- a/gcc/ctfc.h
+++ b/gcc/ctfc.h
@@ -274,6 +274,8 @@ typedef struct GTY (()) ctf_container
   hash_table <ctfc_dtd_hasher> * GTY (()) ctfc_types;
   /* CTF variables.  */
   hash_table <ctfc_dvd_hasher> * GTY (()) ctfc_vars;
+  /* CTF variables to be ignored.  */
+  hash_table <ctfc_dvd_hasher> * GTY (()) ctfc_ignore_vars;
 
   /* CTF string table.  */
   ctf_strtable_t ctfc_strtable;
@@ -394,6 +396,8 @@ extern ctf_dtdef_ref ctf_dtd_lookup (const ctf_container_ref ctfc,
 				     dw_die_ref die);
 extern ctf_dvdef_ref ctf_dvd_lookup (const ctf_container_ref ctfc,
 				     dw_die_ref die);
+extern bool ctf_dvd_ignore_lookup (const ctf_container_ref ctfc,
+				   dw_die_ref die);
 
 extern const char * ctf_add_string (ctf_container_ref, const char *,
 				    uint32_t *, int);
@@ -430,7 +434,7 @@ extern int ctf_add_member_offset (ctf_container_ref, dw_die_ref, const char *,
 extern int ctf_add_function_arg (ctf_container_ref, dw_die_ref,
 				 const char *, ctf_id_t);
 extern int ctf_add_variable (ctf_container_ref, const char *, ctf_id_t,
-			     dw_die_ref, unsigned int);
+			     dw_die_ref, unsigned int, dw_die_ref);
 
 extern ctf_id_t ctf_lookup_tree_type (ctf_container_ref, const tree);
 extern ctf_id_t get_btf_id (ctf_id_t);
diff --git a/gcc/ctfout.cc b/gcc/ctfout.cc
index 28a873b2027d..3cf89b94f993 100644
--- a/gcc/ctfout.cc
+++ b/gcc/ctfout.cc
@@ -212,6 +212,13 @@ ctf_dvd_preprocess_cb (ctf_dvdef_ref * slot, void * arg)
   ctf_dvdef_ref var = (ctf_dvdef_ref) *slot;
   ctf_container_ref arg_ctfc = dvd_arg->dvd_arg_ctfc;
 
+  /* If the CTF variable corresponds to an extern variable declaration with
+     a defining declaration later on, skip it.  Only CTF variable
+     corresponding to the defining declaration for the extern variable is
+     desirable.  */
+  if (ctf_dvd_ignore_lookup (arg_ctfc, var->dvd_key))
+    return 1;
+
   ctf_preprocess_var (arg_ctfc, var);
 
   /* Keep track of global objts.  */
@@ -276,16 +283,16 @@ static void
 ctf_preprocess (ctf_container_ref ctfc)
 {
   size_t num_ctf_types = ctfc->ctfc_types->elements ();
+  size_t num_ctf_vars = ctfc_get_num_ctf_vars (ctfc);
 
   /* Initialize an array to keep track of the CTF variables at global
-     scope.  */
-  size_t num_global_objts = ctfc->ctfc_num_global_objts;
+     scope.  At this time, size it conservatively.  */
+  size_t num_global_objts = num_ctf_vars;
   if (num_global_objts)
     {
       ctfc->ctfc_gobjts_list = ggc_vec_alloc<ctf_dvdef_t*>(num_global_objts);
     }
 
-  size_t num_ctf_vars = ctfc_get_num_ctf_vars (ctfc);
   if (num_ctf_vars)
     {
       ctf_dvd_preprocess_arg_t dvd_arg;
@@ -299,8 +306,11 @@ ctf_preprocess (ctf_container_ref ctfc)
 	 list for sorting.  */
       ctfc->ctfc_vars->traverse<void *, ctf_dvd_preprocess_cb> (&dvd_arg);
       /* Sort the list.  */
-      qsort (ctfc->ctfc_vars_list, num_ctf_vars, sizeof (ctf_dvdef_ref),
-	     ctf_varent_compare);
+      qsort (ctfc->ctfc_vars_list, ctfc->ctfc_vars_list_count,
+	     sizeof (ctf_dvdef_ref), ctf_varent_compare);
+      /* Update the actual number of the generated CTF variables at global
+	 scope.  */
+      ctfc->ctfc_num_global_objts = dvd_arg.dvd_global_obj_idx;
     }
 
   /* Initialize an array to keep track of the CTF functions types for global
@@ -476,7 +486,7 @@ output_ctf_header (ctf_container_ref ctfc)
       /* Vars appear after function index.  */
       varoff = funcidxoff + ctfc->ctfc_num_global_funcs * sizeof (uint32_t);
       /* CTF types appear after vars.  */
-      typeoff = varoff + ctfc_get_num_ctf_vars (ctfc) * sizeof (ctf_varent_t);
+      typeoff = varoff + (ctfc->ctfc_vars_list_count) * sizeof (ctf_varent_t);
       /* The total number of bytes for CTF types is the sum of the number of
 	 times struct ctf_type_t, struct ctf_stype_t are written, plus the
 	 amount of variable length data after each one of these.  */
@@ -595,7 +605,7 @@ static void
 output_ctf_vars (ctf_container_ref ctfc)
 {
   size_t i;
-  size_t num_ctf_vars = ctfc_get_num_ctf_vars (ctfc);
+  unsigned int num_ctf_vars = ctfc->ctfc_vars_list_count;
   if (num_ctf_vars)
     {
       /* Iterate over the list of sorted vars and output the asm.  */
diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc
index 747b2f661072..a6329ab6ee48 100644
--- a/gcc/dwarf2ctf.cc
+++ b/gcc/dwarf2ctf.cc
@@ -808,12 +808,26 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die)
   if (ctf_dvd_lookup (ctfc, die))
     return;
 
+  /* Do not generate CTF variable records for non-defining incomplete
+     declarations.  Such declarations can be known via the DWARF
+     DW_AT_specification attribute.  */
+  if (ctf_dvd_ignore_lookup (ctfc, die))
+    return;
+
+  /* The value of the DW_AT_specification attribute, if present, is a
+     reference to the debugging information entry representing the
+     non-defining declaration.  */
+  dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
+
   /* Add the type of the variable.  */
   var_type_id = gen_ctf_type (ctfc, var_type);
 
   /* Generate the new CTF variable and update global counter.  */
-  (void) ctf_add_variable (ctfc, var_name, var_type_id, die, external_vis);
-  ctfc->ctfc_num_global_objts += 1;
+  (void) ctf_add_variable (ctfc, var_name, var_type_id, die, external_vis,
+			   decl);
+  /* Skip updating the number of global objects at this time.  This is updated
+     later after pre-processing as some CTF variable records although
+     generated now, will not be emitted later.  [PR105089].  */
 }
 
 /* Add a CTF function record for the given input DWARF DIE.  */
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] Refactor and update CTF testcases [PR105089]
  2022-03-30 23:31 [PATCH 0/3] Fix PR debug/105089 Indu Bhagat
  2022-03-30 23:31 ` [PATCH 1/3] ctfc: get rid of the static variable in ctf_list_add_ctf_vars () Indu Bhagat
  2022-03-30 23:31 ` [PATCH 2/3] CTF for extern variable fix [PR105089] Indu Bhagat
@ 2022-03-30 23:31 ` Indu Bhagat
  2022-04-07 20:04 ` [PATCH 0/3] Fix PR debug/105089 Indu Bhagat
  3 siblings, 0 replies; 6+ messages in thread
From: Indu Bhagat @ 2022-03-30 23:31 UTC (permalink / raw)
  To: gcc-patches

This commit splits the ctf-array-2.c into ctf-array-5.c and
ctf-variables.c with the following responsibilities:

[1] ctf-array-2.c: Test CTF generation for unsized arrays.
[2] ctf-array-5.c: Test CTF generation for unsized but initialized array.
[3] ctf-variables-3.c: Test CTF generation for extern variable with defining
decl.

Earlier all three tests above were being done in ctf-array-2.c.
Further, the checks around [3] were very loose in the original version of
ctf-array-2.c in that the testcase was only checking that the types are as
expected.  The compiler was emitting two CTF variable records as follows:

 Variables:
  _CTF_NEWSTR ->  5: const const char [0] (size 0x0) -> 4: const char [0] (size 0x0)
  _CTF_NEWSTR ->  8: const const char [8] (size 0x8) -> 7: const char [8] (size 0x8)

This is incorrect behaviour as it creates ambiguity.  The testcase
ctf-variables-3.c now has added checks that only one CTF variable record
is expected.

2022-03-30  Indu Bhagat  <indu.bhagat@oracle.com>

gcc/testsuite/ChangeLog:

	PR debug/105089
	* gcc.dg/debug/ctf/ctf-array-2.c: Refactor testcase.  Move some
	checks ...
	* gcc.dg/debug/ctf/ctf-array-5.c: ... to here.
	* gcc.dg/debug/ctf/ctf-variables-3.c: ... and here.  Add
	additional checks for one CTF variable and one CTF object info
	record.
---
 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c  | 22 ++++++-------------
 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c  | 17 ++++++++++++++
 .../gcc.dg/debug/ctf/ctf-variables-3.c        | 22 +++++++++++++++++++
 3 files changed, 46 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-3.c

diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c
index 2a19da050fe7..4721c4fb2f97 100644
--- a/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c
@@ -5,34 +5,26 @@
 
    TBD_CTF_FORMAT_OPEN_ISSUES (1) - 
    This testcase makes a note of the case of a probable misrepresentation.
-   See Note 1 and Note 2 below.
+   See Note 1 below.
 
    In the CTF section, these types are encoded as :
 
      Variables:
-      _CTF_NEWSTR ->  7: const char [0] (size 0x0)
-      _CTF_SECTION ->  6: const char [5] (size 0x5)
-      b1 ->  2: int [0] (size 0x0)
-      b2 ->  3: int [0] (size 0x0)
+      b1 ->  3: int [0] (size 0x0)
+      b2 ->  5: int [0] (size 0x0)
 
     Note 1 : There is misrepresentation in that b1 and b2 are specified
     differently by the user.
-    Note 2 : It is arguable though whether the representation for
-    _CTF_NEWSTR is incorrect.  */
+    
+    In this testcase, two CTF array records each of type int [0] is expected.  */
 
 /* { dg-do compile )  */
 /* { dg-options "-O0 -gctf -dA" } */
 
-/* { dg-final { scan-assembler-times "0x12000000\[\t \]+\[^\n\]*ctt_info" 5 } } */
+/* { dg-final { scan-assembler-times "0x12000000\[\t \]+\[^\n\]*ctt_info" 2 } } */
 
-/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*cta_nelems" 3 } } */
-/* { dg-final { scan-assembler-times "\[\t \]0x5\[\t \]+\[^\n\]*cta_nelems" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*cta_nelems" 2 } } */
 
 static int b1[] = {};
 
 int b2[0];
-
-const char _CTF_SECTION[] = ".ctf";
-
-extern const char _CTF_NEWSTR[];
-const char _CTF_NEWSTR[] = "ctfinfo"; 
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c
new file mode 100644
index 000000000000..ec504412ef56
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c
@@ -0,0 +1,17 @@
+/* CTF generation for unsized (but initialized) arrays
+
+   In this testcase, one CTF array type record of size 5 is expected.
+
+     Variables:
+      _CTF_SECTION ->  5: const const char [5] (size 0x5) -> 4: const char [5] (size 0x5)
+
+*/
+
+/* { dg-do compile )  */
+/* { dg-options "-O0 -gctf -dA" } */
+
+/* { dg-final { scan-assembler-times "0x12000000\[\t \]+\[^\n\]*ctt_info" 1 } } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x5\[\t \]+\[^\n\]*cta_nelems" 1 } } */
+
+const char _CTF_SECTION[] = ".ctf";
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-3.c b/gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-3.c
new file mode 100644
index 000000000000..8aea1e82749e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-3.c
@@ -0,0 +1,22 @@
+/* CTF generation for extern variable with defining and non-defining decl
+   in the same CU.
+
+   This testcase checks the case when a non-defining decl is followed by
+   a defining decl for the same variable.  See PR debug/105089.
+   
+   In this testcase,  although two CTF array types are generated, only a
+   single CTF variable and a single entry in the CTF object info section
+   are expected.  */
+
+/* { dg-do compile )  */
+/* { dg-options "-O0 -gctf -dA" } */
+
+/* { dg-final { scan-assembler-times "0x12000000\[\t \]+\[^\n\]*ctt_info" 2 } } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*cta_nelems" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x8\[\t \]+\[^\n\]*cta_nelems" 1 } } */
+/* { dg-final { scan-assembler-times "ctv_name" 1 } } */
+/* { dg-final { scan-assembler-times "objtinfo_var_type" 1 } } */
+
+extern const char _CTF_NEWSTR[];
+const char _CTF_NEWSTR[] = "ctfinfo"; 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Fix PR debug/105089
  2022-03-30 23:31 [PATCH 0/3] Fix PR debug/105089 Indu Bhagat
                   ` (2 preceding siblings ...)
  2022-03-30 23:31 ` [PATCH 3/3] Refactor and update CTF testcases [PR105089] Indu Bhagat
@ 2022-04-07 20:04 ` Indu Bhagat
  2022-04-08  6:37   ` Richard Biener
  3 siblings, 1 reply; 6+ messages in thread
From: Indu Bhagat @ 2022-04-07 20:04 UTC (permalink / raw)
  To: gcc-patches

ping

On 3/30/22 4:31 PM, Indu Bhagat wrote:
> Hello,
> 
> This patch set fixes PR debug/105089.
> 
> [PS: The first patch in the series "ctfc: get rid of the static variable in
> ctf_list_add_ctf_vars" is unrelated to the PR and is combined here only for
> ease of review.]
> 
> As noted in the PR debug/105089, gcc is emitting two CTF variable records
> where it sees an extern variable with declaration and definition in the same
> compilation unit.
> 
> The CTF format format does not distinguish between the non-defining decl vs.
> the defining decl, so the correct behaviour wrt the compiler generating the
> type for such extern variables is to simply emit the type of the defining
> declaration.
> 
> Testing Notes:
> -- bootstrapped and reg tested on x86_64 and aarch64
> -- built binutils package with -gctf (with CTF-capable linker) on x86_64, no
>     CTF errors reported.
> 
> Thanks,
> 
> Indu Bhagat (3):
>    ctfc: get rid of the static variable in ctf_list_add_ctf_vars ()
>    CTF for extern variable fix [PR105089]
>    Refactor and update CTF testcases [PR105089]
> 
>   gcc/ctfc.cc                                   | 62 ++++++++++++++++++-
>   gcc/ctfc.h                                    |  8 ++-
>   gcc/ctfout.cc                                 | 28 ++++++---
>   gcc/dwarf2ctf.cc                              | 18 +++++-
>   gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c  | 22 +++----
>   gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c  | 17 +++++
>   .../gcc.dg/debug/ctf/ctf-variables-3.c        | 22 +++++++
>   7 files changed, 147 insertions(+), 30 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c
>   create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-3.c
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Fix PR debug/105089
  2022-04-07 20:04 ` [PATCH 0/3] Fix PR debug/105089 Indu Bhagat
@ 2022-04-08  6:37   ` Richard Biener
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Biener @ 2022-04-08  6:37 UTC (permalink / raw)
  To: Indu Bhagat; +Cc: GCC Patches

On Thu, Apr 7, 2022 at 9:42 PM Indu Bhagat via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> ping

The series is OK

> On 3/30/22 4:31 PM, Indu Bhagat wrote:
> > Hello,
> >
> > This patch set fixes PR debug/105089.
> >
> > [PS: The first patch in the series "ctfc: get rid of the static variable in
> > ctf_list_add_ctf_vars" is unrelated to the PR and is combined here only for
> > ease of review.]
> >
> > As noted in the PR debug/105089, gcc is emitting two CTF variable records
> > where it sees an extern variable with declaration and definition in the same
> > compilation unit.
> >
> > The CTF format format does not distinguish between the non-defining decl vs.
> > the defining decl, so the correct behaviour wrt the compiler generating the
> > type for such extern variables is to simply emit the type of the defining
> > declaration.
> >
> > Testing Notes:
> > -- bootstrapped and reg tested on x86_64 and aarch64
> > -- built binutils package with -gctf (with CTF-capable linker) on x86_64, no
> >     CTF errors reported.
> >
> > Thanks,
> >
> > Indu Bhagat (3):
> >    ctfc: get rid of the static variable in ctf_list_add_ctf_vars ()
> >    CTF for extern variable fix [PR105089]
> >    Refactor and update CTF testcases [PR105089]
> >
> >   gcc/ctfc.cc                                   | 62 ++++++++++++++++++-
> >   gcc/ctfc.h                                    |  8 ++-
> >   gcc/ctfout.cc                                 | 28 ++++++---
> >   gcc/dwarf2ctf.cc                              | 18 +++++-
> >   gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c  | 22 +++----
> >   gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c  | 17 +++++
> >   .../gcc.dg/debug/ctf/ctf-variables-3.c        | 22 +++++++
> >   7 files changed, 147 insertions(+), 30 deletions(-)
> >   create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-5.c
> >   create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-3.c
> >
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-08  6:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-30 23:31 [PATCH 0/3] Fix PR debug/105089 Indu Bhagat
2022-03-30 23:31 ` [PATCH 1/3] ctfc: get rid of the static variable in ctf_list_add_ctf_vars () Indu Bhagat
2022-03-30 23:31 ` [PATCH 2/3] CTF for extern variable fix [PR105089] Indu Bhagat
2022-03-30 23:31 ` [PATCH 3/3] Refactor and update CTF testcases [PR105089] Indu Bhagat
2022-04-07 20:04 ` [PATCH 0/3] Fix PR debug/105089 Indu Bhagat
2022-04-08  6:37   ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).