btf: fix 'extern const void' variables [PR106773]
authorDavid Faust <david.faust@oracle.com>
Wed, 7 Dec 2022 19:47:26 +0000 (11:47 -0800)
committerDavid Faust <david.faust@oracle.com>
Wed, 14 Dec 2022 18:20:52 +0000 (10:20 -0800)
commit4f7aa145b796c044526c93f390e68f3b56a1b30a
treed00cafaed17f579619ed3a981a3e289e57725731
parent2bce22e88e1c8486a0f2d42311506a8d3da20fb7
btf: fix 'extern const void' variables [PR106773]

The eBPF loader expects to find BTF_KIND_VAR records for references to
extern const void symbols. We were mistakenly identifing these as
unsupported types, and as a result skipping emitting VAR records for
them.

In addition, the internal DWARF representation from which BTF is
produced does not generate 'const' modifier DIEs for the void type,
which meant in BTF the 'const' qualifier was dropped for 'extern const
void' variables. This patch also adds support for generating a const
void type in BTF to correct emission for these variables.

PR target/106773

gcc/

* btfout.cc (btf_collect_datasec): Correct size of void entries.
(btf_dvd_emit_preprocess_cb): Do not skip emitting variables which
refer to void types.
(btf_init_postprocess): Create 'const void' type record if needed and
adjust variables to refer to it as appropriate.

gcc/testsuite/

* gcc.dg/debug/btf/btf-pr106773.c: New test.
gcc/btfout.cc
gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c [new file with mode: 0644]