public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5)
@ 2022-06-23 12:23 Kumar N, Bhuvanendra
  2022-06-23 15:59 ` Nick Clifton
  2022-06-29 11:19 ` Nick Clifton
  0 siblings, 2 replies; 5+ messages in thread
From: Kumar N, Bhuvanendra @ 2022-06-23 12:23 UTC (permalink / raw)
  To: binutils; +Cc: George, Jini Susan, Natarajan, Kavitha

[-- Attachment #1: Type: text/plain, Size: 6351 bytes --]

[Public]

Hi,

As part of dwarf-5 many new things are added. As part of multiple fixes planned to be sent one by one, I am requesting review for the next patch in this series. Patch is inlined below, also attached here.

For clang compiled objects with dwarf-5, location list offset address dump under DW_AT_location is corrected, where DW_FORM_loclistx is used. While dumping the location list offset, either the address dumped is wrong(refers to .debug_addr instead of .debug_loclists) or the below warning was emitted by readelf/objdump.

<49>   DW_AT_location    :readelf: Warning: Offset into section .debug_addr too big: 0x18

Test Scenario 1:
Before fix:   <37>   DW_AT_location    : (addr_index: 0x0): 2016c0 (location list)
After fix:     <37>   DW_AT_location    : (addr_index: 0x0): 18 (location list)

Contents of the .debug_loclists section:
. . .
   Offset Entry 0
    00000018 0000000000000000 0000000000000007  DW_OP_piece: 8; DW_OP_reg4 (rsi); DW_OP_piece: 4
    00000021 <End of list>

Scenario 2:
Before fix:     <49>   DW_AT_location    :readelf: Warning: Offset into section .debug_addr too big: 0x18
  (addr_index: 0x2): 0 (location list)

After fix:       <49>   DW_AT_location    : (addr_index: 0x2): 2a (location list)

Contents of the .debug_loclists section:
. . .
   Offset Entry 2
    0000002a 0000000000000000 0000000000000007  DW_OP_reg8 (r8); DW_OP_piece: 8
    00000031 <End of list>

NOTE: uvalue = fetch_indexed_value (uvalue, rnglists, 0);
Here in this patch you will find the above line where zero is passed in case of rnglists for base_address parameter. In the future upcoming patches we need to fix the range list offset dump under DW_AT_ranges with DW_FORM_rnglistx form similarly. During that time instead of zero, we need to pass the range list section base address. This is exactly similar to the fix added for location list offset support in this patch. Hence zero in the above line might look odd now, but it will be some proper base address value for range list in the upcoming patches.

Regards,
Bhuvan

Patch inlined :

From 77c255a705a4cb444146a47fcd1b53d0bb000feb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cbhkumarn=E2=80=9D?= Bhuvanendra.KumarN@amd.com<mailto:Bhuvanendra.KumarN@amd.com>
Date: Thu, 23 Jun 2022 16:56:24 +0530
Subject: [PATCH] [PATCH] fix location list offset address dump under
DW_AT_location (dwarf-5)

For clang compiled objects with dwarf-5, location list offset address dump
under DW_AT_location is corrected, where DW_FORM_loclistx is used. While
dumping the location list offset, the address dumped is wrong where it was
refering to .debug_addr instead of .debug_loclists

      * dwarf.c (fetch_indexed_value): Add base_address as parameter and
      use it to access the section offset.
      (read_and_display_attr_value): Handle DW_FORM_loclistx form separately.
      Pass loclists_base to fetch_indexed_value.
---
binutils/dwarf.c | 38 ++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 4daa0be0179..594cd6b87d2 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -827,7 +827,8 @@ fetch_indexed_addr (dwarf_vma offset, uint32_t num_bytes)
 static dwarf_vma
fetch_indexed_value (dwarf_vma idx,
-               enum dwarf_section_display_enum sec_enum)
+               enum dwarf_section_display_enum sec_enum,
+               dwarf_vma base_address)
{
   struct dwarf_section *section = &debug_displays [sec_enum].section;
@@ -852,8 +853,12 @@ fetch_indexed_value (dwarf_vma idx,

   dwarf_vma offset = idx * pointer_size;
-  /* Offsets are biased by the size of the section header.  */
-  offset += bias;
+  /* Offsets are biased by the size of the section header
+     or base address.  */
+  if (sec_enum == loclists)
+    offset += base_address;
+  else
+    offset += bias;
   if (offset + pointer_size > section->size)
     {
@@ -2795,13 +2800,23 @@ read_and_display_attr_value (unsigned long           attribute,
        if (do_wide)
         /* We have already displayed the form name.  */
-         printf (_("%c(index: 0x%s): %s"), delimiter,
-              dwarf_vmatoa ("x", uvalue),
-              dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
+         if (form == DW_FORM_loclistx)
+           printf (_("%c(index: 0x%s): %s"), delimiter,
+                   dwarf_vmatoa ("x", uvalue),
+                   dwarf_vmatoa ("x", debug_info_p->loc_offsets [uvalue]));
+         else
+           printf (_("%c(index: 0x%s): %s"), delimiter,
+                   dwarf_vmatoa ("x", uvalue),
+                   dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
       else
-         printf (_("%c(addr_index: 0x%s): %s"), delimiter,
-              dwarf_vmatoa ("x", uvalue),
-              dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
+         if (form == DW_FORM_loclistx)
+           printf (_("%c(addr_index: 0x%s): %s"), delimiter,
+                   dwarf_vmatoa ("x", uvalue),
+                  dwarf_vmatoa ("x", debug_info_p->loc_offsets [uvalue]));
+         else
+           printf (_("%c(addr_index: 0x%s): %s"), delimiter,
+                   dwarf_vmatoa ("x", uvalue),
+                   dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
     }
       break;
@@ -2878,9 +2893,8 @@ read_and_display_attr_value (unsigned long           attribute,
                       lmax, sizeof (*debug_info_p->have_frame_base));
            debug_info_p->max_loc_offsets = lmax;
          }
-
           if (form == DW_FORM_loclistx)
-          uvalue = fetch_indexed_value (uvalue, loclists);
+          uvalue = fetch_indexed_value (num, loclists, debug_info_p->loclists_base);
           else if (this_set != NULL)
          uvalue += this_set->section_offsets [DW_SECT_LOC];
@@ -2949,7 +2963,7 @@ read_and_display_attr_value (unsigned long           attribute,
          }
            if (form == DW_FORM_rnglistx)
-          uvalue = fetch_indexed_value (uvalue, rnglists);
+          uvalue = fetch_indexed_value (uvalue, rnglists, 0);
            debug_info_p->range_lists [num] = uvalue;
           debug_info_p->num_range_lists++;
--
2.17.1




[-- Attachment #2: 0001-PATCH-fix-location-list-offset-address-dump-under-DW.patch --]
[-- Type: application/octet-stream, Size: 3890 bytes --]

From 77c255a705a4cb444146a47fcd1b53d0bb000feb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cbhkumarn=E2=80=9D?= <Bhuvanendra.KumarN@amd.com>
Date: Thu, 23 Jun 2022 16:56:24 +0530
Subject: [PATCH] [PATCH] fix location list offset address dump under
 DW_AT_location (dwarf-5)

For clang compiled objects with dwarf-5, location list offset address dump
under DW_AT_location is corrected, where DW_FORM_loclistx is used. While
dumping the location list offset, the address dumped is wrong where it was
refering to .debug_addr instead of .debug_loclists

	* dwarf.c (fetch_indexed_value): Add base_address as parameter and
	use it to access the section offset.
	(read_and_display_attr_value): Handle DW_FORM_loclistx form separately.
	Pass loclists_base to fetch_indexed_value.
---
 binutils/dwarf.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 4daa0be0179..594cd6b87d2 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -827,7 +827,8 @@ fetch_indexed_addr (dwarf_vma offset, uint32_t num_bytes)
 
 static dwarf_vma
 fetch_indexed_value (dwarf_vma idx,
-		     enum dwarf_section_display_enum sec_enum)
+		     enum dwarf_section_display_enum sec_enum,
+		     dwarf_vma base_address)
 {
   struct dwarf_section *section = &debug_displays [sec_enum].section;
 
@@ -852,8 +853,12 @@ fetch_indexed_value (dwarf_vma idx,
  
   dwarf_vma offset = idx * pointer_size;
 
-  /* Offsets are biased by the size of the section header.  */
-  offset += bias;
+  /* Offsets are biased by the size of the section header
+     or base address.  */
+  if (sec_enum == loclists)
+    offset += base_address;
+  else
+    offset += bias;
 
   if (offset + pointer_size > section->size)
     {
@@ -2795,13 +2800,23 @@ read_and_display_attr_value (unsigned long           attribute,
 
 	  if (do_wide)
 	    /* We have already displayed the form name.  */
-	    printf (_("%c(index: 0x%s): %s"), delimiter,
-		    dwarf_vmatoa ("x", uvalue),
-		    dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
+	    if (form == DW_FORM_loclistx)
+	      printf (_("%c(index: 0x%s): %s"), delimiter,
+	              dwarf_vmatoa ("x", uvalue),
+	              dwarf_vmatoa ("x", debug_info_p->loc_offsets [uvalue]));
+	    else
+	      printf (_("%c(index: 0x%s): %s"), delimiter,
+	              dwarf_vmatoa ("x", uvalue),
+	              dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
 	  else
-	    printf (_("%c(addr_index: 0x%s): %s"), delimiter,
-		    dwarf_vmatoa ("x", uvalue),
-		    dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
+	    if (form == DW_FORM_loclistx)
+	      printf (_("%c(addr_index: 0x%s): %s"), delimiter,
+	              dwarf_vmatoa ("x", uvalue),
+	              dwarf_vmatoa ("x", debug_info_p->loc_offsets [uvalue]));
+	    else
+	      printf (_("%c(addr_index: 0x%s): %s"), delimiter,
+	              dwarf_vmatoa ("x", uvalue),
+	              dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
 	}
       break;
 
@@ -2878,9 +2893,8 @@ read_and_display_attr_value (unsigned long           attribute,
 			       lmax, sizeof (*debug_info_p->have_frame_base));
 		  debug_info_p->max_loc_offsets = lmax;
 		}
-
 	      if (form == DW_FORM_loclistx)
-		uvalue = fetch_indexed_value (uvalue, loclists);
+		uvalue = fetch_indexed_value (num, loclists, debug_info_p->loclists_base);
 	      else if (this_set != NULL)
 		uvalue += this_set->section_offsets [DW_SECT_LOC];
 
@@ -2949,7 +2963,7 @@ read_and_display_attr_value (unsigned long           attribute,
 		}
 
 	      if (form == DW_FORM_rnglistx)
-		uvalue = fetch_indexed_value (uvalue, rnglists);
+		uvalue = fetch_indexed_value (uvalue, rnglists, 0);
 
 	      debug_info_p->range_lists [num] = uvalue;
 	      debug_info_p->num_range_lists++;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5)
  2022-06-23 12:23 [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5) Kumar N, Bhuvanendra
@ 2022-06-23 15:59 ` Nick Clifton
  2022-06-27  8:09   ` Kumar N, Bhuvanendra
  2022-06-29 11:19 ` Nick Clifton
  1 sibling, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2022-06-23 15:59 UTC (permalink / raw)
  To: Kumar N, Bhuvanendra, binutils; +Cc: George, Jini Susan, Natarajan, Kavitha

Hi Kumar,

>        * dwarf.c (fetch_indexed_value): Add base_address as parameter and
>        use it to access the section offset.
>        (read_and_display_attr_value): Handle DW_FORM_loclistx form separately.
>        Pass loclists_base to fetch_indexed_value.

Patch approved - please apply.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5)
  2022-06-23 15:59 ` Nick Clifton
@ 2022-06-27  8:09   ` Kumar N, Bhuvanendra
  0 siblings, 0 replies; 5+ messages in thread
From: Kumar N, Bhuvanendra @ 2022-06-27  8:09 UTC (permalink / raw)
  To: Nick Clifton, binutils
  Cc: George, Jini Susan, Natarajan, Kavitha, Sharma, Alok Kumar

[AMD Official Use Only - General]

Thanks a lot for the approval. I have merged it now

commit 2d1388e73c700f689b23d53b504e0991fe196596 (HEAD -> master, origin/master, origin/HEAD)
Author: Bhuvanendra Kumar N <Bhuvanendra.KumarN@amd.com>
Date:   Mon Jun 27 13:07:55 2022 +0530

    Fix location list offset address dump under DW_AT_location (dwarf-5)

    For clang compiled objects with dwarf-5, location list offset address dump
    under DW_AT_location is corrected, where DW_FORM_loclistx is used. While
    dumping the location list offset, the address dumped is wrong where it was
    refering to .debug_addr instead of .debug_loclists

          * dwarf.c (fetch_indexed_value): Add base_address as parameter and
          use it to access the section offset.
          (read_and_display_attr_value): Handle DW_FORM_loclistx form separately.
          Pass loclists_base to fetch_indexed_value().

-----Original Message-----
From: Nick Clifton <nickc@redhat.com> 
Sent: Thursday, June 23, 2022 9:30 PM
To: Kumar N, Bhuvanendra <Bhuvanendra.KumarN@amd.com>; binutils@sourceware.org
Cc: George, Jini Susan <JiniSusan.George@amd.com>; Natarajan, Kavitha <Kavitha.Natarajan@amd.com>
Subject: Re: [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5)

[CAUTION: External Email]

Hi Kumar,

>        * dwarf.c (fetch_indexed_value): Add base_address as parameter and
>        use it to access the section offset.
>        (read_and_display_attr_value): Handle DW_FORM_loclistx form separately.
>        Pass loclists_base to fetch_indexed_value.

Patch approved - please apply.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5)
  2022-06-23 12:23 [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5) Kumar N, Bhuvanendra
  2022-06-23 15:59 ` Nick Clifton
@ 2022-06-29 11:19 ` Nick Clifton
  2022-06-30 12:26   ` Kumar N, Bhuvanendra
  1 sibling, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2022-06-29 11:19 UTC (permalink / raw)
  To: Kumar N, Bhuvanendra, binutils; +Cc: George, Jini Susan, Natarajan, Kavitha

Hi Kumar,

> As part of dwarf-5 many new things are added. As part of multiple fixes planned to be sent one by one, I am requesting review for the next patch in this series. Patch is inlined below, also attached here.

Sorry - this patch is also affected by my recent changes.
Please could you refactor your patch and resubmit it ?

Cheers
   Nick


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5)
  2022-06-29 11:19 ` Nick Clifton
@ 2022-06-30 12:26   ` Kumar N, Bhuvanendra
  0 siblings, 0 replies; 5+ messages in thread
From: Kumar N, Bhuvanendra @ 2022-06-30 12:26 UTC (permalink / raw)
  To: Nick Clifton, binutils; +Cc: George, Jini Susan, Natarajan, Kavitha

[Public]

Hi,

There was no changes required for the patch already committed to handle location list offset address dump under DW_AT_location

I went thru your latest code changes and also tested few scenarios

Regards,
bhuvan

-----Original Message-----
From: Nick Clifton <nickc@redhat.com> 
Sent: Wednesday, June 29, 2022 4:49 PM
To: Kumar N, Bhuvanendra <Bhuvanendra.KumarN@amd.com>; binutils@sourceware.org
Cc: George, Jini Susan <JiniSusan.George@amd.com>; Natarajan, Kavitha <Kavitha.Natarajan@amd.com>
Subject: Re: [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5)

[CAUTION: External Email]

Hi Kumar,

> As part of dwarf-5 many new things are added. As part of multiple fixes planned to be sent one by one, I am requesting review for the next patch in this series. Patch is inlined below, also attached here.

Sorry - this patch is also affected by my recent changes.
Please could you refactor your patch and resubmit it ?

Cheers
   Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-30 12:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23 12:23 [PATCH] fix location list offset address dump under DW_AT_location (dwarf-5) Kumar N, Bhuvanendra
2022-06-23 15:59 ` Nick Clifton
2022-06-27  8:09   ` Kumar N, Bhuvanendra
2022-06-29 11:19 ` Nick Clifton
2022-06-30 12:26   ` Kumar N, Bhuvanendra

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).