Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5544072iob; Mon, 9 May 2022 20:07:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxr1NgcdP0k1UMBWD+52DjALuZb01BshALWYJiToN7Z42wQDyiOiIMLW81GQvd4V7i3RIVt X-Received: by 2002:a17:906:c14e:b0:6f9:9d73:77e with SMTP id dp14-20020a170906c14e00b006f99d73077emr9609656ejc.258.1652152073632; Mon, 09 May 2022 20:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652152073; cv=none; d=google.com; s=arc-20160816; b=ajv16qOass61cav3Zpc/D1PFgF0scdzHPvE4ff8U+JqKBbO3QMyNE055jJZGOQAf/F WBLEZPjmHsgcSJ9ClN9ftY32vaje/8tRv8CDHW61XNcGQa3kuOGMu4k/tKQ8Vln118QE GiXMjBro0W+USMijt+88lvMpmECeNei/j5tjS8hSvWxwE0zs/pD4FR5J63uI2omiw5u/ oy5Z2ajCBi8LlKnjFYdety8K1lVNqQvJv5T3RwZ+NYamofsKr2+nhb9ejbGS4go71Zs7 1pIjjs18RX4gHmdtM55G5Oo0XdgQq0m6H4/lFi2wsMiD6guuOfu8/SFHu7j2fQ301pZU N1iQ== 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; bh=Pu2anZ+R3B06nqhjgv9ISwTVomKwIVTtmDdQYWCLtaU=; b=nHyR+R+KfOB+p03yf9sHyVMp9SEnKbGafLjuur7gHyrNsMpaK3kVEpu6GmWDO5Fd7e d/wvea+nL8rtNeQuaXBjp8t8dvejyDH3kwQIFCl4lfK2T8l/ZjkvaYpjPeXV8+MSsaWN H2QgQLLzsZZB8yP4gl3cuvqM3Hh6GwxKslFNarxY+xfgZa5HfU0KfjLCOqin6NXQHsCd fXDhtfQwe3Y5k65iHTfFHpsFm8Sc2luRIzJx0PP95FM4mrOkycGmMSYr7OAXg2E0AueH uxwhWftsjrd9+vQFvMqhyLYycvs1SyPkm/RxFq8TV1kz50pEQDSUyu7iiZX/07sh08sg PAIA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b27-20020a170906039b00b006f38d8c0e72si14543755eja.268.2022.05.09.20.07.30; Mon, 09 May 2022 20:07:53 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234090AbiEJBO4 (ORCPT + 99 others); Mon, 9 May 2022 21:14:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233975AbiEJBOx (ORCPT ); Mon, 9 May 2022 21:14:53 -0400 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBD41E16 for ; Mon, 9 May 2022 18:10:54 -0700 (PDT) Received: by mail-yb1-f177.google.com with SMTP id v59so28000982ybi.12 for ; Mon, 09 May 2022 18:10:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Pu2anZ+R3B06nqhjgv9ISwTVomKwIVTtmDdQYWCLtaU=; b=SBzbIGwpogQjc7IMGMxjUwPJcIQHt3GZd3N3nyAvbiVGChqLplRFXUoE1yQym1UPXB ASGMAXbvkzLxER8KdGaoH/ygXeJn5ZoS4BBzbtAGJbH/jh9aagcP52uoALMAp5f4KeQ3 U4282yK7pydR8J8bLtDiwg39BWZ1yAgyQvpXq9Xr4oR2FRJZCj9ja4aOagMQHIqr3tvI Js91IopKS6+Cy49fqkNsNpLqY7dcj0oXxGlPHSTOvtj0QE9JXVeXkoRNBxZUrRVNKvhO Xt+h+lTicrLalVat1V4xkdwJVBJApxkRng6TBN1dTO6PiJXVsmFtD+uGdefGWoSgb2Vz qOfw== X-Gm-Message-State: AOAM5307xGmM73jHMnywd633NZw7CRWOA4PONckI+G4ti3UAhW+nw9T4 4JRMXm+5Zi62gOinS3tksSAP1lkl0F1SgQmItwk= X-Received: by 2002:a5b:491:0:b0:64a:f42f:6973 with SMTP id n17-20020a5b0491000000b0064af42f6973mr3469601ybp.20.1652145054084; Mon, 09 May 2022 18:10:54 -0700 (PDT) MIME-Version: 1.0 References: <20220306171009.1973074-1-mailhol.vincent@wanadoo.fr> <20220508100907.61231-1-mailhol.vincent@wanadoo.fr> In-Reply-To: From: Vincent MAILHOL Date: Tue, 10 May 2022 10:10:43 +0900 Message-ID: Subject: Re: [RESEND PATCH v1] x86/build: add -fno-builtin flag to prevent shadowing To: Nick Desaulniers Cc: Nathan Chancellor , Arnd Bergmann , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "the arch/x86 maintainers" , "H . Peter Anvin" , Linux Kernel Mailing List , clang-built-linux , Tom Rix , Kees Cook Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 On Tue. 10 May 2022 at 08:26, Nick Desaulniers wrote: > On Mon, May 9, 2022 at 4:12 PM Vincent MAILHOL > wrote: > > > > Hi Nick, > > > > On Tue. 10 May 2022 at 04:50, Nick Desaulniers wrote: > > > On Mon, May 9, 2022 at 8:01 AM Vincent MAILHOL > > > wrote: > > > > > > > > Instead, I am thinking of just using -fno-builtin-ffs to remove > > > > the annoying -Wshadow warning. Would that make more sense? > > > > > > Perhaps a pragma would be the best tool to silence this instance of > > > -Wshadow? I understand what GCC is trying to express, but the kernel > > > does straddle a weird place between -ffreestanding and a "hosted" env. > > > > I was a bit reluctant to propose the use of pragma because I received > > negative feedback in another patch for using the __diag_ignore() > > c.f.: > > https://lore.kernel.org/all/YmhZSZWg9YZZLRHA@yury-laptop/ > > > > But the context here is a bit different, I guess. If I receive your support, I > > am fully OK to silence this with some #pragma. > > > > The patch would look as below (I just need to test with clang > > before submitting). > > Do you have a sense for how many other functions trigger -Wshadow? I only witnessed such -Wshadow warnings for ffs(). > For > example, one question I have is: > Why does ffs() trigger this, but not any of the functions defined in > lib/string.c (or declared in include/linux/string.h) which surely also > shadow existing builtins? I can't see your example being sprinkled > all over include/linux/string.h as being ok. Thanks, you are touching on a really interesting point. After checking, the other builtin functions declare the function with two leading underscores (e.g. __foo(...)) and then do: #define foo(...) __foo(...) Or alternatively, if using the builtin function: #define foo(...) __builtin_foo(...) Compilers do not trigger the -Wshadow for such patterns. Example with memcpy(): https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/string_64.h#L75 So, in light of your comment doing this would be more consistent: #define ffs(x) _ffs(x) > If it's more than just ffs(), perhaps the GCC developers can split the > shadowing of builtins into a sub flag under -Wshadow that can then be > disabled; we do want to shadow these functions, but -Wno-shadow would > miss warnings on variables being shadowed due to scope. > > We've done this in the past with various flags in clang. Rather than > having semantic analysis trigger the same warning flag for different > concerns, we split the flag into distinct concerns, and reuse the > original flag as a group that enables the new flags. This gives > developers fine grain control over enabling/disabling distinct > concerns. > > > > > diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h > > index a288ecd230ab..e44911253bdf 100644 > > --- a/arch/x86/include/asm/bitops.h > > +++ b/arch/x86/include/asm/bitops.h > > @@ -269,6 +269,9 @@ static __always_inline unsigned long > > __fls(unsigned long word) > > #undef ADDR > > > > #ifdef __KERNEL__ > > +__diag_push(); > > +__diag_ignore_all("-Wshadow", > > + "-fno-builtin-foo would remove optimization, just > > silence it instead"); > > /** > > * ffs - find first set bit in word > > * @x: the word to search > > @@ -309,6 +312,7 @@ static __always_inline int ffs(int x) > > #endif > > return r + 1; > > } > > +__diag_pop(); /* ignore -Wshadow */ > > > > /** > > * fls - find last set bit in word > > > > -- > Thanks, > ~Nick Desaulniers