[llvm] RISCV: Replace most Specifier constants with relocation types (PR #138644)

Jessica Clarke via llvm-commits llvm-commits at lists.llvm.org
Fri May 16 11:58:43 PDT 2025


jrtc27 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. 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)...

https://github.com/llvm/llvm-project/pull/138644


More information about the llvm-commits mailing list