From patchwork Thu Dec 1 09:44:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Cl=C3=A9ment_Chigot?= X-Patchwork-Id: 28274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp166611wrr; Thu, 1 Dec 2022 01:44:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WwAlW6zNd+tXOyuKh0kH7pU+Sf7q166loE/CQ/XquqRsCoH/BZG+zAQ22LBBHkwde4SaO X-Received: by 2002:a17:906:1811:b0:7ae:5a4:5356 with SMTP id v17-20020a170906181100b007ae05a45356mr40025419eje.748.1669887867544; Thu, 01 Dec 2022 01:44:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669887867; cv=none; d=google.com; s=arc-20160816; b=l6SqNckE+sxbxe5KmthjFx6ZubIp81VZHu2ITTJsGnqP6IMjKzrpehasot4lqJJhYp YCLlNkv7oFg0ZZtFSeJtIdK56YdfcNlY0SCYtgKNIwc9iTzBk6Ngg+RVAgJMWF5AzNDm 7F50Np9opEmNbeYda/OTa3W5E6dEwytQXxX19V3pPqvx18ZqCQU2qlVp4Q81yqcSJj7k 7BzBr9pEBt2Pfhy0Tyt2ThSy80NpNmnETH3h1l7qn3Q+gMO5Q0gAVFby4pNunx4feE+v PXipuGYk2eahcZQc01gof4nAPPhPwtAlcVbZh0URk/Wsw0AGJJY521vYPX0QDTJoOF/i 0zpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Hj7QalOEPmuXCbRwMaLjlejfiIFh6MpnWU0rDGmiZG8=; b=ztjmEsKOGnHeU5jYflda2JNZvdVbf9po3XK4iDcevyw34uuNJHNSJ67jfoig/chCO7 7F/OhCBYXwmpvyXoKkTPLx6r3O7dR5kf4U4DUo8/5rN3SNO8JhUhcEO8Fag94A9dePqv Iw5vjZpQxnRELdqzNSJZ3grDDJPSjny/68XLyr+NUWFg1lHFWeA1bMlw743K8IyNcIR9 YJLKGxEJ9krt4yG5l62iNqxRaMu/WNbl4YZApUf7zA4nY900UlT0LHO1aXme3FEidzBT 6vSyNBXzosoj5HsmR05Rp7b6WWAm8Rj8JbBSxhdHZBxNRX0NlK2Ny3UOq4u5HKKp06ma YwZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=VKDls2lN; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u15-20020a056402064f00b0046b807c1a06si3259856edx.350.2022.12.01.01.44.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 01:44:27 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=VKDls2lN; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75622385841C for ; Thu, 1 Dec 2022 09:44:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75622385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669887866; bh=Hj7QalOEPmuXCbRwMaLjlejfiIFh6MpnWU0rDGmiZG8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=VKDls2lNse8x0xr+HXDOPNrmWe+AK3pLZB3EiDoHwl+H/FD85BLNXyyZxMhZKY0/C FslPWsMRUXV0l46EUMT8PwvciCzrUX5QX60rIj0Zu+zqxg37G68+PTu7rHV6KGLDMN cE/b5SeiOCMD+CLqYwNLfKeL1X7YQVBXnM72320o= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 216A03858C39 for ; Thu, 1 Dec 2022 09:44:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 216A03858C39 Received: by mail-wr1-x42a.google.com with SMTP id x17so1760557wrn.6 for ; Thu, 01 Dec 2022 01:44:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Hj7QalOEPmuXCbRwMaLjlejfiIFh6MpnWU0rDGmiZG8=; b=X/ZygQPNw84LY4LJh883JjmqDHzE9qR/lX70IV62ZPWxwCORr6vNsMjrVA6Hz1TTUO tWYv9YLhkgiIHur3qMNeXbdRcGP22b3qWVSkMOCfYng+EeCZe3bK0QVIlCVHB8gbl+b2 mvU6Hq5z/epH5fQXcPdFlRUgPC1hUuqbuItdIgdoB8XX2LbU87wiKm7G6JghzRUz0U81 PbuAKDuUcjMxKREyvmMPxY8pc3v2VgQcpm9LHknBpgKTMNGxGZ/vzCrXjW0sbLwD0Xrh I/e3c2zB0ygokwUjbCdmBgjZUhtd7MRKQk1YvC+1g92LLsZhpQHvT/U99W+0YZWqaiyV GP6A== X-Gm-Message-State: ANoB5plvW59i3M4KqzBUt7DPsgLV4+ojCjDN6C9IOs3uOY7wAZV3m/gr GcTZBrxGJX41tlbyUqE9VZw93OESP3n08A== X-Received: by 2002:a5d:6089:0:b0:241:e85c:f769 with SMTP id w9-20020a5d6089000000b00241e85cf769mr25935162wrt.69.1669887853351; Thu, 01 Dec 2022 01:44:13 -0800 (PST) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:54fd:3b08:9ea7:4623]) by smtp.gmail.com with ESMTPSA id z12-20020a5d44cc000000b002362f6fcaf5sm3888328wrr.48.2022.12.01.01.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 01:44:12 -0800 (PST) To: binutils@sourceware.org Cc: =?utf-8?q?Cl=C3=A9ment_Chigot?= Subject: [PATCH] binutils: improve holes detection in .debug_loclists. Date: Thu, 1 Dec 2022 10:44:09 +0100 Message-Id: <20221201094409.1982624-1-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Cl=C3=A9ment_Chigot_via_Binutils?= From: =?utf-8?q?Cl=C3=A9ment_Chigot?= Reply-To: =?utf-8?q?Cl=C3=A9ment_Chigot?= Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751004340596138752?= X-GMAIL-MSGID: =?utf-8?q?1751004340596138752?= 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. The following warning can be triggered between two CU. ... ... 0000001d 0000002a v000000000000000 v000000000000000 location view pair 0000002c v000000000000000 v000000000000000 location view pair readelf: Warning: There is a hole [0x1e - 0x2e] in .debug_loclists section. 0000002e v000000000000000 v000000000000000 views at 0000002a for: ... But [0x1e - 0x2a] corresponds to the CU header and [0x2a - 0x2e] are the locviews. Thus there is no hole here. binutils/ChangeLog: * dwarf.c (display_debug_loc): Adjust holes detections for headers and locviews. --- 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, void *file) const char *suffix = strrchr (section->name, '.'); bool is_dwo = false; int is_loclists = strstr (section->name, "debug_loclists") != NULL; - uint64_t expected_start = 0; + uint64_t header_size = 0; if (suffix && strcmp (suffix, ".dwo") == 0) is_dwo = true; @@ -7209,7 +7209,7 @@ display_debug_loc (struct dwarf_section *section, void *file) if (offset_entry_count != 0) return display_offset_entry_loclists (section); - expected_start = hdrptr - section_begin; + header_size = hdrptr - section_begin; } if (load_debug_info (file) == 0) @@ -7265,12 +7265,12 @@ display_debug_loc (struct dwarf_section *section, void *file) error (_("No location lists in .debug_info section!\n")); if (debug_information [first].num_loc_offsets > 0 - && debug_information [first].loc_offsets [0] != expected_start - && debug_information [first].loc_views [0] != expected_start) + && debug_information [first].loc_offsets [0] != header_size + && debug_information [first].loc_views [0] != 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); if (!locs_sorted) array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); @@ -7282,10 +7282,9 @@ display_debug_loc (struct dwarf_section *section, void *file) printf (_(" Offset Begin End Expression\n")); - seen_first_offset = 0; for (i = first; i < num_debug_info_entries; i++) { - uint64_t offset, voffset; + uint64_t offset = 0, voffset = 0; uint64_t base_address; unsigned int k; int has_frame_base; @@ -7300,6 +7299,24 @@ display_debug_loc (struct dwarf_section *section, void *file) sizeof (*array), loc_offsets_compar); } + /* .debug_loclists has a per-unit header. + Update start if we are detecting it. */ + if (debug_information [i].dwarf_version == 5) + { + j = locs_sorted ? 0 : array [0]; + + if (debug_information [i].num_loc_offsets) + offset = debug_information [i].loc_offsets [j]; + + if (debug_information [i].num_loc_views) + voffset = debug_information [i].loc_views [j]; + + /* Assume that the size of the header is constant across CUs. */ + if (((start - section_begin) + header_size == offset) + || ((start -section_begin) + header_size == voffset)) + start += header_size; + } + int adjacent_view_loclists = 1; for (k = 0; k < debug_information [i].num_loc_offsets; k++) { @@ -7330,19 +7347,21 @@ display_debug_loc (struct dwarf_section *section, void *file) start = vstart; } - if (!seen_first_offset || !adjacent_view_loclists) - seen_first_offset = 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 = next; vstart = vnext;