Skip to contentSkip to conversation

riscv: Use -mno-relax when using lld linker

PATCH Superseded Khem Raj 4 participants 5 messages May 14, 2021 – May 29, 2021 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 riscv: Use -mno-relax when using lld linker

lld does not implement the RISCV relaxation optimizations like GNU ld therefore disable it when building with LLVM=1, Also pass it to assembler when using external GNU assembler ( LLVM_IAS != 1 ), this ensures that relevant assembler option is also enabled along. if these options are not used then we see following relocations in objects

0000000000000000 R_RISCV_ALIGN *ABS*+0x0000000000000002

These are then rejected by lld
ld.lld: error: capability.c:(.fixup+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax but the .o is already compiled with -mno-relax

Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 arch/riscv/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/riscv/Makefile +9 -0
index 3eb9590a0775..519f133e0d53 100644
@@ -38,6 +38,15 @@ else
 	KBUILD_LDFLAGS += -melf32lriscv
 endif
 
+ifeq ($(LLVM),1)
+	KBUILD_CFLAGS += -mno-relax
+	KBUILD_AFLAGS += -mno-relax
+ifneq ($(LLVM_IAS),1)
+	KBUILD_CFLAGS += -Wa,-mno-relax
+	KBUILD_AFLAGS += -Wa,-mno-relax
+endif
+endif
+
 # ISA string setting
 riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima
Signature · 7 lines
2.31.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 1/1
#1 lore raw

Hi Khem,

Quoted 11 lines · Khem Raj

lld does not implement the RISCV relaxation optimizations like GNU ld therefore disable it when building with LLVM=1, Also pass it to assembler when using external GNU assembler ( LLVM_IAS != 1 ), this ensures that relevant assembler option is also enabled along. if these options are not used then we see following relocations in objects

0000000000000000 R_RISCV_ALIGN *ABS*+0x0000000000000002

These are then rejected by lld
ld.lld: error: capability.c:(.fixup+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax but the .o is already compiled with -mno-relax

Quoted 6 lines
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>

Thank you for the patch! I can build a ARCH=riscv defconfig kernel with LLVM=1 now. LLVM_IAS=1 still needs work but we have outstanding issues for that:

https://github.com/ClangBuiltLinux/linux/issues/1023
https://github.com/ClangBuiltLinux/linux/issues/1143

One comment below though.

arch/riscv/Makefile else · line 41

Quoted 13 lines
---
  arch/riscv/Makefile | 9 +++++++++
  1 file changed, 9 insertions(+)
arch/riscv/Makefile +1 -0
index 3eb9590a0775..519f133e0d53 100644
@@ -38,6 +38,15 @@ else
  	KBUILD_LDFLAGS += -melf32lriscv
  endif
 
+ifeq ($(LLVM),1)

ifeq ($(CONFIG_LD_IS_LLD),y)

is a better choice so that LD=riscv64-linux-gnu-ld LLVM=1 can still work.

arch/riscv/Makefile else · line 52

Quoted 12 lines
arch/riscv/Makefile +8 -0
+	KBUILD_CFLAGS += -mno-relax
+	KBUILD_AFLAGS += -mno-relax
+ifneq ($(LLVM_IAS),1)
+	KBUILD_CFLAGS += -Wa,-mno-relax
+	KBUILD_AFLAGS += -Wa,-mno-relax
+endif
+endif
+
  # ISA string setting
  riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
  riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima

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

#2 lore raw
In reply to Khem Raj
Quoted 11 lines · Khem Raj

lld does not implement the RISCV relaxation optimizations like GNU ld therefore disable it when building with LLVM=1, Also pass it to assembler when using external GNU assembler ( LLVM_IAS != 1 ), this ensures that relevant assembler option is also enabled along. if these options are not used then we see following relocations in objects

0000000000000000 R_RISCV_ALIGN *ABS*+0x0000000000000002

These are then rejected by lld
ld.lld: error: capability.c:(.fixup+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax but the .o is already compiled with -mno-relax

This means -mno-relax should emit .option norelax in the assembly. I'll try fixing this in Clang 13.

Quoted 37 lines
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 arch/riscv/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/riscv/Makefile +9 -1
index 3eb9590a0775..519f133e0d53 100644
@@ -38,6 +38,15 @@ else
        KBUILD_LDFLAGS += -melf32lriscv
 endif
 
+ifeq ($(LLVM),1)
+       KBUILD_CFLAGS += -mno-relax
+       KBUILD_AFLAGS += -mno-relax
+ifneq ($(LLVM_IAS),1)
+       KBUILD_CFLAGS += -Wa,-mno-relax
+       KBUILD_AFLAGS += -Wa,-mno-relax
+endif
+endif
+
 # ISA string setting
 riscv-march-$(CONFIG_ARCH_RV32I)       := rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)       := rv64ima
--

2.31.1

--
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/20210514205643.383422-1-raj.khem%40gmail.com.

Signature · 6 lines
宋方睿

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
maintainer
#3 lore raw
In reply to Khem Raj
Quoted 31 lines · Khem Raj

lld does not implement the RISCV relaxation optimizations like GNU ld therefore disable it when building with LLVM=1, Also pass it to assembler when using external GNU assembler ( LLVM_IAS != 1 ), this ensures that relevant assembler option is also enabled along. if these options are not used then we see following relocations in objects

0000000000000000 R_RISCV_ALIGN *ABS*+0x0000000000000002

These are then rejected by lld
ld.lld: error: capability.c:(.fixup+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax but the .o is already compiled with -mno-relax

Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 arch/riscv/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/riscv/Makefile +2 -0
index 3eb9590a0775..519f133e0d53 100644
@@ -38,6 +38,15 @@ else
 	KBUILD_LDFLAGS += -melf32lriscv
 endif
 
+ifeq ($(LLVM),1)
+	KBUILD_CFLAGS += -mno-relax

arch/riscv/Makefile else · line 52

Quoted 10 lines
arch/riscv/Makefile +7 -0
+	KBUILD_AFLAGS += -mno-relax
+ifneq ($(LLVM_IAS),1)
+	KBUILD_CFLAGS += -Wa,-mno-relax
+	KBUILD_AFLAGS += -Wa,-mno-relax
+endif
+endif
+
 # ISA string setting
 riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima

Thanks, this is on fixes.

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

maintainer
#4 lore raw
Quoted 30 lines · Palmer Dabbelt
Quoted 29 lines · Khem Raj

lld does not implement the RISCV relaxation optimizations like GNU ld therefore disable it when building with LLVM=1, Also pass it to assembler when using external GNU assembler ( LLVM_IAS != 1 ), this ensures that relevant assembler option is also enabled along. if these options are not used then we see following relocations in objects

0000000000000000 R_RISCV_ALIGN *ABS*+0x0000000000000002

These are then rejected by lld
ld.lld: error: capability.c:(.fixup+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax but the .o is already compiled with -mno-relax

Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 arch/riscv/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/riscv/Makefile +0 -0
index 3eb9590a0775..519f133e0d53 100644
@@ -38,6 +38,15 @@ else
 	KBUILD_LDFLAGS += -melf32lriscv
 endif
 
Quoted 14 lines

arch/riscv/Makefile else · line 52

Quoted 12 lines
arch/riscv/Makefile +9 -0
+ifeq ($(LLVM),1)
+	KBUILD_CFLAGS += -mno-relax
+	KBUILD_AFLAGS += -mno-relax
+ifneq ($(LLVM_IAS),1)
+	KBUILD_CFLAGS += -Wa,-mno-relax
+	KBUILD_AFLAGS += -Wa,-mno-relax
+endif
+endif
+
 # ISA string setting
 riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima

Thanks, this is on fixes.

Sorry, replied to the v1 but I merged the v2.

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