public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Schwinge <thomas@codesourcery.com>
To: <gcc-patches@gcc.gnu.org>, Richard Biener <rguenther@suse.de>,
	"Jakub Jelinek" <jakub@redhat.com>
Cc: Pan Li <pan2.li@intel.com>, <juzhe.zhong@rivai.ai>,
	<rdapp.gcc@gmail.com>, <jeffreyalaw@gmail.com>,
	<yanzhang.wang@intel.com>, <kito.cheng@gmail.com>,
	Tobias Burnus <tobias@codesourcery.com>
Subject: LTO: Capture 'lto_file_decl_data *file_data' in 'class lto_input_block' (was: [PATCH v3] Streamer: Fix out of range memory access of machine mode)
Date: Fri, 30 Jun 2023 10:23:00 +0200	[thread overview]
Message-ID: <87v8f5uzob.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <87sfaauit8.fsf@dem-tschwing-1.ger.mentorg.com>

[-- Attachment #1: Type: text/plain, Size: 770 bytes --]

Hi!

On 2023-06-29T22:14:59+0200, I wrote:
> [the new] 'file_data->mode_bits' needs to be considered [somewhere]
>
> Easiest is in 'gcc/lto-streamer.h:class lto_input_block' to capture
> 'lto_file_decl_data *file_data' instead of just
> 'unsigned char *mode_table', and adjust all users.

I've split this out as a preparational "no change in behavior" patch; is
"LTO: Capture 'lto_file_decl_data *file_data' in 'class lto_input_block'"
OK to push, see attached?


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-LTO-Capture-lto_file_decl_data-file_data-in-class-lt.patch --]
[-- Type: text/x-diff, Size: 9233 bytes --]

From 1b75a8680bdef16633e3fa2479832a1b71dae43f Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 29 Jun 2023 21:33:06 +0200
Subject: [PATCH] LTO: Capture 'lto_file_decl_data *file_data' in 'class
 lto_input_block'

... instead of just 'unsigned char *mode_table'.  Preparation for a forthcoming
change, where we need to capture an additional 'file_data' item, so it seems
easier to just capture that one proper.

	gcc/
	* lto-streamer.h (class lto_input_block): Capture
	'lto_file_decl_data *file_data' instead of just
	'unsigned char *mode_table'.
	* ipa-devirt.cc (ipa_odr_read_section): Adjust.
	* ipa-fnsummary.cc (inline_read_section): Likewise.
	* ipa-icf.cc (sem_item_optimizer::read_section): Likewise.
	* ipa-modref.cc (read_section): Likewise.
	* ipa-prop.cc (ipa_prop_read_section, read_replacements_section):
	Likewise.
	* ipa-sra.cc (isra_read_summary_section): Likewise.
	* lto-cgraph.cc (input_cgraph_opt_section): Likewise.
	* lto-section-in.cc (lto_create_simple_input_block): Likewise.
	* lto-streamer-in.cc (lto_read_body_or_constructor)
	(lto_input_toplevel_asms): Likewise.
	* tree-streamer.h (bp_unpack_machine_mode): Likewise.
	gcc/lto/
	* lto-common.cc (lto_read_decls): Adjust.
---
 gcc/ipa-devirt.cc      |  2 +-
 gcc/ipa-fnsummary.cc   |  2 +-
 gcc/ipa-icf.cc         |  2 +-
 gcc/ipa-modref.cc      |  2 +-
 gcc/ipa-prop.cc        |  4 ++--
 gcc/ipa-sra.cc         |  2 +-
 gcc/lto-cgraph.cc      |  2 +-
 gcc/lto-section-in.cc  |  2 +-
 gcc/lto-streamer-in.cc |  6 +++---
 gcc/lto-streamer.h     | 10 +++++-----
 gcc/lto/lto-common.cc  |  2 +-
 gcc/tree-streamer.h    |  6 +++---
 12 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/gcc/ipa-devirt.cc b/gcc/ipa-devirt.cc
index 2c61a497cee..87529be4515 100644
--- a/gcc/ipa-devirt.cc
+++ b/gcc/ipa-devirt.cc
@@ -4147,7 +4147,7 @@ ipa_odr_read_section (struct lto_file_decl_data *file_data, const char *data,
   class data_in *data_in;
 
   lto_input_block ib ((const char *) data + main_offset, header->main_size,
-		      file_data->mode_table);
+		      file_data);
 
   data_in
     = lto_data_in_create (file_data, (const char *) data + string_offset,
diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
index a5f5a50c8a5..37c1edc2f3a 100644
--- a/gcc/ipa-fnsummary.cc
+++ b/gcc/ipa-fnsummary.cc
@@ -4528,7 +4528,7 @@ inline_read_section (struct lto_file_decl_data *file_data, const char *data,
   unsigned int f_count;
 
   lto_input_block ib ((const char *) data + main_offset, header->main_size,
-		      file_data->mode_table);
+		      file_data);
 
   data_in =
     lto_data_in_create (file_data, (const char *) data + string_offset,
diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index cb9f768d85d..836d0914ded 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -2204,7 +2204,7 @@ sem_item_optimizer::read_section (lto_file_decl_data *file_data,
   unsigned int count;
 
   lto_input_block ib_main ((const char *) data + main_offset, 0,
-			   header->main_size, file_data->mode_table);
+			   header->main_size, file_data);
 
   data_in
     = lto_data_in_create (file_data, (const char *) data + string_offset,
diff --git a/gcc/ipa-modref.cc b/gcc/ipa-modref.cc
index e3196df8aa9..278b2dbd828 100644
--- a/gcc/ipa-modref.cc
+++ b/gcc/ipa-modref.cc
@@ -3816,7 +3816,7 @@ read_section (struct lto_file_decl_data *file_data, const char *data,
   unsigned int f_count;
 
   lto_input_block ib ((const char *) data + main_offset, header->main_size,
-		      file_data->mode_table);
+		      file_data);
 
   data_in
     = lto_data_in_create (file_data, (const char *) data + string_offset,
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 704fe01b02c..8f2119b72e3 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -5337,7 +5337,7 @@ ipa_prop_read_section (struct lto_file_decl_data *file_data, const char *data,
   unsigned int count;
 
   lto_input_block ib_main ((const char *) data + main_offset,
-			   header->main_size, file_data->mode_table);
+			   header->main_size, file_data);
 
   data_in =
     lto_data_in_create (file_data, (const char *) data + string_offset,
@@ -5561,7 +5561,7 @@ read_replacements_section (struct lto_file_decl_data *file_data,
   unsigned int count;
 
   lto_input_block ib_main ((const char *) data + main_offset,
-			   header->main_size, file_data->mode_table);
+			   header->main_size, file_data);
 
   data_in = lto_data_in_create (file_data, (const char *) data + string_offset,
 				header->string_size, vNULL);
diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc
index 21d281a9756..c35e03b7abd 100644
--- a/gcc/ipa-sra.cc
+++ b/gcc/ipa-sra.cc
@@ -2944,7 +2944,7 @@ isra_read_summary_section (struct lto_file_decl_data *file_data,
   unsigned int count;
 
   lto_input_block ib_main ((const char *) data + main_offset,
-			   header->main_size, file_data->mode_table);
+			   header->main_size, file_data);
 
   data_in =
     lto_data_in_create (file_data, (const char *) data + string_offset,
diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index aed5e9ddb18..32c0f5ac6db 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -2174,7 +2174,7 @@ input_cgraph_opt_section (struct lto_file_decl_data *file_data,
   unsigned int count;
 
   lto_input_block ib_main ((const char *) data + main_offset,
-			   header->main_size, file_data->mode_table);
+			   header->main_size, file_data);
 
   data_in =
     lto_data_in_create (file_data, (const char *) data + string_offset,
diff --git a/gcc/lto-section-in.cc b/gcc/lto-section-in.cc
index 07cf7326582..5ff00a3c130 100644
--- a/gcc/lto-section-in.cc
+++ b/gcc/lto-section-in.cc
@@ -262,7 +262,7 @@ lto_create_simple_input_block (struct lto_file_decl_data *file_data,
 
   *datar = data;
   return new lto_input_block (data + main_offset, header->main_size,
-			      file_data->mode_table);
+			      file_data);
 }
 
 
diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc
index 2cb83406db5..6e8bc9516a6 100644
--- a/gcc/lto-streamer-in.cc
+++ b/gcc/lto-streamer-in.cc
@@ -1629,11 +1629,11 @@ lto_read_body_or_constructor (struct lto_file_decl_data *file_data, struct symta
       /* Set up the struct function.  */
       from = data_in->reader_cache->nodes.length ();
       lto_input_block ib_main (data + main_offset, header->main_size,
-			       file_data->mode_table);
+			       file_data);
       if (TREE_CODE (node->decl) == FUNCTION_DECL)
 	{
 	  lto_input_block ib_cfg (data + cfg_offset, header->cfg_size,
-				  file_data->mode_table);
+				  file_data);
 	  input_function (fn_decl, data_in, &ib_main, &ib_cfg,
 			  dyn_cast <cgraph_node *>(node));
 	}
@@ -1954,7 +1954,7 @@ lto_input_toplevel_asms (struct lto_file_decl_data *file_data, int order_base)
   string_offset = sizeof (*header) + header->main_size;
 
   lto_input_block ib (data + sizeof (*header), header->main_size,
-		      file_data->mode_table);
+		      file_data);
 
   data_in = lto_data_in_create (file_data, data + string_offset,
 			      header->string_size, vNULL);
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index fc7133d07ba..2913b808bde 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -344,14 +344,14 @@ public:
   /* Special constructor for the string table, it abuses this to
      do random access but use the uhwi decoder.  */
   lto_input_block (const char *data_, unsigned int p_, unsigned int len_,
-		   const unsigned char *mode_table_)
-      : data (data_), mode_table (mode_table_), p (p_), len (len_) {}
+		   const lto_file_decl_data *file_data_)
+      : data (data_), file_data (file_data_), p (p_), len (len_) {}
   lto_input_block (const char *data_, unsigned int len_,
-		   const unsigned char *mode_table_)
-      : data (data_), mode_table (mode_table_), p (0), len (len_) {}
+		   const lto_file_decl_data *file_data_)
+      : data (data_), file_data (file_data_), p (0), len (len_) {}
 
   const char *data;
-  const unsigned char *mode_table;
+  const lto_file_decl_data *file_data;
   unsigned int p;
   unsigned int len;
 };
diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index 537570204b3..c235df8a5f5 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -1880,7 +1880,7 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
   uint32_t num_decl_states;
 
   lto_input_block ib_main ((const char *) data + main_offset,
-			   header->main_size, decl_data->mode_table);
+			   header->main_size, decl_data);
 
   data_in = lto_data_in_create (decl_data, (const char *) data + string_offset,
 				header->string_size, resolutions);
diff --git a/gcc/tree-streamer.h b/gcc/tree-streamer.h
index 170d61cf20b..6d565acbbc2 100644
--- a/gcc/tree-streamer.h
+++ b/gcc/tree-streamer.h
@@ -114,9 +114,9 @@ bp_pack_machine_mode (struct bitpack_d *bp, machine_mode mode)
 inline machine_mode
 bp_unpack_machine_mode (struct bitpack_d *bp)
 {
-  return (machine_mode)
-	   ((class lto_input_block *)
-	    bp->stream)->mode_table[bp_unpack_enum (bp, machine_mode, 1 << 8)];
+  lto_input_block *ib = (class lto_input_block *) bp->stream;
+  unsigned ix = bp_unpack_enum (bp, machine_mode, 1 << 8);
+  return (machine_mode) ib->file_data->mode_table[ix];
 }
 
 #endif  /* GCC_TREE_STREAMER_H  */
-- 
2.34.1


  parent reply	other threads:[~2023-06-30  8:23 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-19  8:07 [PATCH v1] RISC-V: Fix out of range memory access when lto mode init pan2.li
2023-06-19  8:16 ` Li, Pan2
2023-06-19  8:40   ` Richard Biener
2023-06-19  9:08     ` Li, Pan2
2023-06-19  9:10     ` Jakub Jelinek
2023-06-19  9:05 ` [PATCH] RISC-V: Fix out of range memory access of machine mode table pan2.li
2023-06-19  9:15   ` Richard Biener
2023-06-19  9:16   ` Jakub Jelinek
2023-06-19 13:35     ` Li, Pan2
2023-06-20  7:50       ` Li, Pan2
2023-06-20  8:03         ` Jakub Jelinek
2023-06-20 14:08           ` Li, Pan2
2023-06-20 15:25             ` Jakub Jelinek
2023-06-21  6:59               ` Li, Pan2
2023-06-21  7:16                 ` Jakub Jelinek
2023-06-21  7:23                   ` Li, Pan2
2023-06-22  0:19                     ` Li, Pan2
2023-06-28 18:37                       ` Jeff Law
2023-06-21  7:58 ` [PATCH v3] Streamer: Fix out of range memory access of machine mode pan2.li
2023-06-22 15:26   ` Li, Pan2
2023-06-29  9:29   ` Thomas Schwinge
2023-06-29  9:33     ` juzhe.zhong
2023-06-29  9:47       ` Thomas Schwinge
2023-06-29  9:52         ` juzhe.zhong
2023-06-29 20:14     ` Thomas Schwinge
2023-06-30  1:26       ` juzhe.zhong
2023-06-30  1:39         ` Li, Pan2
2023-06-30  8:50           ` [v4] " Thomas Schwinge
2023-06-30 11:44             ` Li, Pan2
2023-07-04 11:26             ` Richard Biener
2023-07-04 12:40               ` Li, Pan2
2023-06-30  8:23       ` Thomas Schwinge [this message]
2023-06-30  8:39         ` LTO: Capture 'lto_file_decl_data *file_data' in 'class lto_input_block' (was: [PATCH v3] Streamer: Fix out of range memory access of machine mode) Richard Biener

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=87v8f5uzob.fsf@euler.schwinge.homeip.net \
    --to=thomas@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jeffreyalaw@gmail.com \
    --cc=juzhe.zhong@rivai.ai \
    --cc=kito.cheng@gmail.com \
    --cc=pan2.li@intel.com \
    --cc=rdapp.gcc@gmail.com \
    --cc=rguenther@suse.de \
    --cc=tobias@codesourcery.com \
    --cc=yanzhang.wang@intel.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).