From patchwork Thu Oct 3 04:28:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 98311 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D4B3385DDEF for ; Thu, 3 Oct 2024 04:29:01 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id BDCE2385DDCC for ; Thu, 3 Oct 2024 04:28:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDCE2385DDCC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BDCE2385DDCC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727929717; cv=none; b=FM/1d+1XaKi9jPW+FbRWK+mORgYJ/MBuAwhFFkSXl4Zur8jRwwXoE9Qfpse3eLO/rfLxFMxA8GVq5ZhYQbKjxaFNMysqkYCnlPsCCO2uuHKVIQWAD4raQQakr2/aE7m04v2r5oMH/BJ4bKd0LtX/zxIYwiUif7t3XNSC6sG5hsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727929717; c=relaxed/simple; bh=ps8dcYybqHIxzXDz1hrfOcpSmqCl62r6JDy+ujLQKUw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=jqbMGXiNxTPzjxpCWp5GesLgBzaRk7xwxH/Zd8WPOxyYKYJWktW16KZtOeVSnT2TWLgQ3xg70dU5vuBOP/80ulqQCOGjTBvrB23sq+6WFPxJVOxFqNRr1jj08yurH3czt8H1Jpze9VlnWKwoL2E4PAOauC/xuhYaNdAFPfezlfk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-71b8d10e9b3so411218b3a.3 for ; Wed, 02 Oct 2024 21:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727929714; x=1728534514; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=VnBCXel5UwaLUpgJfCzRVGaodR2PCywhYZWaA/qU0Xw=; b=CNtgKgoIaQya5RRBOn8+yRmNh4HMkOpiq8bAEIa8joiuaji5zlqr3o9JBjom/L2EP3 ZBL7TJaEz/yEsBnaUhgGKPNBncMDbc20vDuuOfBqfJbaKftTD9XmnTOeZ+d+Pr4Jf/4J qPjbwQF3AYpN4u1DpE1fLUAU4XLCQlk4d8pylp5mYY0HY1NOmL4PrhrtaAM2IGMP+bmK qqq8ZSYpswScpT8JaTDXFGs2ICcT2QxfPQKpLP4+9wOzc+F9ULu2ZZ6sGeiYqB+bh772 Qu6aYjkW0ayFLzZDcAaAuehcElO791kGHP/vj6IyUtH73tqIwvsh4XbXyK3zA2Cd7K5s d7dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727929714; x=1728534514; 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=VnBCXel5UwaLUpgJfCzRVGaodR2PCywhYZWaA/qU0Xw=; b=qXtd1vc3GWbikODD+NbO0sqNBq60j103jZFHAIgtGqUM0yioeX1hPklnwYK7GTNOLQ 07NvLnDNSlacnWVwAxOOA2XUDowC6Bht0MOoGlI1YnU6oSs8Xha5bZ+x/k6zMFNcpKsY FOhZR+0k5C1kyMF5O3z0HfbdW2Dyuo9fmx62UuRJGyNqRURxCoWBqeSAZBPBoermY5wH gPTTIRMH0TPt9xS+qx9aRY7YYWNjoFpcrkhEcv1dLxnczbgyGvNMUmRxceAUEayYBDO6 jx0RuGaO5QFYyyk0yGmwmzb1URpbFYwp1HvirZqyB6yHdAAEJ8vp9NMK6MXgDFqvq+nk 4kGQ== X-Gm-Message-State: AOJu0Yz2Voa3KPvKPLSNXSSxUfyT8obbuuz9dVUZo52KjDkOpgzzXhYt 0WsReh5X6Esy2JinDlXptAYK5zMn0EVE7cIGD11hM5G16XabZ0GSZfAHvw== X-Google-Smtp-Source: AGHT+IGFZyRUnZFytbnl/Np0fJ3VW1drtBYvPNPNEiYdEY4j7YScGhfYJ8A7Hkjlc567h+u7SvsOsA== X-Received: by 2002:a05:6a00:2d88:b0:714:186a:ae0b with SMTP id d2e1a72fcca58-71dc5d6e144mr9133998b3a.24.1727929714409; Wed, 02 Oct 2024 21:28:34 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:973a:2d6f:8d46:a577]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71dd9d8be83sm360493b3a.54.2024.10.02.21.28.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 21:28:34 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 019B111422FC; Thu, 3 Oct 2024 13:58:32 +0930 (ACST) Date: Thu, 3 Oct 2024 13:58:31 +0930 From: Alan Modra To: binutils@sourceware.org Subject: nm: don't try to print line numbers for symbols without names Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3032.7 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org It doesn't make much sense trying to print line numbers for what are usually broken symbols, and there is a possibility of a segfault if we pass strcmp a NULL. diff --git a/binutils/nm.c b/binutils/nm.c index faf27c59b4d..7acf9a26333 100644 --- a/binutils/nm.c +++ b/binutils/nm.c @@ -1227,7 +1227,8 @@ print_symbol (bfd * abfd, format->print_symbol_info (&info, abfd); - if (line_numbers) + const char *symname = bfd_asymbol_name (sym); + if (line_numbers && symname != NULL && symname[0] != 0) { struct lineno_cache *lc = bfd_usrdata (abfd); const char *filename, *functionname; @@ -1258,7 +1259,6 @@ print_symbol (bfd * abfd, else if (bfd_is_und_section (bfd_asymbol_section (sym))) { unsigned int i; - const char *symname; /* For an undefined symbol, we try to find a reloc for the symbol, and print the line number of the reloc. */ @@ -1274,7 +1274,6 @@ print_symbol (bfd * abfd, bfd_map_over_sections (abfd, get_relocs, &rinfo); } - symname = bfd_asymbol_name (sym); for (i = 0; i < lc->seccount; i++) { long j; @@ -1287,6 +1286,7 @@ print_symbol (bfd * abfd, if (r->sym_ptr_ptr != NULL && (*r->sym_ptr_ptr)->section == sym->section && (*r->sym_ptr_ptr)->value == sym->value + && bfd_asymbol_name (*r->sym_ptr_ptr) != NULL && strcmp (symname, bfd_asymbol_name (*r->sym_ptr_ptr)) == 0 && bfd_find_nearest_line (abfd, lc->secs[i], lc->syms,