This is an archive of the discontinued LLVM Phabricator instance.

[LLD][PPC] Implement R_PPC_REL24 and R_PPC_REL32 relocations
ClosedPublic

Authored by jackoalan on Oct 29 2016, 4:41 PM.

Details

Reviewers
ruiu
rafael
Summary

This enables LLD to relocate PC-relative R_PPC_REL32 and R_PPC_REL24 types (as used in bl instructions).

Diff Detail

Event Timeline

jackoalan updated this revision to Diff 76322.Oct 29 2016, 4:41 PM
jackoalan retitled this revision from to [LLD][PPC] Implement R_PPC_REL24 and R_PPC_REL32 relocations.
jackoalan updated this object.
jackoalan added reviewers: rafael, ruiu.
jackoalan added a subscriber: lld.
ruiu edited edge metadata.Oct 29 2016, 5:04 PM

Can you add a test?

jackoalan added a comment.EditedOct 29 2016, 6:47 PM

Ok, I've appended a simple test for REL24 in ppc-relocs.s:

.align 2
.section .R_PPC_REL24,"ax",@progbits
.globl .FR_PPC_REL24
.FR_PPC_REL24:
  b .Lfoox
.section .R_PPC_REL24_2,"ax",@progbits
.Lfoox:

# CHECK: Disassembly of section .R_PPC_REL24:
# CHECK: .FR_PPC_REL24:
# CHECK:    11014:       48 00 00 04     b .+4

That passes as expected, but I'm not sure how to emit a REL32 using assembler directives. I implemented REL32 because the .eh_frame section needs it when linking C++ (presumably to reference the functions being unwound).

If anyone knows how to do it with assembler directives or symbol variants, I'll write that test as well.

ruiu added a comment.Oct 29 2016, 7:37 PM

I'm not a PowerPC expert, but maybe something like this?

.global foo
.section .R_PPC_REL32,"a"
  .quad foobar
ruiu added a comment.Oct 29 2016, 7:38 PM

Sorry, I mean

.global foo
.section .R_PPC_REL32,"a"
  .quad foo

That ends up emitting R_PPC_ADDR32 (absolute relocation, which also needs to be implemented).

I managed to get it emitting using CFI directives (i.e. .cfi_startproc and .cfi_endproc), but I'm not entirely certain now that particular relocation usage should function.

jackoalan updated this revision to Diff 76327.Oct 30 2016, 12:50 AM
jackoalan edited edge metadata.

This adds a test for REL24.

REL32 conformance uncertain right now. Need assembler directive, or how to validate .cfi* directives that emit REL32.

ruiu accepted this revision.Oct 31 2016, 10:20 AM
ruiu edited edge metadata.

LGTM for now. Please add a test for REL32 in a future patch.

This revision is now accepted and ready to land.Oct 31 2016, 10:20 AM
jackoalan updated this revision to Diff 76519.Oct 31 2016, 9:29 PM
jackoalan edited edge metadata.

Since ADDR32 was a trivial relocation for the last diff, this test is added to validate

jackoalan retitled this revision from [LLD][PPC] Implement R_PPC_REL24 and R_PPC_REL32 relocations to [LLD][PPC] Implement R_PPC_REL24, R_PPC_REL32, R_PPC_ADDR32 relocations.Oct 31 2016, 9:39 PM
jackoalan updated this object.
ruiu added a comment.Oct 31 2016, 10:44 PM

Please submit the previous patch and send the new change as a new patch.

Just to clarify, update diff to include *just* REL24/REL32, then submit ADDR32 standalone?

ruiu added a comment.Oct 31 2016, 10:56 PM

I mean I requested you submit the patch when I LGTMed, and then send me another patch to add ADDR32 support. (You usually want to submit a patch as soon as LGTMed and then make new features as new patches, instead of adding new code to an unsubmitted change. )

jackoalan updated this revision to Diff 76522.Oct 31 2016, 10:58 PM
jackoalan retitled this revision from [LLD][PPC] Implement R_PPC_REL24, R_PPC_REL32, R_PPC_ADDR32 relocations to [LLD][PPC] Implement R_PPC_REL24 and R_PPC_REL32 relocations.
jackoalan updated this object.

Restore LGTM'd patch

jackoalan updated this revision to Diff 76524.Oct 31 2016, 11:16 PM

Ensure patch contents reflects title (no ADDR32)

ruiu added a comment.Nov 1 2016, 10:10 AM

Do you have a commit access? If so, please commit.

All I've set up is the Phabricator access, no commit privileges to my knowledge

ruiu added a comment.Nov 1 2016, 11:32 AM

Ah, I was thinking that you had a commit access but for some reason didn't submit all these changes. I'll do that for you.

ruiu closed this revision.Nov 1 2016, 11:41 AM

Committed as r285719.