llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Michal Marek <michal.lkml@markovi.net>, Tom Rix <trix@redhat.com>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	clang-built-linux <llvm@lists.linux.dev>, X86 ML <x86@kernel.org>,
	Dmitrii Bundin <dmitrii.bundin.a@gmail.com>,
	Fangrui Song <maskray@google.com>,
	Alexey Alexandrov <aalexand@google.com>,
	Bill Wendling <morbo@google.com>,
	Greg Thelen <gthelen@google.com>
Subject: Re: [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option
Date: Mon, 5 Sep 2022 18:09:28 +0900	[thread overview]
Message-ID: <CAK7LNASQJ-B2kRGXea-dQt+1BgEsp_aLEPS_uJb1R6FSOj1Khg@mail.gmail.com> (raw)
In-Reply-To: <Yw+8QgtSbB2/3Eiq@dev-arch.thelio-3990X>

On Thu, Sep 1, 2022 at 4:53 AM Nathan Chancellor <nathan@kernel.org> 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/





> 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/)



> 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.


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



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))






> Do not get me wrong, I still believe this is the correct fix but I think
> it would be good to describe exactly under which conditions this is a
> real issue in case we ever have to revisit this.
>
> > Callers of as-option (and as-instr) likely want to be adding flags to
> > KBUILD_AFLAGS/aflags-y, not KBUILD_CFLAGS/cflags-y.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1699
> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
>
> Regardless of changes to the commit message:
>
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
>
> > ---
> > Changes v1 -> v2:
> > * Split off changes to arch/x86/boot/compressed/Makefile into parent
> >   patch, as per Masahiro.
> >
> >  scripts/Makefile.compiler | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
> > index 94d0d40cddb3..d1739f0d3ce3 100644
> > --- a/scripts/Makefile.compiler
> > +++ b/scripts/Makefile.compiler
> > @@ -29,13 +29,13 @@ try-run = $(shell set -e;         \
> >       fi)
> >
> >  # as-option
> > -# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
> > +# Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
> >
> >  as-option = $(call try-run,\
> > -     $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
> > +     $(CC) $(KBUILD_AFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
> >
> >  # as-instr
> > -# Usage: cflags-y += $(call as-instr,instr,option1,option2)
> > +# Usage: aflags-y += $(call as-instr,instr,option1,option2)
> >
> >  as-instr = $(call try-run,\
> >       printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
> > --
> > 2.37.2.672.g94769d06f0-goog
> >



--
Best Regards



Masahiro Yamada

  reply	other threads:[~2022-09-05  9:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 18:44 [PATCH v2 0/5] fix debug info for asm and DEBUG_INFO_SPLIT Nick Desaulniers
2022-08-31 18:44 ` [PATCH v2 1/5] x86/boot/compressed: prefer cc-option for CFLAGS additions Nick Desaulniers
2022-08-31 19:41   ` Nathan Chancellor
2022-08-31 18:44 ` [PATCH v2 2/5] Makefile.compiler: Use KBUILD_AFLAGS for as-option Nick Desaulniers
2022-08-31 19:53   ` Nathan Chancellor
2022-09-05  9:09     ` Masahiro Yamada [this message]
2022-09-06 16:08       ` Nathan Chancellor
2022-09-07  4:14         ` Masahiro Yamada
2022-09-07  3:12       ` Nick Desaulniers
2022-09-07  4:27         ` Masahiro Yamada
2022-08-31 18:44 ` [PATCH v2 3/5] Makefile.compiler: replace cc-ifversion with compiler-specific macros Nick Desaulniers
2022-08-31 20:08   ` Nathan Chancellor
2022-09-05  6:44   ` Masahiro Yamada
2022-08-31 18:44 ` [PATCH v2 4/5] Makefile.debug: re-enable debug info for .S files Nick Desaulniers
2022-08-31 20:22   ` Nathan Chancellor
2022-09-05  7:49   ` Masahiro Yamada
2022-09-07  4:27     ` Nick Desaulniers
2022-08-31 18:44 ` [PATCH v2 5/5] Makefile.debug: set -g unconditional on CONFIG_DEBUG_INFO_SPLIT Nick Desaulniers
2022-08-31 20:23   ` Nathan Chancellor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAK7LNASQJ-B2kRGXea-dQt+1BgEsp_aLEPS_uJb1R6FSOj1Khg@mail.gmail.com \
    --to=masahiroy@kernel.org \
    --cc=aalexand@google.com \
    --cc=dmitrii.bundin.a@gmail.com \
    --cc=gthelen@google.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=maskray@google.com \
    --cc=michal.lkml@markovi.net \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=trix@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).