[PATCH] riscv: Use -mno-relax when using lld linker

Fāng-ruì Sòng maskray at google.com
Fri May 14 14:14:45 PDT 2021


On Fri, May 14, 2021 at 1:57 PM Khem Raj <raj.khem at gmail.com> wrote:
>
> 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.

> Signed-off-by: Khem Raj <raj.khem at gmail.com>
> Cc: Paul Walmsley <paul.walmsley at sifive.com>
> Cc: Palmer Dabbelt <palmer at dabbelt.com>
> Cc: Albert Ou <aou at eecs.berkeley.edu>
> Cc: Nathan Chancellor <nathan at kernel.org>
> Cc: Nick Desaulniers <ndesaulniers at google.com>
> ---
>  arch/riscv/Makefile | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> index 3eb9590a0775..519f133e0d53 100644
> --- a/arch/riscv/Makefile
> +++ b/arch/riscv/Makefile
> @@ -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 clang-built-linux+unsubscribe at googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20210514205643.383422-1-raj.khem%40gmail.com.



-- 
宋方睿



More information about the linux-riscv mailing list