From patchwork Sat Oct 5 02:37:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 98420 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 5734E385ED4C for ; Sat, 5 Oct 2024 02:38:17 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id EAC23385DDDB for ; Sat, 5 Oct 2024 02:37:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAC23385DDDB 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 EAC23385DDDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728095868; cv=none; b=lIZoaRcKIqv2yzPaZoVWfW1PunQU1JVYns6ek5XjNYvKzRm6HwoC4nRp+duAZUOA3WyX5H7aNw/XTwDjCI+8l/HHr/faYNuoxmv7QDmzm8rQOUEH8ZuaF1AYU21jpOeQK0eRdmqcbM4JPPQZXxPtLG9DCIvhUSCQgF9CBpjpiUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728095868; c=relaxed/simple; bh=Si6XrWr+pn+5v8Qx3vsHJL/C+e+6zlWoh89sxKwLbyY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=AmY36PD0U7v/LrGBK9Ucs9l38yE4AkhwMqGyEvd1LoY0qXAsU8hHDOLtHurhiZV5bX9oU1TUzvIh54sQflV/mzxP3ts1UHGuEWpzkJJ6V+ab5iT+ZKrGSLHurBROG1qdeXRI1Zq0kVe/TmG5ED98r5vNJX/ROh20nZiPZh1Iz58= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-7db238d07b3so2217128a12.2 for ; Fri, 04 Oct 2024 19:37:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728095864; x=1728700664; darn=sourceware.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=bfzyQHY4qzWyVLS2DvxiAjYx0hlxE4RCh33EEsoa9F0=; b=KNZW+R2K6Tv5A3/ivheKIsJmtbU6/YZGI34PPFIp+3QL1XER+wylqlQnsOzZZGXvLx SE7x+EpjFluMgI1jSRrxfGfJbhzvh6ZrSv7SjtexYV6rDowG/tRzCSeg2UDpP3qgTUxZ 6DEvbbZ+MGps3+MO7YvVBuRgaoxElNgW3f0uhiMgLLYHCNuTJitPEbly/UdZ2CDlV9E9 +vT2ED0V58I3hbk1SFcYdoxxEjy4iq/ZzARmnoTPs4xOMP1llQKEMAOKRRjIRLrS+fXM vcI5MxG+Pc6fM5qEPnfysY0Y90po5UnbVlgRZeDe+dvG9EsHMlM+scbo0cmQsSEHyGxs SESA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728095864; x=1728700664; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=bfzyQHY4qzWyVLS2DvxiAjYx0hlxE4RCh33EEsoa9F0=; b=okQu3l6/FKHhvyl9bLbed6j59IDEwNs/SkLiK9HZHg2wdp/Jb0C6MnuwBSL4VIusg5 v8jLRa8kE6Xl9brT6uNTrpDlwfqHlLXGSgAsgRDgqzSMBObfRBzSdMa32uUO0vImIHG4 jPWcyXIPC/TOcD/hr+PFSsDERYfZcfHBwOpnz7WpwujNN9o7+ZzCs0M2flzA6p7RG6ku nNbaOxoHi6ab6vv1clJNL9eLjTPSh+Z58SmdNW4W7T+TlZC62H+DRNwHOeelZSn3HNf8 raRM/xKhknYF2H3138RG5YdWZIciqCy4u4NRWgKyakcpUMVRKBR/qdlmB7zONACg9vi1 R90w== X-Gm-Message-State: AOJu0YwWMLE8nN3eEsUX1REznUt5OxdgTkezhXsqOE2UBSwhcrlRdWU6 kgpKjUaM87oBF2WviF7kVA0cbkRuX8L8FBGV+vHGM5zq7KZ98f9MS99N+A== X-Google-Smtp-Source: AGHT+IH3iceXZRdtH3Jpkud8IQ2g2xygfYoakR6pmniWGV+eZZCgjsjjWVJ9p4n7mEvLpt36AKajZA== X-Received: by 2002:a17:903:22d2:b0:207:7eaa:d6bb with SMTP id d9443c01a7336-20bfe01feecmr76570135ad.29.1728095864447; Fri, 04 Oct 2024 19:37:44 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c138af94csm5065715ad.8.2024.10.04.19.37.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 19:37:44 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 5DC1911405A0; Sat, 5 Oct 2024 12:07:41 +0930 (ACST) Date: Sat, 5 Oct 2024 12:07:41 +0930 From: Alan Modra To: binutils@sourceware.org Subject: elf.c and elflink.c fixes for commit 68bbe1183379 Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3032.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, 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 Plus some tidies to swap_out_syms. * elf.c (swap_out_syms): Handle NULL sym name. Use correct type for return of _bfd_elf_strtab_add. Simplify. * elflink.c (bfd_elf_match_symbols_in_sections): Handle NULL sym name. diff --git a/bfd/elf.c b/bfd/elf.c index 4012d994272..c68d7373b8f 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -8734,21 +8734,21 @@ swap_out_syms (bfd *abfd, Elf_Internal_Sym sym; flagword flags = syms[idx]->flags; - if (!name_local_sections - && (flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM) + if (syms[idx]->name == NULL + || (!name_local_sections + && (flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)) { /* Local section symbols have no name. */ - sym.st_name = (unsigned long) -1; + sym.st_name = 0; } else { /* Call _bfd_elf_strtab_offset after _bfd_elf_strtab_finalize to get the final offset for st_name. */ - sym.st_name - = (unsigned long) _bfd_elf_strtab_add (stt, syms[idx]->name, - false); - if (sym.st_name == (unsigned long) -1) + size_t stridx = _bfd_elf_strtab_add (stt, syms[idx]->name, false); + if (stridx == (size_t) -1) goto error_return; + sym.st_name = stridx; } bfd_vma value = syms[idx]->value; @@ -8959,9 +8959,7 @@ Unable to handle section index %x in ELF symbol. Using ABS instead."), for (idx = 0; idx < outbound_syms_index; idx++) { struct elf_sym_strtab *elfsym = &symstrtab[idx]; - if (elfsym->sym.st_name == (unsigned long) -1) - elfsym->sym.st_name = 0; - else + if (elfsym->sym.st_name != 0) elfsym->sym.st_name = _bfd_elf_strtab_offset (stt, elfsym->sym.st_name); if (info && info->callbacks->ctf_new_symbol) diff --git a/bfd/elflink.c b/bfd/elflink.c index 9eb1122d513..a498dbb12a6 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -8819,6 +8819,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2, symp->name = bfd_elf_string_from_elf_section (bfd1, hdr1->sh_link, ssym->st_name); + if (symp->name == NULL) + goto done; symp++; } @@ -8832,6 +8834,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2, symp->name = bfd_elf_string_from_elf_section (bfd2, hdr2->sh_link, ssym->st_name); + if (symp->name == NULL) + goto done; symp++; } @@ -8878,14 +8882,22 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2, goto done; for (i = 0; i < count1; i++) - symtable1[i].name - = bfd_elf_string_from_elf_section (bfd1, hdr1->sh_link, - symtable1[i].u.isym->st_name); + { + symtable1[i].name + = bfd_elf_string_from_elf_section (bfd1, hdr1->sh_link, + symtable1[i].u.isym->st_name); + if (symtable1[i].name == NULL) + goto done; + } for (i = 0; i < count2; i++) - symtable2[i].name - = bfd_elf_string_from_elf_section (bfd2, hdr2->sh_link, - symtable2[i].u.isym->st_name); + { + symtable2[i].name + = bfd_elf_string_from_elf_section (bfd2, hdr2->sh_link, + symtable2[i].u.isym->st_name); + if (symtable2[i].name == NULL) + goto done; + } /* Sort symbol by name. */ qsort (symtable1, count1, sizeof (struct elf_symbol),