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());
430 W.OS <<
char(OWriter.TargetObjectWriter->getABIVersion());
436 W.write<uint16_t>(OWriter.TargetObjectWriter->getEMachine());
450 W.write<uint16_t>(0);
451 W.write<uint16_t>(0);
458 W.write<uint16_t>(0);
462 W.write<uint16_t>(StringTableIndex);
465 uint64_t ELFWriter::SymbolValue(
const MCSymbol &Sym,
481 uint8_t
Type = newType;
523 Symbol = &cast<MCSymbolELF>(Value->
getSymbol());
528 void ELFWriter::writeSymbol(SymbolTableWriter &Writer,
uint32_t StringIndex,
530 const auto &
Symbol = cast<MCSymbolELF>(*MSD.Symbol);
536 bool IsReserved = !Base ||
Symbol.isCommon();
539 uint8_t Binding =
Symbol.getBinding();
546 uint8_t
Info = (Binding << 4) | Type;
550 uint8_t Visibility =
Symbol.getVisibility();
553 uint64_t Value = SymbolValue(*MSD.Symbol, Layout);
556 const MCExpr *ESize = MSD.Symbol->getSize();
558 ESize = Base->getSize();
568 Writer.writeSymbol(StringIndex, Info, Value, Size, Other, MSD.SectionIndex,
593 bool Used,
bool Renamed) {
597 if (
const auto *
T = dyn_cast<MCTargetExpr>(Expr))
598 if (
T->inlineAssignedExpr())
630 void ELFWriter::computeSymbolTable(
632 const SectionIndexMapTy &SectionIndexMap,
const RevGroupMapTy &RevGroupMap,
633 SectionOffsetsTy &SectionOffsets) {
635 SymbolTableWriter Writer(*
this,
is64Bit());
642 SymbolTableIndex = addToSectionTable(SymtabSection);
645 uint64_t SecStart =
W.OS.tell();
648 Writer.writeSymbol(0, 0, 0, 0, 0, 0,
false);
650 std::vector<ELFSymbolData> LocalSymbolData;
651 std::vector<ELFSymbolData> ExternalSymbolData;
654 bool HasLargeSectionIndex =
false;
656 const auto &Symbol = cast<MCSymbolELF>(S);
661 if (!
isInSymtab(Layout, Symbol, Used || WeakrefUsed || isSignature,
662 OWriter.Renames.count(&Symbol)))
671 MSD.Symbol = cast<MCSymbolELF>(&
Symbol);
680 MSD.SectionIndex = Symbol.
getIndex();
686 if (isSignature && !Used) {
687 MSD.SectionIndex = RevGroupMap.lookup(&Symbol);
689 HasLargeSectionIndex =
true;
706 "Undefined section reference: " + Symbol.
getName());
710 if (
Mode == NonDwoOnly && isDwoSection(Section))
712 MSD.SectionIndex = SectionIndexMap.lookup(&Section);
713 assert(MSD.SectionIndex &&
"Invalid section index!");
715 HasLargeSectionIndex =
true;
723 StrTabBuilder.add(Name);
727 LocalSymbolData.push_back(MSD);
729 ExternalSymbolData.push_back(MSD);
733 unsigned SymtabShndxSectionIndex = 0;
735 if (HasLargeSectionIndex) {
738 SymtabShndxSectionIndex = addToSectionTable(SymtabShndxSection);
743 for (
const std::string &
Name : FileNames)
744 StrTabBuilder.add(
Name);
746 StrTabBuilder.finalize();
750 for (
const std::string &
Name : FileNames)
751 Writer.writeSymbol(StrTabBuilder.getOffset(
Name),
757 array_pod_sort(ExternalSymbolData.begin(), ExternalSymbolData.end());
761 unsigned Index = FileNames.size() + 1;
763 for (ELFSymbolData &MSD : LocalSymbolData) {
766 : StrTabBuilder.getOffset(MSD.Name);
767 MSD.Symbol->setIndex(Index++);
768 writeSymbol(Writer, StringIndex, MSD, Layout);
772 LastLocalSymbolIndex =
Index;
774 for (ELFSymbolData &MSD : ExternalSymbolData) {
775 unsigned StringIndex = StrTabBuilder.getOffset(MSD.Name);
776 MSD.Symbol->setIndex(Index++);
777 writeSymbol(Writer, StringIndex, MSD, Layout);
781 uint64_t SecEnd =
W.OS.tell();
782 SectionOffsets[SymtabSection] = std::make_pair(SecStart, SecEnd);
785 if (ShndxIndexes.
empty()) {
786 assert(SymtabShndxSectionIndex == 0);
789 assert(SymtabShndxSectionIndex != 0);
791 SecStart =
W.OS.tell();
793 SectionTable[SymtabShndxSectionIndex - 1];
796 SecEnd =
W.OS.tell();
797 SectionOffsets[SymtabShndxSection] = std::make_pair(SecStart, SecEnd);
800 void ELFWriter::writeAddrsigSection() {
801 for (
const MCSymbol *Sym : OWriter.AddrsigSyms)
807 if (OWriter.Relocations[&Sec].empty())
811 std::string RelaSectionName = hasRelocationAddend() ?
".rela" :
".rel";
815 if (hasRelocationAddend())
826 Flags, EntrySize, Sec.
getGroup(), &Sec);
832 bool ELFWriter::maybeWriteCompression(
834 unsigned Alignment) {
838 if (
Size <= HdrSize + CompressedContents.
size())
844 write(static_cast<ELF::Elf64_Word>(0));
845 write(static_cast<ELF::Elf64_Xword>(
Size));
846 write(static_cast<ELF::Elf64_Xword>(Alignment));
850 write(static_cast<ELF::Elf32_Word>(
Size));
851 write(static_cast<ELF::Elf32_Word>(Alignment));
877 bool CompressionEnabled =
879 if (!CompressionEnabled || !SectionName.
startswith(
".debug_") ||
880 SectionName ==
".debug_frame") {
887 "expected zlib or zlib-gnu style compression");
896 CompressedContents)) {
898 W.OS << UncompressedData;
903 if (!maybeWriteCompression(UncompressedData.
size(), CompressedContents,
905 W.OS << UncompressedData;
917 MC.renameELFSection(&Section, (
".z" + SectionName.
drop_front(1)).str());
919 W.OS << CompressedContents;
925 uint64_t Alignment, uint64_t EntrySize) {
934 WriteWord(Alignment);
935 WriteWord(EntrySize);
938 void ELFWriter::writeRelocations(
const MCAssembler &Asm,
940 std::vector<ELFRelocationEntry> &Relocs = OWriter.Relocations[&Sec];
949 OWriter.TargetObjectWriter->sortRelocs(Asm, Relocs);
951 for (
unsigned i = 0,
e = Relocs.size(); i !=
e; ++i) {
957 if (OWriter.TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS) {
960 write(OWriter.TargetObjectWriter->getRSsym(Entry.
Type));
961 write(OWriter.TargetObjectWriter->getRType3(Entry.
Type));
962 write(OWriter.TargetObjectWriter->getRType2(Entry.
Type));
963 write(OWriter.TargetObjectWriter->getRType(Entry.
Type));
969 if (hasRelocationAddend())
978 if (hasRelocationAddend())
981 if (OWriter.TargetObjectWriter->getEMachine() ==
ELF::EM_MIPS) {
983 OWriter.TargetObjectWriter->getRType2(Entry.
Type)) {
991 OWriter.TargetObjectWriter->getRType3(Entry.
Type)) {
1004 const MCSectionELF *StrtabSection = SectionTable[StringTableIndex - 1];
1005 StrTabBuilder.write(
W.OS);
1006 return StrtabSection;
1009 void ELFWriter::writeSection(
const SectionIndexMapTy &SectionIndexMap,
1012 uint64_t sh_link = 0;
1013 uint64_t sh_info = 0;
1025 sh_link = SymbolTableIndex;
1026 assert(sh_link &&
".symtab not found");
1028 sh_info = SectionIndexMap.lookup(cast<MCSectionELF>(InfoSection));
1033 sh_link = StringTableIndex;
1034 sh_info = LastLocalSymbolIndex;
1040 sh_link = SymbolTableIndex;
1044 sh_link = SymbolTableIndex;
1045 sh_info = GroupSymbolIndex;
1052 sh_link = SectionIndexMap.lookup(Sec);
1055 WriteSecHdrEntry(StrTabBuilder.getOffset(Section.
getSectionName()),
1061 void ELFWriter::writeSectionHeader(
1062 const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap,
1063 const SectionOffsetsTy &SectionOffsets) {
1064 const unsigned NumSections = SectionTable.size();
1067 uint64_t FirstSectionSize =
1069 WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, 0, 0);
1073 unsigned Type = Section->
getType();
1075 GroupSymbolIndex = 0;
1079 const std::pair<uint64_t, uint64_t> &
Offsets =
1080 SectionOffsets.find(Section)->second;
1085 Size = Offsets.second - Offsets.first;
1087 writeSection(SectionIndexMap, GroupSymbolIndex, Offsets.first, Size,
1093 uint64_t StartOffset =
W.OS.tell();
1098 StringTableIndex = addToSectionTable(StrtabSection);
1100 RevGroupMapTy RevGroupMap;
1101 SectionIndexMapTy SectionIndexMap;
1103 std::map<const MCSymbol *, std::vector<const MCSectionELF *>> GroupMembers;
1109 SectionOffsetsTy SectionOffsets;
1110 std::vector<MCSectionELF *>
Groups;
1111 std::vector<MCSectionELF *> Relocations;
1114 if (
Mode == NonDwoOnly && isDwoSection(Section))
1116 if (
Mode == DwoOnly && !isDwoSection(Section))
1122 uint64_t SecStart =
W.OS.tell();
1125 writeSectionData(Asm, Section, Layout);
1127 uint64_t SecEnd =
W.OS.tell();
1128 SectionOffsets[&
Section] = std::make_pair(SecStart, SecEnd);
1130 MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
1132 if (SignatureSymbol) {
1133 Asm.registerSymbol(*SignatureSymbol);
1134 unsigned &GroupIdx = RevGroupMap[SignatureSymbol];
1137 GroupIdx = addToSectionTable(Group);
1139 Groups.push_back(Group);
1141 std::vector<const MCSectionELF *> &Members =
1142 GroupMembers[SignatureSymbol];
1143 Members.push_back(&Section);
1145 Members.push_back(RelSection);
1148 SectionIndexMap[&
Section] = addToSectionTable(&Section);
1150 SectionIndexMap[RelSection] = addToSectionTable(RelSection);
1151 Relocations.push_back(RelSection);
1154 OWriter.TargetObjectWriter->addTargetSectionFlags(Ctx, Section);
1158 if (!Asm.CGProfile.empty()) {
1159 CGProfileSection = Ctx.
getELFSection(
".llvm.call-graph-profile",
1162 SectionIndexMap[CGProfileSection] = addToSectionTable(CGProfileSection);
1166 align(Group->getAlignment());
1169 uint64_t SecStart =
W.OS.tell();
1171 const MCSymbol *SignatureSymbol = Group->getGroup();
1174 for (
const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
1175 uint32_t SecIndex = SectionIndexMap.lookup(Member);
1179 uint64_t SecEnd =
W.OS.tell();
1180 SectionOffsets[Group] = std::make_pair(SecStart, SecEnd);
1183 if (
Mode == DwoOnly) {
1186 StrTabBuilder.finalize();
1189 if (OWriter.EmitAddrsigSection) {
1192 addToSectionTable(AddrsigSection);
1196 computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap,
1200 align(RelSection->getAlignment());
1203 uint64_t SecStart =
W.OS.tell();
1205 writeRelocations(Asm,
1206 cast<MCSectionELF>(*RelSection->getAssociatedSection()));
1208 uint64_t SecEnd =
W.OS.tell();
1209 SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
1212 if (OWriter.EmitAddrsigSection) {
1213 uint64_t SecStart =
W.OS.tell();
1214 writeAddrsigSection();
1215 uint64_t SecEnd =
W.OS.tell();
1216 SectionOffsets[AddrsigSection] = std::make_pair(SecStart, SecEnd);
1220 if (CGProfileSection) {
1221 uint64_t SecStart =
W.OS.tell();
1225 W.write<uint64_t>(CGPE.
Count);
1227 uint64_t SecEnd =
W.OS.tell();
1228 SectionOffsets[CGProfileSection] = std::make_pair(SecStart, SecEnd);
1232 uint64_t SecStart =
W.OS.tell();
1234 uint64_t SecEnd =
W.OS.tell();
1235 SectionOffsets[Sec] = std::make_pair(SecStart, SecEnd);
1238 uint64_t NaturalAlignment =
is64Bit() ? 8 : 4;
1239 align(NaturalAlignment);
1241 const uint64_t SectionHeaderOffset =
W.OS.tell();
1244 writeSectionHeader(Layout, SectionIndexMap, SectionOffsets);
1246 uint16_t NumSections = support::endian::byte_swap<uint16_t>(
1248 : SectionTable.size() + 1,
1250 unsigned NumSectionsOffset;
1255 support::endian::byte_swap<uint64_t>(SectionHeaderOffset,
W.Endian);
1256 Stream.
pwrite(reinterpret_cast<char *>(&Val),
sizeof(Val),
1261 support::endian::byte_swap<uint32_t>(SectionHeaderOffset,
W.Endian);
1262 Stream.pwrite(reinterpret_cast<char *>(&Val),
sizeof(Val),
1266 Stream.pwrite(reinterpret_cast<char *>(&NumSections),
sizeof(NumSections),
1269 return W.OS.tell() - StartOffset;
1272 bool ELFObjectWriter::hasRelocationAddend()
const {
1273 return TargetObjectWriter->hasRelocationAddend();
1276 void ELFObjectWriter::executePostLayoutBinding(
MCAssembler &Asm,
1280 for (
const std::pair<StringRef, const MCSymbol *> &
P : Asm.
Symvers) {
1282 const auto &Symbol = cast<MCSymbolELF>(*P.second);
1283 size_t Pos = AliasName.
find(
'@');
1296 Alias->setVariableValue(Value);
1302 Alias->setOther(Symbol.
getOther());
1311 " must be defined");
1315 if (Renames.count(&Symbol) && Renames[&
Symbol] != Alias) {
1322 Renames.insert(std::make_pair(&Symbol, Alias));
1325 for (
const MCSymbol *&Sym : AddrsigSyms) {
1326 if (
const MCSymbol *
R = Renames.lookup(cast<MCSymbolELF>(Sym)))
1337 bool ELFObjectWriter::shouldRelocateWithSymbol(
const MCAssembler &Asm,
1341 unsigned Type)
const {
1375 assert(Sym &&
"Expected a symbol");
1410 auto &Sec = cast<MCSectionELF>(Sym->
getSection());
1418 if (!hasRelocationAddend())
1437 if (TargetObjectWriter->needsRelocateWithSymbol(*Sym, Type))
1442 void ELFObjectWriter::recordRelocation(
MCAssembler &Asm,
1446 uint64_t &FixedValue) {
1456 const auto &SymB = cast<MCSymbolELF>(RefB->getSymbol());
1457 if (SymB.isUndefined()) {
1459 Twine(
"symbol '") + SymB.getName() +
1460 "' can not be undefined in a subtraction expression");
1464 assert(!SymB.isAbsolute() &&
"Should have been folded");
1465 const MCSection &SecB = SymB.getSection();
1466 if (&SecB != &FixupSection) {
1468 "Cannot represent a difference across sections");
1472 assert(!IsPCRel &&
"should have been folded");
1479 const auto *SymA = RefA ? cast<MCSymbolELF>(&RefA->
getSymbol()) :
nullptr;
1481 bool ViaWeakRef =
false;
1482 if (SymA && SymA->isVariable()) {
1483 const MCExpr *Expr = SymA->getVariableValue();
1484 if (
const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr)) {
1486 SymA = cast<MCSymbolELF>(&Inner->getSymbol());
1492 const MCSectionELF *SecA = (SymA && SymA->isInSection())
1493 ? cast<MCSectionELF>(&SymA->getSection())
1495 if (!checkRelocation(Ctx, Fixup.
getLoc(), &FixupSection, SecA))
1498 unsigned Type = TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);
1499 bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type);
1500 uint64_t Addend = 0;
1502 FixedValue = !RelocateWithSymbol && SymA && !SymA->isUndefined()
1505 if (hasRelocationAddend()) {
1506 Addend = FixedValue;
1510 if (!RelocateWithSymbol) {
1511 const auto *SectionSymbol =
1514 SectionSymbol->setUsedInReloc();
1516 Relocations[&FixupSection].push_back(Rec);
1531 Relocations[&FixupSection].push_back(Rec);
1534 bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
1536 bool InSet,
bool IsPCRel)
const {
1537 const auto &SymA = cast<MCSymbolELF>(SA);
1547 std::unique_ptr<MCObjectWriter>
1550 return std::make_unique<ELFSingleObjectWriter>(std::move(MOTW), OS,
1554 std::unique_ptr<MCObjectWriter>
1557 bool IsLittleEndian) {
1558 return std::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...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
uint32_t getIndex() const
Get the (implementation defined) index.
void setUsedInReloc() const
void setSymbolAndType(Elf32_Word s, unsigned char t)
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
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
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
unsigned getBinding() const
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Optional< std::vector< StOtherPiece > > Other
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.
void setSymbolAndType(Elf64_Word s, Elf64_Word t)
bool isCommon() const
Is this a 'common' symbol.
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
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
int64_t getConstant() const
const MCSymbolRefExpr * getSymB() const
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.
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
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.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
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()))
Utility for building string tables with deduplicated suffixes.
bool isBindingSet() const
LLVM_NODISCARD size_t size() const
size - Get the string size.
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)
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)
static bool isIFunc(const MCSymbolELF *Symbol)
virtual void reset()
lifetime management
bool isRegistered() const
#define offsetof(TYPE, MEMBER)
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
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 setAlignment(Align Value)
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
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
zlib-gnu style compression
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.
Tail - This calling convention attemps to make calls as fast as possible while guaranteeing that tail...
This represents a section on linux, lots of unix variants and some bare metal systems.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void setIsWeakrefUsedInReloc() const
bool isTargetCommon() const
Is this a target-specific common-like symbol.
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.
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.
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.