From nobody Sun Apr 26 12:18:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2081C433EF for ; Tue, 28 Jun 2022 15:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347210AbiF1Pno (ORCPT ); Tue, 28 Jun 2022 11:43:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232822AbiF1Pnl (ORCPT ); Tue, 28 Jun 2022 11:43:41 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A31C635DE8; Tue, 28 Jun 2022 08:43:40 -0700 (PDT) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25SFhC1H008012; Tue, 28 Jun 2022 15:43:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=7PDB5FSkvAvomXijQiQvYer1vtrWRDpDFMakABgM6Aw=; b=LqwaM7aeMpE+VqTwx0qMxNtZ/kH797UvgdPknwlDHN5K+/TgPBtOJ01NE56Op5QOY26q FC6r2sAHlg7cv44/wSjhBgArxmER8/JVSd3fFsGdIYLYnw1gjZSngQawxreEcExMa2nL 5PDjHKhIetYcSeKmCz+qZNpXmgCBezwKwXBiS2Vz3H/MigFU0/yG1EaX3cLxiWLvmTbV dL+Elz4HepSWEJN8jHjF4LYPJZtKqVfG7G7mD/VA8Sp8Vlc9rmmhu/P6Mob1ZgmI6kfs nLOvp7+K2Nzd8u47dyFt4/X2pzTJQdHxYrIabhiOAba4NAys3r3IWHwdI8sgfPlS75qo 7A== Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3h04hh0034-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jun 2022 15:43:25 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25SFb5rg010438; Tue, 28 Jun 2022 15:43:23 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06fra.de.ibm.com with ESMTP id 3gwsmhutqt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jun 2022 15:43:23 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25SFhKPh20316476 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Jun 2022 15:43:20 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BA1D95204F; Tue, 28 Jun 2022 15:43:20 +0000 (GMT) Received: from li-NotSettable.ibm.com.com (unknown [9.43.54.243]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2222E5204E; Tue, 28 Jun 2022 15:43:17 +0000 (GMT) From: "Naveen N. Rao" To: Greg KH , Cc: , , kexec@lists.infradead.org, Michael Ellerman , "Eric W. Biederman" , Andrew Morton Subject: [PATCH v4.14] kexec_file: drop weak attribute from arch_kexec_apply_relocations[_add] Date: Tue, 28 Jun 2022 21:12:46 +0530 Message-Id: <20220628154249.204911-1-naveen.n.rao@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: SyCfyuZxd_dTWrD3z57P3XOAQdx8LqT1 X-Proofpoint-GUID: SyCfyuZxd_dTWrD3z57P3XOAQdx8LqT1 Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-28_09,2022-06-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 clxscore=1011 priorityscore=1501 lowpriorityscore=0 adultscore=0 phishscore=0 mlxlogscore=910 impostorscore=0 mlxscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206280063 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" commit 3e35142ef99fe6b4fe5d834ad43ee13cca10a2dc upstream. Since commit d1bcae833b32f1 ("ELF: Don't generate unused section symbols") [1], binutils (v2.36+) started dropping section symbols that it thought were unused. This isn't an issue in general, but with kexec_file.c, gcc is placing kexec_arch_apply_relocations[_add] into a separate .text.unlikely section and the section symbol ".text.unlikely" is being dropped. Due to this, recordmcount is unable to find a non-weak symbol in .text.unlikely to generate a relocation record against. Address this by dropping the weak attribute from these functions. Instead, follow the existing pattern of having architectures #define the name of the function they want to override in their headers. [1] https://sourceware.org/git/?p=3Dbinutils-gdb.git;a=3Dcommit;h=3Dd1bcae8= 33b32f1 [akpm@linux-foundation.org: arch/s390/include/asm/kexec.h needs linux/modul= e.h] Link: https://lkml.kernel.org/r/20220519091237.676736-1-naveen.n.rao@linux.= vnet.ibm.com Signed-off-by: Michael Ellerman Signed-off-by: Naveen N. Rao Cc: "Eric W. Biederman" Cc: Signed-off-by: Andrew Morton --- arch/x86/include/asm/kexec.h | 6 ++++++ include/linux/kexec.h | 26 ++++++++++++++++++++++---- kernel/kexec_file.c | 18 ------------------ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index 5125fca472bb0b..e699819bf7b349 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -21,6 +21,7 @@ #ifndef __ASSEMBLY__ =20 #include +#include =20 #include #include @@ -217,6 +218,11 @@ extern int arch_kexec_post_alloc_pages(void *vaddr, un= signed int pages, extern void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages); #define arch_kexec_pre_free_pages arch_kexec_pre_free_pages =20 +#ifdef CONFIG_KEXEC_FILE +int arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, + Elf_Shdr *sechdrs, unsigned int relsec); +#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add +#endif #endif =20 typedef void crash_vmclear_fn(void); diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 1ce6ba5f04077d..07578da0e2f5b1 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -163,6 +163,28 @@ int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(u64, u64, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); + +#ifndef arch_kexec_apply_relocations_add +/* Apply relocations of type RELA */ +static inline int +arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, + Elf_Shdr *sechdrs, unsigned int relsec) +{ + pr_err("RELA relocation unsupported.\n"); + return -ENOEXEC; +} +#endif + +#ifndef arch_kexec_apply_relocations +/* Apply relocations of type REL */ +static inline int +arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, + unsigned int relsec) +{ + pr_err("REL relocation unsupported.\n"); + return -ENOEXEC; +} +#endif #endif /* CONFIG_KEXEC_FILE */ =20 struct kimage { @@ -288,10 +310,6 @@ void * __weak arch_kexec_kernel_image_load(struct kima= ge *image); int __weak arch_kimage_file_post_load_cleanup(struct kimage *image); int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, unsigned long buf_len); -int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, - Elf_Shdr *sechdrs, unsigned int relsec); -int __weak arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *se= chdrs, - unsigned int relsec); void arch_kexec_protect_crashkres(void); void arch_kexec_unprotect_crashkres(void); =20 diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 9d979b2954ef7f..4e95641e8dd6ec 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -53,24 +53,6 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *i= mage, void *buf, } #endif =20 -/* Apply relocations of type RELA */ -int __weak -arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, - unsigned int relsec) -{ - pr_err("RELA relocation unsupported.\n"); - return -ENOEXEC; -} - -/* Apply relocations of type REL */ -int __weak -arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, - unsigned int relsec) -{ - pr_err("REL relocation unsupported.\n"); - return -ENOEXEC; -} - /* * Free up memory used by kernel, initrd, and command line. This is tempor= ary * memory allocation which is not needed any more after these buffers have base-commit: f051383ef03bde49ca992f297ec80757a702e774 --=20 2.36.1