[2.35] DWARF: Check version >= 3 for DW_FORM_ref_addr

Message ID CAMe9rOo-JDdgbujYd20wn3yj3T5=ivCK5ZsN0mNXFB-wyVK-tw@mail.gmail.com
State New
Headers show
Series
  • [2.35] DWARF: Check version >= 3 for DW_FORM_ref_addr
Related show

Commit Message

Alan Modra via Binutils March 22, 2021, 5:08 p.m.
On Mon, Mar 22, 2021 at 6:22 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>

> On Thu, Mar 18, 2021 at 6:32 PM Alan Modra <amodra@gmail.com> wrote:

> >

> > On Thu, Mar 18, 2021 at 06:14:02AM -0700, H.J. Lu wrote:

> > > On Wed, Mar 17, 2021 at 11:14 PM Alan Modra <amodra@gmail.com> wrote:

> > > >

> > > > On Wed, Mar 17, 2021 at 09:25:51PM -0700, H.J. Lu via Binutils wrote:

> > > > > --- a/bfd/dwarf2.c

> > > > > +++ b/bfd/dwarf2.c

> > > > > @@ -3420,10 +3420,14 @@ scan_unit_for_symbols (struct comp_unit *unit)

> > > > >         /* Avoid multiple reports of the same missing abbrev.  */

> > > > >         if (abbrev_number != previous_failed_abbrev)

> > > > >           {

> > > > > -           _bfd_error_handler

> > > > > -             (_("DWARF error: could not find abbrev number %u"),

> > > > > -              abbrev_number);

> > > > > +           /* NB: DWARF5 may have references to other CUs.  */

> > > > > +           if (unit->version < 5)

> > > > > +             _bfd_error_handler

> > > > > +               (_("DWARF error: could not find abbrev number %u"),

> > > > > +                abbrev_number);

> > > > >             previous_failed_abbrev = abbrev_number;

> > > > > +           if (unit->version >= 5)

> > > > > +             goto skip;

> > > > >           }

> > > > >         bfd_set_error (bfd_error_bad_value);

> > > > >         goto fail;

> > > >

> > > > This doesn't feel right to me.  Why are we looking for an abbrev in

> > > > the wrong CU?  Presumably if the reader can do that, then it might

> > > > interpret a lower number abbrev wrongly.

> > >

> > > Here is the updated patch to replace

> > >

> > > if (unit->version == 3 || unit->version == 4)

> > >

> > > with

> > >

> > > if (unit->version >= 3)

> > >

> > > for DWARF5 or above.  OK for master?

> >

> > Yes thanks.

> >

>

> I am backporting it to 2.36 branch.

>


I also checked this into 2.35 branch.

-- 
H.J.

Patch

From d8768ca6a736699e67e85e395b0b6e8058704456 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 18 Mar 2021 18:34:38 -0700
Subject: [2.35] [PATCH] DWARF: Check version >= 3 for DW_FORM_ref_addr

Check version >= 3, instead of version == 3 || version == 4, for
DW_FORM_ref_addr.

bfd/

	PR ld/27587
	* dwarf2.c (read_attribute_value): Check version >= 3 for
	DW_FORM_ref_addr.

(cherry picked from commit 51f6e7a9f4210aed0f8156c1d2e348de6f96f37d)
---
 bfd/ChangeLog | 6 ++++++
 bfd/dwarf2.c  | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 13d36704607..2ef920052cd 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@ 
+2021-03-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/27587
+	* dwarf2.c (read_attribute_value): Check version >= 3 for
+	DW_FORM_ref_addr.
+
 2021-01-30  Nick Clifton  <nickc@redhat.com>
 
 	* development.sh (development): Set to true.
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index 767e9731199..c7561cdeeec 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -1182,7 +1182,7 @@  read_attribute_value (struct attribute *  attr,
     case DW_FORM_ref_addr:
       /* DW_FORM_ref_addr is an address in DWARF2, and an offset in
 	 DWARF3.  */
-      if (unit->version == 3 || unit->version == 4)
+      if (unit->version >= 3)
 	{
 	  if (unit->offset_size == 4)
 	    attr->u.val = read_4_bytes (unit->abfd, info_ptr, info_ptr_end);
-- 
2.30.2