Make debugedit -i recompute build ID only when any DWARF was actually changed.
authorRoland McGrath <roland@redhat.com>
Tue, 11 May 2010 03:05:48 +0000 (20:05 -0700)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 11 May 2010 12:09:53 +0000 (15:09 +0300)
tools/debugedit.c

index 23a21a5..820e5aa 100644 (file)
@@ -454,6 +454,14 @@ has_prefix (const char  *str,
   return strncmp (str, prefix, prefix_len) == 0;
 }
 
+static int dirty_elf;
+static void
+dirty_section (unsigned int sec)
+{
+  elf_flagdata (debug_sections[sec].elf_data, ELF_C_SET, ELF_F_DIRTY);
+  dirty_elf = 1;
+}
+
 static int
 edit_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir, int phase)
 {
@@ -628,6 +636,8 @@ edit_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir, int phase)
          size_t len = strlen ((char *)srcptr) + 1;
          const unsigned char *readptr = srcptr;
 
+         char *orig = strdup ((const char *) srcptr);
+
          if (*srcptr == '/' && has_prefix ((char *)srcptr, base_dir))
            {
              if (dest_len < base_len)
@@ -644,8 +654,9 @@ edit_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir, int phase)
          shrank -= len;
          ptr += len;
 
-         elf_flagdata (debug_sections[DEBUG_STR].elf_data,
-                       ELF_C_SET, ELF_F_DIRTY);
+         if (memcmp (orig, ptr - len, len))
+           dirty_section (DEBUG_STR);
+         free (orig);
        }
 
       if (shrank > 0)
@@ -687,8 +698,7 @@ edit_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir, int phase)
                           len - base_len);
                  ptr += dest_len - base_len;
                }
-             elf_flagdata (debug_sections[DEBUG_STR].elf_data,
-                           ELF_C_SET, ELF_F_DIRTY);
+             dirty_section (DEBUG_STR);
            }
          else if (ptr != srcptr)
            memmove (ptr, srcptr, len);
@@ -755,11 +765,9 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
                                 base_len - dest_len);
 
                        }
-                     elf_flagdata (debug_sections[DEBUG_INFO].elf_data,
-                                   ELF_C_SET, ELF_F_DIRTY);
+                     dirty_section (DEBUG_INFO);
                    }
                }
-
              else if (form == DW_FORM_strp &&
                       debug_sections[DEBUG_STR].data)
                {
@@ -782,8 +790,7 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
                          memmove (dir + dest_len, dir + base_len,
                                   strlen (dir + base_len) + 1);
                        }
-                     elf_flagdata (debug_sections[DEBUG_STR].elf_data,
-                                   ELF_C_SET, ELF_F_DIRTY);
+                     dirty_section (DEBUG_STR);
                    }
                }
            }
@@ -822,8 +829,7 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
                      memmove (name + dest_len, name + base_len,
                               strlen (name + base_len) + 1);
                    }
-                 elf_flagdata (debug_sections[DEBUG_STR].elf_data,
-                               ELF_C_SET, ELF_F_DIRTY);
+                 dirty_section (DEBUG_STR);
                }
            }
 
@@ -1365,6 +1371,9 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
       exit (1);
     }
 
+  if (!dirty_elf)
+    goto print;
+
   if (elf_update (dso->elf, ELF_C_NULL) < 0)
     {
       fprintf (stderr, "Failed to update file: %s\n",
@@ -1444,6 +1453,7 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
 
   elf_flagdata (build_id, ELF_C_SET, ELF_F_DIRTY);
 
+ print:
   /* Now format the build ID bits in hex to print out.  */
   {
     const uint8_t * id = (uint8_t *)build_id->d_buf + build_id_offset;