[PowerPC][XCOFF][MC] Explicitly set containing csect on symbols. [NFC]

Previously we would get the csect a symbol was contained in through its
fragment. This works only if we are writing an object file, and only for
defined symbols. To fix this we set the contating csect explicitly on the
MCSymbolXCOFF object.

Differential Revision: https://reviews.llvm.org/D66032

llvm-svn: 369657
This commit is contained in:
Sean Fertile 2019-08-22 15:11:23 +00:00
parent 08d93f1ed3
commit 18fd1b0b49
3 changed files with 19 additions and 2 deletions

View File

@ -14,6 +14,8 @@
namespace llvm {
class MCSectionXCOFF;
class MCSymbolXCOFF : public MCSymbol {
public:
MCSymbolXCOFF(const StringMapEntry<bool> *Name, bool isTemporary)
@ -33,8 +35,22 @@ public:
return StorageClass.getValue();
}
void setContainingCsect(const MCSectionXCOFF *C) {
assert((!ContainingCsect || ContainingCsect == C) &&
"Trying to set a containing csect that doesn't match the one that"
"this symbol is already mapped to.");
ContainingCsect = C;
}
const MCSectionXCOFF *getContainingCsect() const {
assert(ContainingCsect &&
"Trying to get containing csect but none was set.");
return ContainingCsect;
}
private:
Optional<XCOFF::StorageClass> StorageClass;
const MCSectionXCOFF *ContainingCsect = nullptr;
};
} // end namespace llvm

View File

@ -247,8 +247,7 @@ void XCOFFObjectWriter::executePostLayoutBinding(
const MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(&S);
// Map the symbol into its containing csect.
MCSectionXCOFF *ContainingCsect =
dyn_cast<MCSectionXCOFF>(XSym->getFragment(false)->getParent());
const MCSectionXCOFF *ContainingCsect = XSym->getContainingCsect();
assert(WrapperMap.find(ContainingCsect) != WrapperMap.end() &&
"Expected containing csect to exist in map");

View File

@ -1671,6 +1671,8 @@ void PPCAIXAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(getSymbol(GV));
XSym->setStorageClass(
TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(GV));
XSym->setContainingCsect(CSect);
const DataLayout &DL = GV->getParent()->getDataLayout();
unsigned Align =
GV->getAlignment() ? GV->getAlignment() : DL.getPreferredAlignment(GV);