[PowerPC] Fix issue where binary uses a .got but is missing a .TOC.
authorStefan Pintilie <stefanp@ca.ibm.com>
Mon, 5 Apr 2021 13:07:16 +0000 (08:07 -0500)
committerStefan Pintilie <stefanp@ca.ibm.com>
Mon, 5 Apr 2021 14:13:20 +0000 (09:13 -0500)
commit660c4e57b4a7ac71f9595f31bfdec114369f4ca0
tree7775a7bdb60088be4dfc390440c6e020eee989a2
parent2aebb7cb3c88b1446515563653c821e8165b3aaf
[PowerPC] Fix issue where binary uses a .got but is missing a .TOC.

From the PowerPC ELFv2 ABI section 4.2.3. Global Offset Table.
```
The GOT consists of an 8-byte header that contains the TOC base (the first TOC
base when multiple TOCs are present), followed by an array of 8-byte addresses.
```

Due to the introduction of PC Relative code it is now possible to require a GOT
without having a .TOC. symbol in the object that is being linked. Since LLD uses
the .TOC. symbol to determine whether or not a GOT is required the GOT header is
not setup correctly and the 8-byte header is missing.

This patch allows the Power PC GOT setup to happen when an element is added to
the GOT instead of at the very begining. When this header is added a .TOC.
symbol is also added.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D91426
lld/ELF/SyntheticSections.cpp
lld/test/ELF/ppc64-check-missing-tocbase.s [new file with mode: 0644]
lld/test/ELF/ppc64-ld-got-dtprel.s
lld/test/ELF/ppc64-reloc-got-pcrel34.s
lld/test/ELF/ppc64-tls-gd.s
lld/test/ELF/ppc64-tls-ie.s
lld/test/ELF/ppc64-tls-missing-gdld.s
lld/test/ELF/ppc64-tls-pcrel-gd.s
lld/test/ELF/ppc64-tls-pcrel-ie.s