This is an archive of the discontinued LLVM Phabricator instance.

[JITLink][ELF/AARCH64] Implement R_AARCH64_LDST*_ABS_LO12_NC relocation types
ClosedPublic

Authored by sunho on May 30 2022, 12:02 AM.

Details

Reviewers
lhames
sgraenitz
Summary

Implement R_AARCH64_LDST*_ABS_LO12_NC relocaiton entries by reusing PageOffset21 generic relocation edge. The difference between macho backend is that in ELF, the shift value is explicitly given by relocation type. lld generates the relocation type that matches with instruction bitwidth, so getting the shift value implicitly from instruction bytes should be fine in typical use cases.

Another way to achieve this is create explicit edges like PageOffset21Shift0, PageOffset21Shift1, PageOffset21Shift2, ... and macho backend explicitly lower to that reading instructions bytes, if that's more preferred way, I'll change to that.

Diff Detail

Event Timeline

sunho created this revision.May 30 2022, 12:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2022, 12:02 AM
sunho requested review of this revision.May 30 2022, 12:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2022, 12:02 AM
sunho edited the summary of this revision. (Show Details)May 30 2022, 1:20 AM
sunho added reviewers: lhames, sgraenitz.
sunho updated this revision to Diff 432885.May 30 2022, 4:26 AM
sunho updated this revision to Diff 432886.
sunho updated this revision to Diff 432905.May 30 2022, 6:10 AM
sunho updated this revision to Diff 433034.May 31 2022, 12:50 AM

Merge testcase

The difference between macho backend is that in ELF, the shift value is explicitly given by relocation type. lld generates the relocation type that matches with instruction bitwidth, so getting the shift value implicitly from instruction bytes should be fine in typical use cases.

Good explanation, thanks. Yes, I'd agree that's the best solution.

Merge testcase

Thanks!

llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp
145

Alignment can not be smaller then one byte right? Can we skip the check in this case?

156

Can we factor this out into a helper function like checkAlignment(Instr, N)? I guess it's sufficient for the error message to say something like "not aligned to N byte boundary".

sunho added inline comments.Jun 1 2022, 5:52 AM
llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp
145

I realized the I wrote a very confusing error message here. The more clear message would be "R_AARCH64_LDST8_ABS_LO12_NC target is not a LDRB/STRB (imm12) instruction." I'll change to that.

We still need to check here because technically R_AARCH64_LDST8_ABS_LO12_NC relocation needs the address to be not shifted at all, but if instruction is like LDRH, we're going to shift it left by 1 since getPageOffset12Shift(Instr) returns 1.

I belive such a relocation should not be generated if codegen is doing sane thing, but we still need to check just in case.

sunho updated this revision to Diff 433767.Jun 2 2022, 8:53 AM

Change error messages

sunho marked an inline comment as done.Jun 2 2022, 10:01 AM
sunho updated this revision to Diff 433921.Jun 2 2022, 5:13 PM

Fix MSVC build error

sgraenitz accepted this revision.Jun 5 2022, 12:08 PM

LGTM, thanks for working on this!

This revision is now accepted and ready to land.Jun 5 2022, 12:08 PM
lhames accepted this revision.Jun 7 2022, 5:25 PM

Very nice. LGTM!