From 70b303049e45c180236a4114f844311652bad002 Mon Sep 17 00:00:00 2001 From: David Faust Date: Wed, 7 Dec 2022 11:51:59 -0800 Subject: btf: correct generation for extern funcs [PR106773] The eBPF loader expects to find entries for functions declared as extern in the corresponding BTF_KIND_DATASEC record, but we were not generating these entries. This patch adds support for the 'extern' linkage of function types in BTF, and creates entries for for them BTF_KIND_DATASEC records as needed. PR target/106773 gcc/ * btfout.cc (get_section_name): New function. (btf_collect_datasec): Use it here. Process functions, marking them 'extern' and generating DATASEC entries for them as appropriate. Move creation of BTF_KIND_FUNC records to here... (btf_dtd_emit_preprocess_cb): ... from here. gcc/testsuite/ * gcc.dg/debug/btf/btf-datasec-2.c: New test. * gcc.dg/debug/btf/btf-function-6.c: New test. include/ * btf.h (enum btf_func_linkage): New. (struct btf_var_secinfo): Update comments with notes about extern functions. --- include/btf.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/btf.h b/include/btf.h index da62135..2f8f6f6 100644 --- a/include/btf.h +++ b/include/btf.h @@ -178,6 +178,15 @@ struct btf_param uint32_t type; /* Type of parameter. */ }; +/* BTF_KIND_FUNC records encode linkage information in the VLEN bits + of the type record. These are the supported values. */ +enum btf_func_linkage +{ + BTF_FUNC_STATIC = 0, + BTF_FUNC_GLOBAL = 1, + BTF_FUNC_EXTERN = 2, +}; + /* BTF_KIND_VAR records encode linkage information in a single trailing struct btf_var. These are the supported values. */ enum btf_var_linkage @@ -195,12 +204,13 @@ struct btf_var }; /* BTF_KIND_DATASEC is followed by VLEN struct btf_var_secinfo entries, - which describe all BTF_KIND_VAR types contained in the section. */ + which describe all BTF_KIND_VAR or extern BTF_KIND_FUNC types contained + in the section. */ struct btf_var_secinfo { - uint32_t type; /* Type of variable. */ - uint32_t offset; /* In-section offset of variable (in bytes). */ - uint32_t size; /* Size (in bytes) of variable. */ + uint32_t type; /* Type of BTF_KIND_VAR or BTF_KIND_FUNC item. */ + uint32_t offset; /* In-section offset (in bytes) of item. */ + uint32_t size; /* Size (in bytes) of item. */ }; /* BTF_KIND_ENUM64 is followed by VLEN struct btf_enum64 entries, -- cgit v1.1