[MC][ELF] Rename MC related "Associated" to "LinkedToSym"
"linked-to section" is used by the ELF spec. By analogy, "linked-to
symbol" is a good name for the signature symbol. The word "linked-to"
implies a directed edge and makes it clear its relation with "sh_link",
while one can argue that "associated" means an undirected edge.
Also, combine tests and add precise SMLoc to improve diagnostics.
Reviewed By: eugenis, grimar, jhenderson
Differential Revision: https://reviews.llvm.org/D74082
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 804f999..f9431d5 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1001,7 +1001,7 @@
case ELF::SHT_RELA: {
sh_link = SymbolTableIndex;
assert(sh_link && ".symtab not found");
- const MCSection *InfoSection = Section.getAssociatedSection();
+ const MCSection *InfoSection = Section.getLinkedToSection();
sh_info = SectionIndexMap.lookup(cast<MCSectionELF>(InfoSection));
break;
}
@@ -1024,7 +1024,7 @@
}
if (Section.getFlags() & ELF::SHF_LINK_ORDER) {
- const MCSymbol *Sym = Section.getAssociatedSymbol();
+ const MCSymbol *Sym = Section.getLinkedToSymbol();
const MCSectionELF *Sec = cast<MCSectionELF>(&Sym->getSection());
sh_link = SectionIndexMap.lookup(Sec);
}
@@ -1180,7 +1180,7 @@
uint64_t SecStart = W.OS.tell();
writeRelocations(Asm,
- cast<MCSectionELF>(*RelSection->getAssociatedSection()));
+ cast<MCSectionELF>(*RelSection->getLinkedToSection()));
uint64_t SecEnd = W.OS.tell();
SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index ff4f636..1f89242 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -332,7 +332,7 @@
unsigned EntrySize,
const MCSymbolELF *Group,
unsigned UniqueID,
- const MCSymbolELF *Associated) {
+ const MCSymbolELF *LinkedToSym) {
MCSymbolELF *R;
MCSymbol *&Sym = Symbols[Section];
// A section symbol can not redefine regular symbols. There may be multiple
@@ -352,7 +352,7 @@
R->setType(ELF::STT_SECTION);
auto *Ret = new (ELFAllocator.Allocate()) MCSectionELF(
- Section, Type, Flags, K, EntrySize, Group, UniqueID, R, Associated);
+ Section, Type, Flags, K, EntrySize, Group, UniqueID, R, LinkedToSym);
auto *F = new MCDataFragment();
Ret->getFragmentList().insert(Ret->begin(), F);
@@ -386,20 +386,20 @@
MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
const Twine &Group, unsigned UniqueID,
- const MCSymbolELF *Associated) {
+ const MCSymbolELF *LinkedToSym) {
MCSymbolELF *GroupSym = nullptr;
if (!Group.isTriviallyEmpty() && !Group.str().empty())
GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
- Associated);
+ LinkedToSym);
}
MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *GroupSym,
unsigned UniqueID,
- const MCSymbolELF *Associated) {
+ const MCSymbolELF *LinkedToSym) {
StringRef Group = "";
if (GroupSym)
Group = GroupSym->getName();
@@ -420,8 +420,9 @@
else
Kind = SectionKind::getReadOnly();
- MCSectionELF *Result = createELFSectionImpl(
- CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID, Associated);
+ MCSectionELF *Result =
+ createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
+ UniqueID, LinkedToSym);
Entry.second = Result;
return Result;
}
diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index a55bdd5..848456d 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -158,7 +158,7 @@
bool maybeParseSectionType(StringRef &TypeName);
bool parseMergeSize(int64_t &Size);
bool parseGroup(StringRef &GroupName);
- bool parseMetadataSym(MCSymbolELF *&Associated);
+ bool parseLinkedToSym(MCSymbolELF *&LinkedToSym);
bool maybeParseUniqueID(int64_t &UniqueID);
};
@@ -443,17 +443,18 @@
return false;
}
-bool ELFAsmParser::parseMetadataSym(MCSymbolELF *&Associated) {
+bool ELFAsmParser::parseLinkedToSym(MCSymbolELF *&LinkedToSym) {
MCAsmLexer &L = getLexer();
if (L.isNot(AsmToken::Comma))
- return TokError("expected metadata symbol");
+ return TokError("expected linked-to symbol");
Lex();
StringRef Name;
+ SMLoc StartLoc = L.getLoc();
if (getParser().parseIdentifier(Name))
- return TokError("invalid metadata symbol");
- Associated = dyn_cast_or_null<MCSymbolELF>(getContext().lookupSymbol(Name));
- if (!Associated || !Associated->isInSection())
- return TokError("symbol is not in a section: " + Name);
+ return TokError("invalid linked-to symbol");
+ LinkedToSym = dyn_cast_or_null<MCSymbolELF>(getContext().lookupSymbol(Name));
+ if (!LinkedToSym || !LinkedToSym->isInSection())
+ return Error(StartLoc, "linked-to symbol is not in a section: " + Name);
return false;
}
@@ -495,7 +496,7 @@
unsigned Flags = 0;
const MCExpr *Subsection = nullptr;
bool UseLastGroup = false;
- MCSymbolELF *Associated = nullptr;
+ MCSymbolELF *LinkedToSym = nullptr;
int64_t UniqueID = ~0;
// Set the defaults first.
@@ -568,7 +569,7 @@
if (parseGroup(GroupName))
return true;
if (Flags & ELF::SHF_LINK_ORDER)
- if (parseMetadataSym(Associated))
+ if (parseLinkedToSym(LinkedToSym))
return true;
if (maybeParseUniqueID(UniqueID))
return true;
@@ -633,9 +634,8 @@
}
}
- MCSection *ELFSection =
- getContext().getELFSection(SectionName, Type, Flags, Size, GroupName,
- UniqueID, Associated);
+ MCSection *ELFSection = getContext().getELFSection(
+ SectionName, Type, Flags, Size, GroupName, UniqueID, LinkedToSym);
getStreamer().SwitchSection(ELFSection, Subsection);
if (getContext().getGenDwarfForAssembly()) {
diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp
index efe504b..6950cab 100644
--- a/llvm/lib/MC/MCSectionELF.cpp
+++ b/llvm/lib/MC/MCSectionELF.cpp
@@ -172,9 +172,9 @@
}
if (Flags & ELF::SHF_LINK_ORDER) {
- assert(AssociatedSymbol);
+ assert(LinkedToSym);
OS << ",";
- printName(OS, AssociatedSymbol->getName());
+ printName(OS, LinkedToSym->getName());
}
if (isUnique())