mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-18 18:42:46 +02:00
[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
This commit is contained in:
parent
713501bcf3
commit
7c84cd8ff5
@ -296,7 +296,7 @@ namespace llvm {
|
||||
unsigned EntrySize,
|
||||
const MCSymbolELF *Group,
|
||||
unsigned UniqueID,
|
||||
const MCSymbolELF *Associated);
|
||||
const MCSymbolELF *LinkedToSym);
|
||||
|
||||
/// Map of currently defined macros.
|
||||
StringMap<MCAsmMacro> MacroMap;
|
||||
@ -442,12 +442,12 @@ namespace llvm {
|
||||
MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
|
||||
unsigned Flags, unsigned EntrySize,
|
||||
const Twine &Group, unsigned UniqueID,
|
||||
const MCSymbolELF *Associated);
|
||||
const MCSymbolELF *LinkedToSym);
|
||||
|
||||
MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
|
||||
unsigned Flags, unsigned EntrySize,
|
||||
const MCSymbolELF *Group, unsigned UniqueID,
|
||||
const MCSymbolELF *Associated);
|
||||
const MCSymbolELF *LinkedToSym);
|
||||
|
||||
/// Get a section with the provided group identifier. This section is
|
||||
/// named by concatenating \p Prefix with '.' then \p Suffix. The \p Type
|
||||
|
@ -44,18 +44,19 @@ class MCSectionELF final : public MCSection {
|
||||
|
||||
const MCSymbolELF *Group;
|
||||
|
||||
/// sh_info for SHF_LINK_ORDER (can be null).
|
||||
const MCSymbol *AssociatedSymbol;
|
||||
/// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
|
||||
/// section header index of the section where LinkedToSym is defined.
|
||||
const MCSymbol *LinkedToSym;
|
||||
|
||||
private:
|
||||
friend class MCContext;
|
||||
|
||||
MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
|
||||
unsigned entrySize, const MCSymbolELF *group, unsigned UniqueID,
|
||||
MCSymbol *Begin, const MCSymbolELF *AssociatedSymbol)
|
||||
MCSymbol *Begin, const MCSymbolELF *LinkedToSym)
|
||||
: MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
|
||||
Flags(flags), UniqueID(UniqueID), EntrySize(entrySize), Group(group),
|
||||
AssociatedSymbol(AssociatedSymbol) {
|
||||
LinkedToSym(LinkedToSym) {
|
||||
if (Group)
|
||||
Group->setIsSignature();
|
||||
}
|
||||
@ -83,8 +84,10 @@ public:
|
||||
bool isUnique() const { return UniqueID != ~0U; }
|
||||
unsigned getUniqueID() const { return UniqueID; }
|
||||
|
||||
const MCSection *getAssociatedSection() const { return &AssociatedSymbol->getSection(); }
|
||||
const MCSymbol *getAssociatedSymbol() const { return AssociatedSymbol; }
|
||||
const MCSection *getLinkedToSection() const {
|
||||
return &LinkedToSym->getSection();
|
||||
}
|
||||
const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
|
||||
|
||||
static bool classof(const MCSection *S) {
|
||||
return S->getVariant() == SV_ELF;
|
||||
|
@ -3180,8 +3180,8 @@ void AsmPrinter::emitXRayTable() {
|
||||
MCSection *InstMap = nullptr;
|
||||
MCSection *FnSledIndex = nullptr;
|
||||
if (MF->getSubtarget().getTargetTriple().isOSBinFormatELF()) {
|
||||
auto Associated = dyn_cast<MCSymbolELF>(CurrentFnSym);
|
||||
assert(Associated != nullptr);
|
||||
auto LinkedToSym = dyn_cast<MCSymbolELF>(CurrentFnSym);
|
||||
assert(LinkedToSym != nullptr);
|
||||
auto Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER;
|
||||
std::string GroupName;
|
||||
if (F.hasComdat()) {
|
||||
@ -3192,10 +3192,10 @@ void AsmPrinter::emitXRayTable() {
|
||||
auto UniqueID = ++XRayFnUniqueID;
|
||||
InstMap =
|
||||
OutContext.getELFSection("xray_instr_map", ELF::SHT_PROGBITS, Flags, 0,
|
||||
GroupName, UniqueID, Associated);
|
||||
GroupName, UniqueID, LinkedToSym);
|
||||
FnSledIndex =
|
||||
OutContext.getELFSection("xray_fn_idx", ELF::SHT_PROGBITS, Flags, 0,
|
||||
GroupName, UniqueID, Associated);
|
||||
GroupName, UniqueID, LinkedToSym);
|
||||
} else if (MF->getSubtarget().getTargetTriple().isOSBinFormatMachO()) {
|
||||
InstMap = OutContext.getMachOSection("__DATA", "xray_instr_map", 0,
|
||||
SectionKind::getReadOnlyWithRel());
|
||||
|
@ -512,8 +512,8 @@ static const Comdat *getELFComdat(const GlobalValue *GV) {
|
||||
return C;
|
||||
}
|
||||
|
||||
static const MCSymbolELF *getAssociatedSymbol(const GlobalObject *GO,
|
||||
const TargetMachine &TM) {
|
||||
static const MCSymbolELF *getLinkedToSymbol(const GlobalObject *GO,
|
||||
const TargetMachine &TM) {
|
||||
MDNode *MD = GO->getMetadata(LLVMContext::MD_associated);
|
||||
if (!MD)
|
||||
return nullptr;
|
||||
@ -592,18 +592,18 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
|
||||
// A section can have at most one associated section. Put each global with
|
||||
// MD_associated in a unique section.
|
||||
unsigned UniqueID = MCContext::GenericSectionID;
|
||||
const MCSymbolELF *AssociatedSymbol = getAssociatedSymbol(GO, TM);
|
||||
if (AssociatedSymbol) {
|
||||
const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
|
||||
if (LinkedToSym) {
|
||||
UniqueID = NextUniqueID++;
|
||||
Flags |= ELF::SHF_LINK_ORDER;
|
||||
}
|
||||
|
||||
MCSectionELF *Section = getContext().getELFSection(
|
||||
SectionName, getELFSectionType(SectionName, Kind), Flags,
|
||||
getEntrySizeForKind(Kind), Group, UniqueID, AssociatedSymbol);
|
||||
getEntrySizeForKind(Kind), Group, UniqueID, LinkedToSym);
|
||||
// Make sure that we did not get some other section with incompatible sh_link.
|
||||
// This should not be possible due to UniqueID code above.
|
||||
assert(Section->getAssociatedSymbol() == AssociatedSymbol &&
|
||||
assert(Section->getLinkedToSymbol() == LinkedToSym &&
|
||||
"Associated symbol mismatch between sections");
|
||||
return Section;
|
||||
}
|
||||
@ -696,16 +696,16 @@ MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
|
||||
}
|
||||
EmitUniqueSection |= GO->hasComdat();
|
||||
|
||||
const MCSymbolELF *AssociatedSymbol = getAssociatedSymbol(GO, TM);
|
||||
if (AssociatedSymbol) {
|
||||
const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
|
||||
if (LinkedToSym) {
|
||||
EmitUniqueSection = true;
|
||||
Flags |= ELF::SHF_LINK_ORDER;
|
||||
}
|
||||
|
||||
MCSectionELF *Section = selectELFSectionForGlobal(
|
||||
getContext(), GO, Kind, getMangler(), TM, EmitUniqueSection, Flags,
|
||||
&NextUniqueID, AssociatedSymbol);
|
||||
assert(Section->getAssociatedSymbol() == AssociatedSymbol);
|
||||
&NextUniqueID, LinkedToSym);
|
||||
assert(Section->getLinkedToSymbol() == LinkedToSym);
|
||||
return Section;
|
||||
}
|
||||
|
||||
|
@ -1001,7 +1001,7 @@ void ELFWriter::writeSection(const SectionIndexMapTy &SectionIndexMap,
|
||||
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 @@ void ELFWriter::writeSection(const SectionIndexMapTy &SectionIndexMap,
|
||||
}
|
||||
|
||||
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 ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
|
||||
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);
|
||||
|
@ -332,7 +332,7 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
|
||||
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 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
|
||||
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::getELFNamedSection(const Twine &Prefix,
|
||||
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 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
|
||||
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;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ private:
|
||||
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 @@ bool ELFAsmParser::parseGroup(StringRef &GroupName) {
|
||||
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 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
|
||||
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 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
|
||||
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 @@ EndStmt:
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
|
@ -172,9 +172,9 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
|
||||
}
|
||||
|
||||
if (Flags & ELF::SHF_LINK_ORDER) {
|
||||
assert(AssociatedSymbol);
|
||||
assert(LinkedToSym);
|
||||
OS << ",";
|
||||
printName(OS, AssociatedSymbol->getName());
|
||||
printName(OS, LinkedToSym->getName());
|
||||
}
|
||||
|
||||
if (isUnique())
|
||||
|
@ -1,10 +0,0 @@
|
||||
// RUN: not llvm-mc -triple x86_64-pc-linux-gnu %s \
|
||||
// RUN: -filetype=obj -o %t.o 2>&1 | FileCheck %s
|
||||
|
||||
// Check we do not silently ignore invalid metadata symbol (123).
|
||||
// CHECK: error: invalid metadata symbol
|
||||
|
||||
.section .foo,"a"
|
||||
.quad 0
|
||||
|
||||
.section bar,"ao",@progbits,123
|
18
test/MC/ELF/section-linkorder-error.s
Normal file
18
test/MC/ELF/section-linkorder-error.s
Normal file
@ -0,0 +1,18 @@
|
||||
# RUN: not llvm-mc -triple x86_64 %s -o /dev/null 2>&1 | FileCheck %s
|
||||
|
||||
# CHECK: {{.*}}.s:[[# @LINE+1]]:30: error: expected linked-to symbol
|
||||
.section .link,"ao",@progbits
|
||||
|
||||
# CHECK: {{.*}}.s:[[# @LINE+1]]:31: error: invalid linked-to symbol
|
||||
.section .link,"ao",@progbits,123
|
||||
|
||||
# CHECK: {{.*}}.s:[[# @LINE+1]]:31: error: linked-to symbol is not in a section: foo
|
||||
.section .link,"ao",@progbits,foo
|
||||
|
||||
# CHECK: {{.*}}.s:[[# @LINE+2]]:31: error: linked-to symbol is not in a section: bar
|
||||
bar = 42
|
||||
.section .link,"ao",@progbits,bar
|
||||
|
||||
# CHECK: {{.*}}.s:[[# @LINE+2]]:31: error: linked-to symbol is not in a section: baz
|
||||
.quad baz
|
||||
.section .link,"ao",@progbits,baz
|
@ -1,5 +0,0 @@
|
||||
// RUN: not llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: error: symbol is not in a section: foo
|
||||
|
||||
.section .shf_metadata,"ao",@progbits,foo
|
@ -1,6 +0,0 @@
|
||||
// RUN: not llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: error: symbol is not in a section: foo
|
||||
|
||||
.quad foo
|
||||
.section .shf_metadata,"ao",@progbits,foo
|
@ -1,6 +0,0 @@
|
||||
// RUN: not llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: error: symbol is not in a section: foo
|
||||
|
||||
foo = 42
|
||||
.section .shf_metadata,"ao",@progbits,foo
|
@ -1,5 +0,0 @@
|
||||
// RUN: not llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: error: expected metadata symbol
|
||||
|
||||
.section .shf_metadata,"ao",@progbits
|
Loading…
Reference in New Issue
Block a user