From 2bce22e88e1c8486a0f2d42311506a8d3da20fb7 Mon Sep 17 00:00:00 2001 From: David Faust Date: Wed, 7 Dec 2022 11:44:28 -0800 Subject: 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. --- include/btf.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/btf.h b/include/btf.h index eba67f9d599..da621353aa1 100644 --- a/include/btf.h +++ b/include/btf.h @@ -178,11 +178,20 @@ struct btf_param uint32_t type; /* Type of parameter. */ }; +/* BTF_KIND_VAR records encode linkage information in a single + trailing struct btf_var. These are the supported values. */ +enum btf_var_linkage +{ + BTF_VAR_STATIC = 0, + BTF_VAR_GLOBAL_ALLOCATED = 1, + BTF_VAR_GLOBAL_EXTERN = 2, +}; + /* BTF_KIND_VAR is followed by a single struct btf_var, which describes information about the variable. */ struct btf_var { - uint32_t linkage; /* Currently only 0=static or 1=global. */ + uint32_t linkage; /* 0=static, 1=global, 2=extern. */ }; /* BTF_KIND_DATASEC is followed by VLEN struct btf_var_secinfo entries, -- cgit v1.2.1