linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmer@dabbelt.com>
To: tklauser@distanz.ch
Cc: linux-riscv@lists.infradead.org, aou@eecs.berkeley.edu,
	Paul Walmsley <paul.walmsley@sifive.com>
Subject: Re: [PATCH v2] riscv: don't specify -mno-save-restore when building with clang < 11
Date: Thu, 30 Jul 2020 20:58:13 -0700 (PDT)	[thread overview]
Message-ID: <mhng-91321ec8-a62c-46f3-908f-4bd21148cd05@palmerdabbelt-glaptop1> (raw)
In-Reply-To: <20200729044428.32460-1-tklauser@distanz.ch>

On Tue, 28 Jul 2020 21:44:28 PDT (-0700), tklauser@distanz.ch wrote:
> Clang before version 11 doesn't support -msave-restore and
> -mno-save-restore [1].
>
> [1] https://github.com/ClangBuiltLinux/linux/issues/804
>
> This avoids the following message when building with clang 10 and older:
>
>   '-save-restore' is not a recognized feature for this target (ignoring feature)
>
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> ---
> v2: use cc-option and check for clang version
>
>  arch/riscv/Makefile | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> index fb6e37db836d..30e34946af86 100644
> --- a/arch/riscv/Makefile
> +++ b/arch/riscv/Makefile
> @@ -44,7 +44,14 @@ riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
>  KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
>  KBUILD_AFLAGS += -march=$(riscv-march-y)
>
> -KBUILD_CFLAGS += -mno-save-restore
> +KBUILD_CFLAGS += $(call cc-option,-mno-save-restore)
> +# Clang versions less than 11 do not support save-restore. See
> +# https://github.com/ClangBuiltLinux/linux/issues/804
> +ifeq ($(CONFIG_CC_IS_CLANG), y)
> +  ifeq ($(shell test $(CONFIG_CLANG_VERSION) -lt 110000; echo $$?),0)
> +    KBUILD_CFLAGS := $(filter-out -mno-save-restore,$(KBUILD_CFLAGS))
> +  endif
> +endif
>  KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
>
>  ifeq ($(CONFIG_CMODEL_MEDLOW),y)

Ya, that seems worse ;).

Does this work?  I still get a -mno-save-restore on GCC, but I don't have an
LLVM lying around to test it with.

From 3e3ae8610db0abba9dd6a18e5d6b9bc8c495c2fc Mon Sep 17 00:00:00 2001
From: Palmer Dabbelt <palmerdabbelt@google.com>
Date: Thu, 30 Jul 2020 19:41:11 -0700
Subject: [PATCH 1/2] Kbuild: add cc-option-skipwarn

The documentation describes the behavior of this function.  In theory we could
just add -Werror to cc-option, but I don't want to chase around an infinate
tail of weird build bugs due to compilers that have this odd behavior.

Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
 Documentation/kbuild/makefiles.rst | 7 +++++++
 scripts/Kbuild.include             | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst
index 6515ebc12b6f..dba9faf4af29 100644
--- a/Documentation/kbuild/makefiles.rst
+++ b/Documentation/kbuild/makefiles.rst
@@ -507,6 +507,13 @@ more details, with real examples.
 	cflags-y will be assigned no value if first option is not supported.
 	Note: cc-option uses KBUILD_CFLAGS for $(CC) options
 
+   cc-option-skipwarn
+	Some compilers emit a warning on unsupported options rather than an
+	error.  This trips up cc-option, as the test compiler run will succeed
+	only to spit out the warning for every file.  cc-option-skipwarn allows
+	the build infastructure to detect compiles that behave this way, but
+	otherwise acts exactly as cc-option does.
+
    cc-option-yn
 	cc-option-yn is used to check if gcc supports a given option
 	and return 'y' if supported, otherwise 'n'.
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 9a15fbf66aa1..2efd3a8890c7 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -129,6 +129,12 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
 cc-option = $(call __cc-option, $(CC),\
 	$(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
 
+# cc-option-skipwarn
+# Usage: cflags-y += $(call cc-option-skipwarn,-mno-save-restore)
+
+cc-option-skipwarn = $(call __cc-option, $(CC),\
+	$(KBUILD_CPPFLAGS) -Werror $(CC_OPTION_CFLAGS),$(1),$(2))
+
 # cc-option-yn
 # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
 cc-option-yn = $(call try-run,\
-- 
2.28.0.163.g6104cc2f0b6-goog


From 8509566a1a3480ea309fd81317d8cd6125b5e294 Mon Sep 17 00:00:00 2001
From: Tobias Klauser <tklauser@distanz.ch>
Date: Wed, 29 Jul 2020 06:44:28 +0200
Subject: [PATCH 2/2] riscv: don't specify -mno-save-restore unless it's
 supported

Clang before version 11 doesn't support -msave-restore and
-mno-save-restore [1].

[1] https://github.com/ClangBuiltLinux/linux/issues/804

This avoids the following message when building with clang 10 and older:

  '-save-restore' is not a recognized feature for this target (ignoring feature)

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
[Palmer: Use cc-option-nowarn]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
 arch/riscv/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index fb6e37db836d..532029c887f1 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -44,7 +44,7 @@ riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)
 
-KBUILD_CFLAGS += -mno-save-restore
+KBUILD_CFLAGS += $(call cc-option-skipwarn,-mno-save-restore)
 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
 
 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
-- 
2.28.0.163.g6104cc2f0b6-goog

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2020-07-31  3:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28 13:12 [PATCH RESEND] riscv: don't specify -mno-save-restore when building with clang Tobias Klauser
2020-07-28 15:20 ` Palmer Dabbelt
2020-07-28 16:06   ` Tobias Klauser
2020-07-29  4:41     ` Tobias Klauser
2020-07-29  8:08       ` Jerome Forissier
2020-07-29  8:29         ` Tobias Klauser
2020-07-29  9:36           ` Jerome Forissier
2020-07-29  9:43             ` Jerome Forissier
2020-07-29  4:44 ` [PATCH v2] riscv: don't specify -mno-save-restore when building with clang < 11 Tobias Klauser
2020-07-31  3:58   ` Palmer Dabbelt [this message]
2020-07-31  8:16     ` Tobias Klauser
2020-07-31 16:16       ` Palmer Dabbelt
2020-08-01 10:30         ` Tobias Klauser
2020-08-03 20:28           ` Palmer Dabbelt

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=mhng-91321ec8-a62c-46f3-908f-4bd21148cd05@palmerdabbelt-glaptop1 \
    --to=palmer@dabbelt.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-riscv@lists.infradead.org \
    --cc=paul.walmsley@sifive.com \
    --cc=tklauser@distanz.ch \
    /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).