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;
153 bool IsLittleEndian, DwoMode Mode)
165 template <
typename T>
void write(
T Val) {
171 void writeSymbol(SymbolTableWriter &Writer,
uint32_t StringIndex,
175 using SectionOffsetsTy =
176 std::map<const MCSectionELF *, std::pair<uint64_t, uint64_t>>;
187 const SectionIndexMapTy &SectionIndexMap,
188 const RevGroupMapTy &RevGroupMap,
189 SectionOffsetsTy &SectionOffsets);
191 void writeAddrsigSection();
199 const SectionIndexMapTy &SectionIndexMap,
200 const SectionOffsetsTy &SectionOffsets);
213 void writeSection(
const SectionIndexMapTy &SectionIndexMap,
220 std::unique_ptr<MCELFObjectTargetWriter> TargetObjectWriter;
226 bool SeenGnuAbi =
false;
228 std::optional<uint8_t> OverrideABIVersion;
230 bool hasRelocationAddend()
const;
234 unsigned Type)
const;
237 ELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW)
238 : TargetObjectWriter(std::move(MOTW)) {}
240 void reset()
override {
242 OverrideABIVersion.reset();
251 bool IsPCRel)
const override;
267 void markGnuAbi()
override { SeenGnuAbi =
true; }
268 bool seenGnuAbi()
const {
return SeenGnuAbi; }
270 bool seenOverrideABIVersion()
const {
return OverrideABIVersion.has_value(); }
271 uint8_t getOverrideABIVersion()
const {
return OverrideABIVersion.value(); }
274 friend struct ELFWriter;
277class ELFSingleObjectWriter :
public ELFObjectWriter {
282 ELFSingleObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
284 : ELFObjectWriter(std::move(MOTW)),
OS(
OS),
285 IsLittleEndian(IsLittleEndian) {}
288 return ELFWriter(*
this,
OS, IsLittleEndian, ELFWriter::AllSections)
289 .writeObject(Asm, Layout);
292 friend struct ELFWriter;
295class ELFDwoObjectWriter :
public ELFObjectWriter {
300 ELFDwoObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
303 : ELFObjectWriter(std::move(MOTW)),
OS(
OS), DwoOS(DwoOS),
304 IsLittleEndian(IsLittleEndian) {}
309 Ctx.
reportError(Loc,
"A dwo section may not contain relocations");
313 Ctx.
reportError(Loc,
"A relocation may not refer to a dwo section");
320 uint64_t Size = ELFWriter(*
this,
OS, IsLittleEndian, ELFWriter::NonDwoOnly)
321 .writeObject(Asm, Layout);
322 Size += ELFWriter(*
this, DwoOS, IsLittleEndian, ELFWriter::DwoOnly)
323 .writeObject(Asm, Layout);
333 W.OS.write_zeros(NewOffset -
Offset);
337unsigned ELFWriter::addToSectionTable(
const MCSectionELF *Sec) {
338 SectionTable.push_back(Sec);
339 StrTabBuilder.add(Sec->
getName());
340 return SectionTable.size();
343void SymbolTableWriter::createSymtabShndx() {
344 if (!ShndxIndexes.empty())
347 ShndxIndexes.resize(NumWritten);
350template <
typename T>
void SymbolTableWriter::write(
T Value) {
351 EWriter.write(
Value);
354SymbolTableWriter::SymbolTableWriter(ELFWriter &EWriter,
bool Is64Bit)
355 : EWriter(EWriter), Is64Bit(Is64Bit), NumWritten(0) {}
365 if (!ShndxIndexes.empty()) {
367 ShndxIndexes.push_back(shndx);
369 ShndxIndexes.push_back(0);
393bool ELFWriter::is64Bit()
const {
394 return OWriter.TargetObjectWriter->is64Bit();
398void ELFWriter::writeHeader(
const MCAssembler &Asm) {
417 uint8_t OSABI = OWriter.TargetObjectWriter->getOSABI();
422 W.OS <<
char(OWriter.seenOverrideABIVersion()
423 ? OWriter.getOverrideABIVersion()
424 : OWriter.TargetObjectWriter->getABIVersion());
430 W.write<
uint16_t>(OWriter.TargetObjectWriter->getEMachine());
462 return Sym.getCommonAlignment()->value();
475 uint8_t
Type = newType;
512 if (!Symbol->isVariable() ||
513 !(
Value = dyn_cast<MCSymbolRefExpr>(Symbol->getVariableValue())) ||
517 Symbol = &cast<MCSymbolELF>(
Value->getSymbol());
522void ELFWriter::writeSymbol(SymbolTableWriter &Writer,
uint32_t StringIndex,
524 const auto &
Symbol = cast<MCSymbolELF>(*MSD.Symbol);
533 uint8_t Binding =
Symbol.getBinding();
540 uint8_t
Info = (Binding << 4) |
Type;
544 uint8_t Visibility =
Symbol.getVisibility();
550 const MCExpr *ESize = MSD.Symbol->getSize();
551 if (!ESize &&
Base) {
553 ESize =
Base->getSize();
560 while (
Sym->isVariable()) {
562 dyn_cast<MCSymbolRefExpr>(
Sym->getVariableValue(
false))) {
563 Sym = cast<MCSymbolELF>(&Expr->getSymbol());
566 ESize =
Sym->getSize();
580 Writer.writeSymbol(StringIndex, Info,
Value,
Size,
Other, MSD.SectionIndex,
585 bool Used,
bool Renamed) {
586 if (
Symbol.isVariable()) {
589 if (
const auto *
T = dyn_cast<MCTargetExpr>(Expr))
590 if (
T->inlineAssignedExpr())
619void ELFWriter::createMemtagRelocs(
MCAssembler &Asm) {
622 const auto &SymE = cast<MCSymbolELF>(
Sym);
623 if (!SymE.isMemtag())
625 if (MemtagRelocs ==
nullptr) {
626 MemtagRelocs = OWriter.TargetObjectWriter->getMemtagRelocsSection(
Asm.getContext());
627 if (MemtagRelocs ==
nullptr)
629 Asm.registerSection(*MemtagRelocs);
632 OWriter.Relocations[MemtagRelocs].push_back(Rec);
636void ELFWriter::computeSymbolTable(
638 const SectionIndexMapTy &SectionIndexMap,
const RevGroupMapTy &RevGroupMap,
639 SectionOffsetsTy &SectionOffsets) {
641 SymbolTableWriter Writer(*
this,
is64Bit());
648 SymbolTableIndex = addToSectionTable(SymtabSection);
653 Writer.writeSymbol(0, 0, 0, 0, 0, 0,
false);
655 std::vector<ELFSymbolData> LocalSymbolData;
656 std::vector<ELFSymbolData> ExternalSymbolData;
659 for (
const std::pair<std::string, size_t> &
F : FileNames)
660 StrTabBuilder.add(
F.first);
663 bool HasLargeSectionIndex =
false;
665 const auto &
Symbol = cast<MCSymbolELF>(It.value());
667 bool WeakrefUsed =
Symbol.isWeakrefUsedInReloc();
668 bool isSignature =
Symbol.isSignature();
670 if (!
isInSymtab(Layout, Symbol, Used || WeakrefUsed || isSignature,
671 OWriter.Renames.count(&Symbol)))
680 MSD.Symbol = cast<MCSymbolELF>(&Symbol);
681 MSD.Order = It.index();
686 if (
Symbol.isAbsolute()) {
688 }
else if (
Symbol.isCommon()) {
689 if (
Symbol.isTargetCommon()) {
690 MSD.SectionIndex =
Symbol.getIndex();
695 }
else if (
Symbol.isUndefined()) {
696 if (isSignature && !Used) {
697 MSD.SectionIndex = RevGroupMap.lookup(&Symbol);
699 HasLargeSectionIndex =
true;
716 "Undefined section reference: " +
Symbol.getName());
722 MSD.SectionIndex = SectionIndexMap.lookup(&Section);
723 assert(MSD.SectionIndex &&
"Invalid section index!");
725 HasLargeSectionIndex =
true;
739 StrTabBuilder.add(
Name);
743 LocalSymbolData.push_back(MSD);
745 ExternalSymbolData.push_back(MSD);
749 unsigned SymtabShndxSectionIndex = 0;
751 if (HasLargeSectionIndex) {
754 SymtabShndxSectionIndex = addToSectionTable(SymtabShndxSection);
758 StrTabBuilder.finalize();
762 auto FileNameIt = FileNames.begin();
763 if (!FileNames.empty())
764 FileNames[0].second = 0;
766 for (ELFSymbolData &MSD : LocalSymbolData) {
768 for (; FileNameIt != FileNames.end() && FileNameIt->second <= MSD.Order;
770 Writer.writeSymbol(StrTabBuilder.getOffset(FileNameIt->first),
778 : StrTabBuilder.getOffset(MSD.Name);
779 MSD.Symbol->setIndex(
Index++);
780 writeSymbol(Writer, StringIndex, MSD, Layout);
782 for (; FileNameIt != FileNames.end(); ++FileNameIt) {
783 Writer.writeSymbol(StrTabBuilder.getOffset(FileNameIt->first),
790 LastLocalSymbolIndex =
Index;
792 for (ELFSymbolData &MSD : ExternalSymbolData) {
793 unsigned StringIndex = StrTabBuilder.getOffset(MSD.Name);
794 MSD.Symbol->setIndex(
Index++);
795 writeSymbol(Writer, StringIndex, MSD, Layout);
800 SectionOffsets[SymtabSection] = std::make_pair(SecStart, SecEnd);
803 if (ShndxIndexes.
empty()) {
804 assert(SymtabShndxSectionIndex == 0);
807 assert(SymtabShndxSectionIndex != 0);
809 SecStart =
W.OS.tell();
811 SectionTable[SymtabShndxSectionIndex - 1];
814 SecEnd =
W.OS.tell();
815 SectionOffsets[SymtabShndxSection] = std::make_pair(SecStart, SecEnd);
818void ELFWriter::writeAddrsigSection() {
820 if (
Sym->getIndex() != 0)
826 if (OWriter.Relocations[&Sec].empty())
834 const bool Rela = OWriter.usesRela(Sec);
850bool ELFWriter::maybeWriteCompression(
855 if (
Size <= HdrSize + CompressedContents.
size())
877 auto &Ctx =
Asm.getContext();
880 : DebugCompressionType::None;
881 if (CompressionType == DebugCompressionType::None ||
883 Asm.writeSectionData(
W.OS, &Section, Layout);
889 Asm.writeSectionData(VecOS, &Section, Layout);
891 ArrayRef(
reinterpret_cast<uint8_t *
>(UncompressedData.
data()),
892 UncompressedData.
size());
896 switch (CompressionType) {
897 case DebugCompressionType::None:
899 case DebugCompressionType::Zlib:
902 case DebugCompressionType::Zstd:
908 if (!maybeWriteCompression(ChType, UncompressedData.
size(), Compressed,
910 W.OS << UncompressedData;
933 WriteWord(Alignment ? Alignment->value() : 0);
934 WriteWord(EntrySize);
937void ELFWriter::writeRelocations(
const MCAssembler &Asm,
939 std::vector<ELFRelocationEntry> &Relocs = OWriter.Relocations[&Sec];
940 const bool Rela = OWriter.usesRela(Sec);
943 OWriter.TargetObjectWriter->sortRelocs(Asm, Relocs);
945 if (OWriter.TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS) {
947 uint32_t Symidx = Entry.Symbol ? Entry.Symbol->getIndex() : 0;
951 write(OWriter.TargetObjectWriter->getRSsym(Entry.Type));
952 write(OWriter.TargetObjectWriter->getRType3(Entry.Type));
953 write(OWriter.TargetObjectWriter->getRType2(Entry.Type));
954 write(OWriter.TargetObjectWriter->getRType(Entry.Type));
965 OWriter.TargetObjectWriter->getRType2(Entry.Type)) {
972 OWriter.TargetObjectWriter->getRType3(Entry.Type)) {
983 uint32_t Symidx = Entry.Symbol ? Entry.Symbol->getIndex() : 0;
1002void ELFWriter::writeSection(
const SectionIndexMapTy &SectionIndexMap,
1018 sh_link = SymbolTableIndex;
1019 assert(sh_link &&
".symtab not found");
1021 sh_info = SectionIndexMap.lookup(cast<MCSectionELF>(InfoSection));
1026 sh_link = StringTableIndex;
1027 sh_info = LastLocalSymbolIndex;
1033 sh_link = SymbolTableIndex;
1037 sh_link = SymbolTableIndex;
1038 sh_info = GroupSymbolIndex;
1046 if (
Sym &&
Sym->isInSection()) {
1048 sh_link = SectionIndexMap.lookup(Sec);
1052 WriteSecHdrEntry(StrTabBuilder.getOffset(
Section.getName()),
1054 sh_link, sh_info,
Section.getAlign(),
1058void ELFWriter::writeSectionHeader(
1059 const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap,
1060 const SectionOffsetsTy &SectionOffsets) {
1061 const unsigned NumSections = SectionTable.size();
1066 WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, std::nullopt, 0);
1072 GroupSymbolIndex = 0;
1074 GroupSymbolIndex =
Section->getGroup()->getIndex();
1076 const std::pair<uint64_t, uint64_t> &
Offsets =
1077 SectionOffsets.find(Section)->second;
1084 writeSection(SectionIndexMap, GroupSymbolIndex,
Offsets.first,
Size,
1095 StringTableIndex = addToSectionTable(StrtabSection);
1097 createMemtagRelocs(Asm);
1099 RevGroupMapTy RevGroupMap;
1100 SectionIndexMapTy SectionIndexMap;
1102 std::map<const MCSymbol *, std::vector<const MCSectionELF *>> GroupMembers;
1108 SectionOffsetsTy SectionOffsets;
1109 std::vector<MCSectionELF *>
Groups;
1110 std::vector<MCSectionELF *> Relocations;
1122 writeSectionData(Asm, Section, Layout);
1125 SectionOffsets[&
Section] = std::make_pair(SecStart, SecEnd);
1127 MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
1129 if (SignatureSymbol) {
1130 unsigned &GroupIdx = RevGroupMap[SignatureSymbol];
1134 GroupIdx = addToSectionTable(Group);
1138 std::vector<const MCSectionELF *> &Members =
1139 GroupMembers[SignatureSymbol];
1140 Members.push_back(&Section);
1142 Members.push_back(RelSection);
1145 SectionIndexMap[&
Section] = addToSectionTable(&Section);
1147 SectionIndexMap[RelSection] = addToSectionTable(RelSection);
1148 Relocations.push_back(RelSection);
1151 OWriter.TargetObjectWriter->addTargetSectionFlags(Ctx, Section);
1161 for (
const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
1162 uint32_t SecIndex = SectionIndexMap.lookup(Member);
1167 SectionOffsets[Group] = std::make_pair(SecStart, SecEnd);
1170 if (Mode == DwoOnly) {
1173 StrTabBuilder.finalize();
1176 if (OWriter.EmitAddrsigSection) {
1179 addToSectionTable(AddrsigSection);
1183 computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap,
1190 writeRelocations(Asm,
1194 SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
1197 if (OWriter.EmitAddrsigSection) {
1199 writeAddrsigSection();
1201 SectionOffsets[AddrsigSection] = std::make_pair(SecStart, SecEnd);
1207 StrTabBuilder.write(
W.OS);
1208 SectionOffsets[StrtabSection] = std::make_pair(SecStart,
W.OS.tell());
1214 writeSectionHeader(Layout, SectionIndexMap, SectionOffsets);
1216 uint16_t NumSections = support::endian::byte_swap<uint16_t>(
1218 : SectionTable.size() + 1,
1220 unsigned NumSectionsOffset;
1225 support::endian::byte_swap<uint64_t>(SectionHeaderOffset,
W.Endian);
1226 Stream.pwrite(
reinterpret_cast<char *
>(&Val),
sizeof(Val),
1231 support::endian::byte_swap<uint32_t>(SectionHeaderOffset,
W.Endian);
1232 Stream.pwrite(
reinterpret_cast<char *
>(&Val),
sizeof(Val),
1236 Stream.pwrite(
reinterpret_cast<char *
>(&NumSections),
sizeof(NumSections),
1239 return W.OS.tell() - StartOffset;
1242bool ELFObjectWriter::hasRelocationAddend()
const {
1243 return TargetObjectWriter->hasRelocationAddend();
1246void ELFObjectWriter::executePostLayoutBinding(
MCAssembler &Asm,
1252 const auto &
Symbol = cast<MCSymbolELF>(*S.
Sym);
1253 size_t Pos = AliasName.
find(
'@');
1263 cast<MCSymbolELF>(
Asm.getContext().getOrCreateSymbol(Prefix +
Tail));
1264 Asm.registerSymbol(*Alias);
1266 Alias->setVariableValue(
Value);
1270 Alias->setBinding(
Symbol.getBinding());
1271 Alias->setVisibility(
Symbol.getVisibility());
1272 Alias->setOther(
Symbol.getOther());
1279 Asm.getContext().reportError(S.
Loc,
"default version symbol " +
1280 AliasName +
" must be defined");
1284 if (Renames.count(&Symbol) && Renames[&Symbol] != Alias) {
1285 Asm.getContext().reportError(S.
Loc,
Twine(
"multiple versions for ") +
1290 Renames.insert(std::make_pair(&Symbol, Alias));
1294 if (
const MCSymbol *R = Renames.lookup(cast<MCSymbolELF>(
Sym)))
1296 if (
Sym->isInSection() &&
Sym->getName().starts_with(
".L"))
1297 Sym =
Sym->getSection().getBeginSymbol();
1298 Sym->setUsedInReloc();
1305bool ELFObjectWriter::shouldRelocateWithSymbol(
const MCAssembler &Asm,
1309 unsigned Type)
const {
1346 if (
Sym->isUndefined())
1355 if (
Sym->isMemtag())
1358 unsigned Binding =
Sym->getBinding();
1389 if (
Sym->isInSection()) {
1390 auto &Sec = cast<MCSectionELF>(
Sym->getSection());
1398 if (TargetObjectWriter->getEMachine() ==
ELF::EM_386 &&
1399 Type == ELF::R_386_GOTOFF)
1409 if (TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS &&
1410 !hasRelocationAddend())
1426 if (
Asm.isThumbFunc(
Sym))
1429 if (TargetObjectWriter->needsRelocateWithSymbol(Val, *
Sym,
Type))
1434void ELFObjectWriter::recordRelocation(
MCAssembler &Asm,
1448 const auto &SymB = cast<MCSymbolELF>(RefB->getSymbol());
1449 if (SymB.isUndefined()) {
1451 Twine(
"symbol '") + SymB.getName() +
1452 "' can not be undefined in a subtraction expression");
1456 assert(!SymB.isAbsolute() &&
"Should have been folded");
1457 const MCSection &SecB = SymB.getSection();
1458 if (&SecB != &FixupSection) {
1460 "Cannot represent a difference across sections");
1464 assert(!IsPCRel &&
"should have been folded");
1471 const auto *SymA = RefA ? cast<MCSymbolELF>(&RefA->
getSymbol()) : nullptr;
1473 bool ViaWeakRef =
false;
1474 if (SymA && SymA->isVariable()) {
1475 const MCExpr *Expr = SymA->getVariableValue();
1476 if (
const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr)) {
1478 SymA = cast<MCSymbolELF>(&Inner->getSymbol());
1484 const MCSectionELF *SecA = (SymA && SymA->isInSection())
1485 ? cast<MCSectionELF>(&SymA->getSection())
1487 if (!checkRelocation(Ctx,
Fixup.getLoc(), &FixupSection, SecA))
1490 unsigned Type = TargetObjectWriter->getRelocType(Ctx,
Target,
Fixup, IsPCRel);
1491 const auto *Parent = cast<MCSectionELF>(Fragment->
getParent());
1493 bool RelocateWithSymbol =
1494 shouldRelocateWithSymbol(Asm,
Target, SymA,
C,
Type) ||
1498 FixedValue = !RelocateWithSymbol && SymA && !SymA->isUndefined()
1501 if (usesRela(FixupSection)) {
1502 Addend = FixedValue;
1506 if (!RelocateWithSymbol) {
1507 const auto *SectionSymbol =
1510 SectionSymbol->setUsedInReloc();
1512 Relocations[&FixupSection].push_back(Rec);
1527 Relocations[&FixupSection].push_back(Rec);
1530bool ELFObjectWriter::usesRela(
const MCSectionELF &Sec)
const {
1531 return hasRelocationAddend() &&
1535bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
1537 bool InSet,
bool IsPCRel)
const {
1538 const auto &SymA = cast<MCSymbolELF>(SA);
1549std::unique_ptr<MCObjectWriter>
1552 return std::make_unique<ELFSingleObjectWriter>(std::move(MOTW),
OS,
1556std::unique_ptr<MCObjectWriter>
1559 bool IsLittleEndian) {
1560 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)
const MCTargetOptions * getTargetOptions() const
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 setOverrideABIVersion(uint8_t ABIVersion)
ELF only, override the default ABIVersion in the ELF header.
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
DebugCompressionType CompressDebugSections
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 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.
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.