This is an archive of the discontinued LLVM Phabricator instance.

[lld][ELF] Support for R_ARM_THM_JUMP8
ClosedPublic

Authored by phosek on Nov 9 2021, 12:38 PM.

Details

Summary

This change implements support for R_ARM_THM_JUMP8 relocation in
addition to R_ARM_THM_JUMP11 which is already supported by LLD.

Diff Detail

Event Timeline

phosek created this revision.Nov 9 2021, 12:38 PM
phosek requested review of this revision.Nov 9 2021, 12:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2021, 12:38 PM
MaskRay added a comment.EditedNov 9 2021, 12:50 PM

There should be a regular test in arm-thumb-narrow-branch-check.s.

LGTM, but I am unfamiliar with ARM so it'd be good checked by Peter as well.

Code looks good to me.

Will probably need to use the .reloc directive in a regular test. Most assemblers don't emit the relocation for the Thumb conditional branch as it is so small in range that going out of the section usually means it will be out of range of its target. I think something like:

.text
.thumb
.global undefined
.inst.n 0xd0fe
.reloc 0, R_ARM_THM_JUMP8, undefined

Should work, this produces:

00000000 <$t.0>:
       0: fe d0         beq     0x0 <$t.0>              @ imm = #-4
                        00000000:  R_ARM_THM_JUMP8      undefined
lld/test/ELF/arm-thumb-undefined-weak-narrow.test
27

The R_ARM_THM_JUMP8 is for the thumb conditional branch. I think that for a jump to a symbol this should be with little-endian fed0 for beq undefined_weak

0xd0x00xfe
1101condimm8

Where the imm8 is -4 (Thumb PC-bias).

gulfem added a subscriber: gulfem.Nov 10 2021, 11:51 AM
phosek updated this revision to Diff 386449.Nov 11 2021, 1:41 AM
phosek marked an inline comment as done.

I've added regular test in arm-thumb-narrow-branch-check.s, let me know if this makes sense.

peter.smith accepted this revision.Nov 11 2021, 3:15 AM

Thanks for the updates LGTM. In theory we can now rewrite arm-thumb-narrow-branch-check.s using .reloc but that could be done in a future patch.

lld/test/ELF/Inputs/arm-thumb-narrow-branch.s
4

R_ARM_THM_JUMP8 has an even smaller range of +- 256 bytes, but I don't think it is worth changing the comment as the point still stands.

This revision is now accepted and ready to land.Nov 11 2021, 3:15 AM
MaskRay accepted this revision.Nov 11 2021, 10:41 AM
phosek closed this revision.Nov 11 2021, 11:39 AM