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=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 8E4EBC4363A for ; Tue, 27 Oct 2020 22:18:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E4E720735 for ; Tue, 27 Oct 2020 22:18:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Okz3JM1X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1832247AbgJ0WSU (ORCPT ); Tue, 27 Oct 2020 18:18:20 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36098 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1832246AbgJ0WST (ORCPT ); Tue, 27 Oct 2020 18:18:19 -0400 Received: by mail-pf1-f196.google.com with SMTP id w65so1744493pfd.3 for ; Tue, 27 Oct 2020 15:18:18 -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=ufgPA/bvb7Pg1LGkr1OcketauAPA3Yv1FPQ6TqhY/cCBahLVmhlgJNBhpSravAR6XM /EgP3Sod1umAnFaRCSf5TLt1WBgSRNSI2j/U5dTFQxmGIjnLNhbx3PmquLZZEQKHf+TG 3Czr5IBKQ/wOquH31CQq1DQqzdBxIy5AkfEPGaqJWgmmRVxrw24njZ5qVktzNzrvL/mU JMex3CzQc3gLpogu05ZKtqITYTje3erjPqeRKCOQ+7qDqZPWtd1Wl2KIKaRPeW9luXIJ Fc9epFtGCMsVTKlnakqlcD1g8a4jbz5r4wexICjpV0seQGLkfHY2O6P/CGB90ATGjrLI OWgg== X-Gm-Message-State: AOAM532hinQOkfa9/XvC8zkZ2N+QAqac5Xb327OZnj5Yr+oBM0v0gF0a eUBcJwGZJzjtLK49pH7i1kG1xg== 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 Cc: Nick Desaulniers , LKML , Linux ARM , Will Deacon , Catalin Marinas , Jessica Yu , Kees Cook , Geert Uytterhoeven , clang-built-linux , linux-toolchains@vger.kernel.org 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-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.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