From: Sean Fertile Date: Thu, 22 Aug 2019 15:11:23 +0000 (+0000) Subject: [PowerPC][XCOFF][MC] Explicitly set containing csect on symbols. [NFC] X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a17efce83e8822ad4f67a6a481d69b4016c60c02;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369657 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/MC/MCSymbolXCOFF.h b/include/llvm/MC/MCSymbolXCOFF.h index 087cf5d0feb..566aa7ca8eb 100644 --- a/include/llvm/MC/MCSymbolXCOFF.h +++ b/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 @@ 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 StorageClass; + const MCSectionXCOFF *ContainingCsect = nullptr; }; } // end namespace llvm diff --git a/lib/MC/XCOFFObjectWriter.cpp b/lib/MC/XCOFFObjectWriter.cpp index 94c95279c06..d4dfd467976 100644 --- a/lib/MC/XCOFFObjectWriter.cpp +++ b/lib/MC/XCOFFObjectWriter.cpp @@ -247,8 +247,7 @@ void XCOFFObjectWriter::executePostLayoutBinding( 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/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp index 39641879cc1..8d23238e615 100644 --- a/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1671,6 +1671,8 @@ void PPCAIXAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) { 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);