]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
BTF: fix PR debug/112656
authorIndu Bhagat <indu.bhagat@oracle.com>
Mon, 4 Dec 2023 09:57:34 +0000 (01:57 -0800)
committerIndu Bhagat <indu.bhagat@oracle.com>
Mon, 4 Dec 2023 10:00:37 +0000 (02:00 -0800)
PR debug/112656 - btf: function prototypes generated with name

With this patch, all BTF_KIND_FUNC_PROTO will appear anonymous in the
generated BTF section.

As noted in the discussion in the bugzilla, the number of
BTF_KIND_FUNC_PROTO types output varies across targets (BPF with -mco-re
vs non-BPF targets).  Hence the check in the test case merely checks
that all BTF_KIND_FUNC_PROTO appear anonymous.

gcc/ChangeLog:

PR debug/112656
* btfout.cc (btf_asm_type): Fixup ctti_name for all
BTF types of kind BTF_KIND_FUNC_PROTO.

gcc/testsuite/ChangeLog:

PR debug/112656
* gcc.dg/debug/btf/btf-function-7.c: New test.

gcc/btfout.cc
gcc/testsuite/gcc.dg/debug/btf/btf-function-7.c [new file with mode: 0644]

index 1c25404b2c0af9741453a43de744a34d626945d6..a5e0d640e19864fe6dbe7b6ee67f7eb611cc58ca 100644 (file)
@@ -820,6 +820,10 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd)
        btf_kind = BTF_KIND_ENUM64;
    }
 
+  /* PR debug/112656.  BTF_KIND_FUNC_PROTO is always anonymous.  */
+  if (btf_kind == BTF_KIND_FUNC_PROTO)
+    dtd->dtd_data.ctti_name = 0;
+
   dw2_asm_output_data (4, dtd->dtd_data.ctti_name,
                       "TYPE %" PRIu64 " BTF_KIND_%s '%s'",
                       get_btf_id (dtd->dtd_type), btf_kind_name (btf_kind),
diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-function-7.c b/gcc/testsuite/gcc.dg/debug/btf/btf-function-7.c
new file mode 100644 (file)
index 0000000..b560dc7
--- /dev/null
@@ -0,0 +1,19 @@
+/* Test BTF for inlined functions.
+
+   See PR/112656 - btf: function prototypes generated with name
+   BTF_KIND_FUNC_PROTO must be anonymous.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -gbtf -dA" } */
+
+/* { dg-final { scan-assembler-times "BTF_KIND_FUNC_PROTO ''\\(\[0-9a-z\]*\\)'" 0 } } */
+
+static int log_event(const char *event_name, void *dev_ptr)
+{
+  return 666;
+}
+
+int foo ()
+{
+  return log_event ("foobar", ((void *)0));
+}