diff --git a/llvm/include/llvm/MC/MCSymbolXCOFF.h b/llvm/include/llvm/MC/MCSymbolXCOFF.h --- a/llvm/include/llvm/MC/MCSymbolXCOFF.h +++ b/llvm/include/llvm/MC/MCSymbolXCOFF.h @@ -14,6 +14,8 @@ namespace llvm { +class MCSectionXCOFF; + class MCSymbolXCOFF : public MCSymbol { public: MCSymbolXCOFF(const StringMapEntry *Name, bool isTemporary) @@ -33,8 +35,22 @@ return StorageClass.getValue(); } + void setContainingCsect(const MCSectionXCOFF *C) { + assert((!ContainingCsect || ContainingCsect == C) && + "Trying to set a contain 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 StorageClass; + const MCSectionXCOFF *ContainingCsect = nullptr; }; } // end namespace llvm diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp --- a/llvm/lib/MC/XCOFFObjectWriter.cpp +++ b/llvm/lib/MC/XCOFFObjectWriter.cpp @@ -247,8 +247,7 @@ const MCSymbolXCOFF *XSym = cast(&S); // Map the symbol into its containing csect. - MCSectionXCOFF *ContainingCsect = - dyn_cast(XSym->getFragment(false)->getParent()); + const MCSectionXCOFF *ContainingCsect = XSym->getContainingCsect(); assert(WrapperMap.find(ContainingCsect) != WrapperMap.end() && "Expected containing csect to exist in map"); diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1671,6 +1671,8 @@ MCSymbolXCOFF *XSym = cast(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);