-
Notifications
You must be signed in to change notification settings - Fork 13.5k
llvm-mc uses wrong ABI for RISC-V platform on Linux by default #123077
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
so |
As far as I know, llvm-mc also doesn't default to having F and D extensions enabled. You need to add |
llvm-mc will throw a warning without
I would need a more sophisticated test file than 99 bottles to see what the actual ABI looks like in the .o file, beyond the claims made in the ELF flag. And the point remains that the defaults don't match between tools. |
I'm not sure llvm-mc should have OS triple dependent behavior. It's a low level tool. CC @MaskRay |
I agree with this and would not want any of that logic in these developer tools. That said I know many years ago I initially got confused about |
This option is very important for RISC-V as it controls calling convention and a field in the ELF header. It is used in a large number of RISC-V lit tests. Expose the option to -help. Fixes one issue raised in #123077
I assume some relevant code owner would need to sign off on that concept before I sit down & try to implement it |
(Travelling with limited Internet access) llvm-mc, was originally designed for internal testing of the Machine Code (MC) layer, particularly the assembler and disassembler components. Despite its internal origins, llvm-mc is often distributed as part of the LLVM toolset, making it accessible to users. That said, users should really not treat llvm-mc as user-facing utility (which normally use OptTable instead llvm::cl). Some folks want to add a gas compatible tool in LLVM, but so far I don't think there is sufficient justification for the complexity. https://briancallahan.net/blog/20240122.html is a nice write-up. Agreed that we try to keep target-specific behaviors minimal for llvm-mc. I don't think coding RISC-V specific target-specific behaviors is within the scope of llvm-mc, which would make testing more brittle. Testing is still the primary use case of llvm-mc. |
I'm closing, on the basis of 3acb0e9 It seems |
Sorry for the inconvenience of replying to a closed issue. (I built the AMD ROCm 5.4.0 for RISC-V for testing and had a temporarily suspended project ROCm-port to make ROCm runnable on any reasonable architecture) For example, in the ROCm OpenCL Runtime here, it just uses "llvm-mc" directly. Previously, even after fixing these two parts, HIP will still use llvm-mc in the background in clang/lib/Driver/ToolChains/HIPUtility.cpp:HIP::constructGenerateObjFileFromHIPFatBinary but luckily it has been corrected recently in #112041.
So, (just from my/our perspective), it causes extra architecture-specified complexity for us to fix this problem. And since lp64d is already the default ABI for RV64, and during our current effort we didn't find anywhere other than llvm-mc has the same issue(most should have been fixed in the lp64 to lp64d transition or never happened), I think it should be corrected. |
@llvm/issue-subscribers-clang-driver Author: Jo Shields (directhex)
This is a related issue to https://github.com//issues/115679 and possibly https://github.com//issues/50591. Generally, the default ABI handling is done differently in every tool, where https://reviews.llvm.org/D69383 defined the current behaviour for clang.
Roughly speaking, it is reasonable for a user to expect these two compiler invocations to act in an equivalent way:
However, they don't. Without use of the (undocumented) Per the changes in D69383 to clang/lib/Driver/ToolChains/Arch/RISCV.cpp, the logic used by clang to this day is:
i.e. use As time allows, I intend to try and get a PR filed to unify |
This is a related issue to #115679 and possibly #50591. Generally, the default ABI handling is done differently in every tool, where https://reviews.llvm.org/D69383 defined the current behaviour for clang.
Roughly speaking, it is reasonable for a user to expect these two compiler invocations to act in an equivalent way:
However, they don't. Without use of the (undocumented)
-target-abi=lp64d
flag,llvm-mc
targets a different ABI and the resulting object files cannot be linked with objects produced byclang
/clang++
Per the changes in D69383 to clang/lib/Driver/ToolChains/Arch/RISCV.cpp, the logic used by clang to this day is:
i.e. use
lp64
unless a named OS is used, in which case uselp64d
. Explicitly forcing an OS into the triple (i.e. passing-triple riscv64-unknown-linux-gnu
tollvm-mc
) does not result in theclang
behaviour of defaulting tolp64d
when callingllvm-mc
.As time allows, I intend to try and get a PR filed to unify
llvm-mc
's behaviour - I wanted to document the issue first.The text was updated successfully, but these errors were encountered: