This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Fix large code model with the ELFv2 ABI
ClosedPublic

Authored by uweigand on Dec 14 2015, 9:35 AM.

Details

Summary

The global entry point prologue currently assumes that the TOC associated
with a function is less than 2GB away from the function entry point. This
is always true when using the medium or small code model, but may not be
the case when using the large code model.

This patch adds a new variant of the ELFv2 global entry point prologue that
lifts the 2GB restriction when building with -mcmodel=large. This works by
emitting a quadword containing the distance from the function entry point
to its associated TOC immediately before the entry point, and then using a
prologue like:

ld r2,-8(r12)
add r2,r2,r12

Since creation of the entry point prologue is now split across two separate
routines (PPCLinuxAsmPrinter::EmitFunctionEntryLabel emits the data word,
PPCLinuxAsmPrinter::EmitFunctionBodyStart the prolog code), I've switched
to using named labels instead of just temporaries to indicate the locations
of the global and local entry points and the new TOC offset data word.

These names are provided by new routines in PPCFunctionInfo modeled
after the existing PPCFunctionInfo::getPICOffsetSymbol.

Note that a corresponding change was committed to GCC here:
https://gcc.gnu.org/ml/gcc-patches/2015-12/msg00355.html

[ The GCC patch implements a further optimization, R_PPC64_ENTRY,
which isn't in the LLVM patch yet, since it requires working .reloc
support in the assembler. This can always be added later on. ]

Diff Detail

Repository
rL LLVM

Event Timeline

uweigand updated this revision to Diff 42729.Dec 14 2015, 9:35 AM
uweigand retitled this revision from to [PowerPC] Fix large code model with the ELFv2 ABI.
uweigand updated this object.
uweigand added a reviewer: hfinkel.
uweigand added a subscriber: llvm-commits.
hfinkel accepted this revision.Jan 12 2016, 5:06 PM
hfinkel edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jan 12 2016, 5:06 PM
This revision was automatically updated to reflect the committed changes.