[PATCH 1/3] RISC-V: build: Pass `-mattr` to `lld`

10 views
Skip to first unread message

Wende Tan

unread,
Jul 19, 2021, 4:53:04 PM7/19/21
to pal...@dabbelt.com, paul.w...@sifive.com, a...@eecs.berkeley.edu, linux...@lists.infradead.org, Wende Tan, clang-bu...@googlegroups.com
Pass `-mattr` to `lld` so that it can generate proper machine code.
By the way, it seems that `-march` does not work well now.

Signed-off-by: Wende Tan <twd...@gmail.com>
---
arch/riscv/Makefile | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index bc74afdbf31e..bbc186a3ab45 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -52,9 +52,16 @@ riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
+riscv-mattr-y := +m,+a
+riscv-mattr-$(CONFIG_FPU) := $(riscv-mattr-y),+f,+d
+riscv-mattr-$(CONFIG_RISCV_ISA_C) := $(riscv-mattr-y),+c
KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
KBUILD_AFLAGS += -march=$(riscv-march-y)

+ifeq ($(CONFIG_LD_IS_LLD),y)
+ KBUILD_LDFLAGS += -mllvm -mattr=$(riscv-mattr-y)
+endif
+
KBUILD_CFLAGS += -mno-save-restore
KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)

--
2.25.1

Nick Desaulniers

unread,
Jul 19, 2021, 5:15:10 PM7/19/21
to Wende Tan, pal...@dabbelt.com, paul.w...@sifive.com, a...@eecs.berkeley.edu, linux...@lists.infradead.org, clang-bu...@googlegroups.com, Masahiro Yamada, Kees Cook
On Mon, Jul 19, 2021 at 1:53 PM Wende Tan <twd...@gmail.com> wrote:
>
> Pass `-mattr` to `lld` so that it can generate proper machine code.
> By the way, it seems that `-march` does not work well now.
>
> Signed-off-by: Wende Tan <twd...@gmail.com>
> ---
> arch/riscv/Makefile | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> index bc74afdbf31e..bbc186a3ab45 100644
> --- a/arch/riscv/Makefile
> +++ b/arch/riscv/Makefile
> @@ -52,9 +52,16 @@ riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
> riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
> riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
> riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
> +riscv-mattr-y := +m,+a
> +riscv-mattr-$(CONFIG_FPU) := $(riscv-mattr-y),+f,+d
> +riscv-mattr-$(CONFIG_RISCV_ISA_C) := $(riscv-mattr-y),+c
> KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
> KBUILD_AFLAGS += -march=$(riscv-march-y)
>
> +ifeq ($(CONFIG_LD_IS_LLD),y)
> + KBUILD_LDFLAGS += -mllvm -mattr=$(riscv-mattr-y)

We should prevent the proliferation of the compiler internal `-mllvm`
flags from Kbuild Makefiles; these are indicative of LLVM IR specific
issues with regards to LTO. Can you please file a bug against LLVM
that `-mattr` should be encoded in the IR for LTO's sake?

See also:
commit 0236526d76b8 ("Makefile: lto: Pass -warn-stack-size only on LLD
< 13.0.0")
commit 2398ce80152a ("x86, lto: Pass -stack-alignment only on LLD < 13.0.0")

> +endif
> +
> KBUILD_CFLAGS += -mno-save-restore
> KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
>
> --


--
Thanks,
~Nick Desaulniers

twd2

unread,
Jul 22, 2021, 4:23:55 AM7/22/21
to Nick Desaulniers, pal...@dabbelt.com, paul.w...@sifive.com, a...@eecs.berkeley.edu, linux...@lists.infradead.org, clang-bu...@googlegroups.com, Masahiro Yamada, Kees Cook
Thanks for your advice.  After some investigations, I find minimal code
that can reproduce the issue I have had.  The bug is filed at
https://bugs.llvm.org/show_bug.cgi?id=51161.


Thanks.
Wende

Nick Desaulniers

unread,
Jul 27, 2021, 4:23:11 PM7/27/21
to twd2, pal...@dabbelt.com, paul.w...@sifive.com, a...@eecs.berkeley.edu, linux...@lists.infradead.org, clang-bu...@googlegroups.com, Masahiro Yamada, Kees Cook
On Thu, Jul 22, 2021 at 1:23 AM twd2 <twd...@gmail.com> wrote:
>
> Thanks for your advice. After some investigations, I find minimal code
> that can reproduce the issue I have had. The bug is filed at
> https://bugs.llvm.org/show_bug.cgi?id=51161.

Perfect! Thank you for filing that. Let's get that fixed up, then
revisit LTO for RISCV.
--
Thanks,
~Nick Desaulniers

Palmer Dabbelt

unread,
Aug 4, 2021, 4:59:24 PM8/4/21
to ndesau...@google.com, twd...@gmail.com, Paul Walmsley, a...@eecs.berkeley.edu, linux...@lists.infradead.org, clang-bu...@googlegroups.com, masa...@kernel.org, kees...@chromium.org
Works for me. I'll hold off on taking this until the LLVM bug gets
sorted out and expect a v2 (ideally with the other textual changes Nick
suggested).

Thanks!

twd2

unread,
Aug 5, 2021, 4:12:47 PM8/5/21
to Palmer Dabbelt, Paul Walmsley, a...@eecs.berkeley.edu, linux...@lists.infradead.org, clang-bu...@googlegroups.com, masa...@kernel.org, kees...@chromium.org, Nick Desaulniers
Sure. I'll send a v2 after the LLVM issue is resolved.

Thanks!
Wende

Fāng-ruì Sòng

unread,
Aug 5, 2021, 4:18:48 PM8/5/21
to twd2, Palmer Dabbelt, Paul Walmsley, a...@eecs.berkeley.edu, linux...@lists.infradead.org, clang-bu...@googlegroups.com, masa...@kernel.org, kees...@chromium.org, Nick Desaulniers
For GNU ld compatibility: -mllvm -mattr=xxx => -plugin-opt=-mattr=xxx

Which can allow us to drop the CONFIG_LD_IS_LLD condition.
(gold doesn't support RISC-V yet.)

Note: LLVM LTO + GNU ld support is experimental and has very little testing.
To actually make GNU ld work, we probably also need to teach GNU nm
and ar to specify --plugin LLVMgold.so
https://llvm.org/docs/GoldPlugin.html


> >>
> >> See also:
> >> commit 0236526d76b8 ("Makefile: lto: Pass -warn-stack-size only on LLD
> >> < 13.0.0")
> >> commit 2398ce80152a ("x86, lto: Pass -stack-alignment only on LLD < 13.0.0")
> >>
> >>> +endif
> >>> +
> >>> KBUILD_CFLAGS += -mno-save-restore
> >>> KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
> >>>
> >>> --
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-li...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/a6615b69-d99f-220b-d980-1f5f40ee2999%40gmail.com.



--
宋方睿

twd2

unread,
Aug 5, 2021, 5:05:56 PM8/5/21
to Fāng-ruì Sòng, Palmer Dabbelt, Paul Walmsley, a...@eecs.berkeley.edu, linux...@lists.infradead.org, clang-bu...@googlegroups.com, masa...@kernel.org, kees...@chromium.org, Nick Desaulniers
Hi,

I think we even don't need this option after the issue I filed is fixed.

Thanks!
Wende
Reply all
Reply to author
Forward
0 new messages