From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 75DA43858422 for ; Wed, 8 Mar 2023 03:15:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75DA43858422 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x62a.google.com with SMTP id p20so16384966plw.13 for ; Tue, 07 Mar 2023 19:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678245326; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=eVru6sbTL4L12+yo0nbKfnXqN0dbxj4f0LL7l18fme4=; b=qqiJ1VvbiwzzPfQ8JLQO8JClB/z/B+ZZ7GWHkgvtrfxS88m1ITq1LB+L1LfBNeCWd+ +EoedTqIyMXkp390hIMrYdD+WTTBnSG6nsclGunAYs3uo4ql0017lgfrOUUaRCbT1C8q Odj/STIf16H5rSDjU5vC8ed5Nw77eBV+c+qVYnoOUdIk58LcGsbHogwRa71foEOgN0mk aCxfL8ba8nBftJxa0JSSmLMsu9S40WBYaZQW8EJuJ8C9LaqPe8Bk3Iaz+HwT5+govcEW 46tc5b1vZTUOZxpi7wOQslxrcuchDv/PVK8SN8Tvg6n6kJoUgpE+vCXlybYB0DDJaqql IQ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678245326; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eVru6sbTL4L12+yo0nbKfnXqN0dbxj4f0LL7l18fme4=; b=utoInslPkfb4WDzO9tOIRgHecG6tYNOcZbpn1RR7LNvw1rmh6yJ/BXPVrGsOZE3OG7 b6dfC2wOzsXYmwXJFLGksLXi+drmqWpDfi/tGGsKvFltERyGpVDVW0V4E8Kuilqcz0lf ASusYQexLgEKPr3W9g2eL/TIvpQl67IyK10ntsFkFY5UZHWuEQgPcC9woltuovXK8Uti 6gWMEPyiaTEWNPwOeViR38syct1iLHu+L2Md0WIx8s3z2bHKEddCTV9bfTm9a4/C9Ikr r9iFiW2A9QOVruGOrulCSPFvEdPcSn2ku8/8lOFnNic1Y4cUHOVqu5ahcnbnVSJBmBvx 0SJg== X-Gm-Message-State: AO0yUKWy2/uSfbNVXnFjrLT6LDwRkjUamARORvR9C+Xh4a3yxgLfro2P uwZPdnn94FJA5DouvO9hGi5wgC6JwBk= X-Google-Smtp-Source: AK7set8hqUzbSwGeUXkYJfmwbNfFaZjuCU45SJrOBGNIDPmh99M0qDgWla+diBZwRwLetF69XjTM8Q== X-Received: by 2002:a17:902:ed49:b0:19c:ac9d:f682 with SMTP id y9-20020a170902ed4900b0019cac9df682mr15686092plb.25.1678245326369; Tue, 07 Mar 2023 19:15:26 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:4d08:cebd:d73f:b794]) by smtp.gmail.com with ESMTPSA id kt4-20020a170903088400b00186cf82717fsm9101088plb.165.2023.03.07.19.15.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 19:15:26 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id EC3451142C81; Wed, 8 Mar 2023 13:45:23 +1030 (ACDT) Date: Wed, 8 Mar 2023 13:45:23 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Re: Move nm.c cached line number info to bfd usrdata Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3034.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 List-Id: Commit e3f450f3933d resulted in a nm -l segfault on object files without undefined symbols. Fix that, and be paranoid about bfd section count changing. * nm.c (struct lineno_cache): Add seccount. (free_lineno_cache): Don't segfault on NULL lc->relocs. (print_symbol): Stash section count when creating arrays. diff --git a/binutils/nm.c b/binutils/nm.c index 8b6b249a951..f96cfa31cb9 100644 --- a/binutils/nm.c +++ b/binutils/nm.c @@ -62,6 +62,7 @@ struct lineno_cache long *relcount; asymbol **syms; long symcount; + unsigned int seccount; }; struct extended_symbol_info @@ -1165,9 +1166,8 @@ free_lineno_cache (bfd *abfd) if (lc) { - unsigned int seccount = bfd_count_sections (abfd); - for (unsigned int i = 0; i < seccount; i++) - if (lc->relocs[i] != NULL) + if (lc->relocs) + for (unsigned int i = 0; i < lc->seccount; i++) free (lc->relocs[i]); free (lc->relcount); free (lc->relocs); @@ -1254,12 +1254,13 @@ print_symbol (bfd * abfd, { unsigned int i; const char *symname; - unsigned int seccount = bfd_count_sections (abfd); /* For an undefined symbol, we try to find a reloc for the symbol, and print the line number of the reloc. */ if (lc->relocs == NULL) { + unsigned int seccount = bfd_count_sections (abfd); + lc->seccount = seccount; lc->secs = xmalloc (seccount * sizeof (*lc->secs)); lc->relocs = xmalloc (seccount * sizeof (*lc->relocs)); lc->relcount = xmalloc (seccount * sizeof (*lc->relcount)); @@ -1269,7 +1270,7 @@ print_symbol (bfd * abfd, } symname = bfd_asymbol_name (sym); - for (i = 0; i < seccount; i++) + for (i = 0; i < lc->seccount; i++) { long j; @@ -1290,7 +1291,7 @@ print_symbol (bfd * abfd, { /* We only print the first one we find. */ printf ("\t%s:%u", filename, lineno); - i = seccount; + i = lc->seccount; break; } } -- Alan Modra Australia Development Lab, IBM