Skip to contentSkip to conversation

RISC-V: build: Pass `-mattr` to `lld`

PATCH Superseded Wende Tan 4 participants 8 messages Jul 19, 2021 – Aug 5, 2021 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wende Tan

author
#0 lore raw

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

Pass -mattr to lld so that it can generate proper machine code. By the way, it seems that -march does not work well now.

---
 arch/riscv/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
arch/riscv/Makefile +7 -0
index bc74afdbf31e..bbc186a3ab45 100644
@@ -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)
 
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw
Quoted 15 lines · Wende Tan

Pass -mattr to lld so that it can generate proper machine code. By the way, it seems that -march does not work well now.

---
 arch/riscv/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
arch/riscv/Makefile +0 -0
index bc74afdbf31e..bbc186a3ab45 100644
@@ -52,9 +52,16 @@ riscv-march-$(CONFIG_ARCH_RV32I)     := rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)       := rv64ima

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 62

Quoted 10 lines
arch/riscv/Makefile +5 -0
 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")

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima

Quoted 6 lines
arch/riscv/Makefile +2 -1
+endif
+
 KBUILD_CFLAGS += -mno-save-restore
 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
 
--

--
Thanks,
~Nick Desaulniers

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#2 lore raw

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

Quoted 40 lines · Nick Desaulniers
Quoted 14 lines · Wende Tan

Pass -mattr to lld so that it can generate proper machine code. By the way, it seems that -march does not work well now.

---
 arch/riscv/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
arch/riscv/Makefile +0 -0
index bc74afdbf31e..bbc186a3ab45 100644
@@ -52,9 +52,16 @@ riscv-march-$(CONFIG_ARCH_RV32I)     := rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)       := rv64ima

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 62

Quoted 10 lines
arch/riscv/Makefile +5 -0
 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")

Quoted 5 lines
arch/riscv/Makefile +2 -0
+endif
+
 KBUILD_CFLAGS += -mno-save-restore
 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
 
Quoted 5 lines
Quoted 1 line

--

--
Thanks,
~Nick Desaulniers

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw
Quoted 4 lines · On Thu, Jul 22, 2021 at 1:23 AM twd2 <[email protected]> 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.

Signature · 7 lines
Thanks,
~Nick Desaulniers

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
maintainer
#4 lore raw
In reply to Nick Desaulniers
Quoted 24 lines · On Mon, 19 Jul 2021 14:14:59 PDT (-0700), [email protected] wrote:
Quoted 23 lines · Wende Tan

Pass -mattr to lld so that it can generate proper machine code. By the way, it seems that -march does not work well now.

---
 arch/riscv/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
arch/riscv/Makefile +3 -0
index bc74afdbf31e..bbc186a3ab45 100644
@@ -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)
 
Quoted 7 lines

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 62

Quoted 2 lines
arch/riscv/Makefile +2 -0
+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?

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!

Quoted 6 lines

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

Quoted 6 lines

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima

Quoted 6 lines
arch/riscv/Makefile +2 -1
+endif
+
 KBUILD_CFLAGS += -mno-save-restore
 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
 
--

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#5 lore raw

Sure. I'll send a v2 after the LLVM issue is resolved.

Thanks!
Wende

Quoted 43 lines · Palmer Dabbelt
Quoted 24 lines · On Mon, 19 Jul 2021 14:14:59 PDT (-0700), [email protected] wrote:
Quoted 23 lines · Wende Tan

Pass -mattr to lld so that it can generate proper machine code. By the way, it seems that -march does not work well now.

---
 arch/riscv/Makefile | 7 +++++++

 1 file changed, 7 insertions(+)
arch/riscv/Makefile +0 -0
index bc74afdbf31e..bbc186a3ab45 100644
@@ -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

arch/riscv/Makefile +3 -0
+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)

Quoted 7 lines
Quoted 2 lines

+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?

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!

Quoted 6 lines

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

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/Makefile +2 -0
+endif
+

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

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#6 lore raw
Quoted 44 lines · On Thu, Aug 5, 2021 at 1:12 PM twd2 <[email protected]> wrote:

Sure. I'll send a v2 after the LLVM issue is resolved.

Thanks!
Wende

Quoted 36 lines · Palmer Dabbelt
Quoted 24 lines · On Mon, 19 Jul 2021 14:14:59 PDT (-0700), [email protected] wrote:
Quoted 23 lines · Wende Tan

Pass -mattr to lld so that it can generate proper machine code. By the way, it seems that -march does not work well now.

---
 arch/riscv/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
arch/riscv/Makefile +3 -0
index bc74afdbf31e..bbc186a3ab45 100644
@@ -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)
 
Quoted 7 lines

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 62

Quoted 2 lines
arch/riscv/Makefile +2 -0
+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?

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!

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

Quoted 17 lines
Quoted 6 lines
Quoted 6 lines

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

Quoted 6 lines
Quoted 6 lines

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima

Quoted 6 lines
arch/riscv/Makefile +2 -1
+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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/a6615b69-d99f-220b-d980-1f5f40ee2999%40gmail.com.

Signature · 6 lines
宋方睿

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author
#7 lore raw

Hi,

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

Thanks!
Wende

Quoted 43 lines · Fāng-ruì Sòng
Quoted 40 lines · On Thu, Aug 5, 2021 at 1:12 PM twd2 <[email protected]> wrote:

Sure. I'll send a v2 after the LLVM issue is resolved.

Thanks!
Wende

Quoted 33 lines · Palmer Dabbelt
Quoted 23 lines · On Mon, 19 Jul 2021 14:14:59 PDT (-0700), [email protected] wrote:
Quoted 22 lines · Wende Tan

Pass -mattr to lld so that it can generate proper machine code. By the way, it seems that -march does not work well now.

---
 arch/riscv/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
arch/riscv/Makefile +3 -0
index bc74afdbf31e..bbc186a3ab45 100644
@@ -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)
 
Quoted 6 lines

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 62

Quoted 2 lines
arch/riscv/Makefile +2 -0
+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?

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!

For GNU ld compatibility: -mllvm -mattr=xxx => -plugin-opt=-mattr=xxx

Quoted 25 lines

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

Quoted 15 lines
Quoted 11 lines
Quoted 11 lines

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

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima

Quoted 6 lines
arch/riscv/Makefile +2 -1
+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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/a6615b69-d99f-220b-d980-1f5f40ee2999%40gmail.com.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv