[lld] [ELF] Support relocatable files using CREL (PR #98115)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 31 22:46:40 PDT 2024
MaskRay wrote:
> I've taken a look at the tests. I'm now down to a few last questions, triggered by the no mixing of SHT_REL and CREL in emit-relocs and -r links. I can probably figure this out by running, but I'm hoping I can speed up the process by asking.
>
> I was trying to work out why it would be complex. As I understand it:
>
> * CREL in relocatable objects uses explicit addends even when it is usual to use SHT_REL. (From Addend bit: in https://maskray.me/blog/2024-03-09-a-compact-relocation-format-for-elf)
Yes, the assembler implementation is currently kept simple and assumes the explicit addend form.
Therefore, lld doesn't have to deal with implicit addend input.
> * To convert from SHT_REL to CREL would require extracting the implicit addends from the REL relocations
Yes. We would need `target.getImplicitAddend`.
> * In theory this addend should be encodeable in CREL.
Since multiple relocation sections aren't supported, when combining input sections, their relocation sections, if mixing CREL/RELA, have to be combined as well.
CREL is the desired output format for size.
> * When applying the relocation we'll need to be careful that the implict addend is overwritten, I think this should always be the case for SHT_REL.
Yes.
> Is there anything I've missed?
No:)
> Following up. If CREL in relocatable object files is supposed to use explicit addends, how do we deal with an input that uses implicit addends, or at least a non 0 implicit addend? At a glance it looks like we might assume that there is always an explicit addend, but I don't know the code well enough to easily work that out. I'll try again tomorrow.
There is currently no error checking.
A diagnostic could be added by changing `ret.crels = Relocs<typename ELFT::Crel>` in `InputSectionBase::relsOrRelas` to add an extra argument to indicate the section name.
There will be some minor overhead.
https://github.com/llvm/llvm-project/pull/98115
More information about the llvm-commits
mailing list