summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/XCOFFObjectWriter.cpp
diff options
context:
space:
mode:
authorJason Liu <jasonliu.development@gmail.com>2019-11-08 09:26:28 -0500
committerDavid Tenty <daltenty@ibm.com>2019-11-08 09:30:10 -0500
commit0dc0572b48ed889e6f750fd65b876a0420805377 (patch)
tree266c8f476b8d4b96db8ef9cea064169462ed9edd /llvm/lib/MC/XCOFFObjectWriter.cpp
parente25bc5e0247141cb31093a370e22fe3249bdbb05 (diff)
downloadbcm5719-llvm-0dc0572b48ed889e6f750fd65b876a0420805377.tar.gz
bcm5719-llvm-0dc0572b48ed889e6f750fd65b876a0420805377.zip
[XCOFF][AIX] Differentiate usage of label symbol and csect symbol
Summary: We are using symbols to represent label and csect interchangeably before, and that could be a problem. There are cases we would need to add storage mapping class to the symbol if that symbol is actually the name of a csect, but it's hard for us to figure out whether that symbol is a label or csect. This patch intend to do the following: 1. Construct a QualName (A name include the storage mapping class) MCSymbolXCOFF for every MCSectionXCOFF. 2. Keep a pointer to that QualName inside of MCSectionXCOFF. 3. Use that QualName whenever we need a symbol refers to that MCSectionXCOFF. 4. Adapt the snowball effect from the above changes in XCOFFObjectWriter.cpp. Reviewers: xingxue, DiggerLin, sfertile, daltenty, hubert.reinterpretcast Reviewed By: DiggerLin, daltenty Subscribers: wuzish, nemanjai, mgorny, hiraditya, kbarton, jsji, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69633
Diffstat (limited to 'llvm/lib/MC/XCOFFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/XCOFFObjectWriter.cpp56
1 files changed, 21 insertions, 35 deletions
diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index d8f9e0b593b..cec74ee76c3 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -78,15 +78,7 @@ struct ControlSection {
// (approximately) the same storage mapping class. For example all the csects
// with a storage mapping class of `xmc_pr` will get placed into the same
// container.
-struct CsectGroup {
- enum LabelDefinitionSupport : bool {
- LabelDefSupported = true,
- LabelDefUnsupported = false
- };
-
- const LabelDefinitionSupport SupportLabelDef;
- std::deque<ControlSection> Csects;
-};
+using CsectGroup = std::deque<ControlSection>;
using CsectGroups = std::deque<CsectGroup *>;
@@ -132,7 +124,7 @@ struct Section {
Index = UninitializedIndex;
// Clear any csects we have stored.
for (auto *Group : Groups)
- Group->Csects.clear();
+ Group->clear();
}
Section(const char *N, XCOFF::SectionTypeFlags Flags, bool IsVirtual,
@@ -157,9 +149,9 @@ class XCOFFObjectWriter : public MCObjectWriter {
// CsectGroups. These store the csects which make up different parts of
// the sections. Should have one for each set of csects that get mapped into
// the same section and get handled in a 'similar' way.
- CsectGroup ProgramCodeCsects{CsectGroup::LabelDefSupported, {}};
- CsectGroup DataCsects{CsectGroup::LabelDefSupported, {}};
- CsectGroup BSSCsects{CsectGroup::LabelDefUnsupported, {}};
+ CsectGroup ProgramCodeCsects;
+ CsectGroup DataCsects;
+ CsectGroup BSSCsects;
// The Predefined sections.
Section Text;
@@ -294,8 +286,8 @@ void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
continue;
CsectGroup &Group = getCsectGroup(MCSec);
- Group.Csects.emplace_back(MCSec);
- WrapperMap[MCSec] = &Group.Csects.back();
+ Group.emplace_back(MCSec);
+ WrapperMap[MCSec] = &Group.back();
}
for (const MCSymbol &S : Asm.symbols()) {
@@ -309,6 +301,11 @@ void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
assert(WrapperMap.find(ContainingCsect) != WrapperMap.end() &&
"Expected containing csect to exist in map");
+ // If the symbol is the Csect itself, we don't need to put the symbol
+ // into Csect's Syms.
+ if (XSym == ContainingCsect->getQualNameSymbol())
+ continue;
+
// Lookup the containing csect and add the symbol to it.
WrapperMap[ContainingCsect]->Syms.emplace_back(XSym);
@@ -339,7 +336,7 @@ void XCOFFObjectWriter::writeSections(const MCAssembler &Asm,
assert(CurrentAddressLocation == Section->Address &&
"We should have no padding between sections.");
for (const auto *Group : Section->Groups) {
- for (const auto &Csect : Group->Csects) {
+ for (const auto &Csect : *Group) {
if (uint32_t PaddingSize = Csect.Address - CurrentAddressLocation)
W.OS.write_zeros(PaddingSize);
Asm.writeSectionData(W.OS, Csect.MCCsect, Layout);
@@ -527,20 +524,14 @@ void XCOFFObjectWriter::writeSymbolTable(const MCAsmLayout &Layout) {
continue;
for (const auto *Group : Section->Groups) {
- if (Group->Csects.empty())
+ if (Group->empty())
continue;
- const bool SupportLabelDef = Group->SupportLabelDef;
const int16_t SectionIndex = Section->Index;
- for (const auto &Csect : Group->Csects) {
+ for (const auto &Csect : *Group) {
// Write out the control section first and then each symbol in it.
writeSymbolTableEntryForControlSection(
Csect, SectionIndex, Csect.MCCsect->getStorageClass());
- if (!SupportLabelDef) {
- assert(Csect.Syms.size() == 1 && "Csect should only contain 1 symbol "
- "which is its label definition.");
- continue;
- }
for (const auto Sym : Csect.Syms)
writeSymbolTableEntryForCsectMemberLabel(
@@ -563,9 +554,8 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
for (auto *Section : Sections) {
const bool IsEmpty =
- llvm::all_of(Section->Groups, [](const CsectGroup *Group) {
- return Group->Csects.empty();
- });
+ llvm::all_of(Section->Groups,
+ [](const CsectGroup *Group) { return Group->empty(); });
if (IsEmpty)
continue;
@@ -576,11 +566,10 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
bool SectionAddressSet = false;
for (auto *Group : Section->Groups) {
- if (Group->Csects.empty())
+ if (Group->empty())
continue;
- const bool SupportLabelDef = Group->SupportLabelDef;
- for (auto &Csect : Group->Csects) {
+ for (auto &Csect : *Group) {
const MCSectionXCOFF *MCSec = Csect.MCCsect;
Csect.Address = alignTo(Address, MCSec->getAlignment());
Csect.Size = Layout.getSectionAddressSize(MCSec);
@@ -588,10 +577,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
Csect.SymbolTableIndex = SymbolTableIndex;
// 1 main and 1 auxiliary symbol table entry for the csect.
SymbolTableIndex += 2;
-
- if (!SupportLabelDef)
- continue;
-
+
for (auto &Sym : Csect.Syms) {
Sym.SymbolTableIndex = SymbolTableIndex;
// 1 main and 1 auxiliary symbol table entry for each contained
@@ -601,7 +587,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
}
if (!SectionAddressSet) {
- Section->Address = Group->Csects.front().Address;
+ Section->Address = Group->front().Address;
SectionAddressSet = true;
}
}
OpenPOWER on IntegriCloud