Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp3980294rdb; Wed, 30 Aug 2023 11:37:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQwc8k9mdFZWgIy5YaSmLHMOou5bLbbYdkZiYwizh9mp9f2D9inkfBjlJyUesXGcBck013 X-Received: by 2002:aa7:88c7:0:b0:68b:eae8:1daf with SMTP id k7-20020aa788c7000000b0068beae81dafmr3596187pff.12.1693420642384; Wed, 30 Aug 2023 11:37:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693420642; cv=none; d=google.com; s=arc-20160816; b=Addi4qX5EYg8UsUqLnIJgVUIu5ff7bRKVBW+RhBwI2KZnt+RoHbuNhciFhldDxk+R7 /LG2VFgo2DMwf4EKQabVJTsn78tn+0H1CQkbGMpgZ3b7rdBzpuPsy44oBjtB+m06VH1b IDP1JldVuvKBRri4BnWGRCG32egJpCyu6xMkgnkMaBeLLRkpOeUP9avPWBY3iAI75lkp +uZGWRLJ450ADUT1YaeTq/7xRFIO/l07sQU9rRObLYX0UezPbcUXAYvvcchLe9hQD7oV R+PYCwo/SOk0Qd5DEdUtJ6SmTKWV1qy2eITPkF8qfgr1zEp8uLgYUje9gY4PASaPFAEj KEvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7+76cxPn1SsFf3EtZmaFNlPxXGbAf0pWFkISbXhOUtY=; fh=V0Bg0vSSGVy0ib6bb7xX1RpPTMYp4Kk2a1ilW6aoCuY=; b=ezCXYi+aQKSU7TU9TjnbGopqIqalu2JdWCsO5qNRilt3HEBkPBgMJkpSJIYEc9QeJF /24imQzUHB27bcAJctn5DKyIL3sfn+rQnw6ySxN970Kjb1R1IH+opirTBCPmpZXjE59v xUexMj5HPiZR88dSzA3qLeeMNR1iqAutVNJfNGpVQd+Qfcb3OcvSkXlmDEpoeLVuPxgm fmOk90/46u+NlPVS2bf7/AqVeD9dezYahK9FAhDiyPTdTWutHR7/ge78xzRYrC4m8qN1 RYlqkRi4EXoXPluJXZxLJmAMQg+6GxtRFrf5F+xzUMu4tNVq3l4+tq+63Aog0grfEKwe Fe3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N5CUupjq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e18-20020a633712000000b0056b5496a46fsi3452011pga.166.2023.08.30.11.37.07; Wed, 30 Aug 2023 11:37:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N5CUupjq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240454AbjH2XEj (ORCPT + 99 others); Tue, 29 Aug 2023 19:04:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239194AbjH2XED (ORCPT ); Tue, 29 Aug 2023 19:04:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC4B11BE; Tue, 29 Aug 2023 16:04:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7EC5A63CEB; Tue, 29 Aug 2023 23:04:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5F01C433C7; Tue, 29 Aug 2023 23:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693350239; bh=jVzcnu/UgsHYD4Nl9qqosC0UyycvjOZKdeezuanMBlY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=N5CUupjqE2hmWGcJ1w4pdoCQSaTp7vl8t22wKUpp3/GMVwelN5jFjmKIlEXlFiJ2U OgQ96lJCG/hLuz1SIasmSrTsTfWyq/IMNGt/CbuTEugzMBVBvUUT+8nj1zW+QcSpWF o25tUcVyIJmstbkNkBOHl9qd6sc4XX9HIlNNkancgRX0MZzd8d/m5QUKX0UE3ooY6i r8B8ApDYx7E6yoYXF1fNO9pcq1jH+4r1QD8EsoXaTNu5Y4fhxNvHLo+SaWz3+PHWnk BSRoEH6s+1xVdy+Tud3PqSUKgYMtIxyktWJCsUW0bpakrq0rbRAHseOH28w18DoOir AJG7wqrBLgEFw== Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-4fe1b00fce2so7905532e87.3; Tue, 29 Aug 2023 16:03:59 -0700 (PDT) X-Gm-Message-State: AOJu0YwCPbSXw/l9kGDfeDaextC0MGs80+MWVZghbqkLF5O/zZmOgGmb slhWdgDK9NEuR1g9RWYr+bJv/D+EAAeaDnTCOuc= X-Received: by 2002:a19:e006:0:b0:4ff:7602:5879 with SMTP id x6-20020a19e006000000b004ff76025879mr179992lfg.55.1693350237951; Tue, 29 Aug 2023 16:03:57 -0700 (PDT) MIME-Version: 1.0 References: <20230829-missingvardecl-efi-v1-1-13d055a55176@google.com> In-Reply-To: <20230829-missingvardecl-efi-v1-1-13d055a55176@google.com> From: Ard Biesheuvel Date: Wed, 30 Aug 2023 01:03:46 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] efi: fix -Wmissing-variable-declarations warning To: Justin Stitt Cc: Darren Hart , Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Justin, On Wed, 30 Aug 2023 at 00:54, Justin Stitt wrote: > > When building x86/defconfig with Clang-18 I encounter the following warnings: > | arch/x86/platform/efi/efi.c:934:23: warning: no previous extern declaration for non-static variable 'efi_attr_fw_vendor' [-Wmissing-variable-declarations] > | 934 | struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); > | arch/x86/platform/efi/efi.c:935:23: warning: no previous extern declaration for non-static variable 'efi_attr_runtime' [-Wmissing-variable-declarations] > | 935 | struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); > | arch/x86/platform/efi/efi.c:936:23: warning: no previous extern declaration for non-static variable 'efi_attr_config_table' [-Wmissing-variable-declarations] > | 936 | struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); > > These variables are not externally declared anywhere (AFAIK) They are: drivers/firmware/efi/efi.c:extern __weak struct kobj_attribute efi_attr_fw_vendor; drivers/firmware/efi/efi.c:extern __weak struct kobj_attribute efi_attr_runtime; drivers/firmware/efi/efi.c:extern __weak struct kobj_attribute efi_attr_config_table; > so let's > add the static keyword and ensure we follow the ODR. > One Definition Rule, right? Better to spell that out. > Link: https://github.com/ClangBuiltLinux/linux/issues/1920 > Signed-off-by: Justin Stitt > --- > When building x86/defconfig with Clang-18 I encounter the following warnings: > | arch/x86/platform/efi/efi.c:934:23: warning: no previous extern declaration for non-static variable 'efi_attr_fw_vendor' [-Wmissing-variable-declarations] > | 934 | struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); > | arch/x86/platform/efi/efi.c:935:23: warning: no previous extern declaration for non-static variable 'efi_attr_runtime' [-Wmissing-variable-declarations] > | 935 | struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); > | arch/x86/platform/efi/efi.c:936:23: warning: no previous extern declaration for non-static variable 'efi_attr_config_table' [-Wmissing-variable-declarations] > | 936 | struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); This is duplicated. Is this a b4 fail? > --- > Note: build-tested. > --- > arch/x86/platform/efi/efi.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c > index e9f99c56f3ce..30c354c52ad4 100644 > --- a/arch/x86/platform/efi/efi.c > +++ b/arch/x86/platform/efi/efi.c > @@ -931,9 +931,9 @@ EFI_ATTR_SHOW(fw_vendor); > EFI_ATTR_SHOW(runtime); > EFI_ATTR_SHOW(config_table); > > -struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); > -struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); > -struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); > +static struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); > +static struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); > +static struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); > > umode_t efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) > { > This won't work. Those variables are referenced via weak references in generic code. The idea is that the weak references resolve to NULL pointers on architectures other than x86, terminating the array early and hiding the non-existent variables. Making them static in arch/x86/platform/efi/efi.c means that these references will remain unsatisfied, and so the variables will no longer be exposed on x86 either.