From patchwork Fri Jun 30 08:23:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 114610 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10192847vqr; Fri, 30 Jun 2023 01:24:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlE3RtYMODSjMQ0TTPEzBTv+1lBvNdQybVTWzND6juiN7KWh5230um6WLwLhJ8+I0VhDW00N X-Received: by 2002:a2e:9092:0:b0:2b6:9e1e:f048 with SMTP id l18-20020a2e9092000000b002b69e1ef048mr1847860ljg.31.1688113441937; Fri, 30 Jun 2023 01:24:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688113441; cv=none; d=google.com; s=arc-20160816; b=Pkv6KnENNULN6BgdAPWLF87fmIfYyZf9bsnc9+FLhx3FiK4qbBZ7QCdgRUZprhORFV b2MC5gncIiV+DjxPnszOXFZ5s6jDlUV6W6gTvFit8u03jEN+Qc8E4mconbzeoC7KhZJ1 xcxRkYrIaoBjIS5zL3juiKVjJVPbAs5BKTpxqnsLYJDN51gyJVUKHvVyrnEay5twYKD2 EgRV4FLKNVwq2C+P0QDSTIUtyXhFytKhQ8F/epcXI5QG4kJW/p+ilia25kTBdAZLBPlS wp6RLQM8gGbHJp+HgA81gxs8HSusQAFWoAdcMm9qVdKmQnDmqLx5/OritzgebCQtAEWi JKcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:references:in-reply-to:subject:cc:to:from:ironport-sdr :dmarc-filter:delivered-to; bh=7a7zXypFDkNb4WWhobU0/lv2LsAYZdVimN1Qcu1rytE=; fh=Rng4tvujhfv0LsYBBNecgKJb8lHsshqs3bFA5F2aA2s=; b=Thc3hdQ5VXwS5EnMTk1vi30lQT6szDNCMdaCXPqkSe+sc4MSbt7/qhlVr3B5LKKR9O NeKwqDjDR3k4s/hXiJOmr/0Q3iFH4JXnM8ZPYoiFrStw5Xp3xTcxNP9Ul3ksGHMw5QjZ DeSDl1wJ5ZphkOl8KBkbDLImaX+z3TR62nDI4E24hq3/JOXuo1wfT1izPmlP92Zk9Pyh C9OAsaVl4W+RmO1L1wqiAi5YN5JulYEXKT8gbUPA1CHIFwqQb2CHvblaWAA3y1EwrXuV Wg4k1jjoJ4lOWzwGlZBK4AhvJjEKDFnGREjhE4I9s2W/Vznkno4YWVIrpF1jePstBqno m1hA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z24-20020aa7cf98000000b0051be56c8f79si7031358edx.10.2023.06.30.01.24.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 01:24:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 766E6385414C for ; Fri, 30 Jun 2023 08:23:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 6381F3856DE7 for ; Fri, 30 Jun 2023 08:23:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6381F3856DE7 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="6.01,170,1684828800"; d="scan'208,223";a="10365837" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 30 Jun 2023 00:23:15 -0800 IronPort-SDR: /PmKUW0RWulrnJ+FhjwbNUzHAGIpue1MjH47Or3VKfbEaEcfudSoLDWwqkWNZF1vBJVYonJDg2 CE7ZEsl0TRqD75zuXD+eqcB/j8znypn0/7RIGRU5ZZ/llVqg3ZsW1ipBHKv6qHKtFKhi1absM/ 5jI60aa2aYMlkUYVxXqbWJOAKHdpKPyWN9KJGEUblLQfYiNLVypeqITmjIquh4e2ihEdfi83Et YTbJabqdtx6MX8jlcBjeZk/YFb15LQQdI4GpSWxPytA1KDApOnTYd3KzteEzC/JAMmZYdtr9CO 1W4= From: Thomas Schwinge To: , Richard Biener , "Jakub Jelinek" CC: Pan Li , , , , , , Tobias Burnus 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) In-Reply-To: <87sfaauit8.fsf@dem-tschwing-1.ger.mentorg.com> References: <20230619080710.1536456-1-pan2.li@intel.com> <20230621075824.1990571-1-pan2.li@intel.com> <874jmqwr8q.fsf@euler.schwinge.homeip.net> <87sfaauit8.fsf@dem-tschwing-1.ger.mentorg.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Fri, 30 Jun 2023 10:23:00 +0200 Message-ID: <87v8f5uzob.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770115240708697178?= X-GMAIL-MSGID: =?utf-8?q?1770115240708697178?= 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 From 1b75a8680bdef16633e3fa2479832a1b71dae43f Mon Sep 17 00:00:00 2001 From: Thomas Schwinge 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 (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