This is an archive of the discontinued LLVM Phabricator instance.

[JITLink][RISCV] Fix logic for R_RISCV_ALIGN
AbandonedPublic

Authored by Hahnfeld on Apr 30 2023, 7:55 AM.

Details

Reviewers
lhames
StephenFan
Summary

The relocation's addend encodes the number of bytes with NOP
instructions, which is less than the required alignment. For
example, with compressed instructions, an alignment to 4 bytes
requires only one compressed NOP instruction of two bytes that
the linker can either leave in or remove. This actually means
that R_RISCV_ALIGN can never be ignored.

Diff Detail

Event Timeline

Hahnfeld created this revision.Apr 30 2023, 7:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 30 2023, 7:55 AM
Hahnfeld requested review of this revision.Apr 30 2023, 7:55 AM

The required alignment is defined as NextPowerOf2(Addend) (as you changed it to) and I believe it should be ok to ignore the relocation if this value is <=2 (not sure if this will actually happen in practice).

However, please not that I just submitted a patch to implement linker relaxation which also handles alignment properly: D149526

The required alignment is defined as NextPowerOf2(Addend) (as you changed it to) and I believe it should be ok to ignore the relocation if this value is <=2 (not sure if this will actually happen in practice).

I don't think this can ever happen because the smallest compressed instruction is two bytes.

However, please not that I just submitted a patch to implement linker relaxation which also handles alignment properly: D149526

Thanks for letting me know, I wasn't aware. I left some comments ;-)

Hahnfeld abandoned this revision.May 16 2023, 1:18 AM