[ELF][PPC32] Support --emit-relocs link of R_PPC_PLTREL24
authorFangrui Song <i@maskray.me>
Tue, 28 Jan 2020 08:01:20 +0000 (00:01 -0800)
committerFangrui Song <i@maskray.me>
Tue, 28 Jan 2020 19:04:04 +0000 (11:04 -0800)
commite11b709b1922ca46b443fcfa5d76b87edca48721
tree04ee9ecd6c4a66a8753591bf6de888e81525a3e2
parenta1f6ff26814b86fdd7dfc9083bbefe5cf1790ab8
[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
lld/ELF/InputSection.cpp
lld/test/ELF/ppc32-relocatable-got2.s [new file with mode: 0644]