[LLD] Emit DT_PPC64_OPT into the dynamic section
authorStefan Pintilie <stefanp@ca.ibm.com>
Fri, 2 Jun 2023 18:46:25 +0000 (14:46 -0400)
committerStefan Pintilie <stefanp@ca.ibm.com>
Mon, 5 Jun 2023 16:18:29 +0000 (12:18 -0400)
commit658f23fc462e2fbdddaa056e5cda998653b55b21
tree03d8e04c5d17215c4bfc6dd27be5f46d96090060
parent3f9f1463719d7491768e9a224ac089c8f9baab68
[LLD] Emit DT_PPC64_OPT into the dynamic section

As per section 4.2.2 of the PowerPC ELFv2 ABI, this value tells the dynamic linker which optimizations it is allowed to do.
Specifically, the higher order bit of the two tells the dynamic linker that there may be multiple TOC pointers in the binary.

When we resolve any NOTOC relocations during linking, we need to set this value because we may be calling
TOC functions from NOTOC functions when the NOTOC function already clobbered the TOC pointer.

In practice, this ensures that the PLT resolver always resolves the call to the GEP (global entry point) of
the TOC function (which will set up the TOC for the TOC function).

Original patch by nemanjai

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D150631
24 files changed:
lld/ELF/SyntheticSections.cpp
lld/ELF/Target.h
lld/ELF/Thunks.cpp
lld/test/ELF/basic-ppc64.s
lld/test/ELF/ppc-reloc-copy.s
lld/test/ELF/ppc64-abs64-dyn.s
lld/test/ELF/ppc64-bsymbolic-toc-restore.s
lld/test/ELF/ppc64-check-missing-tocbase.s
lld/test/ELF/ppc64-dtprel.s
lld/test/ELF/ppc64-local-dynamic.s
lld/test/ELF/ppc64-long-branch-pi.s
lld/test/ELF/ppc64-pcrel-call-to-extern.s
lld/test/ELF/ppc64-pcrel-long-branch.s
lld/test/ELF/ppc64-plt-stub-compatible.s
lld/test/ELF/ppc64-plt-stub.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-pcrel-gd.s
lld/test/ELF/ppc64-tls-pcrel-ie.s
lld/test/ELF/ppc64-tls-pcrel-ld.s
lld/test/ELF/ppc64-toc-relax-constants.s
lld/test/ELF/ppc64-toc-relax.s
llvm/include/llvm/BinaryFormat/DynamicTags.def