From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7854) id 3CBD83858CDA; Thu, 1 Dec 2022 14:49:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CBD83858CDA Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Cl?ment Chigot To: bfd-cvs@sourceware.org Subject: [binutils-gdb] binutils: improve holes detection in .debug_loclists. X-Act-Checkin: binutils-gdb X-Git-Author: =?utf-8?q?Cl=C3=A9ment_Chigot?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 6ef35c04dffe685ece08212201c4c032baf8aa86 X-Git-Newrev: de3b40320c35e2336b68c1e534790c77914b3a99 Message-Id: <20221201144919.3CBD83858CDA@sourceware.org> Date: Thu, 1 Dec 2022 14:49:19 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Dec 2022 14:49:19 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dde3b40320c35= e2336b68c1e534790c77914b3a99 commit de3b40320c35e2336b68c1e534790c77914b3a99 Author: Cl=C3=A9ment Chigot Date: Thu Dec 1 09:57:09 2022 +0100 binutils: improve holes detection in .debug_loclists. =20 The previous warnings about holes in .debug_loclists sections don't take into account the headers of each CU and could include the locviews if they precede the loclist. =20 The following warning can be triggered between two CU. ... ... 0000001d =20 0000002a v000000000000000 v000000000000000 location view pair 0000002c v000000000000000 v000000000000000 location view pair =20 readelf: Warning: There is a hole [0x1e - 0x2e] in .debug_loclists sect= ion. 0000002e v000000000000000 v000000000000000 views at 0000002a for: ... =20 But [0x1e - 0x2a] corresponds to the CU header and [0x2a - 0x2e] are the locviews. Thus there is no hole here. =20 binutils/ChangeLog: =20 * dwarf.c (display_debug_loc): Adjust holes detections for headers and locviews. Diff: --- binutils/dwarf.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 404a0bdbac6..ffe3c10ff75 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -7158,7 +7158,7 @@ display_debug_loc (struct dwarf_section *section, voi= d *file) const char *suffix =3D strrchr (section->name, '.'); bool is_dwo =3D false; int is_loclists =3D strstr (section->name, "debug_loclists") !=3D NULL; - uint64_t expected_start =3D 0; + uint64_t header_size =3D 0; =20 if (suffix && strcmp (suffix, ".dwo") =3D=3D 0) is_dwo =3D true; @@ -7209,7 +7209,7 @@ display_debug_loc (struct dwarf_section *section, voi= d *file) if (offset_entry_count !=3D 0) return display_offset_entry_loclists (section); =20 - expected_start =3D hdrptr - section_begin; + header_size =3D hdrptr - section_begin; } =20 if (load_debug_info (file) =3D=3D 0) @@ -7265,12 +7265,12 @@ display_debug_loc (struct dwarf_section *section, v= oid *file) error (_("No location lists in .debug_info section!\n")); =20 if (debug_information [first].num_loc_offsets > 0 - && debug_information [first].loc_offsets [0] !=3D expected_start - && debug_information [first].loc_views [0] !=3D expected_start) + && debug_information [first].loc_offsets [0] !=3D header_size + && debug_information [first].loc_views [0] !=3D header_size) warn (_("Location lists in %s section start at %#" PRIx64 " rather than %#" PRIx64 "\n"), section->name, debug_information [first].loc_offsets [0], - expected_start); + header_size); =20 if (!locs_sorted) array =3D (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned in= t)); @@ -7282,10 +7282,9 @@ display_debug_loc (struct dwarf_section *section, vo= id *file) =20 printf (_(" Offset Begin End Expression\n")= ); =20 - seen_first_offset =3D 0; for (i =3D first; i < num_debug_info_entries; i++) { - uint64_t offset, voffset; + uint64_t offset =3D 0, voffset =3D 0; uint64_t base_address; unsigned int k; int has_frame_base; @@ -7300,6 +7299,24 @@ display_debug_loc (struct dwarf_section *section, vo= id *file) sizeof (*array), loc_offsets_compar); } =20 + /* .debug_loclists has a per-unit header. + Update start if we are detecting it. */ + if (debug_information [i].dwarf_version =3D=3D 5) + { + j =3D locs_sorted ? 0 : array [0]; + + if (debug_information [i].num_loc_offsets) + offset =3D debug_information [i].loc_offsets [j]; + + if (debug_information [i].num_loc_views) + voffset =3D debug_information [i].loc_views [j]; + + /* Assume that the size of the header is constant across CUs. */ + if (((start - section_begin) + header_size =3D=3D offset) + || ((start -section_begin) + header_size =3D=3D voffset)) + start +=3D header_size; + } + int adjacent_view_loclists =3D 1; for (k =3D 0; k < debug_information [i].num_loc_offsets; k++) { @@ -7330,19 +7347,21 @@ display_debug_loc (struct dwarf_section *section, v= oid *file) start =3D vstart; } =20 - if (!seen_first_offset || !adjacent_view_loclists) - seen_first_offset =3D 1; - else + if (start < next) { - if (start < next) + if (vnext && vnext < next) warn (_("There is a hole [%#tx - %#" PRIx64 "]" " in %s section.\n"), - start - section_begin, offset, section->name); - else if (start > next) - warn (_("There is an overlap [%#tx - %#" PRIx64 "]" + start - section_begin, voffset, section->name); + else + warn (_("There is a hole [%#tx - %#" PRIx64 "]" " in %s section.\n"), start - section_begin, offset, section->name); } + else if (start > next) + warn (_("There is an overlap [%#tx - %#" PRIx64 "]" + " in %s section.\n"), + start - section_begin, offset, section->name); start =3D next; vstart =3D vnext;