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=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 3AE1EC4363A for ; Tue, 27 Oct 2020 22:18:57 +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 D1B5E20735 for ; Tue, 27 Oct 2020 22:18:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1F3x7//A"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Okz3JM1X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1B5E20735 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com 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-Type: Content-Transfer-Encoding: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=kmOs0YdGxrUe+imBP9D7omNDIx7EpmlYll5Q1LZw1kQ=; b=1F3x7//AyMZJ22cn+lZDCjG4M euDfTnze0RfH4nlDJuG6eQneXNVs15kgvyIsC4AsTFmehOms/g1b2dfHebBTpueW7A9kZZSe0nep0 TI5MeW5AIm5pCG+WrQYQCwa9ye/TX7RkisVr+VeNB/J68aguHvjp0rY3vYy2DSRsszI/xc8yA0g67 DYGL8o/MTjDc+4peWIWSEgFOHoXawvmRSxv0JKN3YsbLYDICqPbkXYHIjoPXS415rHLSF8X134sXF LnNr2s/aaX9DqWefHHFkRFHDoqMiJ4xHl7hLkMzzN0jgrjTeQCk9HwnIKoK8Sk7k03AKQGM84dglV saAzMwJjg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXXIP-0000r8-HQ; Tue, 27 Oct 2020 22:18:25 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXXIM-0000qN-Mk for linux-arm-kernel@lists.infradead.org; Tue, 27 Oct 2020 22:18:23 +0000 Received: by mail-pf1-x443.google.com with SMTP id o129so1750420pfb.1 for ; Tue, 27 Oct 2020 15:18:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=R+TzVjMGuuOAhuzCd/X5fEku0ly/jO19B59u1oK4LbQ=; b=Okz3JM1XL2nGsxb1umt2mHqpIKQ+k+MWyuFrfrCyx40mavkIIWPiaIfEkAuBDROdJe tlbiQ/Gr4XoD+3zlQLbIrm/t9pU0Z2mlENWFUMLC9JsXD9e4QSxvs1De7eZtcmAis+tk 7ZQwLnxij0pofykJ1B3MrMtMPz1yQ4rwRkYb7PWjYh9DFctmRPVhDMWIS6XCWIG7CIfS PWvvifkuQY6SkpIfAEPngT3HmkdvtSeUaZbEjZt//6hWmBqxmfRgD4wAdpjQzwyhXRht jokEHxj7qc0Smu0DhMj8vYHrAxK1OMgmABWamWw/UxwP12Jeckngab4TJXFNy3NYarKH SMLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=R+TzVjMGuuOAhuzCd/X5fEku0ly/jO19B59u1oK4LbQ=; b=oxLW33fYABLkI1T7JZWm4zCyL+txATS0qbLm5SK2h1FPPVBO5O1Jg2RiuScxs7/xp9 0MmC3vHsaiMhtY/Omf8ocdKdZL16/kfIs8w03+IXATZN4npSChpFOUkxou89ecXR4uHz 9T0qfeyYRGhm821JsRnNdxCF0GFZb9ozAkHEESxqt0b7rsdywbfYnc9iLAA0dUYmBxMK /mTMFhi0pZBLl7Qpf2JZw9JyWK60/dVZyGKRYF6P+42xUVdxYTU0MCvpwc7KBoSzVgFH lajmSOSQWcnlIEq8YEo1KwD1K5LcvFupnxr/hhdCKhcyxT36tcYb8HPIe89US3a5f3Lr +1fA== X-Gm-Message-State: AOAM531WsYqHolr3ZFv1F+1/XH65CXHJRSoy7KwSHWs7ulG4XekyJKLD MGIUx1/9EvFcQhbcjpzkHOxjOA== X-Google-Smtp-Source: ABdhPJz6qXWNZwihj4vmh8FMC8KRX91scrpXZ5I9yPVtl7DBpCVijZUC5X0m4T3lxibWwwThvzSwCQ== X-Received: by 2002:a63:5d44:: with SMTP id o4mr3552930pgm.409.1603837098358; Tue, 27 Oct 2020 15:18:18 -0700 (PDT) Received: from google.com ([2620:15c:2ce:0:a6ae:11ff:fe11:4abb]) by smtp.gmail.com with ESMTPSA id s131sm3183027pgc.18.2020.10.27.15.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 15:18:17 -0700 (PDT) Date: Tue, 27 Oct 2020 15:18:14 -0700 From: Fangrui Song To: Ard Biesheuvel Subject: Re: [PATCH] module: use hidden visibility for weak symbol references Message-ID: <20201027221814.rkm73l5dtyysvagj@google.com> References: <20201027151132.14066-1-ardb@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201027_181822_828770_B1207DA6 X-CRM114-Status: GOOD ( 21.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 , LKML , clang-built-linux , Geert Uytterhoeven , linux-toolchains@vger.kernel.org, Jessica Yu , Will Deacon , Linux ARM Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org One nit about ".got" in the message: Reviewed-by: Fangrui Song On 2020-10-27, Nick Desaulniers wrote: >+ Fangrui > >On Tue, Oct 27, 2020 at 8:11 AM 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, .got -> .got.plt be2881824ae9eb92 does not ASSERT on .got (it can). Strangely *(.got) is placed in .text in arch/arm64/kernel/vmlinux.lds.S I think that line can be removed. On x86, aarch64 and many other archs, the start of .got.plt is the GOT base. .got is not needed (ppc/arm/riscv use .got instead of .got.plt as the GOT base anchor). >> 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). Confirmed. >> 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. Yes, the R_AARCH64_CALL26 relocation referencing an undefined weak symbol causes one .plt entry and one .got.plt 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(-) >> >> diff --git a/include/linux/module.h b/include/linux/module.h >> index 7ccdf87f376f..6264617bab4d 100644 >> --- a/include/linux/module.h >> +++ b/include/linux/module.h >> @@ -740,7 +740,7 @@ static inline bool within_module(unsigned long addr, const struct module *mod) >> } >> >> /* Get/put a kernel symbol (calls should be symmetric) */ >> -#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) >> +#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak,visibility("hidden"))); &(x); }) >> #define symbol_put(x) do { } while (0) >> #define symbol_put_addr(x) do { } while (0) >> >> -- >> 2.17.1 >> > > >-- >Thanks, >~Nick Desaulniers _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel