65 #define DEBUG_TYPE "reloc-info" 71 class ELFObjectWriter;
78 class SymbolTableWriter {
83 std::vector<uint32_t> ShndxIndexes;
88 void createSymtabShndx();
93 SymbolTableWriter(ELFWriter &EWriter,
bool Is64Bit);
96 uint8_t other,
uint32_t shndx,
bool Reserved);
102 ELFObjectWriter &OWriter;
113 bool Used,
bool Renamed);
116 struct ELFSymbolData {
122 bool operator<(
const ELFSymbolData &RHS)
const {
123 unsigned LHSType = Symbol->
getType();
124 unsigned RHSType = RHS.Symbol->getType();
130 return SectionIndex < RHS.SectionIndex;
131 return Name < RHS.Name;
144 unsigned LastLocalSymbolIndex;
146 unsigned StringTableIndex;
148 unsigned SymbolTableIndex;
151 std::vector<const MCSectionELF *> SectionTable;
156 bool hasRelocationAddend()
const;
158 void align(
unsigned Alignment);
160 bool maybeWriteCompression(uint64_t
Size,
162 bool ZLibStyle,
unsigned Alignment);
166 bool IsLittleEndian, DwoMode Mode)
170 void WriteWord(uint64_t
Word) {
177 template <
typename T>
void write(
T Val) {
183 void writeSymbol(SymbolTableWriter &Writer,
uint32_t StringIndex,
187 using SectionOffsetsTy =
188 std::map<const MCSectionELF *, std::pair<uint64_t, uint64_t>>;
199 const SectionIndexMapTy &SectionIndexMap,
200 const RevGroupMapTy &RevGroupMap,
201 SectionOffsetsTy &SectionOffsets);
203 void writeAddrsigSection();
211 const SectionIndexMapTy &SectionIndexMap,
212 const SectionOffsetsTy &SectionOffsets);
225 void writeSection(
const SectionIndexMapTy &SectionIndexMap,
226 uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size,
232 std::unique_ptr<MCELFObjectTargetWriter> TargetObjectWriter;
238 bool EmitAddrsigSection =
false;
239 std::vector<const MCSymbol *> AddrsigSyms;
241 bool hasRelocationAddend()
const;
246 unsigned Type)
const;
249 ELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW)
250 : TargetObjectWriter(std::move(MOTW)) {}
252 void reset()
override {
258 bool isSymbolRefDifferenceFullyResolvedImpl(
const MCAssembler &Asm,
261 bool IsPCRel)
const override;
276 void emitAddrsigSection()
override { EmitAddrsigSection =
true; }
277 void addAddrsigSymbol(
const MCSymbol *Sym)
override {
278 AddrsigSyms.push_back(Sym);
281 friend struct ELFWriter;
284 class ELFSingleObjectWriter :
public ELFObjectWriter {
289 ELFSingleObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
291 : ELFObjectWriter(std::move(MOTW)), OS(OS),
292 IsLittleEndian(IsLittleEndian) {}
295 return ELFWriter(*
this, OS, IsLittleEndian, ELFWriter::AllSections)
296 .writeObject(Asm, Layout);
299 friend struct ELFWriter;
302 class ELFDwoObjectWriter :
public ELFObjectWriter {
307 ELFDwoObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
310 : ELFObjectWriter(std::move(MOTW)), OS(OS), DwoOS(DwoOS),
311 IsLittleEndian(IsLittleEndian) {}
316 if (isDwoSection(*From)) {
317 Ctx.
reportError(Loc,
"A dwo section may not contain relocations");
320 if (To && isDwoSection(*To)) {
321 Ctx.
reportError(Loc,
"A relocation may not refer to a dwo section");
328 uint64_t
Size = ELFWriter(*
this, OS, IsLittleEndian, ELFWriter::NonDwoOnly)
329 .writeObject(Asm, Layout);
330 Size += ELFWriter(*
this, DwoOS, IsLittleEndian, ELFWriter::DwoOnly)
331 .writeObject(Asm, Layout);
338 void ELFWriter::align(
unsigned Alignment) {
340 W.OS.write_zeros(Padding);
343 unsigned ELFWriter::addToSectionTable(
const MCSectionELF *Sec) {
344 SectionTable.push_back(Sec);
346 return SectionTable.size();
349 void SymbolTableWriter::createSymtabShndx() {
350 if (!ShndxIndexes.empty())
353 ShndxIndexes.resize(NumWritten);
357 EWriter.write(Value);
360 SymbolTableWriter::SymbolTableWriter(ELFWriter &EWriter,
bool Is64Bit)
361 : EWriter(EWriter), Is64Bit(Is64Bit), NumWritten(0) {}
363 void SymbolTableWriter::writeSymbol(
uint32_t name, uint8_t
info, uint64_t value,
364 uint64_t
size, uint8_t other,
371 if (!ShndxIndexes.empty()) {
373 ShndxIndexes.push_back(shndx);
375 ShndxIndexes.push_back(0);
400 return OWriter.TargetObjectWriter->is64Bit();
403 bool ELFWriter::hasRelocationAddend()
const {
404 return OWriter.hasRelocationAddend();
427 W.OS <<
char(OWriter.TargetObjectWriter->getOSABI());
434 W.write<uint16_t>(OWriter.TargetObjectWriter->getEMachine());
448 W.write<uint16_t>(0);
449 W.write<uint16_t>(0);
456 W.write<uint16_t>(0);
460 W.write<uint16_t>(StringTableIndex);
463 uint64_t ELFWriter::SymbolValue(
const MCSymbol &Sym,
479 uint8_t
Type = newType;
513 void ELFWriter::writeSymbol(SymbolTableWriter &Writer,
uint32_t StringIndex,
515 const auto &
Symbol = cast<MCSymbolELF>(*MSD.Symbol);
521 bool IsReserved = !Base ||
Symbol.isCommon();
524 uint8_t Binding =
Symbol.getBinding();
529 uint8_t Info = (Binding << 4) | Type;
536 uint64_t Value = SymbolValue(*MSD.Symbol, Layout);
539 const MCExpr *ESize = MSD.Symbol->getSize();
541 ESize = Base->getSize();
551 Writer.writeSymbol(StringIndex, Info, Value, Size, Other, MSD.SectionIndex,
576 bool Used,
bool Renamed) {
609 void ELFWriter::computeSymbolTable(
611 const SectionIndexMapTy &SectionIndexMap,
const RevGroupMapTy &RevGroupMap,
612 SectionOffsetsTy &SectionOffsets) {
614 SymbolTableWriter Writer(*
this,
is64Bit());
621 SymbolTableIndex = addToSectionTable(SymtabSection);
624 uint64_t SecStart =
W.OS.tell();
627 Writer.writeSymbol(0, 0, 0, 0, 0, 0,
false);
629 std::vector<ELFSymbolData> LocalSymbolData;
630 std::vector<ELFSymbolData> ExternalSymbolData;
633 bool HasLargeSectionIndex =
false;
635 const auto &Symbol = cast<MCSymbolELF>(S);
640 if (!
isInSymtab(Layout, Symbol, Used || WeakrefUsed || isSignature,
641 OWriter.Renames.count(&Symbol)))
650 MSD.Symbol = cast<MCSymbolELF>(&
Symbol);
661 if (isSignature && !Used) {
662 MSD.SectionIndex = RevGroupMap.lookup(&Symbol);
664 HasLargeSectionIndex =
true;
671 if (
Mode == NonDwoOnly && isDwoSection(Section))
673 MSD.SectionIndex = SectionIndexMap.lookup(&Section);
674 assert(MSD.SectionIndex &&
"Invalid section index!");
676 HasLargeSectionIndex =
true;
684 StrTabBuilder.add(Name);
688 LocalSymbolData.push_back(MSD);
690 ExternalSymbolData.push_back(MSD);
694 unsigned SymtabShndxSectionIndex = 0;
696 if (HasLargeSectionIndex) {
699 SymtabShndxSectionIndex = addToSectionTable(SymtabShndxSection);
704 for (
const std::string &
Name : FileNames)
705 StrTabBuilder.add(
Name);
707 StrTabBuilder.finalize();
711 for (
const std::string &
Name : FileNames)
712 Writer.writeSymbol(StrTabBuilder.getOffset(
Name),
718 array_pod_sort(ExternalSymbolData.begin(), ExternalSymbolData.end());
722 unsigned Index = FileNames.size() + 1;
724 for (ELFSymbolData &MSD : LocalSymbolData) {
727 : StrTabBuilder.getOffset(MSD.Name);
728 MSD.Symbol->setIndex(Index++);
729 writeSymbol(Writer, StringIndex, MSD, Layout);
733 LastLocalSymbolIndex =
Index;
735 for (ELFSymbolData &MSD : ExternalSymbolData) {
736 unsigned StringIndex = StrTabBuilder.getOffset(MSD.Name);
737 MSD.Symbol->setIndex(Index++);
738 writeSymbol(Writer, StringIndex, MSD, Layout);
742 uint64_t SecEnd =
W.OS.tell();
743 SectionOffsets[SymtabSection] = std::make_pair(SecStart, SecEnd);
746 if (ShndxIndexes.
empty()) {
747 assert(SymtabShndxSectionIndex == 0);
750 assert(SymtabShndxSectionIndex != 0);
752 SecStart =
W.OS.tell();
754 SectionTable[SymtabShndxSectionIndex - 1];
757 SecEnd =
W.OS.tell();
758 SectionOffsets[SymtabShndxSection] = std::make_pair(SecStart, SecEnd);
761 void ELFWriter::writeAddrsigSection() {
762 for (
const MCSymbol *Sym : OWriter.AddrsigSyms)
768 if (OWriter.Relocations[&Sec].empty())
772 std::string RelaSectionName = hasRelocationAddend() ?
".rela" :
".rel";
776 if (hasRelocationAddend())
787 Flags, EntrySize, Sec.
getGroup(), &Sec);
793 bool ELFWriter::maybeWriteCompression(
795 unsigned Alignment) {
799 if (
Size <= HdrSize + CompressedContents.
size())
805 write(static_cast<ELF::Elf64_Word>(0));
806 write(static_cast<ELF::Elf64_Xword>(
Size));
807 write(static_cast<ELF::Elf64_Xword>(Alignment));
811 write(static_cast<ELF::Elf32_Word>(
Size));
812 write(static_cast<ELF::Elf32_Word>(Alignment));
838 bool CompressionEnabled =
840 if (!CompressionEnabled || !SectionName.
startswith(
".debug_") ||
841 SectionName ==
".debug_frame") {
848 "expected zlib or zlib-gnu style compression");
857 CompressedContents)) {
859 W.OS << UncompressedData;
864 if (!maybeWriteCompression(UncompressedData.
size(), CompressedContents,
866 W.OS << UncompressedData;
875 MC.renameELFSection(&Section, (
".z" + SectionName.
drop_front(1)).str());
876 W.OS << CompressedContents;
882 uint64_t Alignment, uint64_t EntrySize) {
891 WriteWord(Alignment);
892 WriteWord(EntrySize);
895 void ELFWriter::writeRelocations(
const MCAssembler &Asm,
897 std::vector<ELFRelocationEntry> &Relocs = OWriter.Relocations[&Sec];
906 OWriter.TargetObjectWriter->sortRelocs(Asm, Relocs);
908 for (
unsigned i = 0, e = Relocs.size(); i != e; ++i) {
914 if (OWriter.TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS) {
917 write(OWriter.TargetObjectWriter->getRSsym(Entry.
Type));
918 write(OWriter.TargetObjectWriter->getRType3(Entry.
Type));
919 write(OWriter.TargetObjectWriter->getRType2(Entry.
Type));
920 write(OWriter.TargetObjectWriter->getRType(Entry.
Type));
926 if (hasRelocationAddend())
935 if (hasRelocationAddend())
938 if (OWriter.TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS) {
940 OWriter.TargetObjectWriter->getRType2(Entry.
Type)) {
948 OWriter.TargetObjectWriter->getRType3(Entry.
Type)) {
961 const MCSectionELF *StrtabSection = SectionTable[StringTableIndex - 1];
962 StrTabBuilder.write(
W.OS);
963 return StrtabSection;
966 void ELFWriter::writeSection(
const SectionIndexMapTy &SectionIndexMap,
969 uint64_t sh_link = 0;
970 uint64_t sh_info = 0;
982 sh_link = SymbolTableIndex;
983 assert(sh_link &&
".symtab not found");
985 sh_info = SectionIndexMap.lookup(cast<MCSectionELF>(InfoSection));
990 sh_link = StringTableIndex;
991 sh_info = LastLocalSymbolIndex;
997 sh_link = SymbolTableIndex;
1001 sh_link = SymbolTableIndex;
1002 sh_info = GroupSymbolIndex;
1009 sh_link = SectionIndexMap.lookup(Sec);
1012 WriteSecHdrEntry(StrTabBuilder.getOffset(Section.
getSectionName()),
1018 void ELFWriter::writeSectionHeader(
1019 const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap,
1020 const SectionOffsetsTy &SectionOffsets) {
1021 const unsigned NumSections = SectionTable.size();
1024 uint64_t FirstSectionSize =
1026 WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, 0, 0);
1030 unsigned Type = Section->
getType();
1032 GroupSymbolIndex = 0;
1036 const std::pair<uint64_t, uint64_t> &
Offsets =
1037 SectionOffsets.find(Section)->second;
1042 Size = Offsets.second - Offsets.first;
1044 writeSection(SectionIndexMap, GroupSymbolIndex, Offsets.first, Size,
1050 uint64_t StartOffset =
W.OS.tell();
1055 StringTableIndex = addToSectionTable(StrtabSection);
1057 RevGroupMapTy RevGroupMap;
1058 SectionIndexMapTy SectionIndexMap;
1060 std::map<const MCSymbol *, std::vector<const MCSectionELF *>> GroupMembers;
1066 SectionOffsetsTy SectionOffsets;
1067 std::vector<MCSectionELF *>
Groups;
1068 std::vector<MCSectionELF *> Relocations;
1071 if (
Mode == NonDwoOnly && isDwoSection(Section))
1073 if (
Mode == DwoOnly && !isDwoSection(Section))
1079 uint64_t SecStart =
W.OS.tell();
1082 writeSectionData(Asm, Section, Layout);
1084 uint64_t SecEnd =
W.OS.tell();
1085 SectionOffsets[&
Section] = std::make_pair(SecStart, SecEnd);
1087 MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
1089 if (SignatureSymbol) {
1090 Asm.registerSymbol(*SignatureSymbol);
1091 unsigned &GroupIdx = RevGroupMap[SignatureSymbol];
1094 GroupIdx = addToSectionTable(Group);
1096 Groups.push_back(Group);
1098 std::vector<const MCSectionELF *> &Members =
1099 GroupMembers[SignatureSymbol];
1100 Members.push_back(&Section);
1102 Members.push_back(RelSection);
1105 SectionIndexMap[&
Section] = addToSectionTable(&Section);
1107 SectionIndexMap[RelSection] = addToSectionTable(RelSection);
1108 Relocations.push_back(RelSection);
1113 if (!Asm.CGProfile.empty()) {
1114 CGProfileSection = Ctx.
getELFSection(
".llvm.call-graph-profile",
1117 SectionIndexMap[CGProfileSection] = addToSectionTable(CGProfileSection);
1121 align(Group->getAlignment());
1124 uint64_t SecStart =
W.OS.tell();
1126 const MCSymbol *SignatureSymbol = Group->getGroup();
1129 for (
const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
1130 uint32_t SecIndex = SectionIndexMap.lookup(Member);
1134 uint64_t SecEnd =
W.OS.tell();
1135 SectionOffsets[Group] = std::make_pair(SecStart, SecEnd);
1138 if (
Mode == DwoOnly) {
1141 StrTabBuilder.finalize();
1144 if (OWriter.EmitAddrsigSection) {
1147 addToSectionTable(AddrsigSection);
1151 computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap,
1155 align(RelSection->getAlignment());
1158 uint64_t SecStart =
W.OS.tell();
1160 writeRelocations(Asm,
1161 cast<MCSectionELF>(*RelSection->getAssociatedSection()));
1163 uint64_t SecEnd =
W.OS.tell();
1164 SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
1167 if (OWriter.EmitAddrsigSection) {
1168 uint64_t SecStart =
W.OS.tell();
1169 writeAddrsigSection();
1170 uint64_t SecEnd =
W.OS.tell();
1171 SectionOffsets[AddrsigSection] = std::make_pair(SecStart, SecEnd);
1175 if (CGProfileSection) {
1176 uint64_t SecStart =
W.OS.tell();
1180 W.write<uint64_t>(CGPE.
Count);
1182 uint64_t SecEnd =
W.OS.tell();
1183 SectionOffsets[CGProfileSection] = std::make_pair(SecStart, SecEnd);
1187 uint64_t SecStart =
W.OS.tell();
1189 uint64_t SecEnd =
W.OS.tell();
1190 SectionOffsets[Sec] = std::make_pair(SecStart, SecEnd);
1193 uint64_t NaturalAlignment =
is64Bit() ? 8 : 4;
1194 align(NaturalAlignment);
1196 const uint64_t SectionHeaderOffset =
W.OS.tell();
1199 writeSectionHeader(Layout, SectionIndexMap, SectionOffsets);
1201 uint16_t NumSections = support::endian::byte_swap<uint16_t>(
1203 : SectionTable.size() + 1,
1205 unsigned NumSectionsOffset;
1210 support::endian::byte_swap<uint64_t>(SectionHeaderOffset,
W.Endian);
1211 Stream.
pwrite(reinterpret_cast<char *>(&Val),
sizeof(Val),
1216 support::endian::byte_swap<uint32_t>(SectionHeaderOffset,
W.Endian);
1217 Stream.pwrite(reinterpret_cast<char *>(&Val),
sizeof(Val),
1221 Stream.pwrite(reinterpret_cast<char *>(&NumSections),
sizeof(NumSections),
1224 return W.OS.tell() - StartOffset;
1227 bool ELFObjectWriter::hasRelocationAddend()
const {
1228 return TargetObjectWriter->hasRelocationAddend();
1231 void ELFObjectWriter::executePostLayoutBinding(
MCAssembler &Asm,
1235 for (
const std::pair<StringRef, const MCSymbol *> &
P : Asm.
Symvers) {
1237 const auto &Symbol = cast<MCSymbolELF>(*P.second);
1238 size_t Pos = AliasName.
find(
'@');
1251 Alias->setVariableValue(Value);
1266 if (Renames.count(&Symbol) && Renames[&
Symbol] != Alias)
1270 Renames.insert(std::make_pair(&Symbol, Alias));
1273 for (
const MCSymbol *&Sym : AddrsigSyms) {
1274 if (
const MCSymbol *
R = Renames.lookup(cast<MCSymbolELF>(Sym)))
1283 bool ELFObjectWriter::shouldRelocateWithSymbol(
const MCAssembler &Asm,
1287 unsigned Type)
const {
1321 assert(Sym &&
"Expected a symbol");
1350 auto &Sec = cast<MCSectionELF>(Sym->
getSection());
1358 if (!hasRelocationAddend())
1377 if (TargetObjectWriter->needsRelocateWithSymbol(*Sym, Type))
1382 void ELFObjectWriter::recordRelocation(
MCAssembler &Asm,
1386 uint64_t &FixedValue) {
1406 "No relocation available to represent this relative expression");
1410 const auto &SymB = cast<MCSymbolELF>(RefB->getSymbol());
1412 if (SymB.isUndefined()) {
1414 Twine(
"symbol '") + SymB.getName() +
1415 "' can not be undefined in a subtraction expression");
1419 assert(!SymB.isAbsolute() &&
"Should have been folded");
1420 const MCSection &SecB = SymB.getSection();
1421 if (&SecB != &FixupSection) {
1423 "Cannot represent a difference across sections");
1428 uint64_t K = SymBOffset - FixupOffset;
1435 const auto *SymA = RefA ? cast<MCSymbolELF>(&RefA->
getSymbol()) :
nullptr;
1437 bool ViaWeakRef =
false;
1438 if (SymA && SymA->isVariable()) {
1439 const MCExpr *Expr = SymA->getVariableValue();
1440 if (
const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr)) {
1442 SymA = cast<MCSymbolELF>(&Inner->getSymbol());
1448 unsigned Type = TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);
1449 uint64_t OriginalC =
C;
1450 bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type);
1451 if (!RelocateWithSymbol && SymA && !SymA->isUndefined())
1454 uint64_t Addend = 0;
1455 if (hasRelocationAddend()) {
1462 const MCSectionELF *SecA = (SymA && SymA->isInSection())
1463 ? cast<MCSectionELF>(&SymA->getSection())
1465 if (!checkRelocation(Ctx, Fixup.
getLoc(), &FixupSection, SecA))
1468 if (!RelocateWithSymbol) {
1469 const auto *SectionSymbol =
1472 SectionSymbol->setUsedInReloc();
1475 Relocations[&FixupSection].push_back(Rec);
1479 const auto *RenamedSymA = SymA;
1485 RenamedSymA->setIsWeakrefUsedInReloc();
1487 RenamedSymA->setUsedInReloc();
1491 Relocations[&FixupSection].push_back(Rec);
1494 bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
1496 bool InSet,
bool IsPCRel)
const {
1497 const auto &SymA = cast<MCSymbolELF>(SA);
1507 std::unique_ptr<MCObjectWriter>
1510 return llvm::make_unique<ELFSingleObjectWriter>(std::move(MOTW), OS,
1514 std::unique_ptr<MCObjectWriter>
1517 bool IsLittleEndian) {
1518 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.
Compute iterated dominance frontiers using a linear time algorithm.
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
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).
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
#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.
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[]
Error compress(StringRef InputBuffer, SmallVectorImpl< char > &CompressedBuffer, CompressionLevel Level=DefaultCompression)
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.
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.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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.