From patchwork Tue Sep 23 02:24:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 120666 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 33BC73858C24 for ; Tue, 23 Sep 2025 02:28:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33BC73858C24 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=bK3x4uf0 X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by sourceware.org (Postfix) with ESMTPS id 4371C3858C78 for ; Tue, 23 Sep 2025 02:25:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4371C3858C78 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 4371C3858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758594330; cv=none; b=mM35fa/Mo4YPV/p+eJ53MZlGdx728H6Pk2YI8q90z+04IO6Gm+9w4vb0zKX7c1Ku3bbrCTuwTDws4TEtreKBo5ZkZWg7a17QJzbYElV1zQTv7vp0Lq5tplBCqIMz1z250+S4SiI1b1xg6AMO6V2D4/+SBbOozOCvIPSwmNtAq08= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758594330; c=relaxed/simple; bh=YWaO6BYSKFYVGRFmbMZ39EJVt4VNhTiewgrdJlQgTkE=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=ZBkYm45APM/TkNFAWxIk4ENBwv6aEnzCVzWFJ8T6EMG4u0yiBTtCh6rZDnLHs7MmgPb64y89R/GiqKiKvA9gvSm4xOjh3qQ2DGdAORHrPBi3BJMtcMev6Bb0Y7TwLaNAzI1IsffnxQfElf4Am9brR1vxG2vHv8jw45XjrTjWZgI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4371C3858C78 Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-71d601859f5so40064907b3.0 for ; Mon, 22 Sep 2025 19:25:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758594329; x=1759199129; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=5FoGwaI5WjPpr/DBFIG0EG3jysZw/XXfX0G3mQ9wCsc=; b=bK3x4uf0Hwh3dR8xn6xoiyYZEabbMuVX2WKZDYcgrKvQevUEBRocAuEeSwmZ5+5Pt0 gpxwEJZ3+Z4NDa1mWrBU6Jcn21hNpp7owhB8dWvtvk+Xm6vjkXmKCiR1BvtBANaXa12+ +6lWAR9dfE4lHJwyQV2Kh15KxDw+HjDeo241W2vP3qjUGiXK2WXeSdLp4OuAqrPiXmOn IcPoxc4FEp+AlswaNhSz9BF3y7ttTiypM8uWXxHGm73JDm3el6Wtnh59xGC4+4O72lzj /evBveH1+z5gw38qspqS3yUExFpzNjT1fbIYSK7qFFllhZntmA9s8kzGz86mxGw+IIc2 xOgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758594329; x=1759199129; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5FoGwaI5WjPpr/DBFIG0EG3jysZw/XXfX0G3mQ9wCsc=; b=EHajCRWOL2tDNjYz5P9VhoUnycdXeiv0qdvuBwFhhhDSEE0VK8xoS1p7JCm/4Pg7Kd OpdudyFQFFOP+H34iOnSUNucCwSm5ScvnyHKv4QfsZ5C4Q3p3F6XgtHcLXR8R5/atcqz pyVvG6I2pFnIR1ArTCNGvRy3bKVlwx6AnpuPT+u+SjwsuYpJtZChntgLpo9NxA3vivpe k5K+6FYMqTZrQIu9kWbtlC3dYzu2b1d2gHgBkGsHvMuDXgwq37q8V5S6p1EpJ6Acqe1Y HiUQabuJjg4EsHFeV8rIh3Y3kCwPZD2bDMj0GbsxMfRraNsfM39J02iL/1XF9HoK1JSG lcmA== X-Gm-Message-State: AOJu0Yyzk9p0H9423D/js1JYPXU3vqKZsO+jJkFW23HatQdaZQSp8aLy 3ULJO1h4J7rpW36r7QXZJxcvkXhHYIOOBzTc7oKTg/9NMA1k9F9gv5C8iwZkNgFgprvzbyzz4iE cF6OgcFwNre97JiHTUGwd9EMI6ebOQWn7Xr1QmVA= X-Gm-Gg: ASbGncuz1H3O+F+01AbBUj6moPlek5swJrbjCd+FO2UEdpqQuQv3VVSPy9awWFmgjw1 hNmVxmGW3jiWgsbMVOw18DOQVclN7a67QpxVoJAaUfUTh8ZY66fDLSWf3St9wR9BFAqRsz9vWtm i4/2Lt5WF6paimqxuD7wjM+fjWU59hp4DXLJQbXpTlSYXEbsZChgSwnPTaly5wTM0SrP1rsXuNk uURi0Q+8dwibiuLXK8= X-Google-Smtp-Source: AGHT+IEb9U3WUfqzG6srxkZzPvNowW4fbehpkJbRbQmiPtu7uY9nKWIZ34igJRqrMzTMtCWDcFEeCEENQ8SWvTzt5ZI= X-Received: by 2002:a05:690c:a06:b0:742:adbc:3a59 with SMTP id 00721157ae682-758a81ef911mr6260747b3.53.1758594329385; Mon, 22 Sep 2025 19:25:29 -0700 (PDT) MIME-Version: 1.0 From: "H.J. Lu" Date: Tue, 23 Sep 2025 10:24:53 +0800 X-Gm-Features: AS18NWCyd5ua1JkxU6wnaMQLDBU25kEFUy89mPMY2ucZo1FDOqy7bsMb0A3d1V8 Message-ID: Subject: [PATCH 4/4] elf: Return error on unsorted symbol table if not allowed To: Binutils , Alan Modra , Nick Clifton , Jan Beulich X-Spam-Status: No, score=-3012.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 Normally ELF symbol table should be sorted, i.e., local symbols precede global symbols. Irix 6 is an exception and its elf_bad_symtab is set to true. Issue an error if elf_bad_symtab is false and symbol table is unsorted. PR ld/33450 * elflink.c (set_symbol_value): Change return type to bool and return false on error. Issue an error on unsorted symbol table if not allowed. (elf_link_input_bfd): Return false if set_symbol_value reurns false. From 18f366556c2328ba62f70a03a227c4b25aad2835 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 23 Sep 2025 08:52:26 +0800 Subject: [PATCH 4/4] elf: Return error on unsorted symbol table if not allowed Normally ELF symbol table should be sorted, i.e., local symbols precede global symbols. Irix 6 is an exception and its elf_bad_symtab is set to true. Issue an error if elf_bad_symtab is false and symbol table is unsorted. PR ld/33450 * elflink.c (set_symbol_value): Change return type to bool and return false on error. Issue an error on unsorted symbol table if not allowed. (elf_link_input_bfd): Return false if set_symbol_value reurns false. Signed-off-by: H.J. Lu --- bfd/elflink.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/bfd/elflink.c b/bfd/elflink.c index f366e8f569e..ec869624cf8 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -9155,7 +9155,7 @@ struct elf_outext_info := as in C := as in C, plus "0-" for unambiguous negation. */ -static void +static bool set_symbol_value (bfd *bfd_with_globals, Elf_Internal_Sym *isymbuf, size_t locsymcount, @@ -9176,9 +9176,15 @@ set_symbol_value (bfd *bfd_with_globals, "absolute" section and give it a value. */ sym->st_shndx = SHN_ABS; sym->st_value = val; - return; + return true; + } + if (!elf_bad_symtab (bfd_with_globals)) + { + _bfd_error_handler (_("%pB: corrupt symbol table"), + bfd_with_globals); + bfd_set_error (bfd_error_bad_value); + return false; } - BFD_ASSERT (elf_bad_symtab (bfd_with_globals)); extsymoff = 0; } @@ -9188,11 +9194,12 @@ set_symbol_value (bfd *bfd_with_globals, if (h == NULL) { /* FIXMEL What should we do ? */ - return; + return false; } h->root.type = bfd_link_hash_defined; h->root.u.def.value = val; h->root.u.def.section = bfd_abs_section_ptr; + return true; } static bool @@ -11890,8 +11897,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd) return false; /* Symbol evaluated OK. Update to absolute value. */ - set_symbol_value (input_bfd, isymbuf, locsymcount, - r_symndx, val); + if (!set_symbol_value (input_bfd, isymbuf, locsymcount, r_symndx, + val)) + return false; + continue; } -- 2.51.0