Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ld.lld: relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax #44181

Closed
berolinux opened this issue Feb 7, 2020 · 5 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party lld:ELF

Comments

@berolinux
Copy link

Bugzilla Link 44836
Version unspecified
OS Linux
Blocks #4440
CC @lattner,@topperc,@jrtc27,@nickdesaulniers,@lenary,@smithp35

Extended Description

Clang 10.0-rc1 on riscv64-linux (RV64IMAFDC) breaks if LTO is enabled -- apparently the correct ABI isn't passed to the linker:

$ clang -march=rv64imafdc test.c
[works perfectly, binary works]
$ clang -march=rv64imafdc -flto test.c
/usr/bin/ld: /tmp/lto-llvm-f65f95.o: can't link soft-float modules with double-float modules
/usr/bin/ld: failed to merge target specific data of file /tmp/lto-llvm-f65f95.o
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
$ clang -march=rv64imafdc -flto -fuse-ld=lld test.c
ld.lld: error: lto.tmp: cannot link object files with different floating-point ABI
ld.lld: error: static-reloc.c:(.text+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax
ld.lld: /builddir/build/BUILD/llvm-project-release-10.x/lld/ELF/Relocations.cpp:987: uint64_t lld::elf::{anonymous}::OffsetGetter::get(uint64_t): Assertion `pieces[i].inputOff <= off && "Relocation not in any piece"' failed.
Stack dump:
0. Program arguments: /usr/bin/ld.lld --build-id --eh-frame-hdr -m elf64lriscv -dynamic-linker /lib/ld-linux-riscv64-lp64d.so.1 -o a.out /usr/bin/../lib64/gcc/riscv64-openmandriva-linux-gnu/9.2.1/../../../../lib64/crt1.o /usr/bin/../lib64/gcc/riscv64-openmandriva-linux-gnu/9.2.1/crti.o /usr/bin/../lib64/gcc/riscv64-openmandriva-linux-gnu/9.2.1/crtbegin.o -L/usr/bin/../lib64/gcc/riscv64-openmandriva-linux-gnu/9.2.1 -L/usr/bin/../lib64/gcc/riscv64-openmandriva-linux-gnu/9.2.1/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib64/lp64d -L/usr/lib64/lp64d -L/usr/bin/../lib64/gcc/riscv64-openmandriva-linux-gnu/9.2.1/../../../../riscv64-openmandriva-linux-gnu/lib -L/usr/bin/../lib64/gcc/riscv64-openmandriva-linux-gnu/9.2.1/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib -plugin /usr/bin/../lib64/LLVMgold.so /tmp/test-6791f6.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib64/gcc/riscv64-openmandriva-linux-gnu/9.2.1/crtend.o /usr/bin/../lib64/gcc/riscv64-openmandriva-linux-gnu/9.2.1/crtn.o
clang-10: error: unable to execute command: Segmentation fault (core dumped)
clang-10: error: linker command failed due to signal (use -v to see invocation)

@lenary
Copy link
Member

lenary commented Jul 29, 2020

This is a known issue. LTO is not yet supported on RISC-V fully automatically.

The short-term fix is to pass -plugin-opt=-target-abi=lp64d to your linker, so it can tell LLVM which ABI to use. We hope to do the equivalent automatically soon.

@nickdesaulniers
Copy link
Member

We're getting quite a few reports from Linux kernel CI services that are trying to link RISC-V Linux kernels with ld.lld about this unsupported relocation type.

@lenary
Copy link
Member

lenary commented Nov 30, 2020

There are two parts to this issue.

  1. R_RISCV_ALIGN error - LLD does not support RISC-V linker relaxations. There are patches in progress, but it's a major feature to design. Compile with -mno-relax if you want to link with LLD.

  2. Invalid ABI when linking with LTO - this is not an LLD issue, this is a LLVM issue in the target configuration code. I handed this work off to someone else, but it requires invasive changes to how we configure the backend when we get a new module (As it has been requested to pass the ABI using module metadata). The workaround addresses this feature.

@nickdesaulniers
Copy link
Member

See also: riscv-non-isa/riscv-elf-psabi-doc#183.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
@MaskRay MaskRay self-assigned this Aug 1, 2022
@MaskRay
Copy link
Member

MaskRay commented Aug 1, 2022

Closed by 6611d58 (milestone: 15.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party lld:ELF
Projects
None yet
Development

No branches or pull requests

5 participants