diff options
author | Indu Bhagat <indu.bhagat@oracle.com> | 2022-04-14 10:01:22 -0700 |
---|---|---|
committer | Indu Bhagat <indu.bhagat@oracle.com> | 2022-04-14 10:03:52 -0700 |
commit | d0b00e74bf59c73b79471bbe9de19373b8661e20 (patch) | |
tree | 44897017cd9f804e3d804144c0526bfcc5a24e28 /gcc/dwarf2ctf.cc | |
parent | 613a6fca75156aadc2e79d78a23e547d39762c1e (diff) | |
download | gcc-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/dwarf2ctf.cc')
-rw-r--r-- | gcc/dwarf2ctf.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index 747b2f6..a6329ab 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. */ |