public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Cupertino Miranda <cupertino.miranda@oracle.com>
To: gcc-patches@gcc.gnu.org
Cc: jose.marchesi@oracle.com, david.faust@oracle.com,
	elena.zannoni@oracle.com,
	Cupertino Miranda <cupertino.miranda@oracle.com>
Subject: [PATCH 2/3] bpf: remove huge memory waste with string allocation.
Date: Thu, 11 Apr 2024 12:11:17 +0100	[thread overview]
Message-ID: <20240411111118.215612-2-cupertino.miranda@oracle.com> (raw)
In-Reply-To: <20240411111118.215612-1-cupertino.miranda@oracle.com>

Code was allocating way too much space for the string.

gcc/ChangeLog:
	* config/bpf/core-builtins.cc (process_enum_value): Corrected
	string allocation.
---
 gcc/config/bpf/core-builtins.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc
index e03e986e2c1..ead1777d465 100644
--- a/gcc/config/bpf/core-builtins.cc
+++ b/gcc/config/bpf/core-builtins.cc
@@ -872,10 +872,11 @@ process_enum_value (struct cr_builtins *data)
 	{
 	  if (TREE_VALUE (l) == expr)
 	    {
-	      char *tmp = (char *) ggc_alloc_atomic ((index / 10) + 1);
+	      /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string
+		 representations of 64 bit integers.  */
+	      char tmp[21];
 	      sprintf (tmp, "%d", index);
-	      ret.str = (const char *) tmp;
-
+	      ret.str = CONST_CAST (char *, ggc_strdup(tmp));
 	      break;
 	    }
 	  index++;
-- 
2.30.2


  reply	other threads:[~2024-04-11 11:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11 11:11 [PATCH 1/3] bpf: support more instructions to match CO-RE relocations Cupertino Miranda
2024-04-11 11:11 ` Cupertino Miranda [this message]
2024-04-11 16:34   ` [PATCH 2/3] bpf: remove huge memory waste with string allocation David Faust
2024-04-11 17:23     ` Cupertino Miranda
2024-04-11 11:11 ` [PATCH 3/3] bpf: add line_info support to BTF.ext section Cupertino Miranda
2024-04-17 15:14   ` Jose E. Marchesi
2024-04-17 15:47     ` Cupertino Miranda
2024-04-17 17:48       ` Jose E. Marchesi
2024-04-17 17:55         ` Jose E. Marchesi
2024-04-17 15:07 ` [PATCH 1/3] bpf: support more instructions to match CO-RE relocations Jose E. Marchesi
2024-04-19 10:17   ` Cupertino Miranda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240411111118.215612-2-cupertino.miranda@oracle.com \
    --to=cupertino.miranda@oracle.com \
    --cc=david.faust@oracle.com \
    --cc=elena.zannoni@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jose.marchesi@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).