58#define DEBUG_TYPE "elf-object-writer"
63STATISTIC(ELFHeaderBytes,
"Total size of ELF headers");
64STATISTIC(SectionHeaderBytes,
"Total size of section headers table");
65STATISTIC(AllocTextBytes,
"Total size of SHF_ALLOC text sections");
66STATISTIC(AllocROBytes,
"Total size of SHF_ALLOC readonly sections");
67STATISTIC(AllocRWBytes,
"Total size of SHF_ALLOC read-write sections");
68STATISTIC(StrtabBytes,
"Total size of SHT_STRTAB sections");
69STATISTIC(SymtabBytes,
"Total size of SHT_SYMTAB sections");
70STATISTIC(RelocationBytes,
"Total size of relocation sections");
71STATISTIC(DynsymBytes,
"Total size of SHT_DYNSYM sections");
74 "Total size of debug info sections (not including those written to .dwo)");
75STATISTIC(UnwindBytes,
"Total size of unwind sections");
76STATISTIC(OtherBytes,
"Total size of uncategorized sections");
77STATISTIC(DwoBytes,
"Total size of sections written to .dwo file");
87class SymbolTableWriter {
92 std::vector<uint32_t> ShndxIndexes;
97 void createSymtabShndx();
102 SymbolTableWriter(ELFWriter &EWriter,
bool Is64Bit);
104 void writeSymbol(uint32_t
name, uint8_t
info, uint64_t value, uint64_t
size,
105 uint8_t other, uint32_t shndx,
bool Reserved);
107 ArrayRef<uint32_t> getShndxIndexes()
const {
return ShndxIndexes; }
112 ELFObjectWriter &OWriter;
113 support::endian::Writer W;
121 uint64_t symbolValue(
const MCSymbol &Sym);
125 struct ELFSymbolData {
126 const MCSymbolELF *Symbol;
128 uint32_t SectionIndex;
141 unsigned LastLocalSymbolIndex = ~0
u;
143 unsigned StringTableIndex = ~0
u;
145 unsigned SymbolTableIndex = ~0
u;
148 std::vector<MCSectionELF *> SectionTable;
149 unsigned addToSectionTable(MCSectionELF *Sec);
154 uint64_t align(Align Alignment);
156 bool maybeWriteCompression(uint32_t ChType, uint64_t
Size,
157 SmallVectorImpl<uint8_t> &CompressedContents,
161 ELFWriter(MCAssembler &Asm, ELFObjectWriter &OWriter, raw_pwrite_stream &OS,
162 bool IsLittleEndian, DwoMode Mode)
163 : Asm(Asm), OWriter(OWriter),
168 MCContext &
getContext()
const {
return Asm.getContext(); }
170 void writeWord(uint64_t Word) {
172 W.write<uint64_t>(
Word);
174 W.write<uint32_t>(
Word);
177 template <
typename T>
void write(
T Val) {
183 void writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
187 using RevGroupMapTy = DenseMap<const MCSymbol *, unsigned>;
193 void computeSymbolTable(
const RevGroupMapTy &RevGroupMap);
195 void writeAddrsigSection();
197 MCSectionELF *createRelocationSection(MCContext &Ctx,
198 const MCSectionELF &Sec);
200 void writeSectionHeaders();
202 void writeSectionData(MCSection &Sec);
204 void writeSectionHeaderEntry(uint32_t Name, uint32_t
Type, uint64_t Flags,
206 uint32_t Link, uint32_t Info,
207 MaybeAlign Alignment, uint64_t EntrySize);
209 void writeRelocations(
const MCSectionELF &Sec);
211 uint64_t writeObject();
212 void writeSectionHeader(uint32_t GroupSymbolIndex, uint64_t
Offset,
213 uint64_t
Size,
const MCSectionELF &Section);
220 W.OS.write_zeros(NewOffset -
Offset);
224unsigned ELFWriter::addToSectionTable(MCSectionELF *Sec) {
225 SectionTable.push_back(Sec);
227 return SectionTable.size();
230void SymbolTableWriter::createSymtabShndx() {
231 if (!ShndxIndexes.empty())
234 ShndxIndexes.resize(NumWritten);
237template <
typename T>
void SymbolTableWriter::write(
T Value) {
238 EWriter.write(
Value);
241SymbolTableWriter::SymbolTableWriter(ELFWriter &EWriter,
bool Is64Bit)
242 : EWriter(EWriter), Is64Bit(Is64Bit), NumWritten(0) {}
252 if (!ShndxIndexes.empty()) {
254 ShndxIndexes.push_back(shndx);
256 ShndxIndexes.push_back(0);
270 write(uint32_t(value));
280bool ELFWriter::is64Bit()
const {
285void ELFWriter::writeHeader() {
328 W.write<uint16_t>(
is64Bit() ?
sizeof(ELF::Elf64_Ehdr)
329 : sizeof(
ELF::Elf32_Ehdr));
331 W.write<uint16_t>(0);
332 W.write<uint16_t>(0);
335 W.write<uint16_t>(
is64Bit() ?
sizeof(ELF::Elf64_Shdr)
336 : sizeof(
ELF::Elf32_Shdr));
339 W.write<uint16_t>(0);
343 W.write<uint16_t>(StringTableIndex);
346uint64_t ELFWriter::symbolValue(
const MCSymbol &Sym) {
351 if (!
Asm.getSymbolOffset(Sym, Res))
354 if (
Asm.isThumbFunc(&Sym))
398 if (!Symbol->isVariable() ||
400 Value->getSpecifier() ||
409void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
410 ELFSymbolData &MSD) {
411 auto &
Symbol =
static_cast<const MCSymbolELF &
>(*MSD.Symbol);
412 auto *
Base =
static_cast<const MCSymbolELF *
>(
Asm.getBaseSymbol(Symbol));
430 uint8_t Visibility =
Symbol.getVisibility();
433 uint64_t
Value = symbolValue(*MSD.Symbol);
436 const MCExpr *ESize = MSD.Symbol->getSize();
437 if (!ESize &&
Base) {
439 ESize =
Base->getSize();
445 const MCSymbolELF *Sym = &
Symbol;
448 Sym =
static_cast<const MCSymbolELF *
>(&Expr->getSymbol());
465 Writer.writeSymbol(StringIndex, Info,
Value,
Size,
Other, MSD.SectionIndex,
469bool ELFWriter::isInSymtab(
const MCSymbolELF &Symbol) {
473 if (OWriter.
Renames.count(&Symbol))
476 if (
Symbol.isVariable()) {
477 const MCExpr *Expr =
Symbol.getVariableValue();
480 if (
T->inlineAssignedExpr())
486 if (
Symbol.isUndefined()) {
488 Asm.getBaseSymbol(Symbol);
499void ELFWriter::computeSymbolTable(
const RevGroupMapTy &RevGroupMap) {
500 MCContext &Ctx =
Asm.getContext();
501 SymbolTableWriter Writer(*
this,
is64Bit());
505 MCSectionELF *SymtabSection =
508 SymbolTableIndex = addToSectionTable(SymtabSection);
510 uint64_t SecStart = align(SymtabSection->
getAlign());
513 Writer.writeSymbol(0, 0, 0, 0, 0, 0,
false);
515 std::vector<ELFSymbolData> LocalSymbolData;
516 std::vector<ELFSymbolData> ExternalSymbolData;
519 for (
const std::pair<std::string, size_t> &
F : FileNames)
520 StrTabBuilder.
add(
F.first);
523 bool HasLargeSectionIndex =
false;
525 auto &
Symbol =
static_cast<const MCSymbolELF &
>(It.value());
535 MSD.Symbol =
static_cast<const MCSymbolELF *
>(&
Symbol);
536 MSD.Order = It.index();
541 if (
Symbol.isAbsolute()) {
543 }
else if (
Symbol.isCommon()) {
544 auto Shndx =
Symbol.getIndex();
549 MSD.SectionIndex = Shndx;
550 }
else if (
Symbol.isUndefined()) {
552 MSD.SectionIndex = RevGroupMap.lookup(&Symbol);
554 HasLargeSectionIndex =
true;
560 static_cast<const MCSectionELF &
>(
Symbol.getSection());
564 MSD.SectionIndex =
Section.getOrdinal();
565 assert(MSD.SectionIndex &&
"Invalid section index!");
567 HasLargeSectionIndex =
true;
581 StrTabBuilder.
add(Name);
585 LocalSymbolData.push_back(MSD);
587 ExternalSymbolData.push_back(MSD);
591 unsigned SymtabShndxSectionIndex = 0;
593 if (HasLargeSectionIndex) {
594 MCSectionELF *SymtabShndxSection =
596 SymtabShndxSectionIndex = addToSectionTable(SymtabShndxSection);
604 auto FileNameIt = FileNames.begin();
605 if (!FileNames.empty())
606 FileNames[0].second = 0;
608 for (ELFSymbolData &MSD : LocalSymbolData) {
610 for (; FileNameIt != FileNames.end() && FileNameIt->second <= MSD.Order;
612 Writer.writeSymbol(StrTabBuilder.
getOffset(FileNameIt->first),
621 MSD.Symbol->setIndex(Index++);
622 writeSymbol(Writer, StringIndex, MSD);
624 for (; FileNameIt != FileNames.end(); ++FileNameIt) {
625 Writer.writeSymbol(StrTabBuilder.
getOffset(FileNameIt->first),
632 LastLocalSymbolIndex =
Index;
634 for (ELFSymbolData &MSD : ExternalSymbolData) {
635 unsigned StringIndex = StrTabBuilder.
getOffset(MSD.Name);
636 MSD.Symbol->setIndex(Index++);
637 writeSymbol(Writer, StringIndex, MSD);
641 uint64_t SecEnd =
W.OS.tell();
644 ArrayRef<uint32_t> ShndxIndexes = Writer.getShndxIndexes();
645 if (ShndxIndexes.
empty()) {
646 assert(SymtabShndxSectionIndex == 0);
649 assert(SymtabShndxSectionIndex != 0);
651 SecStart =
W.OS.tell();
652 MCSectionELF *SymtabShndxSection = SectionTable[SymtabShndxSectionIndex - 1];
653 for (uint32_t Index : ShndxIndexes)
655 SecEnd =
W.OS.tell();
656 SymtabShndxSection->
setOffsets(SecStart, SecEnd);
659void ELFWriter::writeAddrsigSection() {
665MCSectionELF *ELFWriter::createRelocationSection(MCContext &Ctx,
666 const MCSectionELF &Sec) {
677 MCSectionELF *RelaSection =
683 const bool Rela = OWriter.
usesRela(TO, Sec);
686 EntrySize =
is64Bit() ?
sizeof(ELF::Elf64_Rela) : sizeof(
ELF::Elf32_Rela);
688 EntrySize =
is64Bit() ?
sizeof(ELF::Elf64_Rel) : sizeof(
ELF::Elf32_Rel);
690 MCSectionELF *RelaSection =
699bool ELFWriter::maybeWriteCompression(
700 uint32_t ChType, uint64_t
Size,
701 SmallVectorImpl<uint8_t> &CompressedContents, Align Alignment) {
703 is64Bit() ?
sizeof(ELF::Elf64_Chdr) : sizeof(
ELF::Elf32_Chdr);
704 if (
Size <= HdrSize + CompressedContents.
size())
722void ELFWriter::writeSectionData(MCSection &Sec) {
723 MCSectionELF &
Section =
static_cast<MCSectionELF &
>(Sec);
725 auto &Ctx =
Asm.getContext();
728 if (CompressionType == DebugCompressionType::None ||
730 Asm.writeSectionData(
W.OS, &Section);
735 raw_svector_ostream VecOS(UncompressedData);
736 Asm.writeSectionData(VecOS, &Section);
737 ArrayRef<uint8_t> Uncompressed =
738 ArrayRef(
reinterpret_cast<uint8_t *
>(UncompressedData.
data()),
739 UncompressedData.
size());
741 SmallVector<uint8_t, 128> Compressed;
743 switch (CompressionType) {
744 case DebugCompressionType::None:
746 case DebugCompressionType::Zlib:
749 case DebugCompressionType::Zstd:
755 if (!maybeWriteCompression(ChType, UncompressedData.
size(), Compressed,
757 W.OS << UncompressedData;
768void ELFWriter::writeSectionHeaderEntry(uint32_t Name, uint32_t
Type,
769 uint64_t Flags, uint64_t
Address,
771 uint32_t Link, uint32_t Info,
772 MaybeAlign Alignment,
773 uint64_t EntrySize) {
774 W.write<uint32_t>(
Name);
775 W.write<uint32_t>(
Type);
780 W.write<uint32_t>(Link);
781 W.write<uint32_t>(
Info);
782 writeWord(Alignment ? Alignment->value() : 0);
783 writeWord(EntrySize);
788 using uint = std::conditional_t<Is64, uint64_t, uint32_t>;
790 uint32_t SymIdx = R.Symbol ? R.Symbol->getIndex() : 0;
792 std::make_signed_t<uint>(R.Addend)};
796void ELFWriter::writeRelocations(
const MCSectionELF &Sec) {
797 std::vector<ELFRelocationEntry> &Relocs = OWriter.
Relocations[&Sec];
798 const MCTargetOptions *TO =
getContext().getTargetOptions();
799 const bool Rela = OWriter.
usesRela(TO, Sec);
805 for (
const ELFRelocationEntry &Entry : Relocs) {
806 uint32_t SymIdx =
Entry.Symbol ?
Entry.Symbol->getIndex() : 0;
809 write(uint32_t(SymIdx));
818 ELF::Elf32_Rela ERE32;
839 }
else if (TO && TO->
Crel) {
845 for (
const ELFRelocationEntry &Entry : Relocs) {
846 uint32_t Symidx =
Entry.Symbol ?
Entry.Symbol->getIndex() : 0;
866void ELFWriter::writeSectionHeader(uint32_t GroupSymbolIndex, uint64_t
Offset,
867 uint64_t
Size,
const MCSectionELF &Section) {
868 uint64_t sh_link = 0;
869 uint64_t sh_info = 0;
882 sh_link = SymbolTableIndex;
883 assert(sh_link &&
".symtab not found");
884 const MCSection *InfoSection =
Section.getLinkedToSection();
890 sh_link = StringTableIndex;
891 sh_info = LastLocalSymbolIndex;
897 sh_link = SymbolTableIndex;
901 sh_link = SymbolTableIndex;
902 sh_info = GroupSymbolIndex;
914 writeSectionHeaderEntry(
920void ELFWriter::writeSectionHeaders() {
921 uint64_t
Start =
W.OS.tell();
922 const unsigned NumSections = SectionTable.size();
925 uint64_t FirstSectionSize =
927 writeSectionHeaderEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, std::nullopt,
930 for (
const MCSectionELF *Section : SectionTable) {
931 uint32_t GroupSymbolIndex;
934 GroupSymbolIndex = 0;
936 GroupSymbolIndex =
Section->getGroup()->getIndex();
941 Size =
Asm.getSectionAddressSize(*Section);
945 auto SectionHasFlag = [&](uint64_t
Flag) ->
bool {
949 if (
Mode == DwoOnly) {
950 stats::DwoBytes +=
Size;
951 }
else if (
Section->getName().starts_with(
".debug")) {
952 stats::DebugBytes +=
Size;
953 }
else if (
Section->getName().starts_with(
".eh_frame")) {
954 stats::UnwindBytes +=
Size;
957 stats::AllocTextBytes +=
Size;
959 stats::AllocRWBytes +=
Size;
961 stats::AllocROBytes +=
Size;
966 stats::StrtabBytes +=
Size;
969 stats::SymtabBytes +=
Size;
972 stats::DynsymBytes +=
Size;
977 stats::RelocationBytes +=
Size;
980 stats::OtherBytes +=
Size;
985 writeSectionHeader(GroupSymbolIndex,
Offsets.first,
Size, *Section);
988 stats::SectionHeaderBytes +=
W.OS.tell() -
Start;
991uint64_t ELFWriter::writeObject() {
992 uint64_t StartOffset =
W.OS.tell();
995 MCSectionELF *StrtabSection =
997 StringTableIndex = addToSectionTable(StrtabSection);
999 RevGroupMapTy RevGroupMap;
1004 stats::ELFHeaderBytes +=
W.OS.tell() - StartOffset;
1009 SmallVector<unsigned, 0> GroupMap;
1011 for (MCSection &Sec : Asm) {
1012 MCSectionELF &
Section =
static_cast<MCSectionELF &
>(Sec);
1019 const uint64_t SecStart = align(
Section.getAlign());
1021 const MCSymbolELF *SignatureSymbol =
Section.getGroup();
1022 writeSectionData(Section);
1024 uint64_t SecEnd =
W.OS.tell();
1025 Section.setOffsets(SecStart, SecEnd);
1027 MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
1029 unsigned *GroupIdxEntry =
nullptr;
1030 if (SignatureSymbol) {
1031 GroupIdxEntry = &RevGroupMap[SignatureSymbol];
1032 if (!*GroupIdxEntry) {
1033 MCSectionELF *Group =
1035 *GroupIdxEntry = addToSectionTable(Group);
1038 GroupMap.
resize(*GroupIdxEntry + 1);
1039 GroupMap[*GroupIdxEntry] =
Groups.size();
1040 Groups.emplace_back(Group, SmallVector<unsigned>{});
1044 Section.setOrdinal(addToSectionTable(&Section));
1046 RelSection->
setOrdinal(addToSectionTable(RelSection));
1050 if (GroupIdxEntry) {
1051 auto &Members =
Groups[GroupMap[*GroupIdxEntry]];
1052 Members.second.push_back(
Section.getOrdinal());
1054 Members.second.push_back(RelSection->
getOrdinal());
1058 for (
auto &[Group, Members] :
Groups) {
1060 const uint64_t SecStart = align(Group->
getAlign());
1063 W.write<
unsigned>(Members);
1065 uint64_t SecEnd =
W.OS.tell();
1069 if (
Mode == DwoOnly) {
1074 MCSectionELF *AddrsigSection;
1078 addToSectionTable(AddrsigSection);
1082 computeSymbolTable(RevGroupMap);
1084 for (MCSectionELF *RelSection : Relocations) {
1086 const uint64_t SecStart = align(RelSection->
getAlign());
1091 uint64_t SecEnd =
W.OS.tell();
1096 uint64_t SecStart =
W.OS.tell();
1097 writeAddrsigSection();
1098 uint64_t SecEnd =
W.OS.tell();
1099 AddrsigSection->
setOffsets(SecStart, SecEnd);
1104 uint64_t SecStart =
W.OS.tell();
1105 StrTabBuilder.
write(
W.OS);
1112 writeSectionHeaders();
1116 : SectionTable.size() + 1,
1118 unsigned NumSectionsOffset;
1120 auto &Stream =
static_cast<raw_pwrite_stream &
>(
W.OS);
1124 Stream.pwrite(
reinterpret_cast<char *
>(&Val),
sizeof(Val),
1125 offsetof(ELF::Elf64_Ehdr, e_shoff));
1126 NumSectionsOffset =
offsetof(ELF::Elf64_Ehdr, e_shnum);
1130 Stream.pwrite(
reinterpret_cast<char *
>(&Val),
sizeof(Val),
1131 offsetof(ELF::Elf32_Ehdr, e_shoff));
1132 NumSectionsOffset =
offsetof(ELF::Elf32_Ehdr, e_shnum);
1134 Stream.pwrite(
reinterpret_cast<char *
>(&NumSections),
sizeof(NumSections),
1137 return W.OS.tell() - StartOffset;
1151 ELFHeaderEFlags = 0;
1176 auto &Symbol =
static_cast<const MCSymbolELF &
>(*S.Sym);
1177 size_t Pos = AliasName.
find(
'@');
1184 Tail = Rest.
substr(Symbol.isUndefined() ? 2 : 1);
1187 Asm->getContext().getOrCreateSymbol(Prefix +
Tail));
1188 Asm->registerSymbol(*Alias);
1190 Alias->setVariableValue(
Value);
1194 Alias->setBinding(Symbol.getBinding());
1195 Alias->setVisibility(Symbol.getVisibility());
1196 Alias->setOther(Symbol.getOther());
1198 if (!Symbol.isUndefined() && S.KeepOriginalSym)
1201 if (Symbol.isUndefined() && Rest.
starts_with(
"@@") &&
1203 Asm->getContext().reportError(S.Loc,
"default version symbol " +
1204 AliasName +
" must be defined");
1208 if (
auto It =
Renames.find(&Symbol);
1209 It !=
Renames.end() && It->second != Alias) {
1210 Asm->getContext().reportError(S.Loc,
Twine(
"multiple versions for ") +
1215 Renames.insert(std::make_pair(&Symbol, Alias));
1232 if (!Alias->isRegistered())
1234 auto *Expr = Alias->getVariableValue();
1236 auto &Sym =
static_cast<const MCSymbolELF &
>(Inner->getSymbol());
1237 if (
Asm->registerSymbol(Sym))
1248 unsigned Type)
const {
1272 Type == ELF::R_386_GOTOFF)
1306 "A relocation may not refer to a dwo section");
1315 auto &Section =
static_cast<const MCSectionELF &
>(*
F.getParent());
1320 (SymA && SymA->isInSection())
1321 ?
static_cast<const MCSectionELF *
>(&SymA->getSection())
1326 bool IsPCRel =
Fixup.isPCRel();
1329 if (
auto *RefB =
Target.getSubSym()) {
1330 auto &SymB =
static_cast<const MCSymbolELF &
>(*RefB);
1331 if (SymB.isUndefined()) {
1332 Ctx.reportError(
Fixup.getLoc(),
1333 Twine(
"symbol '") + SymB.getName() +
1334 "' can not be undefined in a subtraction expression");
1338 assert(!SymB.isAbsolute() &&
"Should have been folded");
1339 const MCSection &SecB = SymB.getSection();
1340 if (&SecB != &Section) {
1341 Ctx.reportError(
Fixup.getLoc(),
1342 "Cannot represent a difference across sections");
1346 assert(!IsPCRel &&
"should have been folded");
1348 Addend += FixupOffset -
Asm->getSymbolOffset(SymB);
1361 bool UseSectionSym = SymA && SymA->getBinding() ==
ELF::STB_LOCAL &&
1362 !SymA->isUndefined() &&
1364 if (UseSectionSym) {
1369 Ctx.getAsmInfo()->getInternalSymbolPrefix()));
1372 Addend +=
Asm->getSymbolOffset(*SymA);
1378 SymA->setUsedInReloc();
1380 FixedValue =
usesRela(TO, Section) ? 0 : Addend;
1393 auto &SymA =
static_cast<const MCSymbolELF &
>(SA);
1406 DwoOS ? ELFWriter::NonDwoOnly : ELFWriter::AllSections)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
DXIL Resource Implicit Binding
This file defines the DenseMap class.
static uint8_t mergeTypeForSet(uint8_t origType, uint8_t newType)
static void encodeCrel(ArrayRef< ELFRelocationEntry > Relocs, raw_ostream &OS)
static bool isIFunc(const MCSymbolELF *Symbol)
#define offsetof(TYPE, MEMBER)
PowerPC TLS Dynamic Call Fixup
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool isInSymtab(const MCSymbolWasm &Sym)
static bool isDwoSection(const MCSection &Sec)
static bool is64Bit(const char *name)
static const X86InstrFMA3Group Groups[]
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
std::unique_ptr< MCELFObjectTargetWriter > TargetObjectWriter
ELFObjectWriter(std::unique_ptr< MCELFObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
void setAssembler(MCAssembler *Asm) override
SmallVector< const MCSymbolELF *, 0 > Weakrefs
bool checkRelocation(SMLoc Loc, const MCSectionELF *From, const MCSectionELF *To)
unsigned getELFHeaderEFlags() const
void reset() override
lifetime management
std::optional< uint8_t > OverrideABIVersion
uint64_t writeObject() override
Write the object file and returns the number of bytes written.
DenseMap< const MCSectionELF *, std::vector< ELFRelocationEntry > > Relocations
void executePostLayoutBinding() override
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const override
SmallVector< Symver, 0 > Symvers
bool hasRelocationAddend() const
void recordRelocation(const MCFragment &F, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) override
Record a relocation entry.
raw_pwrite_stream * DwoOS
bool usesRela(const MCTargetOptions *TO, const MCSectionELF &Sec) const
bool useSectionSymbol(const MCValue &Val, const MCSymbolELF *Sym, uint64_t C, unsigned Type) const
DenseMap< const MCSymbolELF *, const MCSymbolELF * > Renames
Context object for machine code objects.
LLVM_ABI const MCTargetOptions * getTargetOptions() const
LLVM_ABI MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
LLVM_ABI MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_ABI bool evaluateKnownAbsolute(int64_t &Res, const MCAssembler &Asm) const
Aggressive variant of evaluateAsRelocatable when relocations are unavailable (e.g.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
MCSection * getParent() const
MutableArrayRef< std::pair< std::string, size_t > > getFileNames()
virtual void setAssembler(MCAssembler *A)
bool getEmitAddrsigSection()
std::vector< const MCSymbol * > & getAddrsigSyms()
virtual void reset()
lifetime management
std::vector< const MCSymbol * > AddrsigSyms
MCContext & getContext() const
This represents a section on linux, lots of unix variants and some bare metal systems.
const MCSection * getLinkedToSection() const
unsigned getFlags() const
void setOffsets(uint64_t Start, uint64_t End)
const MCSymbolELF * getGroup() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
void setAlignment(Align Value)
unsigned getOrdinal() const
void setOrdinal(unsigned Value)
StringRef getName() const
MCSymbol * getBeginSymbol()
const MCExpr * getSize() const
Represent a reference to a symbol from inside an expression.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
bool isCommon() const
Is this a 'common' symbol.
StringRef getName() const
getName - Get the symbol name.
bool isVariable() const
isVariable - Check if this is a variable symbol.
MaybeAlign getCommonAlignment() const
Return the alignment of a 'common' symbol.
void setUsedInReloc() const
uint32_t getIndex() const
Get the (implementation defined) index.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
RelocSectionSymType RelocSectionSym
DebugCompressionType CompressDebugSections
Represents a location in source code.
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
StringRef - Represent a constant reference to a string, i.e.
static constexpr size_t npos
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
LLVM_ABI size_t getOffset(CachedHashStringRef S) const
Get the offest of a string in the string table.
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority=0)
Add a string to the builder.
LLVM_ABI void write(raw_ostream &OS) const
LLVM_ABI void finalize()
Analyze the strings and build the final table.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
An abstract base class for streams implementations that also support a pwrite operation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ C
The default llvm calling convention, compatible with C.
void encodeCrel(raw_ostream &OS, RelocsTy Relocs, F ToCrel)
static const char ElfMagic[]
@ SHT_LLVM_CALL_GRAPH_PROFILE
Flag
These should be considered private to the implementation of the MCInstrDesc class.
LLVM_ABI void compress(Params P, ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &Output)
support::ulittle32_t Word
bool isRelocRelocation(MCFixupKind FixupKind)
Context & getContext() const
value_type byte_swap(value_type value, endianness endian)
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
@ FirstLiteralRelocationKind
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue)
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
void setSymbolAndType(Elf32_Word s, unsigned char t)
void setSymbolAndType(Elf64_Word s, Elf64_Word t)