aboutsummaryrefslogtreecommitdiff
path: root/gcc/lto
diff options
context:
space:
mode:
authorPan Li <pan2.li@intel.com>2023-06-21 15:58:24 +0800
committerThomas Schwinge <thomas@codesourcery.com>2023-07-04 14:10:54 +0200
commit86ff0533fcb442be17942eef16f8b8db466c4fd4 (patch)
tree7ba63efbc81e4f7171972335abd7ad79cd0c1193 /gcc/lto
parentd7faf7a54e0598bd6d4042d855b7d7905d269470 (diff)
downloadgcc-86ff0533fcb442be17942eef16f8b8db466c4fd4.zip
gcc-86ff0533fcb442be17942eef16f8b8db466c4fd4.tar.gz
gcc-86ff0533fcb442be17942eef16f8b8db466c4fd4.tar.bz2
Streamer: Fix out of range memory access of machine mode
We extend the machine mode from 8 to 16 bits already. But there still one placing missing from the streamer. It has one hard coded array for the machine code like size 256. In the lto pass, we memset the array by MAX_MACHINE_MODE count but the value of the MAX_MACHINE_MODE will grow as more and more modes are added. While the machine mode array in tree-streamer still leave 256 as is. Then, when the MAX_MACHINE_MODE is greater than 256, the memset of lto_output_init_mode_table will touch the memory out of range unexpected. This patch would like to take the MAX_MACHINE_MODE as the size of the array in streamer, to make sure there is no potential unexpected memory access in future. Meanwhile, this patch also adjust some place which has MAX_MACHINE_MODE <= 256 assumption. Care is taken that for offload compilation, we interpret the stream-in data in terms of the host 'MAX_MACHINE_MODE' ('file_data->mode_bits'), which very likely is different from the offload device 'MAX_MACHINE_MODE'. gcc/ * lto-streamer-in.cc (lto_input_mode_table): Stream in the mode bits for machine mode table. * lto-streamer-out.cc (lto_write_mode_table): Stream out the HOST machine mode bits. * lto-streamer.h (struct lto_file_decl_data): New fields mode_bits. * tree-streamer.cc (streamer_mode_table): Take MAX_MACHINE_MODE as the table size. * tree-streamer.h (streamer_mode_table): Ditto. (bp_pack_machine_mode): Take 1 << ceil_log2 (MAX_MACHINE_MODE) as the packing limit. (bp_unpack_machine_mode): Ditto with 'file_data->mode_bits'. gcc/lto/ * lto-common.cc (lto_file_finalize) [!ACCEL_COMPILER]: Initialize 'file_data->mode_bits'. Signed-off-by: Pan Li <pan2.li@intel.com> Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Diffstat (limited to 'gcc/lto')
-rw-r--r--gcc/lto/lto-common.cc1
1 files changed, 1 insertions, 0 deletions
diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index cdb37c8..703e665 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -2278,6 +2278,7 @@ lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file,
lto_input_mode_table (file_data);
#else
file_data->mode_table = lto_mode_identity_table;
+ file_data->mode_bits = ceil_log2 (MAX_MACHINE_MODE);
#endif
data = lto_get_summary_section_data (file_data, LTO_section_decls, &len);