Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4594068rwb; Tue, 6 Sep 2022 09:35:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR7GpSnnswLgfBqfLq8k/seTliF2xi7IMj6aO4L1MTegdpN98jXrZHmA/rxH2X5zx7bgs3iy X-Received: by 2002:a05:6402:240a:b0:446:39d9:95d7 with SMTP id t10-20020a056402240a00b0044639d995d7mr49200262eda.253.1662482146942; Tue, 06 Sep 2022 09:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662482146; cv=none; d=google.com; s=arc-20160816; b=JbfZKxmI/1+mlh64UP2DCfT+hd+C+OxnpfgjrDJAHEfO/zxhOv1UtzyWXWGGhBljkz z6aD+ixY+xA360BjUXK/SNq6Y3H3+2ChnY+AHBjHiY7jz7+YLWxa/tWAcHB8Cv4IcOE7 u9eZX+/AOtGmr3R7u37freiVwo3WBfN3bJHbO3SVLg52sqfG70mgIQrgtV3LYx3qAEna vXPevW/C/2D12oUf3+sX1pyYjCsn9vsUg+PFsl68aD/LIROv7W6Swt+MfbKE6Zd4UcAt XIXRKHrIy1z/mS4CzqK42w70Bmpy9vib/V6ApZwD8C3aHa3CPmIYkBB5XnfM1QwRTTfx 3fzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=i1pUwmD4ZepPwF4eD7VcTJGKLpffho/LJZ6386t1FCw=; b=v8XinSAR97+UHH36IuuvTKESRv+JkGWh018kWDo8ShEAs+Rn5KRCyYLt2ApIRSa+88 gzP/DWJrV0avYpi28/AFvUmC8GflKlkGw15kqUugZLHEsWgvBD7m0AVTa7k1zNf2kc6q m0KnEel8GKMpQQubs+LvJRyWx254E38Kz6R56WlWYcLlaSF7WKmCvq4TK/kg8cDp1LFO 1f3q9IKzOWRmVyQ2JvPQQ8OLazEqafmC9iTFRU2PvdwSKwhoIySTtBPvZC496p4vCtgY KWrknxiwvofJq4/VKJZPopVw766RF/114sfMwI+bJZXzMTQLaiBM813HcRLRHD0G43wU vFcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ba9F9jP6; 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 s3-20020a17090699c300b0076febee8f6csi643489ejn.886.2022.09.06.09.35.20; Tue, 06 Sep 2022 09:35:46 -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=ba9F9jP6; 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 S231398AbiIFQdz (ORCPT + 99 others); Tue, 6 Sep 2022 12:33:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232035AbiIFQdQ (ORCPT ); Tue, 6 Sep 2022 12:33:16 -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 EF87684EE9; Tue, 6 Sep 2022 09:08:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 261D8615AD; Tue, 6 Sep 2022 16:08:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A69A6C433D6; Tue, 6 Sep 2022 16:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662480495; bh=zCc7fKyX2vVh00Skn6XiWidfTXu0QhuXY1caqeayhMM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ba9F9jP6xg9kM/goDxi/ZxniQ8EZq0lcpVWdjBcc+ux0XgBUqqCPRAweRuoyu2z9e r+joBj/rUf8bX8zUIFs8W7qJieAyaT8X1CqQ2gu5KWXzD4xgONbx78+Y0F6U9F5OKa Bq732ZHvCASpV2p3JitatXHhcrNM4qh+UAfssAQKAHDRKplbHOH5YZPP40mbCZZIzP AIbTA6WW+f9wd4/x1ZppyWmCupDzBZolui7qTwPrIpXidy/y9fNW4Dq1r5A5MOLO1h yABXALX0TfV6e8RHoeC8VlqKW6V/huyMWAKqmENRC1vdxA1g1jS4s9cYQizU2E2QRo i7Z1dJk+JwaTQ== Date: Tue, 6 Sep 2022 09:08:12 -0700 From: Nathan Chancellor To: Masahiro Yamada Cc: Nick Desaulniers , Michal Marek , Tom Rix , Linux Kbuild mailing list , Linux Kernel Mailing List , clang-built-linux , X86 ML , Dmitrii Bundin , Fangrui Song , Alexey Alexandrov , Bill Wendling , Greg Thelen Subject: Re: [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option Message-ID: References: <20220831184408.2778264-1-ndesaulniers@google.com> <20220831184408.2778264-3-ndesaulniers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Mon, Sep 05, 2022 at 06:09:28PM +0900, Masahiro Yamada wrote: > On Thu, Sep 1, 2022 at 4:53 AM Nathan Chancellor wrote: > > > > On Wed, Aug 31, 2022 at 11:44:05AM -0700, Nick Desaulniers wrote: > > > as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can > > > cause as-option to fail unexpectedly because clang will emit > > > -Werror,-Wunused-command-line-argument for various -m and -f flags for > > > assembler sources. > > > > Now that I am looking closer at it, where does that '-Werror' come from? > > The related commit is > c3f0d0bc5b01ad90c45276952802455750444b4f > > The previous discussion with Arnd is > https://lore.kernel.org/linux-kbuild/20170314213724.3836900-1-arnd@arndb.de/ Right, although this is for cc-option, not as-option, no? > > For cc-option, we add it to elevate clang's warnings about unused '-f', > > '-m', and '-W' flags to errors so that we do not add those flags. > > However, I do not see '-Werror' in as-option. I am going to assume it > > came from CONFIG_WERROR, as I believe Android has that turned on by > > default. > > CONFIG_WERROR is added to CFLAGS. > But, I guess it is more correct to do likewise for others. > (https://patchwork.kernel.org/project/linux-kbuild/patch/20220905083619.672091-1-masahiroy@kernel.org/) Ack. > > I think that is the real problem: without '-Werror', the only > > error that should come from as-option is when an option isn't supported > > by the assembler, as clang will still warn but those will not be fatal > > but with '-Werror', those warnings turn fatal, causing all subsequent > > as-option calls to fail. > > Presumably, it is correct to add -Werror to as-option as well. > We have no reason to add it to cc-option, but not to as-option. > > I also believe '-x assembler' should be changed to > '-x assembler-with-cpp'. > > As I mentioned somewhere before, our assembly code (*.S) is always > preprocessed. There is no *.s file in the kernel source tree. > > So, '-x assembler-with-cpp' matches the real situation. All good points, I think that is a good fix as well. > One interesting thing is, clang does not warn > [-Wunused-command-line-argument] for *.S files. > > $ clang -fomit-frame-pointer -c -x assembler /dev/null -o /dev/null > clang: warning: argument unused during compilation: > '-fomit-frame-pointer' [-Wunused-command-line-argument] > > $ clang -fomit-frame-pointer -c -x assembler-with-cpp /dev/null -o /dev/null Interesting... I suspect that is likely intentional, as some compiler flags could be used during preprocessing (it's come up before: https://github.com/llvm/llvm-project/issues/55656) but I was not able to figure out exactly where in clang the flags were consumed but Driver.cpp is quite large and I didn't look too hard :) More importantly, it still allows us to catch invalid assembler arguments: $ clang -c -x assembler-with-cpp /dev/null -o /dev/null -Wa,-foo clang-16: error: unsupported argument '-foo' to option '-Wa,' $ clang -c -x assembler-with-cpp /dev/null -o /dev/null -Wa,--noexecstack > The root cause is we are using '-x assembler', which > never happens in the kernel tree. > > To sum up, the code I think correct is: > > as-option = $(call try-run,\ > $(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp > /dev/null -o "$$TMP",$(1),$(2)) > Agreed. Thank you as always for your feedback! Cheers, Nathan