public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3086] bpf: Fixed GC mistakes in BPF builtins code.
@ 2023-08-08 19:36 Cupertino Miranda
  0 siblings, 0 replies; only message in thread
From: Cupertino Miranda @ 2023-08-08 19:36 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e7cae4f873fe94c1af8401b8d0b53a192957215d

commit r14-3086-ge7cae4f873fe94c1af8401b8d0b53a192957215d
Author: Cupertino Miranda <cupertino.miranda@oracle.com>
Date:   Tue Aug 8 11:12:00 2023 +0100

    bpf: Fixed GC mistakes in BPF builtins code.
    
    This patches fixes problems with GC within the CO-RE builtins
    implementation.
    List of included headers was also revised.
    
    gcc/ChangeLog:
    
            * config/bpf/core-builtins.cc: Cleaned include headers.
            (struct cr_builtins): Added GTY.
            (cr_builtins_ref): Created.
            (builtins_data) Changed to GC root.
            (allocate_builtin_data): Changed.
            Included gt-core-builtins.h.
            * config/bpf/coreout.cc: (bpf_core_extra) Added GTY.
            (bpf_core_extra_ref): Created.
            (bpf_comment_info): Changed to GC root.
            (bpf_core_reloc_add, output_btfext_header, btf_ext_init): Changed.

Diff:
---
 gcc/config/bpf/core-builtins.cc | 64 ++++++++++++++---------------------------
 gcc/config/bpf/coreout.cc       | 12 ++++----
 2 files changed, 28 insertions(+), 48 deletions(-)

diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc
index 575e63d8ea7..60d21a8ae73 100644
--- a/gcc/config/bpf/core-builtins.cc
+++ b/gcc/config/bpf/core-builtins.cc
@@ -22,52 +22,23 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
+#include "target.h"
 #include "rtl.h"
-#include "regs.h"
-#include "insn-config.h"
-#include "insn-attr.h"
-#include "recog.h"
 #include "output.h"
-#include "alias.h"
 #include "tree.h"
 #include "stringpool.h"
 #include "attribs.h"
-#include "varasm.h"
-#include "stor-layout.h"
-#include "calls.h"
 #include "function.h"
-#include "explow.h"
 #include "memmodel.h"
 #include "emit-rtl.h"
-#include "reload.h"
-#include "tm_p.h"
-#include "target.h"
-#include "basic-block.h"
 #include "expr.h"
-#include "optabs.h"
-#include "bitmap.h"
-#include "df.h"
-#include "c-family/c-common.h"
 #include "diagnostic.h"
-#include "builtins.h"
-#include "predict.h"
 #include "langhooks.h"
-#include "flags.h"
-
-#include "cfg.h"
+#include "basic-block.h"
 #include "gimple.h"
 #include "gimple-iterator.h"
 #include "gimple-walk.h"
 #include "tree-pass.h"
-#include "tree-iterator.h"
-
-#include "context.h"
-#include "pass_manager.h"
-
-#include "gimplify.h"
-#include "gimplify-me.h"
-
 #include "plugin.h"
 
 #include "ctfc.h"
@@ -159,37 +130,41 @@ along with GCC; see the file COPYING3.  If not see
     as a builtin.  */
 
 
-struct cr_builtins
+struct GTY(()) cr_builtins
 {
   tree type;
   tree expr;
   tree default_value;
   rtx rtx_default_value;
-  enum btf_core_reloc_kind kind; /* Recovered from proper argument.  */
+  enum btf_core_reloc_kind kind;
   enum bpf_builtins orig_builtin_code;
   tree orig_arg_expr;
 };
+typedef struct cr_builtins *cr_builtins_ref;
 
 #define CORE_BUILTINS_DATA_EMPTY \
   { NULL_TREE, NULL_TREE, NULL_TREE, NULL_RTX, BPF_RELO_INVALID, \
     BPF_BUILTIN_UNUSED, NULL }
 
 /* Vector definition and its access function.  */
-vec<struct cr_builtins> builtins_data;
+static GTY(()) vec<cr_builtins_ref, va_gc> *builtins_data = NULL;
 
 static inline int
 allocate_builtin_data ()
 {
-  struct cr_builtins data = CORE_BUILTINS_DATA_EMPTY;
-  int ret = builtins_data.length ();
-  builtins_data.safe_push (data);
+  if (builtins_data == NULL)
+    vec_alloc (builtins_data, 1);
+
+  cr_builtins_ref data = ggc_cleared_alloc<struct cr_builtins> ();
+  int ret = builtins_data->length ();
+  vec_safe_push (builtins_data, data);
   return ret;
 }
 
 static inline struct cr_builtins *
 get_builtin_data (int index)
 {
-  return &builtins_data[index];
+  return (*builtins_data)[index];
 }
 
 typedef bool
@@ -200,11 +175,12 @@ search_builtin_data (builtin_local_data_compare_fn callback,
 		     struct cr_builtins *elem)
 {
   unsigned int i;
-  for (i = 0; i < builtins_data.length (); i++)
-    if ((callback != NULL && (callback) (elem, &builtins_data[i]))
-       || (callback == NULL
-	   && (builtins_data[i].orig_arg_expr == elem->orig_arg_expr)))
-      return (int) i;
+  if (builtins_data != NULL)
+    for (i = 0; i < builtins_data->length (); i++)
+      if ((callback != NULL && (callback) (elem, (*builtins_data)[i]))
+	  || (callback == NULL
+	      && ((*builtins_data)[i]->orig_arg_expr == elem->orig_arg_expr)))
+	return (int) i;
 
   return -1;
 }
@@ -1392,3 +1368,5 @@ bpf_replace_core_move_operands (rtx *operands)
 	  }
       }
 }
+
+#include "gt-core-builtins.h"
diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
index b84585fb104..0c5d166298f 100644
--- a/gcc/config/bpf/coreout.cc
+++ b/gcc/config/bpf/coreout.cc
@@ -147,11 +147,12 @@ static char btf_ext_info_section_label[MAX_BTF_EXT_LABEL_BYTES];
 
 static GTY (()) vec<bpf_core_section_ref, va_gc> *bpf_core_sections;
 
-struct bpf_core_extra {
+struct GTY(()) bpf_core_extra {
   const char *accessor_str;
   tree type;
 };
-static hash_map<bpf_core_reloc_ref, struct bpf_core_extra *> bpf_comment_info;
+typedef struct bpf_core_extra *bpf_core_extra_ref;
+static GTY(()) hash_map<bpf_core_reloc_ref, bpf_core_extra_ref> *bpf_comment_info;
 
 /* Create a new BPF CO-RE relocation record, and add it to the appropriate
    CO-RE section.  */
@@ -162,7 +163,7 @@ bpf_core_reloc_add (const tree type, const char * section_name,
 		    enum btf_core_reloc_kind kind)
 {
   bpf_core_reloc_ref bpfcr = ggc_cleared_alloc<bpf_core_reloc_t> ();
-  struct bpf_core_extra *info = ggc_cleared_alloc<struct bpf_core_extra> ();
+  bpf_core_extra_ref info = ggc_cleared_alloc<struct bpf_core_extra> ();
   ctf_container_ref ctfc = ctf_get_tu_ctfc ();
 
   /* Buffer the access string in the auxiliary strtab.  */
@@ -173,7 +174,7 @@ bpf_core_reloc_add (const tree type, const char * section_name,
 
   info->accessor_str = accessor;
   info->type = type;
-  bpf_comment_info.put (bpfcr, info);
+  bpf_comment_info->put (bpfcr, info);
 
   /* Add the CO-RE reloc to the appropriate section.  */
   bpf_core_section_ref sec;
@@ -288,7 +289,7 @@ output_btfext_header (void)
 static void
 output_asm_btfext_core_reloc (bpf_core_reloc_ref bpfcr)
 {
-  struct bpf_core_extra **info = bpf_comment_info.get (bpfcr);
+  bpf_core_extra_ref *info = bpf_comment_info->get (bpfcr);
   gcc_assert (info != NULL);
 
   bpfcr->bpfcr_astr_off += ctfc_get_strtab_len (ctf_get_tu_ctfc (),
@@ -365,6 +366,7 @@ btf_ext_init (void)
 			       btf_ext_label_num++);
 
   vec_alloc (bpf_core_sections, 1);
+  bpf_comment_info = hash_map<bpf_core_reloc_ref, bpf_core_extra_ref>::create_ggc ();
 }
 
 /* Output the entire .BTF.ext section.  */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-08 19:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-08 19:36 [gcc r14-3086] bpf: Fixed GC mistakes in BPF builtins code Cupertino Miranda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).