-
Notifications
You must be signed in to change notification settings - Fork 13.5k
LTO plugin uses wrong ABI for LTO objects on riscv #50591
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
Comments
Encountered in the same issue. Minimal recurrence in Arch Linux RISC-V nspawn container:
It seems that clang can't compile even the simplest C program with an empty It does work with LTO disabled:
|
@llvm/issue-subscribers-backend-risc-v |
@zakk0610 did you mind take a look for this? |
This is a long-standing issue, the patches got abandoned before they were finished... |
You can try to give I'm not sure why LTO had enabled for RISC-V in LLVM 12.0. |
Note that the work around should be Ref: https://lists.llvm.org/pipermail/llvm-dev/2020-January/137951.html |
It was caused by that when use codegen module to generate object code, the Related patch: https://reviews.llvm.org/D121183 |
…ibute In the past, when construct RISCVAsmBackend, MCTargetOptions.ABIName would be passed and stored in RISCVAsmBackend. But MCTargetOptions.ABIName can only be specified by -target-abi xxx in command line, if the .ll file has target-abi attribute, the codegen module will ignore it. And the generated object file would have incorrect EFlags value. #50591 also caused by this problem. This patch override the AsmPrinter::emitFunctionEntryLabel function and use it to set the target abi value that get from .ll file's target-abi attribute. And storing the target-abi in RISCVTargetStreamer instead of RISCVAsmBackend. Differential Revision: https://reviews.llvm.org/D121183
build report error for following BP config ``` sanitize: { cfi: true, } ``` build report error for upon BP config > Hard-float 'd' ABI can't be used for a target that doesn't support > the D instruction set extension (ignoring target-abi) > ld.lld: error: lto.tmp: cannot link object files with different > floating-point ABI > clang-12: error: linker command failed with exit code 1 (use -v to see invocation) refer to llvm/llvm-project#50591, it is an existing llvm issue. Before we upgrade the clang version, we provide this workaround to pass build.
…ibute In the past, when construct RISCVAsmBackend, MCTargetOptions.ABIName would be passed and stored in RISCVAsmBackend. But MCTargetOptions.ABIName can only be specified by -target-abi xxx in command line, if the .ll file has target-abi attribute, the codegen module will ignore it. And the generated object file would have incorrect EFlags value. llvm/llvm-project#50591 also caused by this problem. This patch override the AsmPrinter::emitFunctionEntryLabel function and use it to set the target abi value that get from .ll file's target-abi attribute. And storing the target-abi in RISCVTargetStreamer instead of RISCVAsmBackend. Differential Revision: https://reviews.llvm.org/D121183
…ibute In the past, when construct RISCVAsmBackend, MCTargetOptions.ABIName would be passed and stored in RISCVAsmBackend. But MCTargetOptions.ABIName can only be specified by -target-abi xxx in command line, if the .ll file has target-abi attribute, the codegen module will ignore it. And the generated object file would have incorrect EFlags value. llvm/llvm-project#50591 also caused by this problem. This patch override the AsmPrinter::emitFunctionEntryLabel function and use it to set the target abi value that get from .ll file's target-abi attribute. And storing the target-abi in RISCVTargetStreamer instead of RISCVAsmBackend. Differential Revision: https://reviews.llvm.org/D121183
I've been investigating some related issues on RISC-V for a while (65090), and would like to get this solved. Looking at the issue tracker, there seems to be a number of related issues:
I also see a few related posts on discourse https://discourse.llvm.org/t/myterious-soft-float-output-in-lto-cache/70753 and especially https://discourse.llvm.org/t/encode-target-abi-into-llvm-bitcode-for-lto/54116 There are also some earlier attempts to fix the problem, like https://reviews.llvm.org/D132843 and https://reviews.llvm.org/D71387, though it isn't clear to me what the status of those are given that the authors have moved on from RISC-V related work. Within the issues and discussions, I found several comments from maintainers that note that this is a known problem and provide a work around. However, a work around is normally a temporary solution, so I'd like to understand what the problem is in more detail, so we can decide on how to solve it. Or in the case that we do know, what steps are left to have a working solution before the next major release. |
WIP: #100833 |
Extended Description
It looks like the LTO plugin fails to properly set the target-abi for the LTO object.
$ clang -flto hello.c -v
clang version 12.0.1
Target: riscv64-suse-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib64/gcc/riscv64-suse-linux/10
Found candidate GCC installation: /usr/bin/../lib64/gcc/riscv64-suse-linux/11
Found candidate GCC installation: /usr/bin/../lib64/gcc/riscv64-suse-linux/9
Found candidate GCC installation: /usr/lib64/gcc/riscv64-suse-linux/10
Found candidate GCC installation: /usr/lib64/gcc/riscv64-suse-linux/11
Found candidate GCC installation: /usr/lib64/gcc/riscv64-suse-linux/9
Selected GCC installation: /usr/bin/../lib64/gcc/riscv64-suse-linux/11
"/usr/bin/clang-12.0.1" -cc1 -triple riscv64-suse-linux-gnu -emit-llvm-bc -flto -flto-unit -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -target-feature +m -target-feature +a -target-feature +f -target-feature +d -target-feature +c -target-feature +relax -target-feature -save-restore -target-abi lp64d -msmall-data-limit 8 -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/12.0.1 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /suse/schwab/src/test -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o /tmp/hello-229842.o -x c hello.c
clang -cc1 version 12.0.1 based upon LLVM 12.0.1 default target riscv64-suse-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib64/clang/12.0.1/include
/usr/include
End of search list.
"/usr/bin/ld" -z relro --hash-style=gnu --hash-style=both --build-id --enable-new-dtags --eh-frame-hdr -m elf64lriscv -dynamic-linker /lib/ld-linux-riscv64-lp64d.so.1 -o a.out /usr/bin/../lib64/gcc/riscv64-suse-linux/11/../../../../lib64/crt1.o /usr/bin/../lib64/gcc/riscv64-suse-linux/11/crti.o /usr/bin/../lib64/gcc/riscv64-suse-linux/11/crtbegin.o -L/usr/bin/../lib64/gcc/riscv64-suse-linux/11 -L/usr/bin/../lib64/gcc/riscv64-suse-linux/11/../../../../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-suse-linux/11/../../../../riscv64-suse-linux/lib -L/usr/bin/../lib64/gcc/riscv64-suse-linux/11/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib -plugin /usr/bin/../lib64/LLVMgold.so /tmp/hello-229842.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib64/gcc/riscv64-suse-linux/11/crtend.o /usr/bin/../lib64/gcc/riscv64-suse-linux/11/crtn.o
/usr/bin/ld: /tmp/lto-llvm-5c94e7.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-5c94e7.o
clang-12.0: error: linker command failed with exit code 1 (use -v to see invocation)
The text was updated successfully, but these errors were encountered: