Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp258645pxx; Thu, 29 Oct 2020 01:44:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy627yLNzFFAX/93anBp0tOIGF84aghHcpmaUXs3eHvJ9+NbUUifDNltfi4h7FoOBwL6dVB X-Received: by 2002:a50:f749:: with SMTP id j9mr2778408edn.376.1603961095450; Thu, 29 Oct 2020 01:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603961095; cv=none; d=google.com; s=arc-20160816; b=AYehxjLqzJWKegZ+GrVIZwDJwwsa4p7Cr6dBSv1VI3Ke/EImccPRZZ+/o/eJNWTkzQ FcfjFaPpk3fl+Pyjt2sNzGnFhX1gGQSKcfTIcCsh5DY++0qseYUziamYrkQHFpcZmshY Yqc+O5sr5IudjS//j+fm1Al1TM8Ogyp/ne2w/6h1ZidosphuGzkTTxxB4rcXzqFUdfyq SrOiZ0A6i+celDxXZQ6UmCtTAnEMeo52TAOKY1j47fmH/MPlCbErlq9b5Mnw+8gGm4RZ HnVY26IQaznCnW1l6C9Q9vf8xUXxSRhPfcA10yAm81fkG6M16A0ccuzEaoxeJUexuTAi 9LyA== 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=guqBR7xBA4T9wOAGQE+VV3oGmWYz96zo6N8Tw6+XVns=; b=zkKFtvjoy6vCWRQNwe01pmmco3ZnKPCpWlHimHv6yOXqsoS7yAr/LklmcT15mqcl2f pO70uvuBt4bty+51x2XmGvYO8ubNZnpmRTWqfIgJ5vFwtI9YaH6HeiFVg5kP75sJTByX HN9CeVA40bq/+AaG0jat2jykaD5GJGWmlMBxJKeJiOPc56sqDXjD8rpgCFhSpKa9oPXB KbzoXz0cBxRLmwWExYM3NIe4nmcl4ffafZ5UtA9mEShurFHz6cMiM0ZGqDNjTvWMw4SA DGuKDYy0O7imawZTPtPLqy53tXtNyz/E+URWSlEd+UTKVNj0kC7zxBvOgq9gzIUmkuyh QLdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zSE1DqcX; 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 ce20si1629979ejc.317.2020.10.29.01.44.33; Thu, 29 Oct 2020 01:44:55 -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=zSE1DqcX; 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 S2404081AbgJ2BB3 (ORCPT + 99 others); Wed, 28 Oct 2020 21:01:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:60514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731511AbgJ1WR0 (ORCPT ); Wed, 28 Oct 2020 18:17:26 -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 10B48246A3; Wed, 28 Oct 2020 10:00:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603879254; bh=Zt06lJI/dyFmw+ygkxHH5YVanDHB4SbCK4oB2OLbzQ8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zSE1DqcXeyFOXYe0GIro3PncnXe5qeo/vOgtS4PXRISXJH1OqtuoIMS359F505mMk gzBvRfj63gy2UcWFHugd3z8J+g+Q3ltJIvRWwUVKOF9L2wXDOCEThpkxDbZ7xvQuQN MZxdVjMtsjlnbrZXEXq21q8GefUyyUDnTG3Wpo+c= Date: Wed, 28 Oct 2020 10:00:49 +0000 From: Will Deacon To: Ard Biesheuvel Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, Jessica Yu , Kees Cook , Geert Uytterhoeven , Nick Desaulniers Subject: Re: [PATCH] module: use hidden visibility for weak symbol references Message-ID: <20201028100049.GA27873@willie-the-truck> References: <20201027151132.14066-1-ardb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201027151132.14066-1-ardb@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ard, 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? Cheers, Will