Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1441158iob; Thu, 19 May 2022 06:47:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwENssqEdAMJHxq72qkhQj8vvm8EKGEEWnxHE5zf+/rptYju6jANZYNXJYyq5py2RndM9o4 X-Received: by 2002:a17:906:751:b0:6fe:a036:b357 with SMTP id z17-20020a170906075100b006fea036b357mr1371253ejb.185.1652968035896; Thu, 19 May 2022 06:47:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652968035; cv=none; d=google.com; s=arc-20160816; b=YCTON0BKq/OfQtrmi7lgXQksF3QHm0E+FjzBC1jMCjpr9JGXGnnVGXZcRHHyUFiJLQ YEDm02U2EGb2whICvymRRcILBY6AFQaRo/2b+rFiNiBJhGpAjvoyiPb/FfGAHtdr6vCW 5bEjdVzSUi8HXgwcS46dYXDCXJbw8AEPHXVKymyzPp9/kP8atV72UjLND1QMRGpX28Gl vmCyWeu2e43RrbymrMhF9FWRXe2l3O0ckbgPWpp18RjTc//B2okgdqTbV+lKLTjRpq0f boEPTF56+cNBaxT0BSy3cMvQCBE0nDahlE6yfTbjtPAakrUPWdpP2JlD12nDVb9C8e86 hqYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=u4WYQ8CLjhh5TCtN+4GxOyinCwBGkUDiWv+9kOIQ2Aw=; b=WFt3mMx8sEkhs/zyWP8GIv2Bc3i2PfB0mpqvEfaaA9nBjAM+Oq8ZYYB4yD8on+okCC +6lCgjEjmvXwcWV+F10IjgMfvHvV7ss86TvPlcODg85lZVTqdd/vsOIN0xheBx1PeUBi JLy8vzrfOnW2/ykLA7/JqqKqNhgMLYLxaGgOUbsbSMhQ0ME7+geCbFbALpw3BDsy65vi Oh59tYRp9otC1BH9+mkMLMX9ASCAZP3ubDtLQMEIKIAPE2bgSYGGwd+oMJAO16+hYqs3 2vxaWdFjLIpSB01mTbcwPxTT9njqlnMYqFIP1aIntpQ73nsIivYeH3n9r56msq11dXVW OSlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="El/8FD4s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a056402084500b00425fb248b3bsi7085366edz.66.2022.05.19.06.46.49; Thu, 19 May 2022 06:47:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="El/8FD4s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234009AbiESFlv (ORCPT + 99 others); Thu, 19 May 2022 01:41:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231869AbiESFlq (ORCPT ); Thu, 19 May 2022 01:41:46 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6FD39D4FD for ; Wed, 18 May 2022 22:41:42 -0700 (PDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4L3dyX2T4Jz4xD1; Thu, 19 May 2022 15:41:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1652938900; bh=u4WYQ8CLjhh5TCtN+4GxOyinCwBGkUDiWv+9kOIQ2Aw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=El/8FD4sKhUNUJK/ztIhCR4s+G553J0gGwkMOD2jplBk9XzsGORDHXxOIJhHV37r2 yfYv6RMpGwebQu+dtSp3my8M1rZWHHFPiIG4/LeXT9q3U2+uOvZxY+eIzu6wkBn+5x rRCl4wmAGx7LmeDlBMPJcSGzOnj0YqK1psC26Jj9iJJHwKH6zHCcUTGghPQZXQFysP mZ7yuKp6REsmelQ2STkkfe3tnpTYUSrJ2U+3CGaHtZhTfzJDDUqpzUYu67sxRe66xD Z9gHAWSSgjrHWS4+4hAXl7GyMJhoODY3j+txgVTjiMQSgb9s9k7gk8t5QqVGKUU5LS N9D4BUJpat9Xw== From: Michael Ellerman To: "Naveen N. Rao" , Eric Biederman Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org Subject: Re: [PATCH] kexec_file: Drop weak attribute from arch_kexec_apply_relocations[_add] In-Reply-To: <20220518181828.645877-1-naveen.n.rao@linux.vnet.ibm.com> References: <20220518181828.645877-1-naveen.n.rao@linux.vnet.ibm.com> Date: Thu, 19 May 2022 15:41:39 +1000 Message-ID: <874k1mnkoc.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Naveen N. Rao" writes: > 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: > - arch_kexec_apply_relocations() is not overridden by any architecture > today, so just drop the weak attribute. > - arch_kexec_apply_relocations_add() is only overridden by x86 and s390. > Retain the function prototype for those and move the weak > implementation into the header as a static inline for other > architectures. > > [1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1 > > Signed-off-by: Naveen N. Rao > --- > include/linux/kexec.h | 28 ++++++++++++++++++++++++---- > kernel/kexec_file.c | 19 +------------------ > 2 files changed, 25 insertions(+), 22 deletions(-) I think it could be cleaner done with the #define foo foo style, see patch below. It does have its downsides, but for a simple hook like this I think it's not too bad. cheers (only build tested) diff --git a/arch/s390/include/asm/kexec.h b/arch/s390/include/asm/kexec.h index 7f3c9ac34bd8..e818b58ccc43 100644 --- a/arch/s390/include/asm/kexec.h +++ b/arch/s390/include/asm/kexec.h @@ -74,6 +74,8 @@ void *kexec_file_add_components(struct kimage *image, int arch_kexec_do_relocs(int r_type, void *loc, unsigned long val, unsigned long addr); +#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add + #define ARCH_HAS_KIMAGE_ARCH struct kimage_arch { diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index 11b7c06e2828..58e3939a350a 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -186,6 +186,8 @@ extern int arch_kexec_post_alloc_pages(void *vaddr, unsigned 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 +#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add + #endif typedef void crash_vmclear_fn(void); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 8347fc158d2b..6f07acb59f29 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -108,6 +108,7 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, } #endif +#ifndef arch_kexec_apply_relocations_add /* * arch_kexec_apply_relocations_add - apply relocations of type RELA * @pi: Purgatory to be relocated. @@ -117,14 +118,16 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, * * Return: 0 on success, negative errno on error. */ -int __weak +int arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section, const Elf_Shdr *relsec, const Elf_Shdr *symtab) { pr_err("RELA relocation unsupported.\n"); return -ENOEXEC; } +#endif +#ifndef arch_kexec_apply_relocations /* * arch_kexec_apply_relocations - apply relocations of type REL * @pi: Purgatory to be relocated. @@ -134,13 +137,14 @@ arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section, * * Return: 0 on success, negative errno on error. */ -int __weak +int arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section, const Elf_Shdr *relsec, const Elf_Shdr *symtab) { pr_err("REL relocation unsupported.\n"); return -ENOEXEC; } +#endif /* * Free up memory used by kernel, initrd, and command line. This is temporary