Skip to content

Commit ece182b

Browse files
committed
[MC][ELF] Store signature group idx in MCSymbolELF
This removes the need for a reverse lookup map.
1 parent a9f1734 commit ece182b

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

llvm/include/llvm/MC/MCSymbolELF.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class MCSymbolELF : public MCSymbol {
1717
/// symbol has no size this field will be NULL.
1818
const MCExpr *SymbolSize = nullptr;
1919

20+
/// Group section index for signature symbols. Set by ELFWriter.
21+
mutable unsigned GroupIndex = 0;
22+
2023
public:
2124
MCSymbolELF(const MCSymbolTableEntry *Name, bool isTemporary)
2225
: MCSymbol(SymbolKindELF, Name, isTemporary) {}
@@ -44,6 +47,9 @@ class MCSymbolELF : public MCSymbol {
4447
void setIsSignature() const;
4548
bool isSignature() const;
4649

50+
void setGroupIndex(unsigned Index) const { GroupIndex = Index; }
51+
unsigned getGroupIndex() const { return GroupIndex; }
52+
4753
void setMemtag(bool Tagged);
4854
bool isMemtag() const;
4955

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,10 @@ struct ELFWriter {
169169
void writeSymbol(const MCAssembler &Asm, SymbolTableWriter &Writer,
170170
uint32_t StringIndex, ELFSymbolData &MSD);
171171

172-
// Map from a signature symbol to the group section index
173-
using RevGroupMapTy = DenseMap<const MCSymbol *, unsigned>;
174-
175172
/// Compute the symbol table data
176173
///
177174
/// \param Asm - The assembler.
178-
/// \param RevGroupMap - Maps a signature symbol to the group section.
179-
void computeSymbolTable(MCAssembler &Asm,
180-
const RevGroupMapTy &RevGroupMap);
175+
void computeSymbolTable(MCAssembler &Asm);
181176

182177
void writeAddrsigSection();
183178

@@ -599,8 +594,7 @@ bool ELFWriter::isInSymtab(const MCAssembler &Asm, const MCSymbolELF &Symbol,
599594
return true;
600595
}
601596

602-
void ELFWriter::computeSymbolTable(MCAssembler &Asm,
603-
const RevGroupMapTy &RevGroupMap) {
597+
void ELFWriter::computeSymbolTable(MCAssembler &Asm) {
604598
MCContext &Ctx = Asm.getContext();
605599
SymbolTableWriter Writer(*this, is64Bit());
606600

@@ -658,7 +652,7 @@ void ELFWriter::computeSymbolTable(MCAssembler &Asm,
658652
}
659653
} else if (Symbol.isUndefined()) {
660654
if (isSignature && !Used) {
661-
MSD.SectionIndex = RevGroupMap.lookup(&Symbol);
655+
MSD.SectionIndex = Symbol.getGroupIndex();
662656
if (MSD.SectionIndex >= ELF::SHN_LORESERVE)
663657
HasLargeSectionIndex = true;
664658
} else {
@@ -1104,8 +1098,6 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
11041098
Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0);
11051099
StringTableIndex = addToSectionTable(StrtabSection);
11061100

1107-
RevGroupMapTy RevGroupMap;
1108-
11091101
DenseMap<const MCSymbol *, SmallVector<const MCSectionELF *, 0>> GroupMembers;
11101102

11111103
// Write out the ELF header ...
@@ -1133,11 +1125,12 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
11331125
MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
11341126

11351127
if (SignatureSymbol) {
1136-
unsigned &GroupIdx = RevGroupMap[SignatureSymbol];
1128+
unsigned GroupIdx = SignatureSymbol->getGroupIndex();
11371129
if (!GroupIdx) {
11381130
MCSectionELF *Group =
11391131
Ctx.createELFGroupSection(SignatureSymbol, Section.isComdat());
11401132
GroupIdx = addToSectionTable(Group);
1133+
SignatureSymbol->setGroupIndex(GroupIdx);
11411134
Group->setAlignment(Align(4));
11421135
Groups.push_back(Group);
11431136
}
@@ -1184,7 +1177,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
11841177
}
11851178

11861179
// Compute symbol table information.
1187-
computeSymbolTable(Asm, RevGroupMap);
1180+
computeSymbolTable(Asm);
11881181

11891182
for (MCSectionELF *RelSection : Relocations) {
11901183
// Remember the offset into the file for this section.

0 commit comments

Comments
 (0)