From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69471C4363A for ; Thu, 29 Oct 2020 01:01:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A77620790 for ; Thu, 29 Oct 2020 01:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603933262; bh=P9anRD+smK5E/g3Un2TZLwzIT1E1BeUE08BloK8ehZM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=umaBtEmYG/Y5TYpEmQRRg1kUHYjyUw0Iiyggum4sWOZ3QivV1iDE8ywRZ9mRsxEIG 6vM3RAvuchCHrpDXI8s6eTIHVIlhAhrKRgs+4/ZalwIa+hL3CC2Ov/GrYp+KPveqQ4 pX0ioKNy099VMYjDGOZADYjmPriugSsZdu+3yA5I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731550AbgJ2BBB (ORCPT ); Wed, 28 Oct 2020 21:01:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:60528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731533AbgJ1WR2 (ORCPT ); Wed, 28 Oct 2020 18:17:28 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CB5EB24748; Wed, 28 Oct 2020 13:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603891483; bh=P9anRD+smK5E/g3Un2TZLwzIT1E1BeUE08BloK8ehZM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DD8z4tUv85eOpQssDfKpeCLWuN3Yn/an+H36C+E6VeL29EIKvfMknmbVdxY1kmcPU VlaH9rOBnWre3CmWUTfKsxfxaURKPyZLeZ/2pZtekIFnmW9cGSSdIUNk1hUaPq60KY 2I8Itq6TuivTVMEX2JXQ4cpWB9dxuLZRn1y3SGK8= Date: Wed, 28 Oct 2020 13:24:38 +0000 From: Will Deacon To: Ard Biesheuvel Cc: Linux Kernel Mailing List , Linux ARM , Catalin Marinas , Jessica Yu , Kees Cook , Geert Uytterhoeven , Nick Desaulniers Subject: Re: [PATCH] module: use hidden visibility for weak symbol references Message-ID: <20201028132437.GA28251@willie-the-truck> References: <20201027151132.14066-1-ardb@kernel.org> <20201028100049.GA27873@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 28, 2020 at 01:27:01PM +0100, Ard Biesheuvel wrote: > On Wed, 28 Oct 2020 at 11:00, Will Deacon wrote: > > On Tue, Oct 27, 2020 at 04:11:32PM +0100, Ard Biesheuvel wrote: > > > Geert reports that commit be2881824ae9eb92 ("arm64/build: Assert for > > > unwanted sections") results in build errors on arm64 for configurations > > > that have CONFIG_MODULES disabled. > > > > > > The commit in question added ASSERT()s to the arm64 linker script to > > > ensure that linker generated sections such as .got, .plt etc are empty, > > > but as it turns out, there are corner cases where the linker does emit > > > content into those sections. More specifically, weak references to > > > function symbols (which can remain unsatisfied, and can therefore not > > > be emitted as relative references) will be emitted as GOT and PLT > > > entries when linking the kernel in PIE mode (which is the case when > > > CONFIG_RELOCATABLE is enabled, which is on by default). > > > > > > What happens is that code such as > > > > > > struct device *(*fn)(struct device *dev); > > > struct device *iommu_device; > > > > > > fn = symbol_get(mdev_get_iommu_device); > > > if (fn) { > > > iommu_device = fn(dev); > > > > > > essentially gets converted into the following when CONFIG_MODULES is off: > > > > > > struct device *iommu_device; > > > > > > if (&mdev_get_iommu_device) { > > > iommu_device = mdev_get_iommu_device(dev); > > > > > > where mdev_get_iommu_device is emitted as a weak symbol reference into > > > the object file. The first reference is decorated with an ordinary > > > ABS64 data relocation (which yields 0x0 if the reference remains > > > unsatisfied). However, the indirect call is turned into a direct call > > > covered by a R_AARCH64_CALL26 relocation, which is converted into a > > > call via a PLT entry taking the target address from the associated > > > GOT entry. > > > > > > Given that such GOT and PLT entries are unnecessary for fully linked > > > binaries such as the kernel, let's give these weak symbol references > > > hidden visibility, so that the linker knows that the weak reference > > > via R_AARCH64_CALL26 can simply remain unsatisfied. > > > > > > Cc: Jessica Yu > > > Cc: Kees Cook > > > Cc: Geert Uytterhoeven > > > Cc: Nick Desaulniers > > > Signed-off-by: Ard Biesheuvel > > > --- > > > include/linux/module.h | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > Cheers. I gave this a spin, but I unfortunately still see the following > > linker warning with allnoconfig: > > > > aarch64-linux-gnu-ld: warning: orphan section `.igot.plt' from `arch/arm64/kernel/head.o' being placed in section `.igot.plt' > > > > which looks unrelated to symbol_get(), but maybe it's worth knocking these > > things on the head (no pun intended) at the same time? > > > > Yeah, that is just one of those spurious sections that turns up empty > anyway. The head.o is a red herring, it is simply the first file > appearing in the link. > > This should fix it > > diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S > index 6567d80dd15f..48b222f1c700 100644 > --- a/arch/arm64/kernel/vmlinux.lds.S > +++ b/arch/arm64/kernel/vmlinux.lds.S > @@ -278,7 +278,7 @@ SECTIONS > * explicitly check instead of blindly discarding. > */ > .plt : { > - *(.plt) *(.plt.*) *(.iplt) *(.igot) > + *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) > } > ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure > linkages detected!") Cheers, that fixes the extra warning for me. If you could send a proper patch, I'm happy to queue as an arm64 fix! (I'm assuming the former is going via Jessica, but I can also take that with her Ack). Will From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51DF8C388F7 for ; Wed, 28 Oct 2020 13:26:17 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9BC3B2474E for ; Wed, 28 Oct 2020 13:26:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MEDFZdtg"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="DD8z4tUv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BC3B2474E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=giX8+qosigAMshgskhdduv5iluIANEq6dmjTnvC2hsY=; b=MEDFZdtgcF+qVMG4jKWWDp884 E+L/lyR50Zy02uXf248wZkN5LLdiGKd0lY9uHVql1NVi1A/24tT63jOqyjFATJA6g6M7CK3sZGUkt AYZdv4tJ2h4+b1LfLEayj1c5QezMt+ipGJxw6OQZCQmdED0Pv3PmdLJpAfG3RSb/7Y8zAmcAYYkN/ qOLzM72aF1+N7UKGJcyCXnBP+jaRVDufHXB/DrW2Z+XGNJhjoEl/MsIgHbFUbk7e97Dd9HxPosZNa 6c2yvuYcV7rLY9c1d6hcUWomYGmbYgd7gesLcUUP1kF9wopE4sm2vY9Or0uCA2TUl6SCQgueEu3Lp ZTGSVvuaQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXlRX-0001Mb-Nc; Wed, 28 Oct 2020 13:24:47 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXlRU-0001Ld-CR for linux-arm-kernel@lists.infradead.org; Wed, 28 Oct 2020 13:24:45 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CB5EB24748; Wed, 28 Oct 2020 13:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603891483; bh=P9anRD+smK5E/g3Un2TZLwzIT1E1BeUE08BloK8ehZM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DD8z4tUv85eOpQssDfKpeCLWuN3Yn/an+H36C+E6VeL29EIKvfMknmbVdxY1kmcPU VlaH9rOBnWre3CmWUTfKsxfxaURKPyZLeZ/2pZtekIFnmW9cGSSdIUNk1hUaPq60KY 2I8Itq6TuivTVMEX2JXQ4cpWB9dxuLZRn1y3SGK8= Date: Wed, 28 Oct 2020 13:24:38 +0000 From: Will Deacon To: Ard Biesheuvel Subject: Re: [PATCH] module: use hidden visibility for weak symbol references Message-ID: <20201028132437.GA28251@willie-the-truck> References: <20201027151132.14066-1-ardb@kernel.org> <20201028100049.GA27873@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201028_092444_606342_D0377B40 X-CRM114-Status: GOOD ( 38.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kees Cook , Catalin Marinas , Nick Desaulniers , Linux Kernel Mailing List , Geert Uytterhoeven , Jessica Yu , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Oct 28, 2020 at 01:27:01PM +0100, Ard Biesheuvel wrote: > On Wed, 28 Oct 2020 at 11:00, Will Deacon wrote: > > On Tue, Oct 27, 2020 at 04:11:32PM +0100, Ard Biesheuvel wrote: > > > Geert reports that commit be2881824ae9eb92 ("arm64/build: Assert for > > > unwanted sections") results in build errors on arm64 for configurations > > > that have CONFIG_MODULES disabled. > > > > > > The commit in question added ASSERT()s to the arm64 linker script to > > > ensure that linker generated sections such as .got, .plt etc are empty, > > > but as it turns out, there are corner cases where the linker does emit > > > content into those sections. More specifically, weak references to > > > function symbols (which can remain unsatisfied, and can therefore not > > > be emitted as relative references) will be emitted as GOT and PLT > > > entries when linking the kernel in PIE mode (which is the case when > > > CONFIG_RELOCATABLE is enabled, which is on by default). > > > > > > What happens is that code such as > > > > > > struct device *(*fn)(struct device *dev); > > > struct device *iommu_device; > > > > > > fn = symbol_get(mdev_get_iommu_device); > > > if (fn) { > > > iommu_device = fn(dev); > > > > > > essentially gets converted into the following when CONFIG_MODULES is off: > > > > > > struct device *iommu_device; > > > > > > if (&mdev_get_iommu_device) { > > > iommu_device = mdev_get_iommu_device(dev); > > > > > > where mdev_get_iommu_device is emitted as a weak symbol reference into > > > the object file. The first reference is decorated with an ordinary > > > ABS64 data relocation (which yields 0x0 if the reference remains > > > unsatisfied). However, the indirect call is turned into a direct call > > > covered by a R_AARCH64_CALL26 relocation, which is converted into a > > > call via a PLT entry taking the target address from the associated > > > GOT entry. > > > > > > Given that such GOT and PLT entries are unnecessary for fully linked > > > binaries such as the kernel, let's give these weak symbol references > > > hidden visibility, so that the linker knows that the weak reference > > > via R_AARCH64_CALL26 can simply remain unsatisfied. > > > > > > Cc: Jessica Yu > > > Cc: Kees Cook > > > Cc: Geert Uytterhoeven > > > Cc: Nick Desaulniers > > > Signed-off-by: Ard Biesheuvel > > > --- > > > include/linux/module.h | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > Cheers. I gave this a spin, but I unfortunately still see the following > > linker warning with allnoconfig: > > > > aarch64-linux-gnu-ld: warning: orphan section `.igot.plt' from `arch/arm64/kernel/head.o' being placed in section `.igot.plt' > > > > which looks unrelated to symbol_get(), but maybe it's worth knocking these > > things on the head (no pun intended) at the same time? > > > > Yeah, that is just one of those spurious sections that turns up empty > anyway. The head.o is a red herring, it is simply the first file > appearing in the link. > > This should fix it > > diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S > index 6567d80dd15f..48b222f1c700 100644 > --- a/arch/arm64/kernel/vmlinux.lds.S > +++ b/arch/arm64/kernel/vmlinux.lds.S > @@ -278,7 +278,7 @@ SECTIONS > * explicitly check instead of blindly discarding. > */ > .plt : { > - *(.plt) *(.plt.*) *(.iplt) *(.igot) > + *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) > } > ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure > linkages detected!") Cheers, that fixes the extra warning for me. If you could send a proper patch, I'm happy to queue as an arm64 fix! (I'm assuming the former is going via Jessica, but I can also take that with her Ack). Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel