This is an archive of the discontinued LLVM Phabricator instance.

[PPC] Fix indirect access for weak symbols.
ClosedPublic

Authored by iteratee on Nov 3 2015, 11:01 AM.

Details

Summary

Weak non-function symbols were being accessed directly, which is incorrect, as
the chosen representative of the weak symbol may not live with the code
in question. Always indirect the access through the TOC instead.

Diff Detail

Event Timeline

iteratee updated this revision to Diff 39091.Nov 3 2015, 11:01 AM
iteratee retitled this revision from to [PPC] Fix indirect access for weak symbols..
iteratee updated this object.
iteratee added reviewers: echristo, wschmidt.
iteratee set the repository for this revision to rL LLVM.
wschmidt accepted this revision.Nov 3 2015, 2:04 PM
wschmidt edited edge metadata.

Thanks, Kyle. This LGTM. That's a much better interface to use (and one that didn't exist when this code was first written). Thanks for taking care of this!

lib/Target/PowerPC/PPCAsmPrinter.cpp
678

Interesting. People often tell me not to use braces around a single statement, but as I check the coding standards for the projects, this is not mentioned. I prefer your style anyway. Just a heads-up to other reviewers that I'm not gonna take it anymore! ;)

This revision is now accepted and ready to land.Nov 3 2015, 2:04 PM
rnk added a subscriber: rnk.Nov 9 2015, 1:20 PM

This should really be checking visibility, not linkage. See the implementations of ClassifyGlobalReference for AArch64 and X86.

I believe the logic should be: if this is a local definition or (a strong definition that has hidden or protected visibility), then we can skip the TOC reference. Otherwise, we must use the TOC because the symbol could be interposed.

iteratee updated this revision to Diff 39991.Nov 11 2015, 4:37 PM
iteratee edited edge metadata.
iteratee removed rL LLVM as the repository for this revision.

As Eric and Reid mentioned, this should be based on visibility. I created a method in PPCSubtarget to factor this out and made it use visibility.

This caused some tests to fail because it allowed non-toc access to some local symbols in the tests. They've been updated to match.

iteratee updated this revision to Diff 40462.Nov 17 2015, 5:16 PM

There is currently a bug in gold that prevents using non-toc accesses even when the abi would allow it.

Document that bug in the comments, and work around it.
The tests revert in this case as well.

iteratee updated this revision to Diff 40584.Nov 18 2015, 5:45 PM

Relax symbol classification when relocation model is not PIC

Per a discussion with rnk:
If the relocation model is not PIC, then it is safe to use a local definition for non-weak symbols.
Otherwise they may be interposed. This reverts all the tests, as none of them were using PIC access.

iteratee updated this revision to Diff 40586.Nov 18 2015, 6:02 PM

Revert unneeded fix for test and fix typo.

rnk added inline comments.Nov 19 2015, 4:22 PM
lib/Target/PowerPC/PPCAsmPrinter.cpp
680

gv_flags isn't LLVM style, GVFlags would be.

730

ditto

lib/Target/PowerPC/PPCSubtarget.cpp
234

You can probably return early here.

240

You don't need this return, falling through to return flags would be fine

lib/Target/PowerPC/PPCSubtarget.h
289

The case of the name of the method doesn't match. You can just delete it and the Doxygen will probably come out fine.

292

Nobody calls this with forcePIC=false, right? Is the intention that this will change in the future? For now, I'd just remove the parameter and check from the classification function and put in a comment about what we'd have to return to form a direct access.

You can also use a default argument here instead of an overload:

unsigned char classifyGlobalReference(const GlobalValue *GV, bool forcePIC = false) const;
iteratee updated this revision to Diff 40730.Nov 19 2015, 6:01 PM
iteratee marked 6 inline comments as done.

Fixed comments by rnk

Replying to comments.

lib/Target/PowerPC/PPCAsmPrinter.cpp
678

I changed this one because it bothers me to see an if with braces when the else doesn't have one or vice versa.

I'm OK with small statements not having any, but mixing them seemed ugly to me.

iteratee marked 2 inline comments as done.Nov 19 2015, 6:24 PM
echristo edited edge metadata.Nov 19 2015, 6:28 PM

One inline nit. Otherwise rnk has been handling it :)

lib/Target/PowerPC/PPCAsmPrinter.cpp
689–691

I might buy the argument above for single line braces in context of lots of if/else chains. This one isn't though :)

lib/Target/PowerPC/PPCSubtarget.cpp
213–214

This is really over 80-col? Sad.

iteratee updated this revision to Diff 40797.Nov 20 2015, 10:31 AM
iteratee edited edge metadata.
iteratee marked 2 inline comments as done.

Fixed minor nit.

rnk accepted this revision.Nov 20 2015, 11:04 AM
rnk added a reviewer: rnk.

lgtm

Hi Kyle,

Was going to commit this but noticed the testcase changes never made it into the diff?

-eric

iteratee added inline comments.Nov 20 2015, 12:25 PM
lib/Target/PowerPC/PPCSubtarget.cpp
213–214

Blame const.

iteratee updated this revision to Diff 40816.Nov 20 2015, 12:39 PM
iteratee edited edge metadata.

Test case as requested.

echristo accepted this revision.Nov 20 2015, 12:49 PM
echristo edited edge metadata.

Testcase LGTM, Thanks!

-eric

I've committed this thusly:

M lib/Target/PowerPC/PPCISelDAGToDAG.cpp
M lib/Target/PowerPC/PPCFastISel.cpp
M lib/Target/PowerPC/PPCAsmPrinter.cpp
M lib/Target/PowerPC/PPCSubtarget.cpp
M lib/Target/PowerPC/PPCSubtarget.h
A test/CodeGen/PowerPC/mcm-13.ll
r253708 = 1d60d1ecfc3b51bbecc7bf08f59d372397e7772b
(refs/remotes/origin/master)

-eric

iteratee closed this revision.Nov 20 2015, 1:44 PM