This is an archive of the discontinued LLVM Phabricator instance.

[lld][AMDGPU] Handle R_AMDGPU_REL16 relocation.
ClosedPublic

Authored by abidh on Jul 10 2021, 9:55 AM.

Details

Summary

This patch is a followup patch to https://reviews.llvm.org/D105760 which adds this relocation. This handles the relocation in lld.

The s_branch family of instruction does the following:
PC = PC + signext(simm * 4) + 4

so we we do the opposite on the target address before writing it in the instruction stream.

Diff Detail

Event Timeline

abidh created this revision.Jul 10 2021, 9:55 AM
abidh requested review of this revision.Jul 10 2021, 9:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2021, 9:55 AM
MaskRay added inline comments.Jul 11 2021, 11:13 AM
lld/ELF/Arch/AMDGPU.cpp
144

define the local variable as ((sval - 4) / 4) instead (with a variable rename)

lld/test/ELF/amdgpu-relocs2.s
4

See split-file in newer tests and avoid echo for long files.

26

unused .text.unlikely?

abidh updated this revision to Diff 358322.Jul 13 2021, 10:10 AM

Handle review comments.

abidh marked 2 inline comments as done.Jul 13 2021, 10:16 AM
abidh added inline comments.
lld/test/ELF/amdgpu-relocs2.s
26

This section is used. There is a jump to cold2. The test checks that jumps both forward and backward with this relocation generates correct immediate.

MaskRay added inline comments.Jul 13 2021, 11:06 AM
lld/ELF/Arch/AMDGPU.cpp
163

reorder R_AMDGPU_REL16 before REL32

lld/test/ELF/amdgpu-relocs2.s
20

.section .text.likely,"ax"

29

ditto

MaskRay accepted this revision.Jul 13 2021, 11:06 AM
This revision is now accepted and ready to land.Jul 13 2021, 11:06 AM
This revision was automatically updated to reflect the committed changes.
t-tye added inline comments.Jul 13 2021, 5:03 PM
lld/ELF/Arch/AMDGPU.cpp
142

Is there documentation for this relocation in AMDGPUUsage.rst?