From patchwork Thu Oct 3 04:27: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: 98310 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 816D4385C6CC for ; Thu, 3 Oct 2024 04:28:02 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 03DF43858C48 for ; Thu, 3 Oct 2024 04:27:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03DF43858C48 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 03DF43858C48 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727929658; cv=none; b=Fztc1Yk3iBoBGtv3RcjuuM29rRYpFaJpIOBNqPxd+SuG8rSAmneFt7ahWehsPnzrOeRs6MWh/3inLc29yWOYHWpAFhcGUhh6u3Je+Oq4alz3J3ZGTy1GudtoAbCky+h3sdPZDCtkz6ygH6k8tammt0tjtENsnOCI0iec6XNzLbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727929658; c=relaxed/simple; bh=2GV9OOf6O0Ri1tEGzPqPqahD3nXFlORKn0rPx95XBqM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=m9ECpf9IBnP3hJGzZO2/IMoKDuBcytNV+vPa7fpU1mDvcZ2WEFvFIilQQoVnz+XNb6jfEv/XiFwFUYsITQCvhLb/Z5KBiRJj7gvBtVoPQ5batuhx0iHwsg21EMbaSBdWa9twmjwTpOMlHBv9al5laVg/m2J9yzHlLThK2wBREoE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-718e6299191so352035b3a.2 for ; Wed, 02 Oct 2024 21:27:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727929654; x=1728534454; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=6dWbsDVITrSteOo41ovL0itoJ1B/9Wl/vxAmzRfxvSs=; b=A+JqCxgxfoZfYeaqVBH9tkbRpDbDQYCQbppmj+rn+hdVCH63WTanYKB6ffWxnPlb/D ZLfHKjwJQSXh3Bb264AUILArNSN69B5fAIjpKxI3ccPawkIIFCVnlm0rPHTeBY9qe5+N kk+N+FWcH4SiD4wVxOsYPObRofiHL8zf5SW+xpdSEdqg4uKKp67YWrqEBXUJA2zpJai7 n6RErcvEarKAk113E9G3DGEFIGdYXSnAkClrQeK1+cBBg7HTdRsCknbkh3/gPM0IKCmB R5hAK8VEDf7+RbiZFjdps8AjqQSaGIa84IDB/qssLpyEiaUbzZ1pavZL5Vys+qPrkeY/ SQuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727929654; x=1728534454; 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=6dWbsDVITrSteOo41ovL0itoJ1B/9Wl/vxAmzRfxvSs=; b=PU8cyUzCGHac7rCYy2byWXFtzlwBVEtg/rkbScbXYmBamAPKCQmnXyPxEfaFe4yUyy PcOOvvV3KW9PbRtrnuJdk9j6wD4ZhIF+o0wKNjXefgm4qxECgEc5OS89arR1MTe+gLYF 5t5aByEPi+MRVzlTPuJUqExXuFqteUq37kivcD2Qt4slN+c+fruNZGpzIaedr+vNTVEl IdIZ4txq0xUBfR7QahqoazI9DLyFCYm7/fH/d9cfHv/KOMiLI2gc/Y/wsvlTmMXw6Eq/ BBjy/cdlsVp3T8cDIrLCvDB0YIv2t5fUDnzFqD8TaI6OEXA3jr8L+ZSSKK7xvN+JBiPd Tm6w== X-Gm-Message-State: AOJu0Yxo96rCaONkw2cRTtahDNHJwYYtAXaZQz+lT9c6zz1sz/cU2alY 0chDBuBbaOoNGeJtYZQdbCs3QgqRHJ97TxrQywaKdApCYwLHN5FtGbTpfQ== X-Google-Smtp-Source: AGHT+IFXF64iOwLAba4Cx5kRGYNmRsxZCa6Pa8juHvc0/R8w5HXnwVop9BgNhVZnPAWmqiWuOBnE2g== X-Received: by 2002:a05:6a00:ace:b0:717:85e2:28fa with SMTP id d2e1a72fcca58-71dc5c8f73amr8790754b3a.16.1727929654371; Wed, 02 Oct 2024 21:27: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-71dd9df0ae6sm365520b3a.174.2024.10.02.21.27.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 21:27:33 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 4C9B111403E8; Thu, 3 Oct 2024 13:57:31 +0930 (ACST) Date: Thu, 3 Oct 2024 13:57:31 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Don't return "(null)" from bfd_elf_sym_name 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, T_FILL_THIS_FORM_SHORT 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 A NULL return from bfd_elf_string_from_elf_section indicates an error. That shouldn't be masked by bfd_elf_sym_name but rather passed up to callers such as group_signature. If we want to print "(null)" then that should be done at a higher level. That's what this patch does, except that I chose to print "" instead, like readelf. If we see "(null)" we're probably passing a NULL to printf. I haven't changed aoutx.h or pdp11.c print_symbol functions because they already handle NULL names by omitting the name. I also haven't changed mach-o.c, mmo.c, som.c, srec.c, tekhex.c, vms-alpha.c and wasm-module.c print_symbol function because it looks like they will never have NULL symbol names. bfd/ * elf.c (bfd_elf_sym_name): Don't turn a NULL name into a pointer to "(null)". (bfd_elf_print_symbol): Print "" for NULL symbol names. * coffgen.c (coff_print_symbol): Likewise. * ecoff.c (_bfd_ecoff_print_symbol): Likewise. * pef.c (bfd_pef_print_symbol): Likewise. * syms.c (bfd_symbol_info): Return "" in symbol_info.name if symbol name is NULL. ld/ * ldlang.c (ld_is_local_symbol): Don't check for "(null)" symbol name. diff --git a/bfd/coffgen.c b/bfd/coffgen.c index cc1c655738b..ff382a7e9c9 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -2161,11 +2161,12 @@ coff_print_symbol (bfd *abfd, bfd_print_symbol_type how) { FILE * file = (FILE *) filep; + const char *symname = symbol->name ? symbol->name : ""; switch (how) { case bfd_print_symbol_name: - fprintf (file, "%s", symbol->name); + fprintf (file, "%s", symname); break; case bfd_print_symbol_more: @@ -2189,7 +2190,7 @@ coff_print_symbol (bfd *abfd, if (combined < obj_raw_syments (abfd) || combined >= obj_raw_syments (abfd) + obj_raw_syment_count (abfd)) { - fprintf (file, _(" %s"), symbol->name); + fprintf (file, _(" %s"), symname); break; } @@ -2207,7 +2208,7 @@ coff_print_symbol (bfd *abfd, combined->u.syment.n_sclass, combined->u.syment.n_numaux); bfd_fprintf_vma (abfd, file, val); - fprintf (file, " %s", symbol->name); + fprintf (file, " %s", symname); for (aux = 0; aux < combined->u.syment.n_numaux; aux++) { @@ -2297,7 +2298,8 @@ coff_print_symbol (bfd *abfd, if (l) { - fprintf (file, "\n%s :", l->u.sym->name); + fprintf (file, "\n%s :", + l->u.sym->name ? l->u.sym->name : ""); l++; while (l->line_number) { @@ -2317,7 +2319,7 @@ coff_print_symbol (bfd *abfd, symbol->section->name, coffsymbol (symbol)->native ? "n" : "g", coffsymbol (symbol)->lineno ? "l" : " ", - symbol->name); + symname); } } } diff --git a/bfd/ecoff.c b/bfd/ecoff.c index 5ee7ffaf489..93b93f39be1 100644 --- a/bfd/ecoff.c +++ b/bfd/ecoff.c @@ -1452,11 +1452,12 @@ _bfd_ecoff_print_symbol (bfd *abfd, const struct ecoff_debug_swap * const debug_swap = &ecoff_backend (abfd)->debug_swap; FILE *file = (FILE *)filep; + const char *symname = symbol->name ? symbol->name : ""; switch (how) { case bfd_print_symbol_name: - fprintf (file, "%s", symbol->name); + fprintf (file, "%s", symname); break; case bfd_print_symbol_more: if (ecoffsymbol (symbol)->local) @@ -1526,7 +1527,7 @@ _bfd_ecoff_print_symbol (bfd *abfd, (unsigned) ecoff_ext.asym.sc, (unsigned) ecoff_ext.asym.index, jmptbl, cobol_main, weakext, - symbol->name); + symname); if (ecoffsymbol (symbol)->fdr != NULL && ecoff_ext.asym.index != indexNil) diff --git a/bfd/elf.c b/bfd/elf.c index c882a66ab5c..7d3d2063130 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -549,9 +549,7 @@ bfd_elf_sym_name (bfd *abfd, } name = bfd_elf_string_from_elf_section (abfd, shindex, iname); - if (name == NULL) - name = "(null)"; - else if (sym_sec && *name == '\0') + if (sym_sec && name && *name == '\0') name = bfd_section_name (sym_sec); return name; @@ -2314,10 +2312,12 @@ bfd_elf_print_symbol (bfd *abfd, bfd_print_symbol_type how) { FILE *file = (FILE *) filep; + const char *symname = symbol->name ? symbol->name : ""; + switch (how) { case bfd_print_symbol_name: - fprintf (file, "%s", symbol->name); + fprintf (file, "%s", symname); break; case bfd_print_symbol_more: fprintf (file, "elf "); @@ -2340,11 +2340,10 @@ bfd_elf_print_symbol (bfd *abfd, if (bed->elf_backend_print_symbol_all) name = (*bed->elf_backend_print_symbol_all) (abfd, filep, symbol); - if (name == NULL) - { - name = symbol->name; - bfd_print_symbol_vandf (abfd, file, symbol); - } + if (name != NULL) + symname = name; + else + bfd_print_symbol_vandf (abfd, file, symbol); fprintf (file, " %s\t", section_name); /* Print the "other" value for a symbol. For common symbols, @@ -2391,7 +2390,7 @@ bfd_elf_print_symbol (bfd *abfd, fprintf (file, " 0x%02x", (unsigned int) st_other); } - fprintf (file, " %s", name); + fprintf (file, " %s", symname); } break; } diff --git a/bfd/pef.c b/bfd/pef.c index f330b92e821..324adb33d69 100644 --- a/bfd/pef.c +++ b/bfd/pef.c @@ -210,16 +210,17 @@ bfd_pef_print_symbol (bfd *abfd, bfd_print_symbol_type how) { FILE *file = (FILE *) afile; + const char *symname = symbol->name ? symbol->name : ""; switch (how) { case bfd_print_symbol_name: - fprintf (file, "%s", symbol->name); + fprintf (file, "%s", symname); break; default: bfd_print_symbol_vandf (abfd, (void *) file, symbol); - fprintf (file, " %-5s %s", symbol->section->name, symbol->name); - if (startswith (symbol->name, "__traceback_")) + fprintf (file, " %-5s %s", symbol->section->name, symname); + if (startswith (symname, "__traceback_")) { unsigned char *buf; size_t offset = symbol->value + 4; diff --git a/bfd/syms.c b/bfd/syms.c index b370a3375d9..816296b68a3 100644 --- a/bfd/syms.c +++ b/bfd/syms.c @@ -777,7 +777,7 @@ bfd_symbol_info (asymbol *symbol, symbol_info *ret) else ret->value = symbol->value + symbol->section->vma; - ret->name = symbol->name; + ret->name = symbol->name ? symbol->name : ""; } /* diff --git a/ld/ldlang.c b/ld/ldlang.c index 7f9e3d2b119..343c4de53f4 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -4895,9 +4895,6 @@ ld_is_local_symbol (asymbol * sym) if (name == NULL || *name == 0) return false; - if (strcmp (name, "(null)") == 0) - return false; - /* Skip .Lxxx and such like. */ if (bfd_is_local_label (link_info.output_bfd, sym)) return false;