From patchwork Tue Sep 23 02:15:51 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: 120663 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 365383858408 for ; Tue, 23 Sep 2025 02:18:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 365383858408 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=IPzpNc4N X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-yx1-xb12f.google.com (mail-yx1-xb12f.google.com [IPv6:2607:f8b0:4864:20::b12f]) by sourceware.org (Postfix) with ESMTPS id 3D6F63858D1E for ; Tue, 23 Sep 2025 02:16:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D6F63858D1E 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 3D6F63858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758593789; cv=none; b=WbIO3OrGgZcV6HaSS/FANgP8c2pKwyJEOUVluFWBa6/QnE0z83duDQxVU8lCJ7BYOPAUJiABJatpR0EZC2aWIygZrHbepi/XV/xkCrGlZgDZF1M+FFldo4Azk6pXiGFi/J5W1QamQC40jnlSPxu/sdElf0Qe36WtFUc0IDjjfuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758593789; c=relaxed/simple; bh=VKd5Mm4g/kY3bnTXBIIlXmX0lP+TMrt7JIBSePH5cL4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=MmXT5FFgbh7IXECRZPLI3UimtN9sCZA5zXxn5RnM4l/0BT/tbfUrWwqtCO76KxBuKO8fpMMHc4rjeAu67UDQcZBJyzIxLej9DXIz7jP+ObgICMtv1+Cim4NVc1GUiXhfM1zo9xnimKFjPVusT3jwKHYOV+7G4gk+JI3GDl5edRY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D6F63858D1E Received: by mail-yx1-xb12f.google.com with SMTP id 956f58d0204a3-6353e91a04aso1127339d50.2 for ; Mon, 22 Sep 2025 19:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758593788; x=1759198588; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=GqJLtiX0N2qhSfPnWYFvcukrVhu62C8iKaYFpIkmc5g=; b=IPzpNc4NpBa8Il+Owr/SJNv+QZvb2eRA+iZ4PvTkwZ2cTKXymyMtgASkdtCyOhsiug RpBBaFeS7eafL1GlrUc2oqokWDv5QbDtjHq2wR72/MSyDNLERqJCJuvWcmJ0MvENjc0V 3FQVDiIkTj6zaAzlibJM+9BeBi4KQpiWgMjxrHD7n4dz5Kh8/MnyopCkMh98RuXq2b0H erV62IaA1E64CLbFBj9rWfm/WWMLSWEWUEQP6l/YPEgGYaT7WUIUb/iWSgmnWpOQ6fgT zxe0rIBoeEs/Hq0OHNzZbeb3y3vCSkEg2Dd7qrsj8ordYeClwv70iHifE0xZ+D+nWBCr dGWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758593788; x=1759198588; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=GqJLtiX0N2qhSfPnWYFvcukrVhu62C8iKaYFpIkmc5g=; b=P8YFKcbVNNGX1a0mjJ9ATzmiXwKqJlVUIP2nt5U/vhpbPFb6zUOXKivDee0B0wq7oo 9joZFLt3COFYC5PW8VD0ej2aFR69n1nUFc7WMMXIWzMw0go7yKi1NDrjyNaU384rmNl4 8Cft+WqmnHUlnljLpaGJJQb0nUwn+SwHz2LEU5vUYJeTbt+wdMrWGLCacj40QAc2K+Mh NjasKrXzknsK84oO47qXQzD+ZCT6Pi82Xk6bfwQMEmGzgl0o3q84lI1S5b65el4XrsUr abqCZHxjYSUZhnVJwG7fhSX/lbghhzZ8SBLDL42YtLmtNmO95giEZeB9GLCh4guq2vgl fN1A== X-Gm-Message-State: AOJu0YzVQfO65Wsf1JDZHsWajlr9OGrKPjTUissufdWfLoXxi2rwtZVi cxVWFJ+GIngBwv4AwvpUZkUWU2syCcksHwBdJD47H6F93vEwK5fsYdtWNct5P2Rl01EOi3uJ/Yr IJZFZuqgNVcBzXJVhpzxc49awPN+mvHdVhcu3Vj4= X-Gm-Gg: ASbGncs2TUYNw0dYnuTXgdJsCc++HKQhvZf5Ky+qhxRd/jZsyM7Mmlf0FeBKfRMR4ow jBSBQw014hKHvAKHWF0gs0E4tp3phcNKYVlrNgVGmK9NczFleZKHkstePE6n0ZmdsSbPAH5U7c/ cTO+hMy8GShnUTupA58fptKchbVjDKP719vTCp3XVDDXcaUusx9tbpJo2OLPWg4SgyyqJ1/l+cR Ia1Ewzz X-Google-Smtp-Source: AGHT+IFOSACXgfaePvn7jOAIZiHVDIl3I4afM81wwzYUdczcWRpaZymPx5f3od+Yiufh+VnYNsoOMo35VBRfwi/ym6c= X-Received: by 2002:a05:690e:d43:b0:633:f908:1f1a with SMTP id 956f58d0204a3-636047928bemr855872d50.37.1758593788145; Mon, 22 Sep 2025 19:16:28 -0700 (PDT) MIME-Version: 1.0 From: "H.J. Lu" Date: Tue, 23 Sep 2025 10:15:51 +0800 X-Gm-Features: AS18NWAKdlKkn1efayD3SouxRhkrWzovRxcAINFi3Z8NBlr7nKB5Q-phIvIQLjw Message-ID: Subject: [PATCH 1/4] elf: Disallow the empty symbol name To: Binutils , Alan Modra , Nick Clifton , Jan Beulich X-Spam-Status: No, score=-3014.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_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 Reject the empty symbol name, "". PR ld/33456 * elflink.c (elf_link_add_object_symbols): Disallow the empty symbol name. From 3c3fab00d18ef3303e143e44aef88a8f60f1f904 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 23 Sep 2025 10:05:14 +0800 Subject: [PATCH 1/4] elf: Disallow the empty symbol name Reject the empty symbol name, "". PR ld/33456 * elflink.c (elf_link_add_object_symbols): Disallow the empty symbol name. Signed-off-by: H.J. Lu --- bfd/elflink.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bfd/elflink.c b/bfd/elflink.c index b04b017747f..66982f82b94 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -5096,6 +5096,13 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) if (name == NULL) goto error_free_vers; + if (name[0] == '\0') + { + _bfd_error_handler (_("%pB: corrupt symbol table"), abfd); + bfd_set_error (bfd_error_bad_value); + goto error_free_vers; + } + if (isym->st_shndx == SHN_COMMON && (abfd->flags & BFD_PLUGIN) != 0) { -- 2.51.0 From patchwork Tue Sep 23 02:23:45 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: 120665 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 57F5F385840C for ; Tue, 23 Sep 2025 02:25:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57F5F385840C 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=A7+F1grO X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by sourceware.org (Postfix) with ESMTPS id F16A13858D1E for ; Tue, 23 Sep 2025 02:24:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F16A13858D1E 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 F16A13858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b2a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758594263; cv=none; b=bSNklH68VDrR+46EFmamlOug8iD6Q69slpz2GCAXV4ZOzhUuAmA5Qj9H9lJNhO0zXTGzrvUKuUzfeREl5jRDUra8h/V6QPDobcr3myKREaztLO+MTdt8ONwe6ovsFET4Hipp4DY8hIab7yIaNQvvYYQimbcFKIHotVSNWPbbixA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758594263; c=relaxed/simple; bh=dYkcvtvHrvTMkvZTGO9hVZPYzpkObxD0z12bHQVyarE=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=SNqT9Xh4y1IHdvOZ+9kvIWQKp4LNKBKXAfC7ifRaMJpx8NJ5h2/NazjxJ9gSjFESJwCk9D6NQNRuVIl67x0WmAEbJkTM1UbwuUPS4j+wsZnwfjnX9jIvDwlHCTm+kgfyzNNeBj56T7q3Gg/B3ZsZJUuaqrGDe6GnhdO0hhk0//o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F16A13858D1E Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-e94d678e116so5526513276.2 for ; Mon, 22 Sep 2025 19:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758594262; x=1759199062; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ClIfko1S/HPs2AjJCDqrAzbPNOOdmUnsNu1gvjanUrs=; b=A7+F1grOox2STb0T7RtNQcqwg68BVMqVYFdpK55pHXBRkj4zGtisgeG8z6qNJOyEqg m52gURfZuuqWuytWl2Va9sMbqXE76Xc9OUFcjqoYoA9cLTXmgSeb+7RHN/olCVutAEjl O/wwjDa/ZJ8vudyR8mxc8530t8aH+f1ygSPYeJq0vCHcqP62v3aHTby755eniICCiTBO L00ZnxaBR7QXYNcocYtD7Xgk301m6+GdKuiGmEKArPavMx8e6hbvMiJ2PRcEM3fFoops FLxFMovgjyhk9cI4Uwmy6bzIGx+93Yz/LFofsyNrt9sYzKJB7SWukJVTkiKSy/C0jkxg 7LBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758594262; x=1759199062; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ClIfko1S/HPs2AjJCDqrAzbPNOOdmUnsNu1gvjanUrs=; b=Y2TTnPzY+RHyUyou09BLj7UOGvmixWgqdktz0RVMjoyVzBapmip46UvSlt3BgqyB5Y /hZOXH3wCbh6assiAsH0kX84b19M3gOYrqp1vwR9v8k2ek7au0moNW0OZ4y8rZAcvR3j CFBPrwF5OYlIV60GyuqnjfCuVqQVRXRdT7pos31UWCPK+YLY6j5nzR8Si34jtfoH+t+d oz6sQpALpwl0p0nJmBUgLJgq00xgp2U0d4DLwkyfAhIMeTBbD70LVi5UaUO2kkZRw8JH tLuDQ/g5QGbPoFTmAdxT4FY3uyi4Y9ZxsvTfM+vxBPv6+gykhtn0CIcDkFeVmJ3RaoWS pbQQ== X-Gm-Message-State: AOJu0YzcQDbCtP/fCdct/TthXmyAohxy4oUl/GGfEddtkFV4ssJW158H mGm1pEbaqmvwP0vADaQfzyDd8vwAd5bc7I7qwSuyym9TcOYJp0AHxtlFVpBV7+BmBO2HE/BMEGu i44W48TFP7SyOC8wB/gWTpa28NJ0BLy794C7Lf64= X-Gm-Gg: ASbGncuOKWuTu+94MICF/ltXkWPZJg6/BNASa/dJMVKDtH3o59li19gZzq9DMbxOn7z /IXTgnIiA1D/gM/N9EWqCDBwY7PXXkla1XAIYFhketdopaaNVOIyhhi/2FKU0DcA62D6YZRq+gm 2B3PbE9kzz5hu9svAatKU1Ym2ZbbRxkLMvL03/egJwg4PLFYfO1IL/q1860h5fFqbyW6uVVxBTw Mvd5yI+ X-Google-Smtp-Source: AGHT+IFlT8YWq7pauiR97ePM/pMckuNiEguq9vjvk4mQ5kj8MmAsi7BWJPje41IKF0rQcz/r4htZqAUpLMNdIjtvVOU= X-Received: by 2002:a05:690e:2452:b0:635:4ecf:bdc6 with SMTP id 956f58d0204a3-6360464a990mr619385d50.40.1758594262139; Mon, 22 Sep 2025 19:24:22 -0700 (PDT) MIME-Version: 1.0 From: "H.J. Lu" Date: Tue, 23 Sep 2025 10:23:45 +0800 X-Gm-Features: AS18NWBqJiGJOsfO1dLQUmcGB5218BgQfxDHM3oSoQSosKsgfezOh5R6rMV9_eQ Message-ID: Subject: [PATCH 3/4] elf: Avoid linker crash on corrupt .eh_frame section To: Binutils , Alan Modra , Nick Clifton , Jan Beulich X-Spam-Status: No, score=-3012.2 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 Return false on corrupt .eh_frame section. Cap the .eh_frame section alignment to the larger of the section size and the pointer size. PR ld/33453 * elf-bfd.h (ABI_64_P): New. * elf-eh-frame.c (_bfd_elf_write_section_eh_frame): Return false on corrupt .eh_frame section. * elf.c (_bfd_elf_make_section_from_shdr): Limit .eh_frame section alignment. * elfxx-mips.c (ABI_64_P): Removed. * elfxx-sparc.c (ABI_64_P): Likewise. * elfxx-tilegx.c (ABI_64_P): Likewise. * elfxx-x86.h (ABI_64_P): Likewise. From dc96baa76c046ed34b05926a6401c6ebd0d1eb03 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 23 Sep 2025 08:25:49 +0800 Subject: [PATCH 3/4] elf: Avoid linker crash on corrupt .eh_frame section Return false on corrupt .eh_frame section. Cap the .eh_frame section alignment to the larger of the section size and the pointer size. PR ld/33453 * elf-bfd.h (ABI_64_P): New. * elf-eh-frame.c (_bfd_elf_write_section_eh_frame): Return false on corrupt .eh_frame section. * elf.c (_bfd_elf_make_section_from_shdr): Limit .eh_frame section alignment. * elfxx-mips.c (ABI_64_P): Removed. * elfxx-sparc.c (ABI_64_P): Likewise. * elfxx-tilegx.c (ABI_64_P): Likewise. * elfxx-x86.h (ABI_64_P): Likewise. Signed-off-by: H.J. Lu --- bfd/elf-bfd.h | 3 +++ bfd/elf-eh-frame.c | 5 +++++ bfd/elf.c | 21 +++++++++++++++++++-- bfd/elfxx-mips.c | 4 ---- bfd/elfxx-sparc.c | 3 --- bfd/elfxx-tilegx.c | 3 --- bfd/elfxx-x86.h | 3 --- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 51e6ae7bb78..5a131d735ff 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1919,6 +1919,9 @@ struct bfd_elf_section_data #define get_elf_backend_data(abfd) \ xvec_get_elf_backend_data ((abfd)->xvec) +#define ABI_64_P(abfd) \ + (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64) + /* The least object attributes (within an attributes subsection) known for any target. Some code assumes that the value 0 is not used and the field for that attribute can instead be used as a marker to diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c index 30bb313489c..93d412b38f0 100644 --- a/bfd/elf-eh-frame.c +++ b/bfd/elf-eh-frame.c @@ -2126,6 +2126,11 @@ _bfd_elf_write_section_eh_frame (bfd *abfd, /* Skip length. */ cie = ent->u.fde.cie_inf; + if (cie == NULL) + { + _bfd_error_handler (_("corrupt .eh_frame section")); + return false; + } buf += 4; value = ((ent->new_offset + sec->output_offset + 4) - (cie->new_offset + cie->u.cie.u.sec->output_offset)); diff --git a/bfd/elf.c b/bfd/elf.c index 6ef60301091..07428cb91f9 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -981,10 +981,27 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, } } + bfd_size_type alignment = hdr->sh_addralign; + if (streq (name, ".eh_frame")) + { + bfd_size_type eh_alignment = ABI_64_P (abfd) ? 8 : 4; + if (hdr->sh_size > eh_alignment) + eh_alignment = 1 << bfd_log2 (hdr->sh_size); + if (alignment > eh_alignment) + { + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB: warning: ignore .eh_frame section alignment (%ld), limit it to %ld"), + abfd, (unsigned long) alignment, + (unsigned long) eh_alignment); + alignment = eh_alignment; + } + } + if (!bfd_set_section_vma (newsect, hdr->sh_addr / opb) || !bfd_set_section_size (newsect, hdr->sh_size) - || !bfd_set_section_alignment (newsect, bfd_log2 (hdr->sh_addralign - & -hdr->sh_addralign))) + || !bfd_set_section_alignment (newsect, bfd_log2 (alignment + & -alignment))) return false; /* As a GNU extension, if the name begins with .gnu.linkonce, we diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index bf3fd7df805..181f9f5e9fc 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -816,10 +816,6 @@ static bfd *reldyn_sorting_bfd; #define ABI_N32_P(abfd) \ ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0) -/* Nonzero if ABFD is using the N64 ABI. */ -#define ABI_64_P(abfd) \ - (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64) - /* Nonzero if ABFD is using NewABI conventions. */ #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd)) diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c index bbaa7829132..1f3b9d831d8 100644 --- a/bfd/elfxx-sparc.c +++ b/bfd/elfxx-sparc.c @@ -37,9 +37,6 @@ /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */ #define MINUS_ONE (~ (bfd_vma) 0) -#define ABI_64_P(abfd) \ - (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64) - /* The relocation "howto" table. */ /* Utility for performing the standard initial work of an instruction diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c index 79358e6b204..577d259a3b8 100644 --- a/bfd/elfxx-tilegx.c +++ b/bfd/elfxx-tilegx.c @@ -27,9 +27,6 @@ #include "libiberty.h" #include "elfxx-tilegx.h" -#define ABI_64_P(abfd) \ - (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64) - #define TILEGX_ELF_WORD_BYTES(htab) \ ((htab)->bytes_per_word) diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h index 1ebc9d2f2e5..902592a3cf0 100644 --- a/bfd/elfxx-x86.h +++ b/bfd/elfxx-x86.h @@ -102,9 +102,6 @@ header. */ #define PLT_SFRAME_FDE_START_OFFSET sizeof (sframe_header) -#define ABI_64_P(abfd) \ - (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64) - /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid copying dynamic variables from a shared lib into an app's dynbss section, and instead use a dynamic relocation to point into the -- 2.51.0 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