[llvm] RISCV: Replace most Specifier constants with relocation types (PR #138644)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat May 17 09:31:46 PDT 2025
MaskRay wrote:
> > > Mixing VK_ and R_ breaks if any relocation is >= FirstTargetFixupKind (4000 + a few), which is legitimate. This should be following the same model as for fixup_* and separating out the R_ and VK_ cases based on whether it's < FirstTargetFixupKind.
> >
> >
> > `R_*` and `Specifier::VK_*` are already separate. The first `Specifier` constant VK_LO starts at 4000. In `RISCVMCCodeEmitter::getImmOpValue`, there is an assert to catch new `Specifier` constants that are not in the switch.
> > ```
> > + default:
> > + assert(FixupKind && FixupKind < FirstTargetFixupKind &&
> > + "invalid specifier");
> > + break;
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > In the rare scenario that RISC-V needs a static relocation code >= 4000, we shall assign it a `VK_` constant and require the `VK_` to `R_` mapping.
> > What else do you have in mind?
>
> I've re-read the code and at least the version that's there today (maybe also what I skimmed last time) mirrors fixup_* in that regard. So I no longer hold that concern.
Thanks!
> I think the one concern I have that remains is that we no longer have an abstraction over the file format, but I guess the relocations often look different enough that there's not so much code you can share and just end up with VK_FOO containing separate items for each format (at least looking at AArch64)...
I agree that we have lost a file format abstraction, which I believe is OK. From my experience improving internal representation of X86/ARM/AArch64 COFF/Mach-O/ELF, there are not much to share anyway (AArch64AsmParser.cpp has different code paths for ELF/Mach-O)... COFF/Mach-O don't have ELF's RELA r_addend, so it is challenging for them to support RISC-V...
https://github.com/llvm/llvm-project/pull/138644
More information about the llvm-commits
mailing list