[PATCH] Don't handle blocks as exprlocs for DWARF version 4 or higher.

Mark Wielaard mark@klomp.org
Sat Feb 13 22:46:22 GMT 2021


Since DWARF version 4 blocks just contain bytes, trying to interpret
them as exprlocs will most likely fail.

     * dwz.c (add_locexpr_dummy_dies): Only handle block as exprloc
     for cu_version < 4.
     (checksum_die): Likewise.
     (write_die): Likewise.

https://sourceware.org/bugzilla/show_bug.cgi?id=26987
---
 dwz.c | 166 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 84 insertions(+), 82 deletions(-)

diff --git a/dwz.c b/dwz.c
index d6b9df0..02fcd8c 100644
--- a/dwz.c
+++ b/dwz.c
@@ -2913,43 +2913,44 @@ add_locexpr_dummy_dies (DSO *dso, dw_cu_ref cu, dw_die_ref die,
   if (form == DW_FORM_block1)
     {
       /* Old DWARF uses blocks instead of exprlocs.  */
-      switch (attr)
-	{
-	case DW_AT_frame_base:
-	case DW_AT_location:
-	case DW_AT_data_member_location:
-	case DW_AT_vtable_elem_location:
-	case DW_AT_byte_size:
-	case DW_AT_bit_offset:
-	case DW_AT_bit_size:
-	case DW_AT_string_length:
-	case DW_AT_lower_bound:
-	case DW_AT_return_addr:
-	case DW_AT_bit_stride:
-	case DW_AT_upper_bound:
-	case DW_AT_count:
-	case DW_AT_segment:
-	case DW_AT_static_link:
-	case DW_AT_use_location:
-	case DW_AT_allocated:
-	case DW_AT_associated:
-	case DW_AT_data_location:
-	case DW_AT_byte_stride:
-	case DW_AT_rank:
-	case DW_AT_call_value:
-	case DW_AT_call_target:
-	case DW_AT_call_target_clobbered:
-	case DW_AT_call_data_location:
-	case DW_AT_call_data_value:
-	case DW_AT_GNU_call_site_value:
-	case DW_AT_GNU_call_site_data_value:
-	case DW_AT_GNU_call_site_target:
-	case DW_AT_GNU_call_site_target_clobbered:
-	  if (read_exprloc_low_mem_phase1 (dso, die, ptr, len))
-	    return 1;
-	default:
-	  break;
-	}
+      if (cu->cu_version < 4)
+	switch (attr)
+	  {
+	  case DW_AT_frame_base:
+	  case DW_AT_location:
+	  case DW_AT_data_member_location:
+	  case DW_AT_vtable_elem_location:
+	  case DW_AT_byte_size:
+	  case DW_AT_bit_offset:
+	  case DW_AT_bit_size:
+	  case DW_AT_string_length:
+	  case DW_AT_lower_bound:
+	  case DW_AT_return_addr:
+	  case DW_AT_bit_stride:
+	  case DW_AT_upper_bound:
+	  case DW_AT_count:
+	  case DW_AT_segment:
+	  case DW_AT_static_link:
+	  case DW_AT_use_location:
+	  case DW_AT_allocated:
+	  case DW_AT_associated:
+	  case DW_AT_data_location:
+	  case DW_AT_byte_stride:
+	  case DW_AT_rank:
+	  case DW_AT_call_value:
+	  case DW_AT_call_target:
+	  case DW_AT_call_target_clobbered:
+	  case DW_AT_call_data_location:
+	  case DW_AT_call_data_value:
+	  case DW_AT_GNU_call_site_value:
+	  case DW_AT_GNU_call_site_data_value:
+	  case DW_AT_GNU_call_site_target:
+	  case DW_AT_GNU_call_site_target_clobbered:
+	    if (read_exprloc_low_mem_phase1 (dso, die, ptr, len))
+	      return 1;
+	  default:
+	    break;
+	  }
 
       return 0;
     }
@@ -3736,50 +3737,51 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die)
       if (form == DW_FORM_block1)
 	{
 	  /* Old DWARF uses blocks instead of exprlocs.  */
-	  switch (t->attr[i].attr)
-	    {
-	    case DW_AT_frame_base:
-	    case DW_AT_location:
-	    case DW_AT_data_member_location:
-	    case DW_AT_vtable_elem_location:
-	    case DW_AT_byte_size:
-	    case DW_AT_bit_offset:
-	    case DW_AT_bit_size:
-	    case DW_AT_string_length:
-	    case DW_AT_lower_bound:
-	    case DW_AT_return_addr:
-	    case DW_AT_bit_stride:
-	    case DW_AT_upper_bound:
-	    case DW_AT_count:
-	    case DW_AT_segment:
-	    case DW_AT_static_link:
-	    case DW_AT_use_location:
-	    case DW_AT_allocated:
-	    case DW_AT_associated:
-	    case DW_AT_data_location:
-	    case DW_AT_byte_stride:
-	    case DW_AT_rank:
-	    case DW_AT_call_value:
-	    case DW_AT_call_target:
-	    case DW_AT_call_target_clobbered:
-	    case DW_AT_call_data_location:
-	    case DW_AT_call_data_value:
-	    case DW_AT_GNU_call_site_value:
-	    case DW_AT_GNU_call_site_data_value:
-	    case DW_AT_GNU_call_site_target:
-	    case DW_AT_GNU_call_site_target_clobbered:
-	      if (die->die_ck_state != CK_BAD)
-		{
-		  s = t->attr[i].attr;
-		  die->u.p1.die_hash
-		    = iterative_hash_object (s, die->u.p1.die_hash);
-		}
-	      if (read_exprloc (dso, die, ptr, len, NULL))
-		return 1;
-	      handled = true;
-	    default:
-	      break;
-	    }
+	  if (cu->cu_version < 4)
+	    switch (t->attr[i].attr)
+	      {
+	      case DW_AT_frame_base:
+	      case DW_AT_location:
+	      case DW_AT_data_member_location:
+	      case DW_AT_vtable_elem_location:
+	      case DW_AT_byte_size:
+	      case DW_AT_bit_offset:
+	      case DW_AT_bit_size:
+	      case DW_AT_string_length:
+	      case DW_AT_lower_bound:
+	      case DW_AT_return_addr:
+	      case DW_AT_bit_stride:
+	      case DW_AT_upper_bound:
+	      case DW_AT_count:
+	      case DW_AT_segment:
+	      case DW_AT_static_link:
+	      case DW_AT_use_location:
+	      case DW_AT_allocated:
+	      case DW_AT_associated:
+	      case DW_AT_data_location:
+	      case DW_AT_byte_stride:
+	      case DW_AT_rank:
+	      case DW_AT_call_value:
+	      case DW_AT_call_target:
+	      case DW_AT_call_target_clobbered:
+	      case DW_AT_call_data_location:
+	      case DW_AT_call_data_value:
+	      case DW_AT_GNU_call_site_value:
+	      case DW_AT_GNU_call_site_data_value:
+	      case DW_AT_GNU_call_site_target:
+	      case DW_AT_GNU_call_site_target_clobbered:
+		if (die->die_ck_state != CK_BAD)
+		  {
+		    s = t->attr[i].attr;
+		    die->u.p1.die_hash
+		      = iterative_hash_object (s, die->u.p1.die_hash);
+		  }
+		if (read_exprloc (dso, die, ptr, len, NULL))
+		  return 1;
+		handled = true;
+	      default:
+		break;
+	      }
 	  ptr += len;
 	}
       else if (form == DW_FORM_exprloc)
@@ -12392,7 +12394,7 @@ write_die (unsigned char *ptr, dw_cu_ref cu, dw_die_ref die,
 	  ptr += inptr - orig_ptr;
 
 	  /* Old DWARF uses blocks instead of exprlocs.  */
-	  if (form == DW_FORM_block1)
+	  if (form == DW_FORM_block1 && cu->cu_version < 4)
 	    switch (reft->attr[i].attr)
 	      {
 	      case DW_AT_frame_base:
-- 
2.20.1



More information about the Dwz mailing list