66 #define DEBUG_TYPE "reloc-info" 72 class ELFObjectWriter;
79 class SymbolTableWriter {
84 std::vector<uint32_t> ShndxIndexes;
89 void createSymtabShndx();
94 SymbolTableWriter(ELFWriter &EWriter,
bool Is64Bit);
97 uint8_t other,
uint32_t shndx,
bool Reserved);
103 ELFObjectWriter &OWriter;
114 bool Used,
bool Renamed);
117 struct ELFSymbolData {
123 bool operator<(
const ELFSymbolData &RHS)
const {
124 unsigned LHSType = Symbol->
getType();
125 unsigned RHSType = RHS.Symbol->getType();
131 return SectionIndex < RHS.SectionIndex;
132 return Name < RHS.Name;
145 unsigned LastLocalSymbolIndex;
147 unsigned StringTableIndex;
149 unsigned SymbolTableIndex;
152 std::vector<const MCSectionELF *> SectionTable;
157 bool hasRelocationAddend()
const;
159 void align(
unsigned Alignment);
161 bool maybeWriteCompression(uint64_t
Size,
163 bool ZLibStyle,
unsigned Alignment);
167 bool IsLittleEndian, DwoMode Mode)
171 void WriteWord(uint64_t
Word) {
178 template <
typename T>
void write(
T Val) {
184 void writeSymbol(SymbolTableWriter &Writer,
uint32_t StringIndex,
188 using SectionOffsetsTy =
189 std::map<const MCSectionELF *, std::pair<uint64_t, uint64_t>>;
200 const SectionIndexMapTy &SectionIndexMap,
201 const RevGroupMapTy &RevGroupMap,
202 SectionOffsetsTy &SectionOffsets);
204 void writeAddrsigSection();
212 const SectionIndexMapTy &SectionIndexMap,
213 const SectionOffsetsTy &SectionOffsets);
226 void writeSection(
const SectionIndexMapTy &SectionIndexMap,
227 uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size,
233 std::unique_ptr<MCELFObjectTargetWriter> TargetObjectWriter;
239 bool EmitAddrsigSection =
false;
240 std::vector<const MCSymbol *> AddrsigSyms;
242 bool hasRelocationAddend()
const;
247 unsigned Type)
const;
250 ELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW)
251 : TargetObjectWriter(std::move(MOTW)) {}
253 void reset()
override {
259 bool isSymbolRefDifferenceFullyResolvedImpl(
const MCAssembler &Asm,
262 bool IsPCRel)
const override;
277 void emitAddrsigSection()
override { EmitAddrsigSection =
true; }
278 void addAddrsigSymbol(
const MCSymbol *Sym)
override {
279 AddrsigSyms.push_back(Sym);
282 friend struct ELFWriter;
285 class ELFSingleObjectWriter :
public ELFObjectWriter {
290 ELFSingleObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
292 : ELFObjectWriter(std::move(MOTW)), OS(OS),
293 IsLittleEndian(IsLittleEndian) {}
296 return ELFWriter(*
this, OS, IsLittleEndian, ELFWriter::AllSections)
297 .writeObject(Asm, Layout);
300 friend struct ELFWriter;
303 class ELFDwoObjectWriter :
public ELFObjectWriter {
308 ELFDwoObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
311 : ELFObjectWriter(std::move(MOTW)), OS(OS), DwoOS(DwoOS),
312 IsLittleEndian(IsLittleEndian) {}
317 if (isDwoSection(*From)) {
318 Ctx.
reportError(Loc,
"A dwo section may not contain relocations");
321 if (To && isDwoSection(*To)) {
322 Ctx.
reportError(Loc,
"A relocation may not refer to a dwo section");
329 uint64_t
Size = ELFWriter(*
this, OS, IsLittleEndian, ELFWriter::NonDwoOnly)
330 .writeObject(Asm, Layout);
331 Size += ELFWriter(*
this, DwoOS, IsLittleEndian, ELFWriter::DwoOnly)
332 .writeObject(Asm, Layout);
339 void ELFWriter::align(
unsigned Alignment) {
341 W.OS.write_zeros(Padding);
344 unsigned ELFWriter::addToSectionTable(
const MCSectionELF *Sec) {
345 SectionTable.push_back(Sec);
347 return SectionTable.size();
350 void SymbolTableWriter::createSymtabShndx() {
351 if (!ShndxIndexes.empty())
354 ShndxIndexes.resize(NumWritten);
358 EWriter.write(Value);
361 SymbolTableWriter::SymbolTableWriter(ELFWriter &EWriter,
bool Is64Bit)
362 : EWriter(EWriter), Is64Bit(Is64Bit), NumWritten(0) {}
364 void SymbolTableWriter::writeSymbol(
uint32_t name, uint8_t
info, uint64_t value,
365 uint64_t
size, uint8_t other,
372 if (!ShndxIndexes.empty()) {
374 ShndxIndexes.push_back(shndx);
376 ShndxIndexes.push_back(0);
401 return OWriter.TargetObjectWriter->is64Bit();
404 bool ELFWriter::hasRelocationAddend()
const {
405 return OWriter.hasRelocationAddend();
428 W.OS <<
char(OWriter.TargetObjectWriter->getOSABI());
435 W.write<uint16_t>(OWriter.TargetObjectWriter->getEMachine());
449 W.write<uint16_t>(0);
450 W.write<uint16_t>(0);
457 W.write<uint16_t>(0);
461 W.write<uint16_t>(StringTableIndex);
464 uint64_t ELFWriter::SymbolValue(
const MCSymbol &Sym,
480 uint8_t
Type = newType;
514 void ELFWriter::writeSymbol(SymbolTableWriter &Writer,
uint32_t StringIndex,
516 const auto &
Symbol = cast<MCSymbolELF>(*MSD.Symbol);
522 bool IsReserved = !Base ||
Symbol.isCommon();
525 uint8_t Binding =
Symbol.getBinding();
530 uint8_t
Info = (Binding << 4) | Type;
537 uint64_t Value = SymbolValue(*MSD.Symbol, Layout);
540 const MCExpr *ESize = MSD.Symbol->getSize();
542 ESize = Base->getSize();
552 Writer.writeSymbol(StringIndex, Info, Value, Size, Other, MSD.SectionIndex,
577 bool Used,
bool Renamed) {
610 void ELFWriter::computeSymbolTable(
612 const SectionIndexMapTy &SectionIndexMap,
const RevGroupMapTy &RevGroupMap,
613 SectionOffsetsTy &SectionOffsets) {
615 SymbolTableWriter Writer(*
this,
is64Bit());
622 SymbolTableIndex = addToSectionTable(SymtabSection);
625 uint64_t SecStart =
W.OS.tell();
628 Writer.writeSymbol(0, 0, 0, 0, 0, 0,
false);
630 std::vector<ELFSymbolData> LocalSymbolData;
631 std::vector<ELFSymbolData> ExternalSymbolData;
634 bool HasLargeSectionIndex =
false;
636 const auto &Symbol = cast<MCSymbolELF>(S);
641 if (!
isInSymtab(Layout, Symbol, Used || WeakrefUsed || isSignature,
642 OWriter.Renames.count(&Symbol)))
651 MSD.Symbol = cast<MCSymbolELF>(&
Symbol);
662 if (isSignature && !Used) {
663 MSD.SectionIndex = RevGroupMap.lookup(&Symbol);
665 HasLargeSectionIndex =
true;
682 "Undefined section reference: " + Symbol.
getName());
686 if (
Mode == NonDwoOnly && isDwoSection(Section))
688 MSD.SectionIndex = SectionIndexMap.lookup(&Section);
689 assert(MSD.SectionIndex &&
"Invalid section index!");
691 HasLargeSectionIndex =
true;
699 StrTabBuilder.add(Name);
703 LocalSymbolData.push_back(MSD);
705 ExternalSymbolData.push_back(MSD);
709 unsigned SymtabShndxSectionIndex = 0;
711 if (HasLargeSectionIndex) {
714 SymtabShndxSectionIndex = addToSectionTable(SymtabShndxSection);
719 for (
const std::string &
Name : FileNames)
720 StrTabBuilder.add(
Name);
722 StrTabBuilder.finalize();
726 for (
const std::string &
Name : FileNames)
727 Writer.writeSymbol(StrTabBuilder.getOffset(
Name),
733 array_pod_sort(ExternalSymbolData.begin(), ExternalSymbolData.end());
737 unsigned Index = FileNames.size() + 1;
739 for (ELFSymbolData &MSD : LocalSymbolData) {
742 : StrTabBuilder.getOffset(MSD.Name);
743 MSD.Symbol->setIndex(Index++);
744 writeSymbol(Writer, StringIndex, MSD, Layout);
748 LastLocalSymbolIndex =
Index;
750 for (ELFSymbolData &MSD : ExternalSymbolData) {
751 unsigned StringIndex = StrTabBuilder.getOffset(MSD.Name);
752 MSD.Symbol->setIndex(Index++);
753 writeSymbol(Writer, StringIndex, MSD, Layout);
757 uint64_t SecEnd =
W.OS.tell();
758 SectionOffsets[SymtabSection] = std::make_pair(SecStart, SecEnd);
761 if (ShndxIndexes.
empty()) {
762 assert(SymtabShndxSectionIndex == 0);
765 assert(SymtabShndxSectionIndex != 0);
767 SecStart =
W.OS.tell();
769 SectionTable[SymtabShndxSectionIndex - 1];
772 SecEnd =
W.OS.tell();
773 SectionOffsets[SymtabShndxSection] = std::make_pair(SecStart, SecEnd);
776 void ELFWriter::writeAddrsigSection() {
777 for (
const MCSymbol *Sym : OWriter.AddrsigSyms)
783 if (OWriter.Relocations[&Sec].empty())
787 std::string RelaSectionName = hasRelocationAddend() ?
".rela" :
".rel";
791 if (hasRelocationAddend())
802 Flags, EntrySize, Sec.
getGroup(), &Sec);
808 bool ELFWriter::maybeWriteCompression(
810 unsigned Alignment) {
814 if (
Size <= HdrSize + CompressedContents.
size())
820 write(static_cast<ELF::Elf64_Word>(0));
821 write(static_cast<ELF::Elf64_Xword>(
Size));
822 write(static_cast<ELF::Elf64_Xword>(Alignment));
826 write(static_cast<ELF::Elf32_Word>(
Size));
827 write(static_cast<ELF::Elf32_Word>(Alignment));
853 bool CompressionEnabled =
855 if (!CompressionEnabled || !SectionName.
startswith(
".debug_") ||
856 SectionName ==
".debug_frame") {
863 "expected zlib or zlib-gnu style compression");
872 CompressedContents)) {
874 W.OS << UncompressedData;
879 if (!maybeWriteCompression(UncompressedData.
size(), CompressedContents,
881 W.OS << UncompressedData;
890 MC.renameELFSection(&Section, (
".z" + SectionName.
drop_front(1)).str());
891 W.OS << CompressedContents;
897 uint64_t Alignment, uint64_t EntrySize) {
906 WriteWord(Alignment);
907 WriteWord(EntrySize);
910 void ELFWriter::writeRelocations(
const MCAssembler &Asm,
912 std::vector<ELFRelocationEntry> &Relocs = OWriter.Relocations[&Sec];
921 OWriter.TargetObjectWriter->sortRelocs(Asm, Relocs);
923 for (
unsigned i = 0, e = Relocs.size(); i != e; ++i) {
929 if (OWriter.TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS) {
932 write(OWriter.TargetObjectWriter->getRSsym(Entry.
Type));
933 write(OWriter.TargetObjectWriter->getRType3(Entry.
Type));
934 write(OWriter.TargetObjectWriter->getRType2(Entry.
Type));
935 write(OWriter.TargetObjectWriter->getRType(Entry.
Type));
941 if (hasRelocationAddend())
950 if (hasRelocationAddend())
953 if (OWriter.TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS) {
955 OWriter.TargetObjectWriter->getRType2(Entry.
Type)) {
963 OWriter.TargetObjectWriter->getRType3(Entry.
Type)) {
976 const MCSectionELF *StrtabSection = SectionTable[StringTableIndex - 1];
977 StrTabBuilder.write(
W.OS);
978 return StrtabSection;
981 void ELFWriter::writeSection(
const SectionIndexMapTy &SectionIndexMap,
984 uint64_t sh_link = 0;
985 uint64_t sh_info = 0;
997 sh_link = SymbolTableIndex;
998 assert(sh_link &&
".symtab not found");
1000 sh_info = SectionIndexMap.lookup(cast<MCSectionELF>(InfoSection));
1005 sh_link = StringTableIndex;
1006 sh_info = LastLocalSymbolIndex;
1012 sh_link = SymbolTableIndex;
1016 sh_link = SymbolTableIndex;
1017 sh_info = GroupSymbolIndex;
1024 sh_link = SectionIndexMap.lookup(Sec);
1027 WriteSecHdrEntry(StrTabBuilder.getOffset(Section.
getSectionName()),
1033 void ELFWriter::writeSectionHeader(
1034 const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap,
1035 const SectionOffsetsTy &SectionOffsets) {
1036 const unsigned NumSections = SectionTable.size();
1039 uint64_t FirstSectionSize =
1041 WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, 0, 0);
1045 unsigned Type = Section->
getType();
1047 GroupSymbolIndex = 0;
1051 const std::pair<uint64_t, uint64_t> &
Offsets =
1052 SectionOffsets.find(Section)->second;
1057 Size = Offsets.second - Offsets.first;
1059 writeSection(SectionIndexMap, GroupSymbolIndex, Offsets.first, Size,
1065 uint64_t StartOffset =
W.OS.tell();
1070 StringTableIndex = addToSectionTable(StrtabSection);
1072 RevGroupMapTy RevGroupMap;
1073 SectionIndexMapTy SectionIndexMap;
1075 std::map<const MCSymbol *, std::vector<const MCSectionELF *>> GroupMembers;
1081 SectionOffsetsTy SectionOffsets;
1082 std::vector<MCSectionELF *>
Groups;
1083 std::vector<MCSectionELF *> Relocations;
1086 if (
Mode == NonDwoOnly && isDwoSection(Section))
1088 if (
Mode == DwoOnly && !isDwoSection(Section))
1094 uint64_t SecStart =
W.OS.tell();
1097 writeSectionData(Asm, Section, Layout);
1099 uint64_t SecEnd =
W.OS.tell();
1100 SectionOffsets[&
Section] = std::make_pair(SecStart, SecEnd);
1102 MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
1104 if (SignatureSymbol) {
1105 Asm.registerSymbol(*SignatureSymbol);
1106 unsigned &GroupIdx = RevGroupMap[SignatureSymbol];
1109 GroupIdx = addToSectionTable(Group);
1111 Groups.push_back(Group);
1113 std::vector<const MCSectionELF *> &Members =
1114 GroupMembers[SignatureSymbol];
1115 Members.push_back(&Section);
1117 Members.push_back(RelSection);
1120 SectionIndexMap[&
Section] = addToSectionTable(&Section);
1122 SectionIndexMap[RelSection] = addToSectionTable(RelSection);
1123 Relocations.push_back(RelSection);
1126 OWriter.TargetObjectWriter->addTargetSectionFlags(Ctx, Section);
1130 if (!Asm.CGProfile.empty()) {
1131 CGProfileSection = Ctx.
getELFSection(
".llvm.call-graph-profile",
1134 SectionIndexMap[CGProfileSection] = addToSectionTable(CGProfileSection);
1138 align(Group->getAlignment());
1141 uint64_t SecStart =
W.OS.tell();
1143 const MCSymbol *SignatureSymbol = Group->getGroup();
1146 for (
const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
1147 uint32_t SecIndex = SectionIndexMap.lookup(Member);
1151 uint64_t SecEnd =
W.OS.tell();
1152 SectionOffsets[Group] = std::make_pair(SecStart, SecEnd);
1155 if (
Mode == DwoOnly) {
1158 StrTabBuilder.finalize();
1161 if (OWriter.EmitAddrsigSection) {
1164 addToSectionTable(AddrsigSection);
1168 computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap,
1172 align(RelSection->getAlignment());
1175 uint64_t SecStart =
W.OS.tell();
1177 writeRelocations(Asm,
1178 cast<MCSectionELF>(*RelSection->getAssociatedSection()));
1180 uint64_t SecEnd =
W.OS.tell();
1181 SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
1184 if (OWriter.EmitAddrsigSection) {
1185 uint64_t SecStart =
W.OS.tell();
1186 writeAddrsigSection();
1187 uint64_t SecEnd =
W.OS.tell();
1188 SectionOffsets[AddrsigSection] = std::make_pair(SecStart, SecEnd);
1192 if (CGProfileSection) {
1193 uint64_t SecStart =
W.OS.tell();
1197 W.write<uint64_t>(CGPE.
Count);
1199 uint64_t SecEnd =
W.OS.tell();
1200 SectionOffsets[CGProfileSection] = std::make_pair(SecStart, SecEnd);
1204 uint64_t SecStart =
W.OS.tell();
1206 uint64_t SecEnd =
W.OS.tell();
1207 SectionOffsets[Sec] = std::make_pair(SecStart, SecEnd);
1210 uint64_t NaturalAlignment =
is64Bit() ? 8 : 4;
1211 align(NaturalAlignment);
1213 const uint64_t SectionHeaderOffset =
W.OS.tell();
1216 writeSectionHeader(Layout, SectionIndexMap, SectionOffsets);
1218 uint16_t NumSections = support::endian::byte_swap<uint16_t>(
1220 : SectionTable.size() + 1,
1222 unsigned NumSectionsOffset;
1227 support::endian::byte_swap<uint64_t>(SectionHeaderOffset,
W.Endian);
1228 Stream.
pwrite(reinterpret_cast<char *>(&Val),
sizeof(Val),
1233 support::endian::byte_swap<uint32_t>(SectionHeaderOffset,
W.Endian);
1234 Stream.pwrite(reinterpret_cast<char *>(&Val),
sizeof(Val),
1238 Stream.pwrite(reinterpret_cast<char *>(&NumSections),
sizeof(NumSections),
1241 return W.OS.tell() - StartOffset;
1244 bool ELFObjectWriter::hasRelocationAddend()
const {
1245 return TargetObjectWriter->hasRelocationAddend();
1248 void ELFObjectWriter::executePostLayoutBinding(
MCAssembler &Asm,
1252 for (
const std::pair<StringRef, const MCSymbol *> &
P : Asm.
Symvers) {
1254 const auto &Symbol = cast<MCSymbolELF>(*P.second);
1255 size_t Pos = AliasName.
find(
'@');
1268 Alias->setVariableValue(Value);
1274 Alias->setOther(Symbol.
getOther());
1283 " must be defined");
1287 if (Renames.count(&Symbol) && Renames[&
Symbol] != Alias) {
1294 Renames.insert(std::make_pair(&Symbol, Alias));
1297 for (
const MCSymbol *&Sym : AddrsigSyms) {
1298 if (
const MCSymbol *
R = Renames.lookup(cast<MCSymbolELF>(Sym)))
1309 bool ELFObjectWriter::shouldRelocateWithSymbol(
const MCAssembler &Asm,
1313 unsigned Type)
const {
1347 assert(Sym &&
"Expected a symbol");
1376 auto &Sec = cast<MCSectionELF>(Sym->
getSection());
1384 if (!hasRelocationAddend())
1403 if (TargetObjectWriter->needsRelocateWithSymbol(*Sym, Type))
1408 void ELFObjectWriter::recordRelocation(
MCAssembler &Asm,
1412 uint64_t &FixedValue) {
1432 "No relocation available to represent this relative expression");
1436 const auto &SymB = cast<MCSymbolELF>(RefB->getSymbol());
1438 if (SymB.isUndefined()) {
1440 Twine(
"symbol '") + SymB.getName() +
1441 "' can not be undefined in a subtraction expression");
1445 assert(!SymB.isAbsolute() &&
"Should have been folded");
1446 const MCSection &SecB = SymB.getSection();
1447 if (&SecB != &FixupSection) {
1449 "Cannot represent a difference across sections");
1454 uint64_t K = SymBOffset - FixupOffset;
1461 const auto *SymA = RefA ? cast<MCSymbolELF>(&RefA->
getSymbol()) :
nullptr;
1463 bool ViaWeakRef =
false;
1464 if (SymA && SymA->isVariable()) {
1465 const MCExpr *Expr = SymA->getVariableValue();
1466 if (
const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr)) {
1468 SymA = cast<MCSymbolELF>(&Inner->getSymbol());
1474 unsigned Type = TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);
1475 uint64_t OriginalC =
C;
1476 bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type);
1477 if (!RelocateWithSymbol && SymA && !SymA->isUndefined())
1480 uint64_t Addend = 0;
1481 if (hasRelocationAddend()) {
1488 const MCSectionELF *SecA = (SymA && SymA->isInSection())
1489 ? cast<MCSectionELF>(&SymA->getSection())
1491 if (!checkRelocation(Ctx, Fixup.
getLoc(), &FixupSection, SecA))
1494 if (!RelocateWithSymbol) {
1495 const auto *SectionSymbol =
1498 SectionSymbol->setUsedInReloc();
1501 Relocations[&FixupSection].push_back(Rec);
1505 const auto *RenamedSymA = SymA;
1511 RenamedSymA->setIsWeakrefUsedInReloc();
1513 RenamedSymA->setUsedInReloc();
1517 Relocations[&FixupSection].push_back(Rec);
1520 bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
1522 bool InSet,
bool IsPCRel)
const {
1523 const auto &SymA = cast<MCSymbolELF>(SA);
1533 std::unique_ptr<MCObjectWriter>
1536 return llvm::make_unique<ELFSingleObjectWriter>(std::move(MOTW), OS,
1540 std::unique_ptr<MCObjectWriter>
1543 bool IsLittleEndian) {
1544 return llvm::make_unique<ELFDwoObjectWriter>(std::move(MOTW), OS, DwoOS,
const MCAsmInfo * getAsmInfo() const
Instances of this class represent a uniqued identifier for a section in the current translation unit...
uint32_t getIndex() const
Get the (implementation defined) index.
void setUsedInReloc() const
void setSymbolAndType(Elf32_Word s, unsigned char t)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
bool isVariable() const
isVariable - Check if this is a variable symbol.
This represents an "assembler immediate".
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
VariantKind getKind() const
unsigned getBinding() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
void setAlignment(unsigned Value)
A raw_ostream that writes to an SmallVector or SmallString.
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
unsigned getCommonAlignment() const
Return the alignment of a 'common' symbol.
ELFYAML::ELF_STV Visibility
void setSymbolAndType(Elf64_Word s, Elf64_Word t)
bool isCommon() const
Is this a 'common' symbol.
Defines the object file and target independent interfaces used by the assembler backend to write nati...
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
unsigned getAlignment() const
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
MCContext & getContext() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
int64_t getConstant() const
const MCSymbolRefExpr * getSymB() const
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Error compress(StringRef InputBuffer, SmallVectorImpl< char > &CompressedBuffer, int Level=DefaultCompression)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Encapsulates the layout of an assembly file at a particular point in time.
const MCSection * getAssociatedSection() const
const MCSymbolRefExpr * From
support::ulittle32_t Word
Base class for the full range of assembler expressions which are needed for parsing.
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
The access may reference the value stored in memory.
Represent a reference to a symbol from inside an expression.
zlib-gnu style compression
DebugCompressionType compressDebugSections() const
ArrayRef< std::string > getFileNames()
Context object for machine code objects.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Utility for building string tables with deduplicated suffixes.
bool isBindingSet() const
const MCSymbolRefExpr * To
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
std::unique_ptr< MCObjectWriter > createELFObjectWriter(std::unique_ptr< MCELFObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
Construct a new ELF writer instance.
static uint8_t mergeTypeForSet(uint8_t origType, uint8_t newType)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
unsigned getOther() const
Analysis containing CSE Info
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
const MCSymbolELF * getGroup() const
The instances of the Type class are immutable: once they are created, they are never changed...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool is64Bit(const char *name)
virtual void reset()
lifetime management
bool isRegistered() const
#define offsetof(TYPE, MEMBER)
void setFlags(unsigned F)
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
const MCSymbolRefExpr * getSymA() const
void reportError(SMLoc L, const Twine &Msg)
uint32_t getOffset() const
void writeSectionData(raw_ostream &OS, const MCSection *Section, const MCAsmLayout &Layout) const
Emit the section contents to OS.
unsigned getELFHeaderEFlags() const
ELF e_header flags.
static void write(bool isBE, void *P, T V)
void consumeError(Error Err)
Consume a Error without doing anything.
static wasm::ValType getType(const TargetRegisterClass *RC)
unsigned getEntrySize() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
PowerPC TLS Dynamic Call Fixup
static const char *const Magic
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
static const X86InstrFMA3Group Groups[]
static const char ElfMagic[]
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
BlockVerifier::State From
void write(ArrayRef< value_type > Val)
bool isWeakrefUsedInReloc() const
MCAsmBackend & getBackend() const
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
std::unique_ptr< MCObjectWriter > createELFDwoObjectWriter(std::unique_ptr< MCELFObjectTargetWriter > MOTW, raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS, bool IsLittleEndian)
const MCSymbol & getSymbol() const
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
MCSymbol * getBeginSymbol()
Target - Wrapper for Target specific information.
bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
MCSection * getParent() const
static bool isWeak(const MCSymbolELF &Sym)
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
bool isAbsolute() const
isAbsolute - Check if this is an absolute symbol.
bool isUsedInReloc() const
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B, bool InSet) const
Adapter to write values to a stream in a particular byte order.
pointer data()
Return a pointer to the vector's buffer, even if empty().
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
This represents a section on linux, lots of unix variants and some bare metal systems.
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group)
StringRef getName() const
getName - Get the symbol name.
An abstract base class for streams implementations that also support a pwrite operation.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
bool operator<(int64_t V1, const APSInt &V2)
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
LLVM Value Representation.
Generic interface to target specific assembler backends.
Lightweight error class with error context and mandatory checking.
uint64_t OffsetToAlignment(uint64_t Value, uint64_t Align)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
const MCSymbol * getAssociatedSymbol() const
StringRef - Represent a constant reference to a string, i.e.
const MCSymbolELF * Symbol
unsigned getFlags() const
Represents a location in source code.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
static bool isInSymtab(const MCSymbolWasm &Sym)
std::vector< std::pair< StringRef, const MCSymbol * > > Symvers
const MCSymbol * getBaseSymbol(const MCSymbol &Symbol) const
If this symbol is equivalent to A + Constant, return A.
MCFixupKind getKind() const
StringRef getSectionName() const
bool empty() const
empty - Check if the array is empty.