Llvm linker (lld) unimplemented linker relaxation error

Hi all,

I could successfully build llvm for riscv64-unknown-linux-gnu target.
But when I use clang+lld to build hello-world program, I get the following error although I pass the “-mno-relax” flag to clang. Any idea what the problem could be?

with “-mno-relax” flag:
./_install/bin/clang -fuse-ld=lld -mno-relax -o hello hello.c
ld.lld: error: static-reloc.c:(.text+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

without “-mno-relax” flag:
./_install/bin/clang -fuse-ld=lld -o hello hello.c
ld.lld: error: static-reloc.c:(.text+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax
ld.lld: error: hello.c:(.text+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

" ./_install/bin/clang -o hello hello.c" works well, but it’s using gnu linker instead.

Thank you!

Relaxation support for riscv is pending. There was two attempt in ⚙ D77694 [WIP][RISCV][ELF] Linker relaxation support and ⚙ D100835 [WIP][LLD][RISCV] Linker Relaxation. But with current implementation of lld it is difficult to implement riscv relaxation support. More details of problem in maskray blog - The dark side of RISC-V linker relaxation | MaskRay.

You are welcome to contribute.

Thanks @Shivam for the info!

The point is that I pass -mno-relax flag to Clang. So what other options I need to use to fix this error?

Do I also need to build glibc with -mno-relax to use lld?

Hi @zazad,

I could successfully build llvm for riscv64-unknown-linux-gnu target.

Did you followed GitHub - sifive/riscv-llvm: SiFive's LLVM working tree

with “-mno-relax” flag:
./_install/bin/clang -fuse-ld=lld -mno-relax -o hello hello.c
ld.lld: error: static-reloc.c:(.text+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

I tried after following the above sifive/riscv-llvm’s instructions, I didn’t get any such error when passed -mno-relax to clang/lld.

Do I also need to build glibc with -mno-relax to use lld?

Nope :slight_smile:

Please follow those instructions carefully, if still get any issue, let us know.

Best,
Shivam