[pph] Fix relocations of included_from indices (issue5549045)

Diego Novillo dnovillo@google.com
Tue Jan 17 15:15:00 GMT 2012


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  <dnovillo@google.com>
+
+	* 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  <dnovillo@google.com>
 
 	* 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



More information about the Gcc-patches mailing list