From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 33C023858402; Thu, 26 Aug 2021 17:12:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33C023858402 From: "mark at klomp dot org" To: elfutils-devel@sourceware.org Subject: [Bug libdw/28220] dwarf_location_attr returns high-bit junk from .debug_addr when fetching 32-bit addresses Date: Thu, 26 Aug 2021 17:12:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: elfutils X-Bugzilla-Component: libdw X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mark at klomp dot org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status cc cf_reconfirmed_on everconfirmed Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Aug 2021 17:12:02 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D28220 Mark Wielaard changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |ASSIGNED CC| |mark at klomp dot org Last reconfirmed| |2021-08-26 Ever confirmed|0 |1 --- Comment #2 from Mark Wielaard --- That was an interesting bug. The issue is the use of DW_OP_addrx which crea= tes a fake attribute of DW_FORM_addr pointing to the actual address. This fake attribute also has a fake CU. We didn't set the correct address size on this fake CU. The following patch fixes it: commit d18228697f750e651bf0bdf19abdaab0a4217008 Author: Mark Wielaard Date: Thu Aug 26 19:05:45 2021 +0200 PR28220 diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c index 9e944b86..a368feb8 100644 --- a/libdw/dwarf_begin_elf.c +++ b/libdw/dwarf_begin_elf.c @@ -224,6 +224,23 @@ valid_p (Dwarf *result) result =3D NULL; } + /* We are setting up some "fake" CUs, which need an address size. + Check the ELF class to come up with something reasonable. */ + int elf_addr_size =3D 8; + if (result !=3D NULL) + { + GElf_Ehdr ehdr; + if (gelf_getehdr (result->elf, &ehdr) =3D=3D NULL) + { + Dwarf_Sig8_Hash_free (&result->sig8_hash); + __libdw_seterrno (DWARF_E_INVALID_ELF); + free (result); + result =3D NULL; + } + else if (ehdr.e_ident[EI_CLASS] =3D=3D ELFCLASS32) + elf_addr_size =3D 4; + } + /* For dwarf_location_attr () we need a "fake" CU to indicate where the "fake" attribute data comes from. This is a block inside the .debug_loc or .debug_loclists section. */ @@ -247,8 +264,9 @@ valid_p (Dwarf *result) =3D (result->sectiondata[IDX_debug_loc]->d_buf + result->sectiondata[IDX_debug_loc]->d_size); result->fake_loc_cu->locs =3D NULL; - result->fake_loc_cu->address_size =3D 0; - result->fake_loc_cu->version =3D 0; + result->fake_loc_cu->address_size =3D elf_addr_size; + result->fake_loc_cu->offset_size =3D 4; + result->fake_loc_cu->version =3D 4; result->fake_loc_cu->split =3D NULL; } } @@ -274,8 +292,9 @@ valid_p (Dwarf *result) =3D (result->sectiondata[IDX_debug_loclists]->d_buf + result->sectiondata[IDX_debug_loclists]->d_size); result->fake_loclists_cu->locs =3D NULL; - result->fake_loclists_cu->address_size =3D 0; - result->fake_loclists_cu->version =3D 0; + result->fake_loclists_cu->address_size =3D elf_addr_size; + result->fake_loclists_cu->offset_size =3D 4; + result->fake_loclists_cu->version =3D 5; result->fake_loclists_cu->split =3D NULL; } } @@ -306,8 +325,9 @@ valid_p (Dwarf *result) =3D (result->sectiondata[IDX_debug_addr]->d_buf + result->sectiondata[IDX_debug_addr]->d_size); result->fake_addr_cu->locs =3D NULL; - result->fake_addr_cu->address_size =3D 0; - result->fake_addr_cu->version =3D 0; + result->fake_addr_cu->address_size =3D elf_addr_size; + result->fake_addr_cu->offset_size =3D 4; + result->fake_addr_cu->version =3D 5; result->fake_addr_cu->split =3D NULL; } } Also on https://code.wildebeest.org/git/user/mjw/elfutils/commit/?h=3Dfake_cu_elf_a= ddr_size Thanks for the testcases I'll try to incorporate them into the testsuite. --=20 You are receiving this mail because: You are on the CC list for the bug.=