From patchwork Thu Feb 12 00:13:59 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1831 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855289; bh=ANFZkXFpvbfPzA0IxSPhtdzdD0Giy9gMOsalDZnw1ig=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=skk52+zcMOCcR7XHSZWLth2AnoTzqtI7nDD4JhSc1byeR9Xm2QJqEe1lknl2FLYFv TQja1KuQlP1kpkvgScL8IuE8U08SRMoum2xoVJzh29kYkl2yuf6H+VsBKF9soCLWYL Hs8jk1bhswN0LnZtwzq4EHGjH+KTh9OtUjMOzfBRQJyoKi79mBcd5Zor7AZ507IZRV ipFzRCTqtvzrquTQpaGgza1Pf7e052ebaCn5VYtq9MQh7B2+mni7XF++fUjnoa3NKP oNAfuNI00aWsPXEAL5O8aA3fwJBdHhXmBpLFcYmNSBm/vD6jzTMvzmHcSPZkagWYqD LrIoTSaOsCefA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3841169AB0 for ; Wed, 11 Feb 2026 17:14:49 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id oarCiRYj0vnD for ; Wed, 11 Feb 2026 17:14:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855289; bh=ANFZkXFpvbfPzA0IxSPhtdzdD0Giy9gMOsalDZnw1ig=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=skk52+zcMOCcR7XHSZWLth2AnoTzqtI7nDD4JhSc1byeR9Xm2QJqEe1lknl2FLYFv TQja1KuQlP1kpkvgScL8IuE8U08SRMoum2xoVJzh29kYkl2yuf6H+VsBKF9soCLWYL Hs8jk1bhswN0LnZtwzq4EHGjH+KTh9OtUjMOzfBRQJyoKi79mBcd5Zor7AZ507IZRV ipFzRCTqtvzrquTQpaGgza1Pf7e052ebaCn5VYtq9MQh7B2+mni7XF++fUjnoa3NKP oNAfuNI00aWsPXEAL5O8aA3fwJBdHhXmBpLFcYmNSBm/vD6jzTMvzmHcSPZkagWYqD LrIoTSaOsCefA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 26F7169AAD for ; Wed, 11 Feb 2026 17:14:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855287; bh=nv88Sahdq+IRDaw5UWXnFzVnlY52j3oiuStrI1+ig4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ut+TYLL8V05OhQVI3PMbAl5sjfr+HQX+YjOk2DbM/baccf00ibbuyon7KprJtDa8K YhUWTiGH3+Wi67niWlbNW4d5m+eewE0KCldsDf8wG1WkoS56r1dCiuJ9nyTpkwTq3m weO0WL0k0C7wNiEFnSiw7GRDxE/DzZrP/P0oLK4VEtrUZTkW1PBNWneDMStk95P+O5 hVyggneVv1mmJtwj07tZbJUSXWx4eOAktpxDYiQ7gyaybie9P7y17SmEwzLccBECP7 wYX5Lqqrd9+VB4sSDGANX+Ld+RAgChAR49/3NF1HasdheYyqFXVdaePwA6YbjJ//Wq 0NbAMzjnXXrDg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 74B5B69A99; Wed, 11 Feb 2026 17:14:47 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 17ZWqurcY8lP; Wed, 11 Feb 2026 17:14:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855287; bh=7dv0Ed0HgP1E1pREUrwZOaSSVFRjRTQIKEIhx5yoBQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BRk5PGnUr9xmz7BOGaOFNw7mAjyhbpuggmEyj+90StMb2vRwgZffp2ZHr+Whb1RBK ayxpPRETNTiLcqWXPdwDrz3n91SYUHl4HjtY2HZzK7WBcKN1LEuH4p/ZlTJ6kRrFi7 UZw9X+FvW/CLqwDJksSKRDPu+/xvmP2yodQzWNRzYVja/Ylf+UaQ2DvQGZV2poJBH/ n/iNrSGC67SpWtMKKfRYiNuayMq+ROCNI9JZkhm2EIxpwBQz/65vsQgLZWGtHPilKa WN0Y44tDEN5Bew5e4ZDgshb/aAw1ovyY/jUr6V7dKI4KQDhVh/ykUfEJ4atVyy5s7o KSRJo8+TkPvcA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B8E55699C6; Wed, 11 Feb 2026 17:14:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 11 Feb 2026 17:13:59 -0700 Message-ID: <20260212001410.1919749-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212001410.1919749-1-sjg@u-boot.org> References: <20260212001410.1919749-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JQ7ZZY2UELYJZLDZR7JQLZ7TJKQDSBWB X-Message-ID-Hash: JQ7ZZY2UELYJZLDZR7JQLZ7TJKQDSBWB X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 08/15] riscv: efi: Exclude PLT relocations from the reloc loop List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass GNU ld includes DT_PLTRELSZ in DT_RELASZ, so the EFI self-relocation code processes R_RISCV_JUMP_SLOT entries from .rela.plt alongside the expected R_RISCV_RELATIVE entries from .rela.dyn. JUMP_SLOT entries have a different format and cause incorrect fixups. Subtract DT_PLTRELSZ from the total relocation size so that only R_RISCV_RELATIVE entries are processed. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- arch/riscv/lib/reloc_riscv_efi.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/riscv/lib/reloc_riscv_efi.c b/arch/riscv/lib/reloc_riscv_efi.c index c1039dd165d..da448bfdf96 100644 --- a/arch/riscv/lib/reloc_riscv_efi.c +++ b/arch/riscv/lib/reloc_riscv_efi.c @@ -52,7 +52,7 @@ efi_status_t EFIAPI _relocate(long ldbase, Elf_Dyn *dyn) { - long relsz = 0, relent = 0; + long relsz = 0, relent = 0, pltrelsz = 0; Elf_Rela *rel = 0; unsigned long *addr; int i; @@ -68,11 +68,21 @@ efi_status_t EFIAPI _relocate(long ldbase, Elf_Dyn *dyn) case DT_RELAENT: relent = dyn[i].d_un.d_val; break; + case DT_PLTRELSZ: + pltrelsz = dyn[i].d_un.d_val; + break; default: break; } } + /* + * GNU ld includes DT_PLTRELSZ in DT_RELASZ. Subtract it so + * we only process R_RISCV_RELATIVE entries from .rela.dyn and + * do not run into R_RISCV_JUMP_SLOT entries from .rela.plt. + */ + relsz -= pltrelsz; + if (!rel && relent == 0) return EFI_SUCCESS;