diff options
| author | Fangrui Song <i@maskray.me> | 2020-01-28 00:01:20 -0800 |
|---|---|---|
| committer | Fangrui Song <i@maskray.me> | 2020-01-28 11:04:33 -0800 |
| commit | 684c216d73cdcd64fc0186b533870cb79dc03810 (patch) | |
| tree | b2daee58a29203253729a3ebf45979dd5811703d /lld/ELF/InputSection.cpp | |
| parent | 54b022d344412fc9f1dfe37ee05de934a01e1ea4 (diff) | |
| download | bcm5719-llvm-684c216d73cdcd64fc0186b533870cb79dc03810.tar.gz bcm5719-llvm-684c216d73cdcd64fc0186b533870cb79dc03810.zip | |
[ELF][PPC32] Support --emit-relocs link of R_PPC_PLTREL24
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 to a relocatable link or a non-relocatable link with --emit-relocs.
Reviewed By: Bdragon28
Differential Revision: https://reviews.llvm.org/D73532
(cherry picked from commit e11b709b1922ca46b443fcfa5d76b87edca48721)
Diffstat (limited to 'lld/ELF/InputSection.cpp')
| -rw-r--r-- | lld/ELF/InputSection.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index aab272f53a7..147c51ab285 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -485,6 +485,14 @@ void InputSection::copyRelocations(uint8_t *buf, ArrayRef<RelTy> rels) { p->r_addend = sym.getVA(addend) - section->getOutputSection()->addr; else if (config->relocatable && type != target->noneRel) sec->relocations.push_back({R_ABS, type, rel.r_offset, addend, &sym}); + } else if (config->emachine == EM_PPC && type == R_PPC_PLTREL24 && + p->r_addend >= 0x8000) { + // Similar to R_MIPS_GPREL{16,32}. If the addend of R_PPC_PLTREL24 + // indicates that r30 is relative to the input section .got2 + // (r_addend>=0x8000), after linking, r30 should be relative to the output + // section .got2 . To compensate for the shift, adjust r_addend by + // ppc32Got2OutSecOff. + p->r_addend += sec->file->ppc32Got2OutSecOff; } } } |

