public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: dwz@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] Break out of while loop correctly to make sure loclists are adjusted.
Date: Sun, 17 Jan 2021 23:25:59 +0100	[thread overview]
Message-ID: <20210117222559.23364-1-mark@klomp.org> (raw)

The reading and adjusting of DWARF5 .debug_loclists was modelled on
the DWARF4 .debug_loc section parsing. The .debug_loc parsing used
a while loop and breaks out when done. But .debug_loclists use a
switch statement inside the  while loop, so break doesn't actually
break out of the loop when done, and return on end of list exits
the functions too early. This meant that although the loclists were
parsed correctly, then were then not actually adjusted. Fix this
by using gotos inside the switch statements.

	* dwz.c (read_loclist_low_mem_phase1): Use again and done
	labels to goto inside switch.
	(read_loclist): Likewise.
	(adjust_loclist): Likewise.
---
 dwz.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/dwz.c b/dwz.c
index b3cf346..8903570 100644
--- a/dwz.c
+++ b/dwz.c
@@ -2807,6 +2807,7 @@ read_loclist_low_mem_phase1 (DSO *dso, dw_cu_ref cu, dw_die_ref die,
     }
   endsec = ptr + debug_sections[sec].size;
   ptr += offset;
+again:
   while (ptr < endsec)
     {
       if (sec == DEBUG_LOC)
@@ -2828,11 +2829,11 @@ read_loclist_low_mem_phase1 (DSO *dso, dw_cu_ref cu, dw_die_ref die,
 	  switch (lle)
 	    {
 	    case DW_LLE_end_of_list:
-	      return 0;
+	      goto done;
 
 	    case DW_LLE_base_addressx:
 	      skip_leb128 (ptr);
-	      continue;
+	      goto again;
 
 	    case DW_LLE_startx_endx:
 	      skip_leb128 (ptr);
@@ -2858,7 +2859,7 @@ read_loclist_low_mem_phase1 (DSO *dso, dw_cu_ref cu, dw_die_ref die,
 
 	    case DW_LLE_base_address:
 	      ptr += ptr_size;
-	      continue;
+	      goto again;
 
 	    case DW_LLE_start_end:
 	      ptr += 2 * ptr_size;
@@ -2878,7 +2879,7 @@ read_loclist_low_mem_phase1 (DSO *dso, dw_cu_ref cu, dw_die_ref die,
 		       dso->filename, cu->cu_version);
 	      skip_leb128 (ptr);
 	      skip_leb128 (ptr);
-	      continue;
+	      goto again;
 
 	    default:
 	      error (0, 0,
@@ -2903,6 +2904,7 @@ read_loclist_low_mem_phase1 (DSO *dso, dw_cu_ref cu, dw_die_ref die,
       ptr += len;
     }
 
+done:
   return 0;
 }
 
@@ -3061,6 +3063,7 @@ read_loclist (DSO *dso, dw_cu_ref cu, dw_die_ref die, GElf_Addr offset)
     }
   endsec = ptr + debug_sections[sec].size;
   ptr += offset;
+again:
   while (ptr < endsec)
     {
       if (cu->cu_version < 5)
@@ -3082,11 +3085,11 @@ read_loclist (DSO *dso, dw_cu_ref cu, dw_die_ref die, GElf_Addr offset)
 	  switch (lle)
 	    {
 	    case DW_LLE_end_of_list:
-	      return 0;
+	      goto done;
 
 	    case DW_LLE_base_addressx:
 	      skip_leb128 (ptr);
-	      continue;
+	      goto again;
 
 	    case DW_LLE_startx_endx:
 	      skip_leb128 (ptr);
@@ -3112,7 +3115,7 @@ read_loclist (DSO *dso, dw_cu_ref cu, dw_die_ref die, GElf_Addr offset)
 
 	    case DW_LLE_base_address:
 	      ptr += ptr_size;
-	      continue;
+	      goto again;
 
 	    case DW_LLE_start_end:
 	      ptr += 2 * ptr_size;
@@ -3132,7 +3135,7 @@ read_loclist (DSO *dso, dw_cu_ref cu, dw_die_ref die, GElf_Addr offset)
 		       dso->filename, cu->cu_version);
 	      skip_leb128 (ptr);
 	      skip_leb128 (ptr);
-	      continue;
+	      goto again;
 
 	    default:
 	      error (0, 0,
@@ -3156,6 +3159,7 @@ read_loclist (DSO *dso, dw_cu_ref cu, dw_die_ref die, GElf_Addr offset)
       ptr += len;
     }
 
+done:
   if (need_adjust)
     {
       struct debug_loc_adjust adj, *a;
@@ -12708,17 +12712,18 @@ adjust_loclists (void **slot, void *data)
   ptr = debug_sections[DEBUG_LOCLISTS].new_data + adj->start_offset;
   endsec = ptr + debug_sections[DEBUG_LOCLISTS].size;
 
+again:
   while (ptr < endsec)
     {
       uint8_t lle = *ptr++;
       switch (lle)
 	{
 	case DW_LLE_end_of_list:
-	  return 1;
+	  goto done;
 
 	case DW_LLE_base_addressx:
 	  skip_leb128 (ptr);
-	  continue;
+	  goto again;
 
 	case DW_LLE_startx_endx:
 	  skip_leb128 (ptr);
@@ -12744,7 +12749,7 @@ adjust_loclists (void **slot, void *data)
 
 	case DW_LLE_base_address:
 	  ptr += ptr_size;
-	  continue;
+	  goto again;
 
 	case DW_LLE_start_end:
 	  ptr += 2 * ptr_size;
@@ -12762,7 +12767,7 @@ adjust_loclists (void **slot, void *data)
 	     warning on the original parsing if CU version is not 5.*/
 	  skip_leb128 (ptr);
 	  skip_leb128 (ptr);
-	  continue;
+	  goto again;
 
 	default:
 	  error (0, 0, "unhandled location list entry 0x%x", lle);
@@ -12777,6 +12782,7 @@ adjust_loclists (void **slot, void *data)
       ptr += len;
     }
 
+done:
   return 1;
 }
 
-- 
2.18.4


             reply	other threads:[~2021-01-17 22:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-17 22:25 Mark Wielaard [this message]
2021-01-18  8:11 ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210117222559.23364-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=dwz@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).