teknoraver / rpms / rpm

Forked from rpms/rpm 3 months ago
Clone

Blame SOURCES/0002-NFC-debugedit-Move-code-from-edit_dwarf2-to-edit_inf.patch

813822
From de119ea9797f3ccfa3842e3926b6ea8198607207 Mon Sep 17 00:00:00 2001
813822
From: Jan Kratochvil <jan.kratochvil@redhat.com>
813822
Date: Sat, 1 Aug 2020 10:43:12 +0200
813822
Subject: [PATCH 2/6] [NFC] debugedit: Move code from edit_dwarf2() to
813822
 edit_info().
813822
813822
---
813822
 tools/debugedit.c | 672 +++++++++++++++++++++++-----------------------
813822
 1 file changed, 343 insertions(+), 329 deletions(-)
813822
813822
diff --git a/tools/debugedit.c b/tools/debugedit.c
813822
index a351adec8..cad0cc349 100644
813822
--- a/tools/debugedit.c
813822
+++ b/tools/debugedit.c
813822
@@ -1964,6 +1964,106 @@ line_rel_cmp (const void *a, const void *b)
813822
   return 0;
813822
 }
813822
 
813822
+static int
813822
+edit_info (DSO *dso, int phase)
813822
+{
813822
+  unsigned char *ptr, *endcu, *endsec;
813822
+  uint32_t value;
813822
+  htab_t abbrev;
813822
+  struct abbrev_tag tag, *t;
813822
+
813822
+  ptr = debug_sections[DEBUG_INFO].data;
813822
+  setup_relbuf(dso, &debug_sections[DEBUG_INFO], &reltype);
813822
+  endsec = ptr + debug_sections[DEBUG_INFO].size;
813822
+  while (ptr < endsec)
813822
+    {
813822
+      if (ptr + 11 > endsec)
813822
+	{
813822
+	  error (0, 0, "%s: .debug_info CU header too small",
813822
+		 dso->filename);
813822
+	  return 1;
813822
+	}
813822
+
813822
+      endcu = ptr + 4;
813822
+      endcu += read_32 (ptr);
813822
+      if (endcu == ptr + 0xffffffff)
813822
+	{
813822
+	  error (0, 0, "%s: 64-bit DWARF not supported", dso->filename);
813822
+	  return 1;
813822
+	}
813822
+
813822
+      if (endcu > endsec)
813822
+	{
813822
+	  error (0, 0, "%s: .debug_info too small", dso->filename);
813822
+	  return 1;
813822
+	}
813822
+
813822
+      cu_version = read_16 (ptr);
813822
+      if (cu_version != 2 && cu_version != 3 && cu_version != 4)
813822
+	{
813822
+	  error (0, 0, "%s: DWARF version %d unhandled", dso->filename,
813822
+		 cu_version);
813822
+	  return 1;
813822
+	}
813822
+
813822
+      value = read_32_relocated (ptr);
813822
+      if (value >= debug_sections[DEBUG_ABBREV].size)
813822
+	{
813822
+	  if (debug_sections[DEBUG_ABBREV].data == NULL)
813822
+	    error (0, 0, "%s: .debug_abbrev not present", dso->filename);
813822
+	  else
813822
+	    error (0, 0, "%s: DWARF CU abbrev offset too large",
813822
+		   dso->filename);
813822
+	  return 1;
813822
+	}
813822
+
813822
+      if (ptr_size == 0)
813822
+	{
813822
+	  ptr_size = read_8 (ptr);
813822
+	  if (ptr_size != 4 && ptr_size != 8)
813822
+	    {
813822
+	      error (0, 0, "%s: Invalid DWARF pointer size %d",
813822
+		     dso->filename, ptr_size);
813822
+	      return 1;
813822
+	    }
813822
+	}
813822
+      else if (read_8 (ptr) != ptr_size)
813822
+	{
813822
+	  error (0, 0, "%s: DWARF pointer size differs between CUs",
813822
+		 dso->filename);
813822
+	  return 1;
813822
+	}
813822
+
813822
+      abbrev = read_abbrev (dso,
813822
+			    debug_sections[DEBUG_ABBREV].data + value);
813822
+      if (abbrev == NULL)
813822
+	return 1;
813822
+
813822
+      while (ptr < endcu)
813822
+	{
813822
+	  tag.entry = read_uleb128 (ptr);
813822
+	  if (tag.entry == 0)
813822
+	    continue;
813822
+	  t = htab_find_with_hash (abbrev, &tag, tag.entry);
813822
+	  if (t == NULL)
813822
+	    {
813822
+	      error (0, 0, "%s: Could not find DWARF abbreviation %d",
813822
+		     dso->filename, tag.entry);
813822
+	      htab_delete (abbrev);
813822
+	      return 1;
813822
+	    }
813822
+
813822
+	  ptr = edit_attributes (dso, ptr, t, phase);
813822
+	  if (ptr == NULL)
813822
+	    break;
813822
+	}
813822
+
813822
+      htab_delete (abbrev);
813822
+    }
813822
+
813822
+  return 0;
813822
+}
813822
+
813822
 static int
813822
 edit_dwarf2 (DSO *dso)
813822
 {
813822
@@ -2100,385 +2200,299 @@ edit_dwarf2 (DSO *dso)
813822
       return 1;
813822
     }
813822
 
813822
-  if (debug_sections[DEBUG_INFO].data != NULL)
813822
+  if (debug_sections[DEBUG_INFO].data == NULL)
813822
+    return 0;
813822
+
813822
+  unsigned char *ptr, *endcu, *endsec;
813822
+  uint32_t value;
813822
+  htab_t abbrev;
813822
+  struct abbrev_tag tag, *t;
813822
+  int phase;
813822
+  bool info_rel_updated = false;
813822
+  bool macro_rel_updated = false;
813822
+
813822
+  for (phase = 0; phase < 2; phase++)
813822
     {
813822
-      unsigned char *ptr, *endcu, *endsec;
813822
-      uint32_t value;
813822
-      htab_t abbrev;
813822
-      struct abbrev_tag tag, *t;
813822
-      int phase;
813822
-      bool info_rel_updated = false;
813822
-      bool macro_rel_updated = false;
813822
+      /* If we don't need to update anyhing, skip phase 1. */
813822
+      if (phase == 1
813822
+	  && !need_strp_update
813822
+	  && !need_string_replacement
813822
+	  && !need_stmt_update)
813822
+	break;
813822
 
813822
-      for (phase = 0; phase < 2; phase++)
813822
+      rel_updated = false;
813822
+      if (edit_info (dso, phase))
813822
+       return 1;
813822
+
813822
+      /* Remember whether any .debug_info relocations might need
813822
+	 to be updated. */
813822
+      info_rel_updated = rel_updated;
813822
+
813822
+      /* We might have to recalculate/rewrite the debug_line
813822
+	 section.  We need to do that before going into phase one
813822
+	 so we have all new offsets.  We do this separately from
813822
+	 scanning the dirs/file names because the DW_AT_stmt_lists
813822
+	 might not be in order or skip some padding we might have
813822
+	 to (re)move. */
813822
+      if (phase == 0 && need_stmt_update)
813822
 	{
813822
-	  /* If we don't need to update anyhing, skip phase 1. */
813822
-	  if (phase == 1
813822
-	      && !need_strp_update
813822
-	      && !need_string_replacement
813822
-	      && !need_stmt_update)
813822
-	    break;
813822
+	  edit_dwarf2_line (dso);
813822
 
813822
-	  ptr = debug_sections[DEBUG_INFO].data;
813822
-	  setup_relbuf(dso, &debug_sections[DEBUG_INFO], &reltype);
813822
-	  rel_updated = false;
813822
-	  endsec = ptr + debug_sections[DEBUG_INFO].size;
813822
-	  while (ptr < endsec)
813822
+	  /* The line table programs will be moved
813822
+	     forward/backwards a bit in the new data. Update the
813822
+	     debug_line relocations to the new offsets. */
813822
+	  int rndx = debug_sections[DEBUG_LINE].relsec;
813822
+	  if (rndx != 0)
813822
 	    {
813822
-	      if (ptr + 11 > endsec)
813822
-		{
813822
-		  error (0, 0, "%s: .debug_info CU header too small",
813822
-			 dso->filename);
813822
-		  return 1;
813822
-		}
813822
-
813822
-	      endcu = ptr + 4;
813822
-	      endcu += read_32 (ptr);
813822
-	      if (endcu == ptr + 0xffffffff)
813822
-		{
813822
-		  error (0, 0, "%s: 64-bit DWARF not supported", dso->filename);
813822
-		  return 1;
813822
-		}
813822
-
813822
-	      if (endcu > endsec)
813822
-		{
813822
-		  error (0, 0, "%s: .debug_info too small", dso->filename);
813822
-		  return 1;
813822
-		}
813822
-
813822
-	      cu_version = read_16 (ptr);
813822
-	      if (cu_version != 2 && cu_version != 3 && cu_version != 4)
813822
-		{
813822
-		  error (0, 0, "%s: DWARF version %d unhandled", dso->filename,
813822
-			 cu_version);
813822
-		  return 1;
813822
-		}
813822
-
813822
-	      value = read_32_relocated (ptr);
813822
-	      if (value >= debug_sections[DEBUG_ABBREV].size)
813822
+	      LINE_REL *rbuf;
813822
+	      size_t rels;
813822
+	      Elf_Data *rdata = elf_getdata (dso->scn[rndx], NULL);
813822
+	      int rtype = dso->shdr[rndx].sh_type;
813822
+	      rels = dso->shdr[rndx].sh_size / dso->shdr[rndx].sh_entsize;
813822
+	      rbuf = malloc (rels * sizeof (LINE_REL));
813822
+	      if (rbuf == NULL)
813822
+		error (1, errno, "%s: Could not allocate line relocations",
813822
+		       dso->filename);
813822
+
813822
+	      /* Sort them by offset into section. */
813822
+	      for (size_t i = 0; i < rels; i++)
813822
 		{
813822
-		  if (debug_sections[DEBUG_ABBREV].data == NULL)
813822
-		    error (0, 0, "%s: .debug_abbrev not present", dso->filename);
813822
+		  if (rtype == SHT_RELA)
813822
+		    {
813822
+		      GElf_Rela rela;
813822
+		      if (gelf_getrela (rdata, i, &rela) == NULL)
813822
+			error (1, 0, "Couldn't get relocation: %s",
813822
+			       elf_errmsg (-1));
813822
+		      rbuf[i].r_offset = rela.r_offset;
813822
+		      rbuf[i].ndx = i;
813822
+		    }
813822
 		  else
813822
-		    error (0, 0, "%s: DWARF CU abbrev offset too large",
813822
-			   dso->filename);
813822
-		  return 1;
813822
-		}
813822
-
813822
-	      if (ptr_size == 0)
813822
-		{
813822
-		  ptr_size = read_8 (ptr);
813822
-		  if (ptr_size != 4 && ptr_size != 8)
813822
 		    {
813822
-		      error (0, 0, "%s: Invalid DWARF pointer size %d",
813822
-			     dso->filename, ptr_size);
813822
-		      return 1;
813822
+		      GElf_Rel rel;
813822
+		      if (gelf_getrel (rdata, i, &rel) == NULL)
813822
+			error (1, 0, "Couldn't get relocation: %s",
813822
+			       elf_errmsg (-1));
813822
+		      rbuf[i].r_offset = rel.r_offset;
813822
+		      rbuf[i].ndx = i;
813822
 		    }
813822
 		}
813822
-	      else if (read_8 (ptr) != ptr_size)
813822
-		{
813822
-		  error (0, 0, "%s: DWARF pointer size differs between CUs",
813822
-			 dso->filename);
813822
-		  return 1;
813822
-		}
813822
+	      qsort (rbuf, rels, sizeof (LINE_REL), line_rel_cmp);
813822
 
813822
-	      abbrev = read_abbrev (dso,
813822
-				    debug_sections[DEBUG_ABBREV].data + value);
813822
-	      if (abbrev == NULL)
813822
-		return 1;
813822
-
813822
-	      while (ptr < endcu)
813822
+	      size_t lndx = 0;
813822
+	      for (size_t i = 0; i < rels; i++)
813822
 		{
813822
-		  tag.entry = read_uleb128 (ptr);
813822
-		  if (tag.entry == 0)
813822
-		    continue;
813822
-		  t = htab_find_with_hash (abbrev, &tag, tag.entry);
813822
-		  if (t == NULL)
813822
+		  /* These relocations only happen in ET_REL files
813822
+		     and are section offsets. */
813822
+		  GElf_Addr r_offset;
813822
+		  size_t ndx = rbuf[i].ndx;
813822
+
813822
+		  GElf_Rel rel;
813822
+		  GElf_Rela rela;
813822
+		  if (rtype == SHT_RELA)
813822
 		    {
813822
-		      error (0, 0, "%s: Could not find DWARF abbreviation %d",
813822
-			     dso->filename, tag.entry);
813822
-		      htab_delete (abbrev);
813822
-		      return 1;
813822
+		      if (gelf_getrela (rdata, ndx, &rela) == NULL)
813822
+			error (1, 0, "Couldn't get relocation: %s",
813822
+			       elf_errmsg (-1));
813822
+		      r_offset = rela.r_offset;
813822
+		    }
813822
+		  else
813822
+		    {
813822
+		      if (gelf_getrel (rdata, ndx, &rel) == NULL)
813822
+			error (1, 0, "Couldn't get relocation: %s",
813822
+			       elf_errmsg (-1));
813822
+		      r_offset = rel.r_offset;
813822
 		    }
813822
 
813822
-		  ptr = edit_attributes (dso, ptr, t, phase);
813822
-		  if (ptr == NULL)
813822
-		    break;
813822
-		}
813822
+		  while (lndx < dso->lines.used
813822
+			 && r_offset > (dso->lines.table[lndx].old_idx
813822
+					+ 4
813822
+					+ dso->lines.table[lndx].unit_length))
813822
+		    lndx++;
813822
 
813822
-	      htab_delete (abbrev);
813822
-	    }
813822
+		  if (lndx >= dso->lines.used)
813822
+		    error (1, 0,
813822
+			   ".debug_line relocation offset out of range");
813822
 
813822
-	  /* Remember whether any .debug_info relocations might need
813822
-	     to be updated. */
813822
-	  info_rel_updated = rel_updated;
813822
-
813822
-	  /* We might have to recalculate/rewrite the debug_line
813822
-	     section.  We need to do that before going into phase one
813822
-	     so we have all new offsets.  We do this separately from
813822
-	     scanning the dirs/file names because the DW_AT_stmt_lists
813822
-	     might not be in order or skip some padding we might have
813822
-	     to (re)move. */
813822
-	  if (phase == 0 && need_stmt_update)
813822
-	    {
813822
-	      edit_dwarf2_line (dso);
813822
+		  /* Offset (pointing into the line program) moves
813822
+		     from old to new index including the header
813822
+		     size diff. */
813822
+		  r_offset += (ssize_t)((dso->lines.table[lndx].new_idx
813822
+					 - dso->lines.table[lndx].old_idx)
813822
+					+ dso->lines.table[lndx].size_diff);
813822
 
813822
-	      /* The line table programs will be moved
813822
-		 forward/backwards a bit in the new data. Update the
813822
-		 debug_line relocations to the new offsets. */
813822
-	      int rndx = debug_sections[DEBUG_LINE].relsec;
813822
-	      if (rndx != 0)
813822
-		{
813822
-		  LINE_REL *rbuf;
813822
-		  size_t rels;
813822
-		  Elf_Data *rdata = elf_getdata (dso->scn[rndx], NULL);
813822
-		  int rtype = dso->shdr[rndx].sh_type;
813822
-		  rels = dso->shdr[rndx].sh_size / dso->shdr[rndx].sh_entsize;
813822
-		  rbuf = malloc (rels * sizeof (LINE_REL));
813822
-		  if (rbuf == NULL)
813822
-		    error (1, errno, "%s: Could not allocate line relocations",
813822
-			   dso->filename);
813822
-
813822
-		  /* Sort them by offset into section. */
813822
-		  for (size_t i = 0; i < rels; i++)
813822
+		  if (rtype == SHT_RELA)
813822
 		    {
813822
-		      if (rtype == SHT_RELA)
813822
-			{
813822
-			  GElf_Rela rela;
813822
-			  if (gelf_getrela (rdata, i, &rela) == NULL)
813822
-			    error (1, 0, "Couldn't get relocation: %s",
813822
-				   elf_errmsg (-1));
813822
-			  rbuf[i].r_offset = rela.r_offset;
813822
-			  rbuf[i].ndx = i;
813822
-			}
813822
-		      else
813822
-			{
813822
-			  GElf_Rel rel;
813822
-			  if (gelf_getrel (rdata, i, &rel) == NULL)
813822
-			    error (1, 0, "Couldn't get relocation: %s",
813822
-				   elf_errmsg (-1));
813822
-			  rbuf[i].r_offset = rel.r_offset;
813822
-			  rbuf[i].ndx = i;
813822
-			}
813822
+		      rela.r_offset = r_offset;
813822
+		      if (gelf_update_rela (rdata, ndx, &rela) == 0)
813822
+			error (1, 0, "Couldn't update relocation: %s",
813822
+			       elf_errmsg (-1));
813822
 		    }
813822
-		  qsort (rbuf, rels, sizeof (LINE_REL), line_rel_cmp);
813822
-
813822
-		  size_t lndx = 0;
813822
-		  for (size_t i = 0; i < rels; i++)
813822
+		  else
813822
 		    {
813822
-		      /* These relocations only happen in ET_REL files
813822
-			 and are section offsets. */
813822
-		      GElf_Addr r_offset;
813822
-		      size_t ndx = rbuf[i].ndx;
813822
-
813822
-		      GElf_Rel rel;
813822
-		      GElf_Rela rela;
813822
-		      if (rtype == SHT_RELA)
813822
-			{
813822
-			  if (gelf_getrela (rdata, ndx, &rela) == NULL)
813822
-			    error (1, 0, "Couldn't get relocation: %s",
813822
-				   elf_errmsg (-1));
813822
-			  r_offset = rela.r_offset;
813822
-			}
813822
-		      else
813822
-			{
813822
-			  if (gelf_getrel (rdata, ndx, &rel) == NULL)
813822
-			    error (1, 0, "Couldn't get relocation: %s",
813822
-				   elf_errmsg (-1));
813822
-			  r_offset = rel.r_offset;
813822
-			}
813822
-
813822
-		      while (lndx < dso->lines.used
813822
-			     && r_offset > (dso->lines.table[lndx].old_idx
813822
-					    + 4
813822
-					    + dso->lines.table[lndx].unit_length))
813822
-			lndx++;
813822
-
813822
-		      if (lndx >= dso->lines.used)
813822
-			error (1, 0,
813822
-			       ".debug_line relocation offset out of range");
813822
-
813822
-		      /* Offset (pointing into the line program) moves
813822
-			 from old to new index including the header
813822
-			 size diff. */
813822
-		      r_offset += (ssize_t)((dso->lines.table[lndx].new_idx
813822
-					     - dso->lines.table[lndx].old_idx)
813822
-					    + dso->lines.table[lndx].size_diff);
813822
-
813822
-		      if (rtype == SHT_RELA)
813822
-			{
813822
-			  rela.r_offset = r_offset;
813822
-			  if (gelf_update_rela (rdata, ndx, &rela) == 0)
813822
-			    error (1, 0, "Couldn't update relocation: %s",
813822
-				   elf_errmsg (-1));
813822
-			}
813822
-		      else
813822
-			{
813822
-			  rel.r_offset = r_offset;
813822
-			  if (gelf_update_rel (rdata, ndx, &rel) == 0)
813822
-			    error (1, 0, "Couldn't update relocation: %s",
813822
-				   elf_errmsg (-1));
813822
-			}
813822
+		      rel.r_offset = r_offset;
813822
+		      if (gelf_update_rel (rdata, ndx, &rel) == 0)
813822
+			error (1, 0, "Couldn't update relocation: %s",
813822
+			       elf_errmsg (-1));
813822
 		    }
813822
-
813822
-		  elf_flagdata (rdata, ELF_C_SET, ELF_F_DIRTY);
813822
-		  free (rbuf);
813822
 		}
813822
+
813822
+	      elf_flagdata (rdata, ELF_C_SET, ELF_F_DIRTY);
813822
+	      free (rbuf);
813822
 	    }
813822
+	}
813822
 
813822
-	  /* The .debug_macro section also contains offsets into the
813822
-	     .debug_str section and references to the .debug_line
813822
-	     tables, so we need to update those as well if we update
813822
-	     the strings or the stmts.  */
813822
-	  if ((need_strp_update || need_stmt_update)
813822
-	      && debug_sections[DEBUG_MACRO].data)
813822
+      /* The .debug_macro section also contains offsets into the
813822
+	 .debug_str section and references to the .debug_line
813822
+	 tables, so we need to update those as well if we update
813822
+	 the strings or the stmts.  */
813822
+      if ((need_strp_update || need_stmt_update)
813822
+	  && debug_sections[DEBUG_MACRO].data)
813822
+	{
813822
+	  /* There might be multiple (COMDAT) .debug_macro sections.  */
813822
+	  struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO];
813822
+	  while (macro_sec != NULL)
813822
 	    {
813822
-	      /* There might be multiple (COMDAT) .debug_macro sections.  */
813822
-	      struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO];
813822
-	      while (macro_sec != NULL)
813822
-		{
813822
-		  setup_relbuf(dso, macro_sec, &reltype);
813822
-		  rel_updated = false;
813822
+	      setup_relbuf(dso, macro_sec, &reltype);
813822
+	      rel_updated = false;
813822
 
813822
-		  ptr = macro_sec->data;
813822
-		  endsec = ptr + macro_sec->size;
813822
-		  int op = 0, macro_version, macro_flags;
813822
-		  int offset_len = 4, line_offset = 0;
813822
+	      ptr = macro_sec->data;
813822
+	      endsec = ptr + macro_sec->size;
813822
+	      int op = 0, macro_version, macro_flags;
813822
+	      int offset_len = 4, line_offset = 0;
813822
 
813822
-		  while (ptr < endsec)
813822
+	      while (ptr < endsec)
813822
+		{
813822
+		  if (!op)
813822
 		    {
813822
-		      if (!op)
813822
-			{
813822
-			  macro_version = read_16 (ptr);
813822
-			  macro_flags = read_8 (ptr);
813822
-			  if (macro_version < 4 || macro_version > 5)
813822
-			    error (1, 0, "unhandled .debug_macro version: %d",
813822
-				   macro_version);
813822
-			  if ((macro_flags & ~2) != 0)
813822
-			    error (1, 0, "unhandled .debug_macro flags: 0x%x",
813822
-				   macro_flags);
813822
-
813822
-			  offset_len = (macro_flags & 0x01) ? 8 : 4;
813822
-			  line_offset = (macro_flags & 0x02) ? 1 : 0;
813822
-
813822
-			  if (offset_len != 4)
813822
-			    error (0, 1,
813822
-				   "Cannot handle 8 byte macro offsets: %s",
813822
-				   dso->filename);
813822
-
813822
-			  /* Update the line_offset if it is there.  */
813822
-			  if (line_offset)
813822
-			    {
813822
-			      if (phase == 0)
813822
-				ptr += offset_len;
813822
-			      else
813822
-				{
813822
-				  size_t idx, new_idx;
813822
-				  idx = do_read_32_relocated (ptr);
813822
-				  new_idx = find_new_list_offs (&dso->lines,
813822
-								idx);
813822
-				  write_32_relocated (ptr, new_idx);
813822
-				}
813822
-			    }
813822
-			}
813822
+		      macro_version = read_16 (ptr);
813822
+		      macro_flags = read_8 (ptr);
813822
+		      if (macro_version < 4 || macro_version > 5)
813822
+			error (1, 0, "unhandled .debug_macro version: %d",
813822
+			       macro_version);
813822
+		      if ((macro_flags & ~2) != 0)
813822
+			error (1, 0, "unhandled .debug_macro flags: 0x%x",
813822
+			       macro_flags);
813822
+
813822
+		      offset_len = (macro_flags & 0x01) ? 8 : 4;
813822
+		      line_offset = (macro_flags & 0x02) ? 1 : 0;
813822
+
813822
+		      if (offset_len != 4)
813822
+			error (0, 1,
813822
+			       "Cannot handle 8 byte macro offsets: %s",
813822
+			       dso->filename);
813822
 
813822
-		      op = read_8 (ptr);
813822
-		      if (!op)
813822
-			continue;
813822
-		      switch(op)
813822
+		      /* Update the line_offset if it is there.  */
813822
+		      if (line_offset)
813822
 			{
813822
-			case DW_MACRO_GNU_define:
813822
-			case DW_MACRO_GNU_undef:
813822
-			  read_uleb128 (ptr);
813822
-			  ptr = ((unsigned char *) strchr ((char *) ptr, '\0')
813822
-				 + 1);
813822
-			  break;
813822
-			case DW_MACRO_GNU_start_file:
813822
-			  read_uleb128 (ptr);
813822
-			  read_uleb128 (ptr);
813822
-			  break;
813822
-			case DW_MACRO_GNU_end_file:
813822
-			  break;
813822
-			case DW_MACRO_GNU_define_indirect:
813822
-			case DW_MACRO_GNU_undef_indirect:
813822
-			  read_uleb128 (ptr);
813822
 			  if (phase == 0)
813822
-			    {
813822
-			      size_t idx = read_32_relocated (ptr);
813822
-			      record_existing_string_entry_idx (&dso->strings,
813822
-								idx);
813822
-			    }
813822
+			    ptr += offset_len;
813822
 			  else
813822
 			    {
813822
-			      struct stridxentry *entry;
813822
 			      size_t idx, new_idx;
813822
 			      idx = do_read_32_relocated (ptr);
813822
-			      entry = string_find_entry (&dso->strings, idx);
813822
-			      new_idx = strent_offset (entry->entry);
813822
+			      new_idx = find_new_list_offs (&dso->lines,
813822
+							    idx);
813822
 			      write_32_relocated (ptr, new_idx);
813822
 			    }
813822
-			  break;
813822
-			case DW_MACRO_GNU_transparent_include:
813822
-			  ptr += offset_len;
813822
-			  break;
813822
-			default:
813822
-			  error (1, 0, "Unhandled DW_MACRO op 0x%x", op);
813822
-			  break;
813822
 			}
813822
 		    }
813822
 
813822
-		  if (rel_updated)
813822
-		    macro_rel_updated = true;
813822
-		  macro_sec = macro_sec->next;
813822
+		  op = read_8 (ptr);
813822
+		  if (!op)
813822
+		    continue;
813822
+		  switch(op)
813822
+		    {
813822
+		    case DW_MACRO_GNU_define:
813822
+		    case DW_MACRO_GNU_undef:
813822
+		      read_uleb128 (ptr);
813822
+		      ptr = ((unsigned char *) strchr ((char *) ptr, '\0')
813822
+			     + 1);
813822
+		      break;
813822
+		    case DW_MACRO_GNU_start_file:
813822
+		      read_uleb128 (ptr);
813822
+		      read_uleb128 (ptr);
813822
+		      break;
813822
+		    case DW_MACRO_GNU_end_file:
813822
+		      break;
813822
+		    case DW_MACRO_GNU_define_indirect:
813822
+		    case DW_MACRO_GNU_undef_indirect:
813822
+		      read_uleb128 (ptr);
813822
+		      if (phase == 0)
813822
+			{
813822
+			  size_t idx = read_32_relocated (ptr);
813822
+			  record_existing_string_entry_idx (&dso->strings,
813822
+							    idx);
813822
+			}
813822
+		      else
813822
+			{
813822
+			  struct stridxentry *entry;
813822
+			  size_t idx, new_idx;
813822
+			  idx = do_read_32_relocated (ptr);
813822
+			  entry = string_find_entry (&dso->strings, idx);
813822
+			  new_idx = strent_offset (entry->entry);
813822
+			  write_32_relocated (ptr, new_idx);
813822
+			}
813822
+		      break;
813822
+		    case DW_MACRO_GNU_transparent_include:
813822
+		      ptr += offset_len;
813822
+		      break;
813822
+		    default:
813822
+		      error (1, 0, "Unhandled DW_MACRO op 0x%x", op);
813822
+		      break;
813822
+		    }
813822
 		}
813822
-	    }
813822
 
813822
-	  /* Same for the debug_str section. Make sure everything is
813822
-	     in place for phase 1 updating of debug_info
813822
-	     references. */
813822
-	  if (phase == 0 && need_strp_update)
813822
-	    {
813822
-	      Strtab *strtab = dso->strings.str_tab;
813822
-	      Elf_Data *strdata = debug_sections[DEBUG_STR].elf_data;
813822
-	      int strndx = debug_sections[DEBUG_STR].sec;
813822
-	      Elf_Scn *strscn = dso->scn[strndx];
813822
-
813822
-	      /* Out with the old. */
813822
-	      strdata->d_size = 0;
813822
-	      /* In with the new. */
813822
-	      strdata = elf_newdata (strscn);
813822
-
813822
-	      /* We really should check whether we had enough memory,
813822
-		 but the old ebl version will just abort on out of
813822
-		 memory... */
813822
-	      strtab_finalize (strtab, strdata);
813822
-	      debug_sections[DEBUG_STR].size = strdata->d_size;
813822
-	      dso->strings.str_buf = strdata->d_buf;
813822
+	      if (rel_updated)
813822
+		macro_rel_updated = true;
813822
+	      macro_sec = macro_sec->next;
813822
 	    }
813822
+	}
813822
 
813822
+      /* Same for the debug_str section. Make sure everything is
813822
+	 in place for phase 1 updating of debug_info
813822
+	 references. */
813822
+      if (phase == 0 && need_strp_update)
813822
+	{
813822
+	  Strtab *strtab = dso->strings.str_tab;
813822
+	  Elf_Data *strdata = debug_sections[DEBUG_STR].elf_data;
813822
+	  int strndx = debug_sections[DEBUG_STR].sec;
813822
+	  Elf_Scn *strscn = dso->scn[strndx];
813822
+
813822
+	  /* Out with the old. */
813822
+	  strdata->d_size = 0;
813822
+	  /* In with the new. */
813822
+	  strdata = elf_newdata (strscn);
813822
+
813822
+	  /* We really should check whether we had enough memory,
813822
+	     but the old ebl version will just abort on out of
813822
+	     memory... */
813822
+	  strtab_finalize (strtab, strdata);
813822
+	  debug_sections[DEBUG_STR].size = strdata->d_size;
813822
+	  dso->strings.str_buf = strdata->d_buf;
813822
 	}
813822
 
813822
-      /* After phase 1 we might have rewritten the debug_info with
813822
-	 new strp, strings and/or linep offsets.  */
813822
-      if (need_strp_update || need_string_replacement || need_stmt_update)
813822
-	dirty_section (DEBUG_INFO);
813822
-      if (need_strp_update || need_stmt_update)
813822
-	dirty_section (DEBUG_MACRO);
813822
-      if (need_stmt_update)
813822
-	dirty_section (DEBUG_LINE);
813822
+    }
813822
+
813822
+  /* After phase 1 we might have rewritten the debug_info with
813822
+     new strp, strings and/or linep offsets.  */
813822
+  if (need_strp_update || need_string_replacement || need_stmt_update)
813822
+    dirty_section (DEBUG_INFO);
813822
+  if (need_strp_update || need_stmt_update)
813822
+    dirty_section (DEBUG_MACRO);
813822
+  if (need_stmt_update)
813822
+    dirty_section (DEBUG_LINE);
813822
 
813822
-      /* Update any relocations addends we might have touched. */
813822
-      if (info_rel_updated)
813822
-	update_rela_data (dso, &debug_sections[DEBUG_INFO]);
813822
+  /* Update any relocations addends we might have touched. */
813822
+  if (info_rel_updated)
813822
+    update_rela_data (dso, &debug_sections[DEBUG_INFO]);
813822
 
813822
-      if (macro_rel_updated)
813822
+  if (macro_rel_updated)
813822
+    {
813822
+      struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO];
813822
+      while (macro_sec != NULL)
813822
 	{
813822
-	  struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO];
813822
-	  while (macro_sec != NULL)
813822
-	    {
813822
-	      update_rela_data (dso, macro_sec);
813822
-	      macro_sec = macro_sec->next;
813822
-	    }
813822
+	  update_rela_data (dso, macro_sec);
813822
+	  macro_sec = macro_sec->next;
813822
 	}
813822
     }
813822
 
813822
-- 
813822
2.18.4
813822