summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp14
-rw-r--r--llvm/lib/MC/MCContext.cpp14
-rw-r--r--llvm/lib/MC/MCParser/ELFAsmParser.cpp16
-rw-r--r--llvm/lib/MC/MCSectionELF.cpp8
4 files changed, 32 insertions, 20 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 18dd50826a5..b6f21ba26b6 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1156,8 +1156,8 @@ void ELFObjectWriter::writeSection(const SectionIndexMapTy &SectionIndexMap,
case ELF::SHT_RELA: {
sh_link = SymbolTableIndex;
assert(sh_link && ".symtab not found");
- const MCSectionELF *InfoSection = Section.getAssociatedSection();
- sh_info = SectionIndexMap.lookup(InfoSection);
+ const MCSection *InfoSection = Section.getAssociatedSection();
+ sh_info = SectionIndexMap.lookup(cast<MCSectionELF>(InfoSection));
break;
}
@@ -1177,8 +1177,11 @@ void ELFObjectWriter::writeSection(const SectionIndexMapTy &SectionIndexMap,
break;
}
- if (Section.getFlags() & ELF::SHF_LINK_ORDER)
- sh_link = SectionIndexMap.lookup(Section.getAssociatedSection());
+ if (Section.getFlags() & ELF::SHF_LINK_ORDER) {
+ const MCSymbol *Sym = Section.getAssociatedSymbol();
+ const MCSectionELF *Sec = cast<MCSectionELF>(&Sym->getSection());
+ sh_link = SectionIndexMap.lookup(Sec);
+ }
WriteSecHdrEntry(StrTabBuilder.getOffset(Section.getSectionName()),
Section.getType(), Section.getFlags(), 0, Offset, Size,
@@ -1302,7 +1305,8 @@ void ELFObjectWriter::writeObject(MCAssembler &Asm,
// Remember the offset into the file for this section.
uint64_t SecStart = getStream().tell();
- writeRelocations(Asm, *RelSection->getAssociatedSection());
+ writeRelocations(Asm,
+ cast<MCSectionELF>(*RelSection->getAssociatedSection()));
uint64_t SecEnd = getStream().tell();
SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 9d5bd39b56f..4628d0ab88f 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -317,7 +317,7 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
unsigned EntrySize,
const MCSymbolELF *Group,
unsigned UniqueID,
- const MCSectionELF *Associated) {
+ const MCSymbolELF *Associated) {
MCSymbolELF *R;
MCSymbol *&Sym = Symbols[Section];
// A section symbol can not redefine regular symbols. There may be multiple
@@ -350,15 +350,15 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
MCSectionELF *MCContext::createELFRelSection(const Twine &Name, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *Group,
- const MCSectionELF *Associated) {
+ const MCSectionELF *RelInfoSection) {
StringMap<bool>::iterator I;
bool Inserted;
std::tie(I, Inserted) =
RelSecNames.insert(std::make_pair(Name.str(), true));
- return createELFSectionImpl(I->getKey(), Type, Flags,
- SectionKind::getReadOnly(), EntrySize, Group,
- true, Associated);
+ return createELFSectionImpl(
+ I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
+ true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
}
MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix,
@@ -371,7 +371,7 @@ MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix,
MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
const Twine &Group, unsigned UniqueID,
- const MCSectionELF *Associated) {
+ const MCSymbolELF *Associated) {
MCSymbolELF *GroupSym = nullptr;
if (!Group.isTriviallyEmpty() && !Group.str().empty())
GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
@@ -384,7 +384,7 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *GroupSym,
unsigned UniqueID,
- const MCSectionELF *Associated) {
+ const MCSymbolELF *Associated) {
StringRef Group = "";
if (GroupSym)
Group = GroupSym->getName();
diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index 8838f16d60a..4ac16615ceb 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -157,7 +157,7 @@ private:
bool maybeParseSectionType(StringRef &TypeName);
bool parseMergeSize(int64_t &Size);
bool parseGroup(StringRef &GroupName);
- bool parseMetadataSym(MCSectionELF *&Associated);
+ bool parseMetadataSym(MCSymbolELF *&Associated);
bool maybeParseUniqueID(int64_t &UniqueID);
};
@@ -432,7 +432,7 @@ bool ELFAsmParser::parseGroup(StringRef &GroupName) {
return false;
}
-bool ELFAsmParser::parseMetadataSym(MCSectionELF *&Associated) {
+bool ELFAsmParser::parseMetadataSym(MCSymbolELF *&Associated) {
MCAsmLexer &L = getLexer();
if (L.isNot(AsmToken::Comma))
return TokError("expected metadata symbol");
@@ -440,10 +440,9 @@ bool ELFAsmParser::parseMetadataSym(MCSectionELF *&Associated) {
StringRef Name;
if (getParser().parseIdentifier(Name))
return true;
- MCSymbol *Sym = getContext().lookupSymbol(Name);
- if (!Sym || !Sym->isInSection())
+ Associated = dyn_cast_or_null<MCSymbolELF>(getContext().lookupSymbol(Name));
+ if (!Associated || !Associated->isInSection())
return TokError("symbol is not in a section: " + Name);
- Associated = cast<MCSectionELF>(&Sym->getSection());
return false;
}
@@ -482,7 +481,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
const MCExpr *Subsection = nullptr;
bool UseLastGroup = false;
StringRef UniqueStr;
- MCSectionELF *Associated = nullptr;
+ MCSymbolELF *Associated = nullptr;
int64_t UniqueID = ~0;
// Set the defaults first.
@@ -597,8 +596,9 @@ EndStmt:
}
}
- MCSection *ELFSection = getContext().getELFSection(
- SectionName, Type, Flags, Size, GroupName, UniqueID, Associated);
+ MCSection *ELFSection =
+ getContext().getELFSection(SectionName, Type, Flags, Size, GroupName,
+ UniqueID, Associated);
getStreamer().SwitchSection(ELFSection, Subsection);
if (getContext().getGenDwarfForAssembly()) {
diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp
index a352f84cfe9..56c51d7539e 100644
--- a/llvm/lib/MC/MCSectionELF.cpp
+++ b/llvm/lib/MC/MCSectionELF.cpp
@@ -103,6 +103,8 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
OS << 'S';
if (Flags & ELF::SHF_TLS)
OS << 'T';
+ if (Flags & ELF::SHF_LINK_ORDER)
+ OS << 'm';
// If there are target-specific flags, print them.
Triple::ArchType Arch = T.getArch();
@@ -160,6 +162,12 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
OS << ",comdat";
}
+ if (Flags & ELF::SHF_LINK_ORDER) {
+ assert(AssociatedSymbol);
+ OS << ",";
+ printName(OS, AssociatedSymbol->getName());
+ }
+
if (isUnique())
OS << ",unique," << UniqueID;
OpenPOWER on IntegriCloud