btf: correct generation for extern funcs [PR106773]
authorDavid Faust <david.faust@oracle.com>
Wed, 7 Dec 2022 19:51:59 +0000 (11:51 -0800)
committerDavid Faust <david.faust@oracle.com>
Wed, 14 Dec 2022 18:20:53 +0000 (10:20 -0800)
commit70b303049e45c180236a4114f844311652bad002
treeb43b62a7a552c0d8ca4a21596aaf950c50bbd3df
parent4f7aa145b796c044526c93f390e68f3b56a1b30a
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.
gcc/btfout.cc
gcc/testsuite/gcc.dg/debug/btf/btf-datasec-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/debug/btf/btf-function-6.c [new file with mode: 0644]
include/btf.h