65#define DEBUG_TYPE "reloc-info"
78class SymbolTableWriter {
83 std::vector<uint32_t> ShndxIndexes;
88 void createSymtabShndx();
93 SymbolTableWriter(ELFWriter &EWriter,
bool Is64Bit);
102 ELFObjectWriter &OWriter;
113 bool Used,
bool Renamed);
116 struct ELFSymbolData {
132 unsigned LastLocalSymbolIndex = ~0u;
134 unsigned StringTableIndex = ~0u;
136 unsigned SymbolTableIndex = ~0u;
139 std::vector<const MCSectionELF *> SectionTable;
154 bool IsLittleEndian, DwoMode Mode)
166 template <
typename T>
void write(
T Val) {
172 void writeSymbol(SymbolTableWriter &Writer,
uint32_t StringIndex,
176 using SectionOffsetsTy =
177 std::map<const MCSectionELF *, std::pair<uint64_t, uint64_t>>;
188 const SectionIndexMapTy &SectionIndexMap,
189 const RevGroupMapTy &RevGroupMap,
190 SectionOffsetsTy &SectionOffsets);
192 void writeAddrsigSection();
200 const SectionIndexMapTy &SectionIndexMap,
201 const SectionOffsetsTy &SectionOffsets);
214 void writeSection(
const SectionIndexMapTy &SectionIndexMap,
221 std::unique_ptr<MCELFObjectTargetWriter> TargetObjectWriter;
227 bool SeenGnuAbi =
false;
229 bool hasRelocationAddend()
const;
233 unsigned Type)
const;
236 ELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW)
237 : TargetObjectWriter(std::move(MOTW)) {}
239 void reset()
override {
249 bool IsPCRel)
const override;
264 void markGnuAbi()
override { SeenGnuAbi =
true; }
265 bool seenGnuAbi()
const {
return SeenGnuAbi; }
267 friend struct ELFWriter;
270class ELFSingleObjectWriter :
public ELFObjectWriter {
275 ELFSingleObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
277 : ELFObjectWriter(std::move(MOTW)),
OS(
OS),
278 IsLittleEndian(IsLittleEndian) {}
281 return ELFWriter(*
this,
OS, IsLittleEndian, ELFWriter::AllSections)
282 .writeObject(Asm, Layout);
285 friend struct ELFWriter;
288class ELFDwoObjectWriter :
public ELFObjectWriter {
293 ELFDwoObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
296 : ELFObjectWriter(std::move(MOTW)),
OS(
OS), DwoOS(DwoOS),
297 IsLittleEndian(IsLittleEndian) {}
302 Ctx.
reportError(Loc,
"A dwo section may not contain relocations");
306 Ctx.
reportError(Loc,
"A relocation may not refer to a dwo section");
313 uint64_t Size = ELFWriter(*
this,
OS, IsLittleEndian, ELFWriter::NonDwoOnly)
314 .writeObject(Asm, Layout);
315 Size += ELFWriter(*
this, DwoOS, IsLittleEndian, ELFWriter::DwoOnly)
316 .writeObject(Asm, Layout);
326 W.OS.write_zeros(NewOffset -
Offset);
330unsigned ELFWriter::addToSectionTable(
const MCSectionELF *Sec) {
331 SectionTable.push_back(Sec);
332 StrTabBuilder.add(Sec->
getName());
333 return SectionTable.size();
336void SymbolTableWriter::createSymtabShndx() {
337 if (!ShndxIndexes.empty())
340 ShndxIndexes.resize(NumWritten);
343template <
typename T>
void SymbolTableWriter::write(
T Value) {
344 EWriter.write(
Value);
347SymbolTableWriter::SymbolTableWriter(ELFWriter &EWriter,
bool Is64Bit)
348 : EWriter(EWriter), Is64Bit(Is64Bit), NumWritten(0) {}
358 if (!ShndxIndexes.empty()) {
360 ShndxIndexes.push_back(shndx);
362 ShndxIndexes.push_back(0);
386bool ELFWriter::is64Bit()
const {
387 return OWriter.TargetObjectWriter->is64Bit();
390bool ELFWriter::usesRela(
const MCSectionELF &Sec)
const {
391 return OWriter.hasRelocationAddend() &&
396void ELFWriter::writeHeader(
const MCAssembler &Asm) {
415 uint8_t OSABI = OWriter.TargetObjectWriter->getOSABI();
420 W.OS <<
char(OWriter.TargetObjectWriter->getABIVersion());
426 W.write<
uint16_t>(OWriter.TargetObjectWriter->getEMachine());
458 return Sym.getCommonAlignment()->value();
471 uint8_t
Type = newType;
508 if (!Symbol->isVariable() ||
509 !(
Value = dyn_cast<MCSymbolRefExpr>(Symbol->getVariableValue())) ||
513 Symbol = &cast<MCSymbolELF>(
Value->getSymbol());
518void ELFWriter::writeSymbol(SymbolTableWriter &Writer,
uint32_t StringIndex,
520 const auto &
Symbol = cast<MCSymbolELF>(*MSD.Symbol);
529 uint8_t Binding =
Symbol.getBinding();
536 uint8_t
Info = (Binding << 4) |
Type;
540 uint8_t Visibility =
Symbol.getVisibility();
546 const MCExpr *ESize = MSD.Symbol->getSize();
547 if (!ESize &&
Base) {
549 ESize =
Base->getSize();
556 while (
Sym->isVariable()) {
558 dyn_cast<MCSymbolRefExpr>(
Sym->getVariableValue(
false))) {
559 Sym = cast<MCSymbolELF>(&Expr->getSymbol());
562 ESize =
Sym->getSize();
576 Writer.writeSymbol(StringIndex, Info,
Value,
Size,
Other, MSD.SectionIndex,
581 bool Used,
bool Renamed) {
582 if (
Symbol.isVariable()) {
585 if (
const auto *
T = dyn_cast<MCTargetExpr>(Expr))
586 if (
T->inlineAssignedExpr())
615void ELFWriter::createMemtagRelocs(
MCAssembler &Asm) {
618 const auto &SymE = cast<MCSymbolELF>(
Sym);
619 if (!SymE.isMemtag())
621 if (MemtagRelocs ==
nullptr) {
622 MemtagRelocs = OWriter.TargetObjectWriter->getMemtagRelocsSection(
Asm.getContext());
623 if (MemtagRelocs ==
nullptr)
625 Asm.registerSection(*MemtagRelocs);
628 OWriter.Relocations[MemtagRelocs].push_back(Rec);
632void ELFWriter::computeSymbolTable(
634 const SectionIndexMapTy &SectionIndexMap,
const RevGroupMapTy &RevGroupMap,
635 SectionOffsetsTy &SectionOffsets) {
637 SymbolTableWriter Writer(*
this,
is64Bit());
644 SymbolTableIndex = addToSectionTable(SymtabSection);
649 Writer.writeSymbol(0, 0, 0, 0, 0, 0,
false);
651 std::vector<ELFSymbolData> LocalSymbolData;
652 std::vector<ELFSymbolData> ExternalSymbolData;
655 for (
const std::pair<std::string, size_t> &
F : FileNames)
656 StrTabBuilder.add(
F.first);
659 bool HasLargeSectionIndex =
false;
661 const auto &
Symbol = cast<MCSymbolELF>(It.value());
663 bool WeakrefUsed =
Symbol.isWeakrefUsedInReloc();
664 bool isSignature =
Symbol.isSignature();
666 if (!
isInSymtab(Layout, Symbol, Used || WeakrefUsed || isSignature,
667 OWriter.Renames.count(&Symbol)))
676 MSD.Symbol = cast<MCSymbolELF>(&Symbol);
677 MSD.Order = It.index();
682 if (
Symbol.isAbsolute()) {
684 }
else if (
Symbol.isCommon()) {
685 if (
Symbol.isTargetCommon()) {
686 MSD.SectionIndex =
Symbol.getIndex();
691 }
else if (
Symbol.isUndefined()) {
692 if (isSignature && !Used) {
693 MSD.SectionIndex = RevGroupMap.lookup(&Symbol);
695 HasLargeSectionIndex =
true;
712 "Undefined section reference: " +
Symbol.getName());
718 MSD.SectionIndex = SectionIndexMap.lookup(&Section);
719 assert(MSD.SectionIndex &&
"Invalid section index!");
721 HasLargeSectionIndex =
true;
729 StrTabBuilder.add(
Name);
733 LocalSymbolData.push_back(MSD);
735 ExternalSymbolData.push_back(MSD);
739 unsigned SymtabShndxSectionIndex = 0;
741 if (HasLargeSectionIndex) {
744 SymtabShndxSectionIndex = addToSectionTable(SymtabShndxSection);
748 StrTabBuilder.finalize();
752 auto FileNameIt = FileNames.begin();
753 if (!FileNames.empty())
754 FileNames[0].second = 0;
756 for (ELFSymbolData &MSD : LocalSymbolData) {
758 for (; FileNameIt != FileNames.end() && FileNameIt->second <= MSD.Order;
760 Writer.writeSymbol(StrTabBuilder.getOffset(FileNameIt->first),
768 : StrTabBuilder.getOffset(MSD.Name);
769 MSD.Symbol->setIndex(
Index++);
770 writeSymbol(Writer, StringIndex, MSD, Layout);
772 for (; FileNameIt != FileNames.end(); ++FileNameIt) {
773 Writer.writeSymbol(StrTabBuilder.getOffset(FileNameIt->first),
780 LastLocalSymbolIndex =
Index;
782 for (ELFSymbolData &MSD : ExternalSymbolData) {
783 unsigned StringIndex = StrTabBuilder.getOffset(MSD.Name);
784 MSD.Symbol->setIndex(
Index++);
785 writeSymbol(Writer, StringIndex, MSD, Layout);
790 SectionOffsets[SymtabSection] = std::make_pair(SecStart, SecEnd);
793 if (ShndxIndexes.
empty()) {
794 assert(SymtabShndxSectionIndex == 0);
797 assert(SymtabShndxSectionIndex != 0);
799 SecStart =
W.OS.tell();
801 SectionTable[SymtabShndxSectionIndex - 1];
804 SecEnd =
W.OS.tell();
805 SectionOffsets[SymtabShndxSection] = std::make_pair(SecStart, SecEnd);
808void ELFWriter::writeAddrsigSection() {
810 if (
Sym->getIndex() != 0)
816 if (OWriter.Relocations[&Sec].empty())
820 bool Rela = usesRela(Sec);
821 std::string RelaSectionName = Rela ?
".rela" :
".rel";
842bool ELFWriter::maybeWriteCompression(
847 if (
Size <= HdrSize + CompressedContents.
size())
870 auto &MC =
Asm.getContext();
871 const auto &MAI = MC.getAsmInfo();
874 if (CompressionType == DebugCompressionType::None ||
876 Asm.writeSectionData(
W.OS, &Section, Layout);
882 Asm.writeSectionData(VecOS, &Section, Layout);
884 ArrayRef(
reinterpret_cast<uint8_t *
>(UncompressedData.
data()),
885 UncompressedData.
size());
889 switch (CompressionType) {
890 case DebugCompressionType::None:
892 case DebugCompressionType::Zlib:
895 case DebugCompressionType::Zstd:
901 if (!maybeWriteCompression(ChType, UncompressedData.
size(), Compressed,
903 W.OS << UncompressedData;
926 WriteWord(Alignment ? Alignment->value() : 0);
927 WriteWord(EntrySize);
930void ELFWriter::writeRelocations(
const MCAssembler &Asm,
932 std::vector<ELFRelocationEntry> &Relocs = OWriter.Relocations[&Sec];
938 std::reverse(Relocs.begin(), Relocs.end());
941 OWriter.TargetObjectWriter->sortRelocs(Asm, Relocs);
943 const bool Rela = usesRela(Sec);
944 for (
unsigned i = 0, e = Relocs.size(); i != e; ++i) {
946 unsigned Index = Entry.Symbol ? Entry.Symbol->getIndex() : 0;
950 if (OWriter.TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS) {
953 write(OWriter.TargetObjectWriter->getRSsym(Entry.Type));
954 write(OWriter.TargetObjectWriter->getRType3(Entry.Type));
955 write(OWriter.TargetObjectWriter->getRType2(Entry.Type));
956 write(OWriter.TargetObjectWriter->getRType(Entry.Type));
974 if (OWriter.TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS) {
976 OWriter.TargetObjectWriter->getRType2(Entry.Type)) {
979 ERE32.setSymbolAndType(0, RType);
984 OWriter.TargetObjectWriter->getRType3(Entry.Type)) {
987 ERE32.setSymbolAndType(0, RType);
996void ELFWriter::writeSection(
const SectionIndexMapTy &SectionIndexMap,
1012 sh_link = SymbolTableIndex;
1013 assert(sh_link &&
".symtab not found");
1015 sh_info = SectionIndexMap.lookup(cast<MCSectionELF>(InfoSection));
1020 sh_link = StringTableIndex;
1021 sh_info = LastLocalSymbolIndex;
1027 sh_link = SymbolTableIndex;
1031 sh_link = SymbolTableIndex;
1032 sh_info = GroupSymbolIndex;
1040 if (
Sym &&
Sym->isInSection()) {
1042 sh_link = SectionIndexMap.lookup(Sec);
1046 WriteSecHdrEntry(StrTabBuilder.getOffset(
Section.getName()),
1048 sh_link, sh_info,
Section.getAlign(),
1052void ELFWriter::writeSectionHeader(
1053 const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap,
1054 const SectionOffsetsTy &SectionOffsets) {
1055 const unsigned NumSections = SectionTable.size();
1060 WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, std::nullopt, 0);
1066 GroupSymbolIndex = 0;
1068 GroupSymbolIndex =
Section->getGroup()->getIndex();
1070 const std::pair<uint64_t, uint64_t> &
Offsets =
1071 SectionOffsets.find(Section)->second;
1078 writeSection(SectionIndexMap, GroupSymbolIndex,
Offsets.first,
Size,
1089 StringTableIndex = addToSectionTable(StrtabSection);
1091 createMemtagRelocs(Asm);
1093 RevGroupMapTy RevGroupMap;
1094 SectionIndexMapTy SectionIndexMap;
1096 std::map<const MCSymbol *, std::vector<const MCSectionELF *>> GroupMembers;
1102 SectionOffsetsTy SectionOffsets;
1103 std::vector<MCSectionELF *>
Groups;
1104 std::vector<MCSectionELF *> Relocations;
1116 writeSectionData(Asm, Section, Layout);
1119 SectionOffsets[&
Section] = std::make_pair(SecStart, SecEnd);
1121 MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
1123 if (SignatureSymbol) {
1124 unsigned &GroupIdx = RevGroupMap[SignatureSymbol];
1128 GroupIdx = addToSectionTable(Group);
1132 std::vector<const MCSectionELF *> &Members =
1133 GroupMembers[SignatureSymbol];
1134 Members.push_back(&Section);
1136 Members.push_back(RelSection);
1139 SectionIndexMap[&
Section] = addToSectionTable(&Section);
1141 SectionIndexMap[RelSection] = addToSectionTable(RelSection);
1142 Relocations.push_back(RelSection);
1145 OWriter.TargetObjectWriter->addTargetSectionFlags(Ctx, Section);
1155 for (
const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
1156 uint32_t SecIndex = SectionIndexMap.lookup(Member);
1161 SectionOffsets[Group] = std::make_pair(SecStart, SecEnd);
1164 if (Mode == DwoOnly) {
1167 StrTabBuilder.finalize();
1170 if (OWriter.EmitAddrsigSection) {
1173 addToSectionTable(AddrsigSection);
1177 computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap,
1184 writeRelocations(Asm,
1188 SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
1191 if (OWriter.EmitAddrsigSection) {
1193 writeAddrsigSection();
1195 SectionOffsets[AddrsigSection] = std::make_pair(SecStart, SecEnd);
1201 StrTabBuilder.write(
W.OS);
1202 SectionOffsets[StrtabSection] = std::make_pair(SecStart,
W.OS.tell());
1208 writeSectionHeader(Layout, SectionIndexMap, SectionOffsets);
1210 uint16_t NumSections = support::endian::byte_swap<uint16_t>(
1212 : SectionTable.size() + 1,
1214 unsigned NumSectionsOffset;
1219 support::endian::byte_swap<uint64_t>(SectionHeaderOffset,
W.Endian);
1220 Stream.pwrite(
reinterpret_cast<char *
>(&Val),
sizeof(Val),
1225 support::endian::byte_swap<uint32_t>(SectionHeaderOffset,
W.Endian);
1226 Stream.pwrite(
reinterpret_cast<char *
>(&Val),
sizeof(Val),
1230 Stream.pwrite(
reinterpret_cast<char *
>(&NumSections),
sizeof(NumSections),
1233 return W.OS.tell() - StartOffset;
1236bool ELFObjectWriter::hasRelocationAddend()
const {
1237 return TargetObjectWriter->hasRelocationAddend();
1240void ELFObjectWriter::executePostLayoutBinding(
MCAssembler &Asm,
1246 const auto &
Symbol = cast<MCSymbolELF>(*S.
Sym);
1247 size_t Pos = AliasName.
find(
'@');
1257 cast<MCSymbolELF>(
Asm.getContext().getOrCreateSymbol(Prefix +
Tail));
1258 Asm.registerSymbol(*Alias);
1260 Alias->setVariableValue(
Value);
1264 Alias->setBinding(
Symbol.getBinding());
1265 Alias->setVisibility(
Symbol.getVisibility());
1266 Alias->setOther(
Symbol.getOther());
1273 Asm.getContext().reportError(S.
Loc,
"default version symbol " +
1274 AliasName +
" must be defined");
1278 if (Renames.count(&Symbol) && Renames[&Symbol] != Alias) {
1279 Asm.getContext().reportError(S.
Loc,
Twine(
"multiple versions for ") +
1284 Renames.insert(std::make_pair(&Symbol, Alias));
1288 if (
const MCSymbol *R = Renames.lookup(cast<MCSymbolELF>(
Sym)))
1290 if (
Sym->isInSection() &&
Sym->getName().startswith(
".L"))
1291 Sym =
Sym->getSection().getBeginSymbol();
1292 Sym->setUsedInReloc();
1299bool ELFObjectWriter::shouldRelocateWithSymbol(
const MCAssembler &Asm,
1303 unsigned Type)
const {
1340 if (
Sym->isUndefined())
1349 if (
Sym->isMemtag())
1352 unsigned Binding =
Sym->getBinding();
1383 if (
Sym->isInSection()) {
1384 auto &Sec = cast<MCSectionELF>(
Sym->getSection());
1392 if (TargetObjectWriter->getEMachine() ==
ELF::EM_386 &&
1393 Type == ELF::R_386_GOTOFF)
1403 if (TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS &&
1404 !hasRelocationAddend())
1420 if (
Asm.isThumbFunc(
Sym))
1423 if (TargetObjectWriter->needsRelocateWithSymbol(Val, *
Sym,
Type))
1428void ELFObjectWriter::recordRelocation(
MCAssembler &Asm,
1442 const auto &SymB = cast<MCSymbolELF>(RefB->getSymbol());
1443 if (SymB.isUndefined()) {
1445 Twine(
"symbol '") + SymB.getName() +
1446 "' can not be undefined in a subtraction expression");
1450 assert(!SymB.isAbsolute() &&
"Should have been folded");
1451 const MCSection &SecB = SymB.getSection();
1452 if (&SecB != &FixupSection) {
1454 "Cannot represent a difference across sections");
1458 assert(!IsPCRel &&
"should have been folded");
1465 const auto *SymA = RefA ? cast<MCSymbolELF>(&RefA->
getSymbol()) : nullptr;
1467 bool ViaWeakRef =
false;
1468 if (SymA && SymA->isVariable()) {
1469 const MCExpr *Expr = SymA->getVariableValue();
1470 if (
const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr)) {
1472 SymA = cast<MCSymbolELF>(&Inner->getSymbol());
1478 const MCSectionELF *SecA = (SymA && SymA->isInSection())
1479 ? cast<MCSectionELF>(&SymA->getSection())
1481 if (!checkRelocation(Ctx,
Fixup.getLoc(), &FixupSection, SecA))
1484 unsigned Type = TargetObjectWriter->getRelocType(Ctx,
Target,
Fixup, IsPCRel);
1485 const auto *Parent = cast<MCSectionELF>(Fragment->
getParent());
1487 bool RelocateWithSymbol =
1488 shouldRelocateWithSymbol(Asm,
Target, SymA,
C,
Type) ||
1492 FixedValue = !RelocateWithSymbol && SymA && !SymA->isUndefined()
1495 if (hasRelocationAddend()) {
1496 Addend = FixedValue;
1500 if (!RelocateWithSymbol) {
1501 const auto *SectionSymbol =
1504 SectionSymbol->setUsedInReloc();
1506 Relocations[&FixupSection].push_back(Rec);
1521 Relocations[&FixupSection].push_back(Rec);
1524bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
1526 bool InSet,
bool IsPCRel)
const {
1527 const auto &SymA = cast<MCSymbolELF>(SA);
1538std::unique_ptr<MCObjectWriter>
1541 return std::make_unique<ELFSingleObjectWriter>(std::move(MOTW),
OS,
1545std::unique_ptr<MCObjectWriter>
1548 bool IsLittleEndian) {
1549 return std::make_unique<ELFDwoObjectWriter>(std::move(MOTW),
OS, DwoOS,
#define offsetof(TYPE, MEMBER)
BlockVerifier::State From
Analysis containing CSE Info
Given that RA is a live value
This file defines the DenseMap class.
static uint8_t mergeTypeForSet(uint8_t origType, uint8_t newType)
static bool isIFunc(const MCSymbolELF *Symbol)
std::optional< std::vector< StOtherPiece > > Other
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
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.
Generic interface to target specific assembler backends.
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Encapsulates the layout of an assembly file at a particular point in time.
const MCSymbol * getBaseSymbol(const MCSymbol &Symbol) const
If this symbol is equivalent to A + Constant, return A.
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
Context object for machine code objects.
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)
void reportError(SMLoc L, const Twine &Msg)
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
Base class for the full range of assembler expressions which are needed for parsing.
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
MCSection * getParent() const
Defines the object file and target independent interfaces used by the assembler backend to write nati...
virtual void executePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
virtual void reset()
lifetime management
virtual void markGnuAbi()
ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN).
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B, bool InSet) const
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
This represents a section on linux, lots of unix variants and some bare metal systems.
const MCSection * getLinkedToSection() const
unsigned getFlags() const
const MCSymbolELF * getGroup() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
void setAlignment(Align Value)
StringRef getName() const
MCSymbol * getBeginSymbol()
void setIsWeakrefUsedInReloc() const
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
VariantKind getKind() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void setUsedInReloc() const
This represents an "assembler immediate".
const MCSymbolRefExpr * getSymA() const
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Represents a location in source code.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool startswith(StringRef Prefix) const
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
bool endswith(StringRef Suffix) const
static constexpr size_t npos
Utility for building string tables with deduplicated suffixes.
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.
An abstract base class for streams implementations that also support a pwrite operation.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ 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.
static const char ElfMagic[]
@ SHT_LLVM_CALL_GRAPH_PROFILE
void compress(Params P, ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &Output)
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
This is an optimization pass for GlobalISel generic memory operations.
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.
std::unique_ptr< MCObjectWriter > createELFObjectWriter(std::unique_ptr< MCELFObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
Construct a new ELF writer instance.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
std::unique_ptr< MCObjectWriter > createELFDwoObjectWriter(std::unique_ptr< MCELFObjectTargetWriter > MOTW, raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS, bool IsLittleEndian)
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
@ Ref
The access may reference the value stored in memory.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
This struct is a compact representation of a valid (non-zero power of two) alignment.
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)
@ FKF_IsPCRel
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
unsigned Flags
Flags describing additional information on this fixup kind.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Adapter to write values to a stream in a particular byte order.