From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4327 invoked by alias); 17 Jan 2012 15:15:12 -0000 Received: (qmail 4318 invoked by uid 22791); 17 Jan 2012 15:15:11 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,TW_SV,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-yw0-f73.google.com (HELO mail-yw0-f73.google.com) (209.85.213.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 17 Jan 2012 15:14:58 +0000 Received: by yhpp56 with SMTP id p56so461818yhp.2 for ; Tue, 17 Jan 2012 07:14:58 -0800 (PST) Received: by 10.236.131.138 with SMTP id m10mr23645537yhi.7.1326813298036; Tue, 17 Jan 2012 07:14:58 -0800 (PST) Received: by 10.236.131.138 with SMTP id m10mr23645514yhi.7.1326813297762; Tue, 17 Jan 2012 07:14:57 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id g10si7383655yhn.7.2012.01.17.07.14.57 (version=TLSv1/SSLv3 cipher=AES128-SHA); Tue, 17 Jan 2012 07:14:57 -0800 (PST) Received: from tobiano.tor.corp.google.com (tobiano.tor.corp.google.com [172.29.41.6]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 976A01E004D; Tue, 17 Jan 2012 07:14:57 -0800 (PST) Received: by tobiano.tor.corp.google.com (Postfix, from userid 54752) id BB598AE1D7; Tue, 17 Jan 2012 10:14:56 -0500 (EST) To: reply@codereview.appspotmail.com,crowl@google.com,gcc-patches@gcc.gnu.org Subject: [pph] Fix relocations of included_from indices (issue5549045) Message-Id: <20120117151456.BB598AE1D7@tobiano.tor.corp.google.com> Date: Tue, 17 Jan 2012 15:15:00 -0000 From: dnovillo@google.com (Diego Novillo) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-01/txt/msg00852.txt.bz2 In a line map entry, there is a field 'included_from' which is the index into the line table corresponding to the file that is including the current line map entry. This index is an absolute value, but given that PPH images may be loaded in different order from different TUs, absolute values cannot be used. Instead, we save an offset from the entry back to its includer. The problem we were having is that I had messed up the reconstruction of the value. I switched the order of the subtraction operands, so we were computing negative absolute values. Produces various failures in larger tests. * pph-in.c (pph_in_line_table_and_includes): Fix computation of includer file index relocation. * pph-out.c (pph_out_line_map_ordinary): Add documentation. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/pph@183229 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog.pph | 6 ++++++ gcc/cp/pph-in.c | 7 ++++++- gcc/cp/pph-out.c | 18 ++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/gcc/cp/ChangeLog.pph b/gcc/cp/ChangeLog.pph index d04a55d..8ea94b2 100644 --- a/gcc/cp/ChangeLog.pph +++ b/gcc/cp/ChangeLog.pph @@ -1,3 +1,9 @@ +2012-01-13 Diego Novillo + + * pph-in.c (pph_in_line_table_and_includes): Fix computation of + includer file index relocation. + * pph-out.c (pph_out_line_map_ordinary): Add documentation. + 2011-12-12 Diego Novillo * pph-out.c (pph_out_global_binding): Do not assert that diff --git a/gcc/cp/pph-in.c b/gcc/cp/pph-in.c index 780d208..aba7be0 100644 --- a/gcc/cp/pph-in.c +++ b/gcc/cp/pph-in.c @@ -409,7 +409,12 @@ pph_in_line_table_and_includes (pph_stream *stream) if (ORDINARY_MAP_INCLUDER_FILE_INDEX (lm) == -1) ORDINARY_MAP_INCLUDER_FILE_INDEX (lm) = top_includer_ix; else - ORDINARY_MAP_INCLUDER_FILE_INDEX (lm) -= last_entry_ix; + { + gcc_assert (last_entry_ix + > ORDINARY_MAP_INCLUDER_FILE_INDEX (lm)); + ORDINARY_MAP_INCLUDER_FILE_INDEX (lm) + = last_entry_ix - ORDINARY_MAP_INCLUDER_FILE_INDEX (lm); + } lm->start_location += pph_loc_offset; } diff --git a/gcc/cp/pph-out.c b/gcc/cp/pph-out.c index a001aa4..4aa1d65 100644 --- a/gcc/cp/pph-out.c +++ b/gcc/cp/pph-out.c @@ -226,8 +226,22 @@ pph_out_line_map_ordinary (pph_stream *stream, struct line_map *lm, int ix) /* To support relocating this table into other translation units, emit a relative index to LM's includer. All the relative indices - are positive values indicating the distance from LM to the line - map for its includer. */ + are positive values indicating the distance from LM *back* to the + line map for its includer. + + So, if we had header top.h including [1234].h, the line table + entries look something like this: + + Map #10 LC_ENTER "top.h" FROM: -1 (top file). + Map #11 LC_ENTER "1.h" FROM: 10 (top.h) -> saved as offset 1 (11 - 10). + Map #12 LC_ENTER "2.h" FROM: 10 (top.h) -> saved as offset 2 (12 - 10). + Map #13 LC_ENTER "3.h" FROM: 10 (top.h) -> saved as offset 3 (13 - 10). + Map #14 LC_ENTER "4.h" FROM: 10 (top.h) -> saved as offset 4 (14 - 10). + + When saving the map entry for #13 (3.h), we do not want to save + the absolute index value '10', since top.pph may be included from + different TUs. Instead, we save the offset 3, so that the reader + knows that the includer for 3.h is 3 slots before 3.h's entry. */ includer_ix = ORDINARY_MAP_INCLUDER_FILE_INDEX (lm); if (includer_ix >= 0) { -- 1.7.7.3 -- This patch is available for review at http://codereview.appspot.com/5549045