[llvm] r369657 - [PowerPC][XCOFF][MC] Explicitly set containing csect on symbols. [NFC]
Sean Fertile via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 08:11:23 PDT 2019
Author: sfertile
Date: Thu Aug 22 08:11:23 2019
New Revision: 369657
URL: http://llvm.org/viewvc/llvm-project?rev=369657&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/MC/MCSymbolXCOFF.h
llvm/trunk/lib/MC/XCOFFObjectWriter.cpp
llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
Modified: llvm/trunk/include/llvm/MC/MCSymbolXCOFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbolXCOFF.h?rev=369657&r1=369656&r2=369657&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbolXCOFF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbolXCOFF.h Thu Aug 22 08:11:23 2019
@@ -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
Modified: llvm/trunk/lib/MC/XCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/XCOFFObjectWriter.cpp?rev=369657&r1=369656&r2=369657&view=diff
==============================================================================
--- llvm/trunk/lib/MC/XCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/XCOFFObjectWriter.cpp Thu Aug 22 08:11:23 2019
@@ -247,8 +247,7 @@ void XCOFFObjectWriter::executePostLayou
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");
Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=369657&r1=369656&r2=369657&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Thu Aug 22 08:11:23 2019
@@ -1671,6 +1671,8 @@ void PPCAIXAsmPrinter::EmitGlobalVariabl
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);
More information about the llvm-commits
mailing list