Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp258012pxx; Thu, 29 Oct 2020 01:43:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcVw5xcm79wBQuaaEUtdAInmFHQdqVERin4tOUo7fvXYaqI9FyJebmT3iT85vRohgwbzNq X-Received: by 2002:a17:906:2f10:: with SMTP id v16mr2912647eji.320.1603961001848; Thu, 29 Oct 2020 01:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603961001; cv=none; d=google.com; s=arc-20160816; b=DrrLl1C9nxEByuSIlyh49WfScBJXE9ye1sZITeuFtGuXct/m1uxWy5wrn1ZokXRrLN ePEiIw4/DgON8bF8J+egUen05B7YCNSvlTkwKL7g+cky/Rb4B367P/F8RrV0C06aGQli pfAf27kUPHaMY7ra2fkKcaiqZW5l60cjV3o17yGQ88nZjRtcxHV0mXn9qCSEOlSgkZ3x +AsZzY9gwdrNspTN45umg+LxjuG3qZmMXbVE/He6iu0MQuPY9wnYrrVB3M8k97qpGZQ6 EhE/PIpWuEpAZt0fa+W/c7KDuiURMkmhH5ZNvTcvN64lmU+19H/i7O8fK8lHJlqiqmm1 yytA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=lcW6Rp5Ujji+1h60jgd+EYtKsC55L2mCIOduy/+8f+Q=; b=Kp09SHhOthu2CCFX7zJnw1d8bMF60yCF/O5Lq60yVduxvEYBnjhJMcM6qbzm3m+SUi 55s3JnJKjVXs35DbJeSMP9/LFUZfrQ6atAJMkfIhL/TbYF8eT5raX01sZI8XGJH5ZCGk hzHufZwprPl7YHkPHGpax2Z8BMvZbydlnF0nDUfJaY8TTUKt9X5rgKHNyN+Ol8AG49H4 vtCTGQKgmIxtiWQsMYthnoE8D5RI84fBJTyUeEHLwCskLKoKRZIGp7JzKppeXNfgexD5 YfwCwiR0Pijk4/RkUnN64VIhI8jiTKNlFDFQoOChkANki/qgTxHWPQlsONgYKdeqw//k Bzjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y08StW8c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si1063290ejb.200.2020.10.29.01.43.00; Thu, 29 Oct 2020 01:43:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y08StW8c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403962AbgJ2A6c (ORCPT + 99 others); Wed, 28 Oct 2020 20:58:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:60516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731574AbgJ1WRc (ORCPT ); Wed, 28 Oct 2020 18:17:32 -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 664C1246CA; Wed, 28 Oct 2020 14:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603894073; bh=DsEwn1Aha0aISLTxhqMFeop4UEe24Ykwyy3xN/SnAJU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=y08StW8cfkj105JGXGm6iImQCDwPVwR+LXCEKF1cbyQAyEZqjo75Gtt0TAGj4bYPv gYY/vhLIlnEIrKILv7vbgoNZNgeyntbnOjL2P3goFEIYSIgCXuuNlEHmmLJ4mMo0oy vLa1b0hR6yqm8Ndop2Y4XuoLMDz6bHHyWj0k0adE= Date: Wed, 28 Oct 2020 14:07:48 +0000 From: Will Deacon To: Jessica Yu Cc: Ard Biesheuvel , Linux Kernel Mailing List , Linux ARM , Catalin Marinas , Kees Cook , Geert Uytterhoeven , Nick Desaulniers Subject: Re: [PATCH] module: use hidden visibility for weak symbol references Message-ID: <20201028140747.GB28554@willie-the-truck> References: <20201027151132.14066-1-ardb@kernel.org> <20201028100049.GA27873@willie-the-truck> <20201028132437.GA28251@willie-the-truck> <20201028140344.GB6867@linux-8ccs> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201028140344.GB6867@linux-8ccs> 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 03:03:44PM +0100, Jessica Yu wrote: > +++ Will Deacon [28/10/20 13:24 +0000]: > > 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). > > Hi! Yes, please feel free to take this patch along with the other fix: > > Acked-by: Jessica Yu Cheers, Jessica -- I'll queue them in a sec! Will