btf: do not skip emitting void variables [PR106773]

Message ID 20220901195340.10653-1-david.faust@oracle.com
State New, archived
Headers
Series btf: do not skip emitting void variables [PR106773] |

Commit Message

David Faust Sept. 1, 2022, 7:53 p.m. UTC
  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.

Tested on bpf-unknown-none and x86_64, no known regressions.
OK?

Thanks.

gcc/ChangeLog:

	PR target/106773
	* btfout.cc (btf_dvd_emit_preprocess_cb): Do not skip emitting
	variables which refer to void types.

gcc/testsuite/ChangeLog:

	PR target/106773
	* gcc.dg/debug/btf/btf-pr106773.c: New test.
---
 gcc/btfout.cc                                 |  2 +-
 gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c | 21 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c
  

Comments

Indu Bhagat Sept. 4, 2022, 4:57 p.m. UTC | #1
On 9/1/22 12:53, David Faust wrote:
> 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.
> 
> Tested on bpf-unknown-none and x86_64, no known regressions.
> OK?

Hi David,

LGTM.

Thanks,

> 
> Thanks.
> 
> gcc/ChangeLog:
> 
> 	PR target/106773
> 	* btfout.cc (btf_dvd_emit_preprocess_cb): Do not skip emitting
> 	variables which refer to void types.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR target/106773
> 	* gcc.dg/debug/btf/btf-pr106773.c: New test.
> ---
>   gcc/btfout.cc                                 |  2 +-
>   gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c | 21 +++++++++++++++++++
>   2 files changed, 22 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c
> 
> diff --git a/gcc/btfout.cc b/gcc/btfout.cc
> index 997a33fa089..37ec662c190 100644
> --- a/gcc/btfout.cc
> +++ b/gcc/btfout.cc
> @@ -430,7 +430,7 @@ btf_dvd_emit_preprocess_cb (ctf_dvdef_ref *slot, ctf_container_ref arg_ctfc)
>     ctf_dvdef_ref var = (ctf_dvdef_ref) * slot;
>   
>     /* Do not add variables which refer to unsupported types.  */
> -  if (btf_removed_type_p (var->dvd_type))
> +  if (!voids.contains (var->dvd_type) && btf_removed_type_p (var->dvd_type))
>       return 1;
>   
>     arg_ctfc->ctfc_vars_list[num_vars_added] = var;
> diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c b/gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c
> new file mode 100644
> index 00000000000..4de15f76546
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c
> @@ -0,0 +1,21 @@
> +/* Test BTF generation for extern const void symbols.
> +   BTF_KIND_VAR records should be emitted for such symbols if they are used.  */
> +
> +/* { dg-do compile } */
> +/* { dg-options "-O0 -gbtf -dA" } */
> +
> +/* Expect 1 variable record only for foo.  */
> +/* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t \]+\[^\n\]*btv_info" 1 } } */
> +/* { dg-final { scan-assembler-times "\[\t \]0x1\[\t \]+\[^\n\]*btv_linkage" 1 } } */
> +
> +/* { dg-final { scan-assembler-times "ascii \"foo.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
> +
> +extern const void foo;
> +extern const void bar;
> +
> +unsigned long func () {
> +  unsigned long x = (unsigned long) &foo;
> +
> +  return x;
> +}
> +
  

Patch

diff --git a/gcc/btfout.cc b/gcc/btfout.cc
index 997a33fa089..37ec662c190 100644
--- a/gcc/btfout.cc
+++ b/gcc/btfout.cc
@@ -430,7 +430,7 @@  btf_dvd_emit_preprocess_cb (ctf_dvdef_ref *slot, ctf_container_ref arg_ctfc)
   ctf_dvdef_ref var = (ctf_dvdef_ref) * slot;
 
   /* Do not add variables which refer to unsupported types.  */
-  if (btf_removed_type_p (var->dvd_type))
+  if (!voids.contains (var->dvd_type) && btf_removed_type_p (var->dvd_type))
     return 1;
 
   arg_ctfc->ctfc_vars_list[num_vars_added] = var;
diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c b/gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c
new file mode 100644
index 00000000000..4de15f76546
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c
@@ -0,0 +1,21 @@ 
+/* Test BTF generation for extern const void symbols.
+   BTF_KIND_VAR records should be emitted for such symbols if they are used.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O0 -gbtf -dA" } */
+
+/* Expect 1 variable record only for foo.  */
+/* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t \]+\[^\n\]*btv_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x1\[\t \]+\[^\n\]*btv_linkage" 1 } } */
+
+/* { dg-final { scan-assembler-times "ascii \"foo.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+
+extern const void foo;
+extern const void bar;
+
+unsigned long func () {
+  unsigned long x = (unsigned long) &foo;
+
+  return x;
+}
+