Patchwork [google/gcc-4_7,google/gcc-4_8] Fix non-deterministic output with -gsplit-dwarf

login
register
mail settings
Submitter Cary Coutant
Date July 2, 2013, 8:37 p.m.
Message ID <20130702203743.727A7160B7C@ccoutant.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/256510/
State New
Headers show

Comments

Cary Coutant - July 2, 2013, 8:37 p.m.
This patch is for the google/gcc-4_7 and google/gcc-4_8 branches.

When using -gsplit-dwarf, we use die_checksum to calculate a hash
over the compilation unit for the DW_AT_dwo_id attribute.  When
hashing location expressions, the hash may include pointers that
can vary from run to run of GCC.  This patch fixes loc_checksum
to use the (already existing) hash_loc_operands function, which
calculates a hash deterministically.

OK for google branches?

Google ref: 9654852


2013-07-02  Cary Coutant  <ccoutant@google.com>

gcc/
	* dwarf2out.c (loc_checksum): Call hash_loc_operands for a
	deterministic hash.
	(loc_checksum_ordered): Likewise.
	(hash_loc_operands): Remove inline keyword.
Sterling Augustine - July 2, 2013, 9:23 p.m.
On Tue, Jul 2, 2013 at 1:37 PM, Cary Coutant <ccoutant@google.com> wrote:
>
> This patch is for the google/gcc-4_7 and google/gcc-4_8 branches.
>
> When using -gsplit-dwarf, we use die_checksum to calculate a hash
> over the compilation unit for the DW_AT_dwo_id attribute.  When
> hashing location expressions, the hash may include pointers that
> can vary from run to run of GCC.  This patch fixes loc_checksum
> to use the (already existing) hash_loc_operands function, which
> calculates a hash deterministically.
>
> OK for google branches?

This patch is OK for google branches, and probably ought to be applied
to trunk at some point.

Sterling

Patch

Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c	(revision 200619)
+++ gcc/dwarf2out.c	(working copy)
@@ -3618,6 +3618,8 @@  static void gen_scheduled_generic_parms_
 
 static const char *comp_dir_string (void);
 
+static hashval_t hash_loc_operands (dw_loc_descr_ref, hashval_t);
+
 /* enum for tracking thread-local variables whose address is really an offset
    relative to the TLS pointer, which will need link-time relocation, but will
    not need relocation by the DWARF consumer.  */
@@ -6268,11 +6270,12 @@  static inline void
 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
 {
   int tem;
+  hashval_t hash = 0;
 
   tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
   CHECKSUM (tem);
-  CHECKSUM (loc->dw_loc_oprnd1);
-  CHECKSUM (loc->dw_loc_oprnd2);
+  hash = hash_loc_operands (loc, hash);
+  CHECKSUM (hash);
 }
 
 /* Calculate the checksum of an attribute.  */
@@ -6474,9 +6477,12 @@  loc_checksum_ordered (dw_loc_descr_ref l
   /* Otherwise, just checksum the raw location expression.  */
   while (loc != NULL)
     {
+      hashval_t hash = 0;
+
+      CHECKSUM_ULEB128 (loc->dtprel);
       CHECKSUM_ULEB128 (loc->dw_loc_opc);
-      CHECKSUM (loc->dw_loc_oprnd1);
-      CHECKSUM (loc->dw_loc_oprnd2);
+      hash = hash_loc_operands (loc, hash);
+      CHECKSUM (hash);
       loc = loc->dw_loc_next;
     }
 }
@@ -23399,7 +23405,7 @@  resolve_addr (dw_die_ref die)
 
 /* Iteratively hash operands of LOC opcode.  */
 
-static inline hashval_t
+static hashval_t
 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
 {
   dw_val_ref val1 = &loc->dw_loc_oprnd1;