public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Jakub Jelinek <jakub@redhat.com>
Cc: dwz@sourceware.org
Subject: Re: [PATCH] Don't handle blocks as exprlocs for DWARF version 4 or higher.
Date: Thu, 18 Feb 2021 17:18:10 +0100	[thread overview]
Message-ID: <bbeec145346023a0895783901bb0b743bf9c1778.camel@klomp.org> (raw)
In-Reply-To: <20210218140947.GG4020736@tucnak>

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

On Thu, 2021-02-18 at 15:09 +0100, Jakub Jelinek wrote:
> On Thu, Feb 18, 2021 at 02:40:36PM +0100, Mark Wielaard wrote:
> > On Sat, 2021-02-13 at 23:46 +0100, Mark Wielaard wrote:
> > > 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
> > 
> > Ping. Any comments?
> 
> Doing some GCC archeology if it is safe, I think it principially ok, but I'd
> like slightly different patch, see below.
> [...]
> > > +++ 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.  */
> 
> Instead of reindenting everything, can't you simply change
> -  if (form == DW_FORM_block1)
> +  if (form == DW_FORM_block1 && cu->cu_version < 4)

Yes, I was under the impression that the return 0; in the block was
special, but it isn't, the rest of the function does explicitly check
the form (isn't DW_FORM_block1) and so if it simply falls-through it
will also end up at return 0; at the end.

> > >        if (form == DW_FORM_block1)
> 
> And likewise here:
> -      if (form == DW_FORM_block1)
> +      if (form == DW_FORM_block1 && cu->cu_version < 4)

But here we do need to handle the DW_FORM_block && cu->cu_version >=4
version separately. But that can be done by not indention the large
block and adding an small else if block.

Does the attached variant look better?

Thanks,

Mark

[-- Attachment #2: 0001-Don-t-handle-blocks-as-exprlocs-for-DWARF-version-4-.patch --]
[-- Type: text/x-patch, Size: 2016 bytes --]

From 3c23d7075af603d1cb8ed5e66f1659c46ec85dc7 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Sat, 13 Feb 2021 23:34:55 +0100
Subject: [PATCH] Don't handle blocks as exprlocs for DWARF version 4 or
 higher.

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 | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/dwz.c b/dwz.c
index d6b9df0..5f0cc1d 100644
--- a/dwz.c
+++ b/dwz.c
@@ -2910,7 +2910,7 @@ add_locexpr_dummy_dies (DSO *dso, dw_cu_ref cu, dw_die_ref die,
 			unsigned char *ptr, uint32_t form, unsigned int attr,
 			size_t len)
 {
-  if (form == DW_FORM_block1)
+  if (form == DW_FORM_block1 && cu->cu_version < 4)
     {
       /* Old DWARF uses blocks instead of exprlocs.  */
       switch (attr)
@@ -3733,7 +3733,7 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die)
 	  abort ();
 	}
 
-      if (form == DW_FORM_block1)
+      if (form == DW_FORM_block1 && cu->cu_version < 4)
 	{
 	  /* Old DWARF uses blocks instead of exprlocs.  */
 	  switch (t->attr[i].attr)
@@ -3782,6 +3782,11 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die)
 	    }
 	  ptr += len;
 	}
+      else if (form == DW_FORM_block1)
+	{
+	  /* DWARF4 or higher, handle block as an opaque block of bytes.  */
+	  ptr += len;
+	}
       else if (form == DW_FORM_exprloc)
 	{
 	  if (die->die_ck_state != CK_BAD)
@@ -12392,7 +12397,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.18.4


  reply	other threads:[~2021-02-18 16:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-13 22:46 Mark Wielaard
2021-02-18 13:40 ` Mark Wielaard
2021-02-18 14:09   ` Jakub Jelinek
2021-02-18 16:18     ` Mark Wielaard [this message]
2021-02-18 16:59       ` Jakub Jelinek
2021-02-18 17:32         ` Jakub Jelinek
2021-02-18 20:01         ` Mark Wielaard
2021-02-18 20:06           ` Jakub Jelinek
2021-02-18 21:17             ` Mark Wielaard

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=bbeec145346023a0895783901bb0b743bf9c1778.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    /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).