aboutsummaryrefslogtreecommitdiff
path: root/gcc/ctfout.cc
diff options
context:
space:
mode:
authorIndu Bhagat <indu.bhagat@oracle.com>2022-04-14 10:01:22 -0700
committerIndu Bhagat <indu.bhagat@oracle.com>2022-04-14 10:03:52 -0700
commitd0b00e74bf59c73b79471bbe9de19373b8661e20 (patch)
tree44897017cd9f804e3d804144c0526bfcc5a24e28 /gcc/ctfout.cc
parent613a6fca75156aadc2e79d78a23e547d39762c1e (diff)
downloadgcc-d0b00e74bf59c73b79471bbe9de19373b8661e20.zip
gcc-d0b00e74bf59c73b79471bbe9de19373b8661e20.tar.gz
gcc-d0b00e74bf59c73b79471bbe9de19373b8661e20.tar.bz2
CTF for extern variable fix [PR105089]
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 be pruned by the link-time de-duplicator as usual, if deemed unused. 2022-04-14 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.
Diffstat (limited to 'gcc/ctfout.cc')
-rw-r--r--gcc/ctfout.cc24
1 files changed, 17 insertions, 7 deletions
diff --git a/gcc/ctfout.cc b/gcc/ctfout.cc
index 28a873b..3cf89b9 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. */