From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 1B0FB3858D28 for ; Wed, 15 Dec 2021 19:47:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1B0FB3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: 8R7bFqGDqkqBBJ0+3IkAYdUJnN/oHzgtxtxSRfQ8EZt8Aio58UC3QObxOxMCajC2d+kpcf6y+q LzsZHjfB4IH83HGJWqIlefD6TvgotHI6oKje3WT5MNI8hdF4PIzIjufsl1oO+BFSCOCTaxiobQ YwHw7WTJdwPnibqSK3WFmXjnG/Spi4VFyYqthCPYf62DqhfsYveAu/fw2q0NGxRWc6g2O6CfMy qBAgj5mw2ArZ1IdCvw29rPBygv2fT6jJI0OEl3W+bkl+/gM5PgGgxU9vWHbqxsPzO/Xp5IHWyl GElSbRq1qDzxvdE7wp0IkslB X-IronPort-AV: E=Sophos;i="5.88,207,1635235200"; d="scan'208";a="69749076" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 15 Dec 2021 11:47:52 -0800 IronPort-SDR: cyVsNGMBJxiowOQ4SWra25GxiToMGtpao0JnC2wNes2De2riKEUA2W0LsWmaPykXBE6v/gtbIJ VDgl5vGHdsE7kRkuDxQBhoSnjswCqm+SzMpfSRz+S/hkLUMwR1iBw9gC4atFiM9to2sY9+Trlm uO2vX3EKNHQWZ36yvPT49VYwMmYaDsb5ADhoYb1czdxMU2a7NsNYMXCMtl9fjBelLkU1xEpngx 7GDIK6oAwwRNkz3s7lMu/Rfj/g94OzwNG1ORctF0fOOY6kUQYZT6ubzfRsBiyIhzfaMIfvQlLp KEE= From: Thomas Schwinge To: "Mark J. Wielaard" , Subject: Re: [PATCH] dwarf-reader: Workaround libdw dwarf_location_expression bug In-Reply-To: <20211215160021.24200-1-mark@klomp.org> References: <190f644f891540161747b351fa4f873d948632c5.camel@klomp.org> <20211215160021.24200-1-mark@klomp.org> User-Agent: Notmuch/0.29.1+93~g67ed7df (https://notmuchmail.org) Emacs/27.1 (i686-pc-linux-gnu) Date: Wed, 15 Dec 2021 20:47:43 +0100 Message-ID: <87h7b9wsyo.fsf@dirichlet.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Dec 2021 19:47:56 -0000 Hi! On 2021-12-15T17:00:21+0100, "Mark J. Wielaard" wrote: > From: Mark Wielaard > > elfutils libdw before 0.184 would not correctly handle a > DW_AT_data_member_location when encoded as a DW_FORM_implicit const > in dwarf_location_expression. > > Work around this by first trying to read a data_member_location as a > constant value and only try to get it as a DWARF expression if that > > * src/abg-dwarf-reader.cc (die_constant_data_member_location): > New function. > (die_member_offset): Use die_constant_data_member_location > before calling die_location_expr and eval_quickly. > > Signed-off-by: Mark Wielaard Tested-by: Thomas Schwinge Due to infamiliarity with the API, I cannot comment on the code changes, but I'm confirming that this does resolve the 'runtestreaddwarf' testsuite regression that I as well as Mark's buildbot have seen with recent commit f76484cc9da0befa90e9c60867ce508202192282 "Add regression tests for ctf reading". In my case, with Ubuntu focal 0.176-1.1build1 elfutils, these were: diff --git build-libabigail/tests/runtestreaddwarf.log build-libabigail= /tests/runtestreaddwarf.log index 243f92e..74ae893 100644 --- build-libabigail/tests/runtestreaddwarf.log +++ build-libabigail/tests/runtestreaddwarf.log @@ -1,5 +1,49 @@ Could not load elf symtab: Skipping symtab load. -Symbol table of '[...]/source-libabigail/tests/data/test-read-dwarf/te= st25-bogus-binary.elf' could not be loaded -Could not load elf symtab: Skipping symtab load. Symbol table of '[...]/source-libabigail/tests/data/test-read-dwarf/te= st26-bogus-binary.elf' could not be loaded -PASS runtestreaddwarf (exit status: 0) +Could not load elf symtab: Skipping symtab load. +Symbol table of '[...]/source-libabigail/tests/data/test-read-dwarf/te= st25-bogus-binary.elf' could not be loaded +--- [...]/source-libabigail/tests/data/test-read-dwarf/test-PR26568-2.= o.abi 2021-12-14 20:09:43.841418541 +0100 ++++ [...]/build-libabigail/tests/output/test-read-dwarf/test-PR26568-2= .o.abi 2021-12-14 20:28:52.053435017 +0100 +@@ -14,12 +14,12 @@ + + + +- ++ + + + + +- ++ + + + +--- [...]/source-libabigail/tests/data/test-read-dwarf/test-PR26568-1.= o.abi 2021-12-14 20:09:43.841418541 +0100 ++++ [...]/build-libabigail/tests/output/test-read-dwarf/test-PR26568-1= .o.abi 2021-12-14 20:28:52.049435017 +0100 +@@ -19,12 +19,12 @@ + + + +- ++ + + + + +- ++ + + + +ABIs differ: +[...]/source-libabigail/tests/data/test-read-dwarf/test-PR26568-2.o.ab= i +and: +[...]/build-libabigail/tests/output/test-read-dwarf/test-PR26568-2.o.a= bi + +ABIs differ: +[...]/source-libabigail/tests/data/test-read-dwarf/test-PR26568-1.o.ab= i +and: +[...]/build-libabigail/tests/output/test-read-dwarf/test-PR26568-1.o.a= bi + +FAIL runtestreaddwarf (exit status: 1) Gr=C3=BC=C3=9Fe Thomas > src/abg-dwarf-reader.cc | 72 +++++++++++++++++++++++++++++++++-------- > 1 file changed, 58 insertions(+), 14 deletions(-) > > https://code.wildebeest.org/git/user/mjw/libabigail/commit/?h=3Ddata_memb= er_location > > diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc > index ec92f3f8..3f716944 100644 > --- a/src/abg-dwarf-reader.cc > +++ b/src/abg-dwarf-reader.cc > @@ -8693,6 +8693,37 @@ read_and_convert_DW_at_bit_offset(const Dwarf_Die*= die, > return true; > } > > +/// Get the value of the DW_AT_data_member_location of the given DIE > +/// attribute as an constant. > +/// > +/// @param die the DIE to read the attribute from. > +/// > +/// @param offset the attribute as a constant value. This is set iff > +/// the function returns true. > +/// > +/// @return true if the attribute exists and has a constant value. In > +/// that case the offset is set to the value. > +static bool > +die_constant_data_member_location(const Dwarf_Die *die, > + int64_t& offset) > +{ > + if (!die) > + return false; > + > + Dwarf_Attribute attr; > + if (!dwarf_attr(const_cast(die), > + DW_AT_data_member_location, > + &attr)) > + return false; > + > + Dwarf_Word val; > + if (dwarf_formudata(&attr, &val) !=3D 0) > + return false; > + > + offset =3D val; > + return true; > +} > + > /// Get the offset of a struct/class member as represented by the > /// value of the DW_AT_data_member_location attribute. > /// > @@ -8758,21 +8789,34 @@ die_member_offset(const read_context& ctxt, > return true; > } > > - // Otherwise, let's see if the DW_AT_data_member_location attribute an= d, > - // optionally, the DW_AT_bit_offset attributes are present. > - if (!die_location_expr(die, DW_AT_data_member_location, &expr, &expr_l= en)) > - return false; > - > - // The DW_AT_data_member_location attribute is present. > - // Let's evaluate it and get its constant > - // sub-expression and return that one. > - if (!eval_quickly(expr, expr_len, offset)) > - { > - bool is_tls_address =3D false; > - if (!eval_last_constant_dwarf_sub_expr(expr, expr_len, > - offset, is_tls_address, > - ctxt.dwarf_expr_eval_ctxt())) > + // First try to read DW_AT_data_member_location as a plain constant. > + // We do this because the generic method using die_location_expr > + // might hit a bug in elfutils libdw dwarf_location_expression only > + // fixed in elfutils 0.184+. The bug only triggers if the attribute > + // is expressed as a (DWARF 5) DW_FORM_implicit_constant. But we > + // handle all constants here because that is more consistent (and > + // slightly faster in the general case where the attribute isn't a > + // full DWARF expression). > + if (!die_constant_data_member_location(die, offset)) > + { > + // Otherwise, let's see if the DW_AT_data_member_location > + // attribute and, optionally, the DW_AT_bit_offset attributes > + // are present. > + if (!die_location_expr(die, DW_AT_data_member_location, > + &expr, &expr_len)) > return false; > + > + // The DW_AT_data_member_location attribute is present. Let's > + // evaluate it and get its constant sub-expression and return > + // that one. > + if (!eval_quickly(expr, expr_len, offset)) > + { > + bool is_tls_address =3D false; > + if (!eval_last_constant_dwarf_sub_expr(expr, expr_len, > + offset, is_tls_address, > + ctxt.dwarf_expr_eval_ctxt(= ))) > + return false; > + } > } > offset *=3D 8; > > -- > 2.18.4 ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955