aboutsummaryrefslogtreecommitdiff
path: root/gcc/btfout.cc
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2022-12-07 11:44:28 -0800
committerDavid Faust <david.faust@oracle.com>2022-12-14 10:20:52 -0800
commit2bce22e88e1c8486a0f2d42311506a8d3da20fb7 (patch)
tree911e7df680b0a6f1ea5ccd4ecfe80cf1ea5a3efa /gcc/btfout.cc
parent0e9495303db062cf118869b7526132b5821833e9 (diff)
downloadgcc-2bce22e88e1c8486a0f2d42311506a8d3da20fb7.zip
gcc-2bce22e88e1c8486a0f2d42311506a8d3da20fb7.tar.gz
gcc-2bce22e88e1c8486a0f2d42311506a8d3da20fb7.tar.bz2
btf: add 'extern' linkage for variables [PR106773]
Add support for the 'extern' linkage value for BTF_KIND_VAR records, which is used for variables declared as extern in the source file. This also fixes a bug with BTF generation for extern variables which have both a non-defining declaration and a defining declaration in the same CU. PR target/106773 gcc/ * btfout.cc (btf_collect_datasec): Mark extern variables as such. (btf_dvd_emit_preprocess_cb): Skip non-defining extern variable decl if there is a defining decl for the same variable. (btf_asm_varent): Accomodate 'extern' linkage. gcc/testsuite/ * gcc.dg/debug/btf/btf-variables-4.c: New test. * gcc.dg/debug/btf/btf-variables-5.c: New test. include/ * btf.h (enum btf_var_linkage): New. (struct btf_var): Update comment to note 'extern' linkage.
Diffstat (limited to 'gcc/btfout.cc')
-rw-r--r--gcc/btfout.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/gcc/btfout.cc b/gcc/btfout.cc
index aef9fd7..677e832 100644
--- a/gcc/btfout.cc
+++ b/gcc/btfout.cc
@@ -314,6 +314,9 @@ btf_collect_datasec (ctf_container_ref ctfc)
continue;
const char *section_name = node->get_section ();
+ /* Mark extern variables. */
+ if (DECL_EXTERNAL (node->decl))
+ dvd->dvd_visibility = BTF_VAR_GLOBAL_EXTERN;
if (section_name == NULL)
{
@@ -431,6 +434,12 @@ btf_dvd_emit_preprocess_cb (ctf_dvdef_ref *slot, ctf_container_ref arg_ctfc)
{
ctf_dvdef_ref var = (ctf_dvdef_ref) * slot;
+ /* If this is an extern variable declaration with a defining declaration
+ later, skip it so that only the defining declaration is emitted.
+ This is the same case, fix and reasoning as in CTF; see PR105089. */
+ if (ctf_dvd_ignore_lookup (arg_ctfc, var->dvd_key))
+ return 1;
+
/* Do not add variables which refer to unsupported types. */
if (btf_removed_type_p (var->dvd_type))
return 1;
@@ -676,7 +685,7 @@ btf_asm_varent (ctf_dvdef_ref var)
dw2_asm_output_data (4, var->dvd_name_offset, "btv_name");
dw2_asm_output_data (4, BTF_TYPE_INFO (BTF_KIND_VAR, 0, 0), "btv_info");
dw2_asm_output_data (4, get_btf_id (var->dvd_type), "btv_type");
- dw2_asm_output_data (4, (var->dvd_visibility ? 1 : 0), "btv_linkage");
+ dw2_asm_output_data (4, var->dvd_visibility, "btv_linkage");
}
/* Asm'out a member description following a BTF_KIND_STRUCT or