SmallPtrSet<const MCSymbol *, 16> WeakrefUsedInReloc;
DenseMap<const MCSymbol *, const MCSymbol *> Renames;
- llvm::DenseMap<const MCSectionData *, std::vector<ELFRelocationEntry>>
- Relocations;
+ llvm::DenseMap<const MCSectionELF *, std::vector<ELFRelocationEntry>>
+ Relocations;
StringTableBuilder ShStrTabBuilder;
/// @}
SectionIndexMapTy &SectionIndexMap,
const RevGroupMapTy &RevGroupMap);
- void createRelocationSection(MCAssembler &Asm, const MCSectionData &SD);
+ void createRelocationSection(MCAssembler &Asm, const MCSectionELF &Sec);
void CompressDebugSections(MCAssembler &Asm, MCAsmLayout &Layout);
uint64_t Size, uint32_t Link, uint32_t Info,
uint64_t Alignment, uint64_t EntrySize);
- void writeRelocations(const MCAssembler &Asm, const MCSectionData &SD);
+ void writeRelocations(const MCAssembler &Asm, const MCSectionELF &Sec);
bool
IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target,
bool &IsPCRel, uint64_t &FixedValue) {
- const MCSectionData *FixupSection = Fragment->getParent();
+ const MCSectionData *FixupSectionD = Fragment->getParent();
+ const MCSectionELF &FixupSection =
+ cast<MCSectionELF>(FixupSectionD->getSection());
uint64_t C = Target.getConstant();
uint64_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
assert(!SymB.isAbsolute() && "Should have been folded");
const MCSection &SecB = SymB.getSection();
- if (&SecB != &FixupSection->getSection())
+ if (&SecB != &FixupSection)
Asm.getContext().FatalError(
Fixup.getLoc(), "Cannot represent a difference across sections");
ELFSec ? Asm.getContext().getOrCreateSectionSymbol(*ELFSec)
: nullptr;
ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend);
- Relocations[FixupSection].push_back(Rec);
+ Relocations[&FixupSection].push_back(Rec);
return;
}
UsedInReloc.insert(SymA);
}
ELFRelocationEntry Rec(FixupOffset, SymA, Type, Addend);
- Relocations[FixupSection].push_back(Rec);
+ Relocations[&FixupSection].push_back(Rec);
return;
}
unsigned Index = Sections.size();
SectionIndexMap[&Section] = Index;
maybeAddToGroup(Asm, Sections, RevGroupMap, Section, Index);
- createRelocationSection(Asm, SD);
+ createRelocationSection(Asm, Section);
}
}
}
void ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
- const MCSectionData &SD) {
- if (Relocations[&SD].empty())
+ const MCSectionELF &Sec) {
+ if (Relocations[&Sec].empty())
return;
MCContext &Ctx = Asm.getContext();
- const MCSectionELF &Section =
- static_cast<const MCSectionELF &>(SD.getSection());
-
- const StringRef SectionName = Section.getSectionName();
+ const StringRef SectionName = Sec.getSectionName();
std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";
RelaSectionName += SectionName;
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
unsigned Flags = 0;
- if (Section.getFlags() & ELF::SHF_GROUP)
+ if (Sec.getFlags() & ELF::SHF_GROUP)
Flags = ELF::SHF_GROUP;
const MCSectionELF *RelaSection = Ctx.createELFRelSection(
RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
- Flags, EntrySize, Section.getGroup(), &Section);
+ Flags, EntrySize, Sec.getGroup(), &Sec);
MCSectionData &RelSD = Asm.getOrCreateSectionData(*RelaSection);
RelSD.setAlignment(is64Bit() ? 8 : 4);
}
}
void ELFObjectWriter::writeRelocations(const MCAssembler &Asm,
- const MCSectionData &SD) {
- std::vector<ELFRelocationEntry> &Relocs = Relocations[&SD];
+ const MCSectionELF &Sec) {
+ std::vector<ELFRelocationEntry> &Relocs = Relocations[&Sec];
// Sort the relocation entries. Most targets just sort by Offset, but some
// (e.g., MIPS) have additional constraints.
uint64_t SecStart = OS.tell();
unsigned Type = Sec.getType();
- if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA) {
+ if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA)
writeDataSectionData(Asm, Layout, SD);
- } else {
- const MCSectionELF &RelocatedSec = *Sec.getAssociatedSection();
- MCSectionData &RelocatedSecD = Asm.getOrCreateSectionData(RelocatedSec);
- writeRelocations(Asm, RelocatedSecD);
- }
+ else
+ writeRelocations(Asm, *Sec.getAssociatedSection());
uint64_t SecEnd = OS.tell();
SectionOffsets.push_back(std::make_pair(SecStart, SecEnd));