This is an archive of the discontinued LLVM Phabricator instance.

[ELF][PPC32] Support --emit-relocs link of R_PPC_PLTREL24
ClosedPublic

Authored by MaskRay on Jan 28 2020, 1:09 AM.

Details

Summary

Similar to R_MIPS_GPREL16 and R_MIPS_GPREL32 (D45972).

If the addend of an R_PPC_PLTREL24 is >= 0x8000, it indicates that r30
is relative to the input section .got2.

addis 30, 30, .got2+0x8000-.L1$pb@ha
addi 30, 30, .got2+0x8000-.L1$pb@l
...
bl foo+0x8000@PLT

After linking, the relocation will be relative to the output section .got2.
To compensate for the shift address(input section .got2) - address(output section .got2) = ppc32Got2OutSecOff, adjust by ppc32Got2OutSecOff:

addis 30, 30, .got2+0x8000-.L1+ppc32Got2OutSecOff$pb@ha
addi 30, 30, .got2+0x8000-.L1+ppc32Got2OutSecOff$pb@ha$pb@l
...
bl foo+0x8000+ppc32Got2OutSecOff@PLT

This rule applys in a relocatable link or in a non-relocatable link with --emit-relocs.

Diff Detail

Event Timeline

MaskRay created this revision.Jan 28 2020, 1:09 AM

Unit tests: pass. 62253 tests passed, 0 failed and 816 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

I am now able to load pf.ko on FreeBSD powerpc32 without it crashing.

Examining the .ko, it now appears to properly have separate plt stubs for the different .got2 offsets.

Excellent!

I will do a buildworld test and ensure this doesn't break FreeBSD powerpc32 userland, but it's looking great so far.

MaskRay updated this revision to Diff 240921.Jan 28 2020, 9:54 AM
MaskRay edited the summary of this revision. (Show Details)
MaskRay removed subscribers: wuzish, merge_guards_bot.

Improve tests

MaskRay retitled this revision from [ELF][PPC32] Support relocatable link of R_PPC_PLTREL24 to [ELF][PPC32] Support --emit-relocs link of R_PPC_PLTREL24.Jan 28 2020, 10:48 AM
MaskRay edited the summary of this revision. (Show Details)
Bdragon28 accepted this revision.Jan 28 2020, 10:50 AM

Looks correct to me, works great, and fixes the last lld-related problem I am aware of currently on FreeBSD powerpc32.

This revision is now accepted and ready to land.Jan 28 2020, 10:50 AM

Unit tests: fail. 62268 tests passed, 3 failed and 827 were skipped.

failed: Clang.CodeGenOpenCL/amdgpu-features.cl
failed: Clang.CodeGenOpenCL/builtins-amdgcn-mfma.cl
failed: Clang.SemaOpenCL/builtins-amdgcn-error-gfx908-param.cl

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

This revision was automatically updated to reflect the committed changes.