This is an archive of the discontinued LLVM Phabricator instance.

Use PIC relocation mode by default for PowerPC64 ELF
ClosedPublic

Authored by joerg on Nov 11 2016, 2:29 PM.

Details

Summary

Most of the PowerPC64 code generation already creates PIC access. This changes to a full PIC default, similar to what GCC is doing.

Overall, a monolithic clang binary shrinks by 600KB (about 1%). This can be a slight regression for TLS access and will use the TOC more aggressively instead of synthesizing immediates. It is expected to be performance neutral.

Diff Detail

Event Timeline

joerg updated this revision to Diff 77670.Nov 11 2016, 2:29 PM
joerg retitled this revision from to Use PIC relocation mode by default for PowerPC64 ELF.
joerg updated this object.
joerg added a reviewer: hfinkel.
joerg added a subscriber: cfe-commits.
hfinkel edited edge metadata.Nov 11 2016, 2:43 PM
hfinkel added subscribers: kbarton, amehsan, wschmidt.

@wschmidt and other IBM folks, w.r.t. this and D26566, can you please comment on what GCC does here? Does GCC use -fPIC by default for PPC64 (literally or in effect)?

@wschmidt and other IBM folks, w.r.t. this and D26566, can you please comment on what GCC does here? Does GCC use -fPIC by default for PPC64 (literally or in effect)?

This is an area that I always find a bit confusing. There is a lot of cruft in GCC regarding -fpic / -fPIC because of the many subtargets.

I can say with confidence that -fPIC behavior is the default for powerpc64le (more correctly, for ELFv2 ABI), and I'm pretty sure that's true for powerpc64 (ELFv1) as well. Certainly -fpic and -fPIE are not defaults for either ABI. The weird crufty stuff arises with 32-bit PPC, where R30 is reserved to point to a PIC offset table that doesn't exist for the 64-bit ABIs, so far as I can tell.

So, longwinded, caveat-filled response is, I think this is just fine. :)

amehsan added inline comments.Nov 17 2016, 9:57 AM
lib/Driver/ToolChains.cpp
2799–2807

This is a minor nit. Almost any switch statement that I have come across in LLVM code, has default in the very beginning instead of the end. At least for the sake of consistency this is better to change here. (The reason that I have heard for it, is readability for large switch statements. But in the codebase, even stmts of this size, have default first).

hfinkel accepted this revision.Dec 13 2016, 11:51 PM
hfinkel edited edge metadata.

LGTM

This revision is now accepted and ready to land.Dec 13 2016, 11:51 PM
This revision was automatically updated to reflect the committed changes.