From patchwork Sun Nov 30 07:50:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 125618 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 408C248FD395 for ; Sun, 30 Nov 2025 07:51:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 408C248FD395 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Jahsz+H7 X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by sourceware.org (Postfix) with ESMTPS id 2A8CA48FD863 for ; Sun, 30 Nov 2025 07:51:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A8CA48FD863 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 2A8CA48FD863 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764489079; cv=none; b=VXp67WyTvbhh+Rzpqgx87XJQZCNSJZBp4KpCezMbIEw7KhAulU3/SDGiQmTK4vXexYjuRHdBNCQS6J/TtnylqCcl+KaoPNQkDuNDEDzf07EktKJLW+f5Et0m042ybcPEpLFIUtadqFCSJm560biPwArhnBDE7HooJgBe3BTQBzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764489079; c=relaxed/simple; bh=MTNjIVCKn+oYPcnTyeLNEIvYy6gRWq7PKVqhZ2pbkgc=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=e1fPc+zvD2DWZtRkrpwJ3V7WqVMKowdppDzXJ7+Po0n2FJ9URKGkN3lCqDneSb0Jlk5yojFqV4goJoV+4DfasZfZSK6UO+WTz3A1dlT/oOt+u0xqSxfMel55/Mfdtm4wBlgGhAjP1xzuRLwnh2hqtXgQl4zY+Lec7dv2jVsp4jc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A8CA48FD863 Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-341988c720aso2710611a91.3 for ; Sat, 29 Nov 2025 23:51:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764489078; x=1765093878; darn=sourceware.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Y8Mbdl/EDByykIk9Pn6LQRZjGFRPNRUO+nqCreu/iSg=; b=Jahsz+H7KJJor0Udx4tDiSc8Kd/pAoz3uUKfEJn/Zf7zQW5i5Bx70+hq+qoQ1ulgPW JTcYQvWMjMj1y+4u3FzI0KFx/J8oaP5tpKs4IZNNvSbwMjQsPGoEKt0TU7HnTKzCOf4j sbSAGHHZHG2zhzDZSqFzay6oYGQ+5bodyX1cwTpbrzmLRqogRyFeTBnkxMJf+q1tWLwD ZAm8II0vuTUl344UCPAd3+Mfpo7PWFbttVsyG/5c3RgPGq2yjKfOjoNa0phH86TUt2Ad uGxp+G2ynhBbmciglMPxLHaTLgTvPtYHDvjQXmgF/bgrmx6VZwnscoIz0qbKzJmpheg3 5QaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764489078; x=1765093878; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Y8Mbdl/EDByykIk9Pn6LQRZjGFRPNRUO+nqCreu/iSg=; b=TFcI/QL01BeciQgPcRWmauCBlYHalLNDD0nykY4Y+gwtPU416smfeGfWrO7DURKRzl WW+1Pioh11Vn0QacA/OKMjvEpUuNGNHUkJq38w8mePYZdoK5f6eA7zCsQLfd1t1hpgzD y0/Dq83JrHyfKVvX5pcrtYBfzWVtsPr867FiGpN51qAoYGbOJuVNuSKjeXDHUxh9Df0x tjHGFg7CqLxOAb2jADggN/5yVcxufoKfjnqzuWk6xIvivF8NW5vEMEy+/Vex7Kv5rPja EfQUl8vF0+97vCN4B4Pe1AQHNrmgzUS+kZE5OtqFzZIG51p+iMBTJCq4XqoMHAg2KjJU xPZA== X-Gm-Message-State: AOJu0Yyn7zre2+IL212/zxxGKnhqBHho0yuEJ3CGTYetVgFQ17H3jnou S00gZiH62/1e7XVsbFKu0gXgilQpme651ez2X5Y7K+3QqfZK6IwpDtY2Xn9G7TypGR92CnahQDA 6xFHSTEFElxuZHRhkx1oeEIow+8kOSeg= X-Gm-Gg: ASbGncvMhmkJMhtREtw7H+D+Uw8qKtXEj6dZu8L1xEcVGo86yjGiFDW5n4wRXf/OWCO XU3XPRcZucabmF6lhtiA55B6VkYOx9kqtdiyr4HYPif39/P9nQ3slJldRJZNKgw7arU/AkNQ2ok cuXiIfWZJf0QwJcrV5HoLwlWzZErX/CVYhODI0+8D5aNj3PajJtOfjQkyC6iMlGRlcNF9dciU+K QS6yYsyE0v3uDCxsvw0lpbSvj4q1wxH5p8T6iRup1QHmdaz5CPoVB5UfQv2urkDEg1LBtXGg/BF CGny X-Google-Smtp-Source: AGHT+IHxrIoHPnCLQFTnN15g3HwqqHh5M5TU7ETO+35suYeo04t96izBNu3+Toahv2ZWEosFKg4OnQrom0lOJbxiFSk= X-Received: by 2002:a17:90b:2d4f:b0:341:c964:126c with SMTP id 98e67ed59e1d1-34733f5b790mr28903821a91.34.1764489077901; Sat, 29 Nov 2025 23:51:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "H.J. Lu" Date: Sun, 30 Nov 2025 15:50:39 +0800 X-Gm-Features: AWmQ_bkMfv5-UHzKfN1L-o_LqJxxi8E_KltvtiWcM42NhH0F-ee2dBkwNMgYRQM Message-ID: Subject: [PATCH] mips: Assert dynamic symbol counts only with dynamic sections To: Alan Modra , "Maciej W. Rozycki" Cc: Binutils , Nick Clifton , Jan Beulich X-Spam-Status: No, score=-3012.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 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 On Sun, Nov 30, 2025 at 11:10 AM Alan Modra wrote: > > OK. > After commit 54fbc12d6404b645363f901110a21f4410067df5 Author: H.J. Lu Date: Fri Nov 28 16:07:57 2025 +0800 elf: Renumber local dynamic symbols only if needed mips-linux got FAIL: MIPS magic __ehdr_start symbol test 1 (o32) FAIL: PR ld/21334 MIPS GOT16 relocation in static binary with assertion failures on BFD_ASSERT (hsd.max_local_dynindx <= htab->root.local_dynsymcount + 1); Since there are dynamic symbols only if there are dynamic sections, assert dynamic symbol counts only if there are dynamic sections. * elfxx-mips.c (mips_elf_sort_hash_table): Assert dynamic symbol counts only if there are dynamic sections. From e63ad8aeb72c21a00397d2366cb89d65e638b39c Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sun, 30 Nov 2025 15:32:53 +0800 Subject: [PATCH] mips: Assert dynamic symbol counts only with dynamic sections After commit 54fbc12d6404b645363f901110a21f4410067df5 Author: H.J. Lu Date: Fri Nov 28 16:07:57 2025 +0800 elf: Renumber local dynamic symbols only if needed mips-linux got FAIL: MIPS magic __ehdr_start symbol test 1 (o32) FAIL: PR ld/21334 MIPS GOT16 relocation in static binary with assertion failures on BFD_ASSERT (hsd.max_local_dynindx <= htab->root.local_dynsymcount + 1); Since there are dynamic symbols only if there are dynamic sections, assert dynamic symbol counts only if there are dynamic sections. * elfxx-mips.c (mips_elf_sort_hash_table): Assert dynamic symbol counts only if there are dynamic sections. Signed-off-by: H.J. Lu --- bfd/elfxx-mips.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index e37c45fec15..fe896839d76 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -4034,12 +4034,15 @@ mips_elf_sort_hash_table (bfd *abfd, struct bfd_link_info *info) hsd.mipsxhash = NULL; mips_elf_link_hash_traverse (htab, mips_elf_sort_hash_table_f, &hsd); - /* There should have been enough room in the symbol table to - accommodate both the GOT and non-GOT symbols. */ - BFD_ASSERT (hsd.max_local_dynindx <= htab->root.local_dynsymcount + 1); - BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx); - BFD_ASSERT (hsd.max_unref_got_dynindx == htab->root.dynsymcount); - BFD_ASSERT (htab->root.dynsymcount - hsd.min_got_dynindx == g->global_gotno); + if (htab->root.dynamic_sections_created) + { + /* There should have been enough room in the symbol table to + accommodate both the GOT and non-GOT symbols. */ + BFD_ASSERT (hsd.max_local_dynindx <= htab->root.local_dynsymcount + 1); + BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx); + BFD_ASSERT (hsd.max_unref_got_dynindx == htab->root.dynsymcount); + BFD_ASSERT (htab->root.dynsymcount - hsd.min_got_dynindx == g->global_gotno); + } /* Now we know which dynamic symbol has the lowest dynamic symbol table index in the GOT. */ -- 2.52.0