Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6211063iob; Tue, 10 May 2022 12:57:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9aBZFfSSEfH1GCXSmQfQveDTmmEyv6TkAyb2xi9NCWimQVL+q6AgceZKpwoWd1rmsZufE X-Received: by 2002:a17:903:240e:b0:158:eab9:2662 with SMTP id e14-20020a170903240e00b00158eab92662mr22059251plo.87.1652212625863; Tue, 10 May 2022 12:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652212625; cv=none; d=google.com; s=arc-20160816; b=z2jzKWY6xQqdEoCw/pNcDuHDuTJ7e89CCMDs3O3j0okOF9rSEzo1v/ehqi9Hd7mRYq WIrhdXsm+6SezxNhy8McdxRFseY2JhWQ5To8hy0pKrBY5/J0ihrYejezUyjFFPgGJiBl 1TLzICyUOZ9spct7MN/KlGhLFOfTbnG3NhgCrHI6+0xpTjfAL9w1aTBES4X6+9eGOudz ZhJhgvjPctri0n4Rn41UVSN2kk8eTd/G12rjpKyjorGeWVXvMtwBBNzWJDguSlQ9B3Tu wMYUmLc7UbofJ+/x+OCzMnqxAZ5iNMvGvFD9yAmnMD0AqHSgeVmkkoZSe4FUVYuT/QNH 3Qzg== 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=mx7jkXBBdOIkJsGSW9sVzyIselbqrtRZw2WUonRIsCM=; b=L+CiLqv4tS62M1K8x2AcTj8DxfR+VeFZm1gvHvYCCrQUerRTYstfvA2gnHQVhfNGC3 D5VXA46adpWHdFmXz1eeMndY57CgI+9MVWbUa5p5Xzln1Mq87aNV2OBqr4XOHbbiER1v hKRsC9EwxAxoPzqg6sDJNG1TF0qVuCXCLt8ZZ7lSCfdEOy09aPNvlf/8svwuRa6EvDj0 eQtwdAqmd3JEXI/BnG8UjLHr/b9P2kaEZnwK/B1Yk2X5jcvkISa6xW3OBgaDQUVzAUbA WnMu6pvOiwHswgfZIoHF3tvXnMqHEIMtC7mjGJbmVu/w3NkKM4aX3Ngg8U9Sq4knt5+1 rA6w== 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 nu15-20020a17090b1b0f00b001d297b4e1a9si136392pjb.166.2022.05.10.12.56.50; Tue, 10 May 2022 12:57:05 -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 S1345460AbiEJPHj (ORCPT + 99 others); Tue, 10 May 2022 11:07:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346045AbiEJPGq (ORCPT ); Tue, 10 May 2022 11:06:46 -0400 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B2F931937 for ; Tue, 10 May 2022 07:33:26 -0700 (PDT) Received: by mail-yb1-f175.google.com with SMTP id i11so9018922ybq.9 for ; Tue, 10 May 2022 07:33:26 -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=mx7jkXBBdOIkJsGSW9sVzyIselbqrtRZw2WUonRIsCM=; b=sT1jp4rCdLtP0oStePP6Vp5MUtS+Y4Tuj3TUHO63hUCsDuH+LIss6UNQP5gafSuuiq Qu8lzWWmSNdd7NlzTjhvZT1BBIVP9PcVG4SgL7cv+1paOq0CQDgXDlanFKHwAPtrBKzG oE3NNyvrBvMJVmuXvkebo9o8XGfgxO1ltmUsWzdpe+3G96oSvNmFTmeP38TfPQylXgRY wvRk9of/sf2JJNYY5TIaMP6RKBsoICO/XQOS1KPWOvTaqsxV9D/u8gahf+Q1cavWINGx N+2BsI0EUObt986G3zq5vBSphgAQW8EqnaaYsWe1siGWcsv5CUI9O6x+K5pPrhpGCVrl cDCw== X-Gm-Message-State: AOAM5339N7qnZ30Mcjs1i1WcyGZnJ3FsXA45MPXa+RWh5xsZSfVVc0bN nY+luOMfVN0frVHyxC8OenJl+tH6DUrEQYZjtVCRnMv0iERgTw== X-Received: by 2002:a5b:491:0:b0:64a:f42f:6973 with SMTP id n17-20020a5b0491000000b0064af42f6973mr6000334ybp.20.1652193205241; Tue, 10 May 2022 07:33:25 -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 23:33:13 +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 10:10, Vincent MAILHOL wrote: > 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) I created this patch: https://lore.kernel.org/all/20220510142550.1686866-1-mailhol.vincent@wanadoo.fr/T/#m55da229f67d2c84470a55df32e71d8600c581024 This solves the -Wshadow and also adds some optimizations for when ffs() is called with constant variables. Yours sincerely, Vincent Mailhol