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.
Details
Diff Detail
Event Timeline
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 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.
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.
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.
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.
lib/Target/PowerPC/PPCAsmPrinter.cpp | ||
---|---|---|
680 | gv_flags isn't LLVM style, GVFlags would be. | |
735 | ditto | |
lib/Target/PowerPC/PPCSubtarget.cpp | ||
234 ↗ | (On Diff #40586) | You can probably return early here. |
240 ↗ | (On Diff #40586) | You don't need this return, falling through to return flags would be fine |
lib/Target/PowerPC/PPCSubtarget.h | ||
293 ↗ | (On Diff #40586) | The case of the name of the method doesn't match. You can just delete it and the Doxygen will probably come out fine. |
296 ↗ | (On Diff #40586) | 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; |
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. |
One inline nit. Otherwise rnk has been handling it :)
lib/Target/PowerPC/PPCAsmPrinter.cpp | ||
---|---|---|
687–689 | 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 ↗ | (On Diff #40730) | This is really over 80-col? Sad. |
Hi Kyle,
Was going to commit this but noticed the testcase changes never made it into the diff?
-eric
lib/Target/PowerPC/PPCSubtarget.cpp | ||
---|---|---|
213–214 ↗ | (On Diff #40730) | Blame const. |
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
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! ;)