Make debugedit -i recompute build ID only when any DWARF was actually changed.
This commit is contained in:
parent
c4b6362353
commit
e6a0b0e566
|
@ -454,6 +454,14 @@ has_prefix (const char *str,
|
||||||
return strncmp (str, prefix, prefix_len) == 0;
|
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
|
static int
|
||||||
edit_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir, int phase)
|
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;
|
size_t len = strlen ((char *)srcptr) + 1;
|
||||||
const unsigned char *readptr = srcptr;
|
const unsigned char *readptr = srcptr;
|
||||||
|
|
||||||
|
char *orig = strdup ((const char *) srcptr);
|
||||||
|
|
||||||
if (*srcptr == '/' && has_prefix ((char *)srcptr, base_dir))
|
if (*srcptr == '/' && has_prefix ((char *)srcptr, base_dir))
|
||||||
{
|
{
|
||||||
if (dest_len < base_len)
|
if (dest_len < base_len)
|
||||||
|
@ -644,8 +654,9 @@ edit_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir, int phase)
|
||||||
shrank -= len;
|
shrank -= len;
|
||||||
ptr += len;
|
ptr += len;
|
||||||
|
|
||||||
elf_flagdata (debug_sections[DEBUG_STR].elf_data,
|
if (memcmp (orig, ptr - len, len))
|
||||||
ELF_C_SET, ELF_F_DIRTY);
|
dirty_section (DEBUG_STR);
|
||||||
|
free (orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shrank > 0)
|
if (shrank > 0)
|
||||||
|
@ -687,8 +698,7 @@ edit_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir, int phase)
|
||||||
len - base_len);
|
len - base_len);
|
||||||
ptr += dest_len - base_len;
|
ptr += dest_len - base_len;
|
||||||
}
|
}
|
||||||
elf_flagdata (debug_sections[DEBUG_STR].elf_data,
|
dirty_section (DEBUG_STR);
|
||||||
ELF_C_SET, ELF_F_DIRTY);
|
|
||||||
}
|
}
|
||||||
else if (ptr != srcptr)
|
else if (ptr != srcptr)
|
||||||
memmove (ptr, srcptr, len);
|
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);
|
base_len - dest_len);
|
||||||
|
|
||||||
}
|
}
|
||||||
elf_flagdata (debug_sections[DEBUG_INFO].elf_data,
|
dirty_section (DEBUG_INFO);
|
||||||
ELF_C_SET, ELF_F_DIRTY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (form == DW_FORM_strp &&
|
else if (form == DW_FORM_strp &&
|
||||||
debug_sections[DEBUG_STR].data)
|
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,
|
memmove (dir + dest_len, dir + base_len,
|
||||||
strlen (dir + base_len) + 1);
|
strlen (dir + base_len) + 1);
|
||||||
}
|
}
|
||||||
elf_flagdata (debug_sections[DEBUG_STR].elf_data,
|
dirty_section (DEBUG_STR);
|
||||||
ELF_C_SET, ELF_F_DIRTY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -822,8 +829,7 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
|
||||||
memmove (name + dest_len, name + base_len,
|
memmove (name + dest_len, name + base_len,
|
||||||
strlen (name + base_len) + 1);
|
strlen (name + base_len) + 1);
|
||||||
}
|
}
|
||||||
elf_flagdata (debug_sections[DEBUG_STR].elf_data,
|
dirty_section (DEBUG_STR);
|
||||||
ELF_C_SET, ELF_F_DIRTY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1365,6 +1371,9 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dirty_elf)
|
||||||
|
goto print;
|
||||||
|
|
||||||
if (elf_update (dso->elf, ELF_C_NULL) < 0)
|
if (elf_update (dso->elf, ELF_C_NULL) < 0)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Failed to update file: %s\n",
|
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);
|
elf_flagdata (build_id, ELF_C_SET, ELF_F_DIRTY);
|
||||||
|
|
||||||
|
print:
|
||||||
/* Now format the build ID bits in hex to print out. */
|
/* Now format the build ID bits in hex to print out. */
|
||||||
{
|
{
|
||||||
const uint8_t * id = (uint8_t *)build_id->d_buf + build_id_offset;
|
const uint8_t * id = (uint8_t *)build_id->d_buf + build_id_offset;
|
||||||
|
|
Loading…
Reference in New Issue