49constexpr unsigned DefaultSectionAlign = 4;
50constexpr int16_t MaxSectionIndex = INT16_MAX;
55struct XCOFFRelocation {
56 uint32_t SymbolTableIndex;
57 uint32_t FixupOffsetInCsect;
64 const MCSymbolXCOFF *
const MCSym;
65 uint32_t SymbolTableIndex;
68 return MCSym->getVisibilityType();
72 return MCSym->getStorageClass();
74 StringRef getSymbolTableName()
const {
return MCSym->getSymbolTableName(); }
75 Symbol(
const MCSymbolXCOFF *MCSym) : MCSym(MCSym), SymbolTableIndex(-1) {}
81 const MCSectionXCOFF *
const MCSec;
82 uint32_t SymbolTableIndex;
88 StringRef getSymbolTableName()
const {
return MCSec->getSymbolTableName(); }
90 return MCSec->getVisibilityType();
92 XCOFFSection(
const MCSectionXCOFF *MCSec)
93 : MCSec(MCSec), SymbolTableIndex(-1), Address(-1), Size(0) {}
100using CsectGroup = std::deque<XCOFFSection>;
101using CsectGroups = std::deque<CsectGroup *>;
117 uint32_t RelocationCount;
124 FileOffsetToData = RawPointer;
125 uint64_t NewPointer = RawPointer + Size;
126 if (NewPointer > MaxRawDataSize)
138 static constexpr int16_t UninitializedIndex =
142 : Name(), Address(0), Size(0), FileOffsetToData(0),
143 FileOffsetToRelocations(0), RelocationCount(0), Flags(Flags),
144 Index(UninitializedIndex) {
146 memcpy(Name,
N.data(),
N.size());
149 virtual void reset() {
152 FileOffsetToData = 0;
153 FileOffsetToRelocations = 0;
155 Index = UninitializedIndex;
168 const bool IsVirtual;
175 : SectionEntry(
N,
Flags), IsVirtual(IsVirtual), Groups(Groups) {
177 memcpy(Name,
N.data(),
N.size());
180 void reset()
override {
181 SectionEntry::reset();
183 for (
auto *Group : Groups)
187 ~CsectSectionEntry()
override =
default;
192 std::unique_ptr<XCOFFSection> DwarfSect;
203 const uint64_t RawPointer)
override {
204 FileOffsetToData = RawPointer;
205 uint64_t NewPointer = RawPointer + MemorySize;
206 assert(NewPointer <= MaxRawDataSize &&
207 "Section raw data overflowed this object file.");
211 DwarfSectionEntry(StringRef
N, int32_t Flags,
212 std::unique_ptr<XCOFFSection> Sect)
215 assert(DwarfSect->MCSec->isDwarfSect() &&
216 "This should be a DWARF section!");
218 memcpy(Name,
N.data(),
N.size());
221 DwarfSectionEntry(DwarfSectionEntry &&s) =
default;
223 ~DwarfSectionEntry()
override =
default;
226struct ExceptionTableEntry {
232 ExceptionTableEntry(
const MCSymbol *Trap,
unsigned Lang,
unsigned Reason)
233 : Trap(Trap), Lang(Lang), Reason(Reason) {}
236struct ExceptionInfo {
238 unsigned FunctionSize;
239 std::vector<ExceptionTableEntry> Entries;
243 std::map<const StringRef, ExceptionInfo> ExceptionTable;
244 bool isDebugEnabled =
false;
246 ExceptionSectionEntry(StringRef
N, int32_t Flags)
249 memcpy(Name,
N.data(),
N.size());
252 ~ExceptionSectionEntry()
override =
default;
258 std::string Metadata;
262 CInfoSymInfo(std::string Name, std::string Metadata)
263 : Name(Name), Metadata(Metadata) {}
265 uint32_t paddingSize()
const {
266 return alignTo(Metadata.size(),
sizeof(uint32_t)) - Metadata.size();
270 uint32_t
size()
const {
271 return Metadata.size() + paddingSize() +
sizeof(uint32_t);
276 std::unique_ptr<CInfoSymInfo> Entry;
278 CInfoSymSectionEntry(StringRef
N, int32_t Flags) : SectionEntry(
N,
Flags) {}
279 ~CInfoSymSectionEntry()
override =
default;
280 void addEntry(std::unique_ptr<CInfoSymInfo> NewEntry) {
281 Entry = std::move(NewEntry);
282 Entry->Offset =
sizeof(uint32_t);
283 Size += Entry->size();
285 void reset()
override {
286 SectionEntry::reset();
292 uint32_t SymbolTableEntryCount = 0;
294 uint16_t SectionCount = 0;
295 uint32_t PaddingsBeforeDwarf = 0;
296 bool HasVisibility =
false;
298 support::endian::Writer W;
299 std::unique_ptr<MCXCOFFObjectTargetWriter> TargetObjectWriter;
300 StringTableBuilder Strings;
303 TargetObjectWriter->is64Bit() ?
UINT64_MAX : UINT32_MAX;
308 DenseMap<const MCSectionXCOFF *, XCOFFSection *> SectionMap;
312 DenseMap<const MCSymbol *, uint32_t> SymbolIndexMap;
317 CsectGroup UndefinedCsects;
318 CsectGroup ProgramCodeCsects;
319 CsectGroup ReadOnlyCsects;
320 CsectGroup DataCsects;
321 CsectGroup FuncDSCsects;
322 CsectGroup TOCCsects;
323 CsectGroup BSSCsects;
324 CsectGroup TDataCsects;
325 CsectGroup TBSSCsects;
328 CsectSectionEntry Text;
329 CsectSectionEntry Data;
330 CsectSectionEntry BSS;
331 CsectSectionEntry TData;
332 CsectSectionEntry TBSS;
336 std::array<CsectSectionEntry *const, 5> Sections{
337 {&Text, &Data, &BSS, &TData, &TBSS}};
339 std::vector<DwarfSectionEntry> DwarfSections;
340 std::vector<SectionEntry> OverflowSections;
342 ExceptionSectionEntry ExceptionSection;
343 CInfoSymSectionEntry CInfoSymSection;
345 CsectGroup &getCsectGroup(
const MCSectionXCOFF *MCSec);
347 void reset()
override;
349 void executePostLayoutBinding()
override;
351 void recordRelocation(
const MCFragment &,
const MCFixup &, MCValue,
356 bool is64Bit()
const {
return TargetObjectWriter->is64Bit(); }
357 bool nameShouldBeInStringTable(
const StringRef &);
358 void writeSymbolName(
const StringRef &);
359 bool auxFileSymNameShouldBeInStringTable(
const StringRef &);
360 void writeAuxFileSymName(
const StringRef &);
362 void writeSymbolEntryForCsectMemberLabel(
const Symbol &SymbolRef,
363 const XCOFFSection &CSectionRef,
364 int16_t SectionIndex,
366 void writeSymbolEntryForControlSection(
const XCOFFSection &CSectionRef,
367 int16_t SectionIndex,
369 void writeSymbolEntryForDwarfSection(
const XCOFFSection &DwarfSectionRef,
370 int16_t SectionIndex);
371 void writeFileHeader();
372 void writeAuxFileHeader();
374 void writeSectionHeaderTable();
375 void writeSections(
const MCAssembler &Asm);
376 void writeSectionForControlSectionEntry(
const MCAssembler &Asm,
377 const CsectSectionEntry &CsectEntry,
379 void writeSectionForDwarfSectionEntry(
const MCAssembler &Asm,
380 const DwarfSectionEntry &DwarfEntry,
383 writeSectionForExceptionSectionEntry(
const MCAssembler &Asm,
384 ExceptionSectionEntry &ExceptionEntry,
386 void writeSectionForCInfoSymSectionEntry(
const MCAssembler &Asm,
387 CInfoSymSectionEntry &CInfoSymEntry,
390 void writeSymbolAuxFileEntry(StringRef &Name, uint8_t ftype);
391 void writeSymbolAuxDwarfEntry(
uint64_t LengthOfSectionPortion,
393 void writeSymbolAuxCsectEntry(
uint64_t SectionOrLength,
394 uint8_t SymbolAlignmentAndType,
396 void writeSymbolAuxFunctionEntry(uint32_t EntryOffset, uint32_t FunctionSize,
399 void writeSymbolAuxExceptionEntry(
uint64_t EntryOffset, uint32_t FunctionSize,
404 void writeRelocations();
405 void writeRelocation(XCOFFRelocation Reloc,
const XCOFFSection &Section);
415 void assignAddressesAndIndices(MCAssembler &Asm);
417 void finalizeSectionInfo();
418 void finalizeRelocationInfo(SectionEntry *Sec,
uint64_t RelCount);
419 void calcOffsetToRelocations(SectionEntry *Sec,
uint64_t &RawPointer);
421 bool hasExceptionSection() {
422 return !ExceptionSection.ExceptionTable.empty();
424 unsigned getExceptionSectionSize();
425 unsigned getExceptionOffset(
const MCSymbol *Symbol);
427 size_t auxiliaryHeaderSize()
const {
433 XCOFFWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
434 raw_pwrite_stream &OS);
440 void addExceptionEntry(
const MCSymbol *Symbol,
const MCSymbol *
Trap,
441 unsigned LanguageCode,
unsigned ReasonCode,
442 unsigned FunctionSize,
bool hasDebug)
override;
443 void addCInfoSymEntry(StringRef Name, StringRef
Metadata)
override;
446XCOFFWriter::XCOFFWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
451 CsectGroups{&ProgramCodeCsects, &ReadOnlyCsects}),
453 CsectGroups{&DataCsects, &FuncDSCsects, &TOCCsects}),
455 CsectGroups{&BSSCsects}),
457 CsectGroups{&TDataCsects}),
459 CsectGroups{&TBSSCsects}),
463void XCOFFWriter::reset() {
465 SymbolIndexMap.
clear();
468 UndefinedCsects.clear();
470 for (
auto *Sec : Sections)
472 for (
auto &DwarfSec : DwarfSections)
474 for (
auto &OverflowSec : OverflowSections)
476 ExceptionSection.reset();
477 CInfoSymSection.reset();
480 SymbolTableEntryCount = 0;
481 SymbolTableOffset = 0;
483 PaddingsBeforeDwarf = 0;
489CsectGroup &XCOFFWriter::getCsectGroup(
const MCSectionXCOFF *MCSec) {
493 "Only an initialized csect can contain program code.");
494 return ProgramCodeCsects;
497 "Only an initialized csect can contain read only data.");
498 return ReadOnlyCsects;
511 "Mapping invalid csect. CSECT with bss storage class must be "
516 "Mapping invalid csect. CSECT with tdata storage class must be "
517 "an initialized csect.");
521 "Mapping invalid csect. CSECT with tbss storage class must be "
522 "an uninitialized csect.");
526 "Only an initialized csect can contain TOC-base.");
527 assert(TOCCsects.empty() &&
528 "We should have only one TOC-base, and it should be the first csect "
529 "in this CsectGroup.");
534 "A TOC symbol must be an initialized csect.");
535 assert(!TOCCsects.empty() &&
536 "We should at least have a TOC-base in this CsectGroup.");
541 "Symbol type incompatible with toc-data.");
542 assert(!TOCCsects.empty() &&
543 "We should at least have a TOC-base in this CsectGroup.");
550static MCSectionXCOFF *getContainingCsect(
const MCSymbolXCOFF *XSym) {
558static bool haveDifferentSections(
const MCFragment &
F, MCValue Target) {
567 const MCSection *FragSection =
F.getParent();
569 return TargetSection != FragSection;
572static bool callOverflows(MCFixupKindInfo Info,
uint64_t FixedValue) {
573 if (
Info.TargetSize != 24)
576 return !
isIntN(26, FixedValue);
580 if (
Info.TargetSize != 24)
586void XCOFFWriter::executePostLayoutBinding() {
587 for (
const auto &S : *Asm) {
588 auto *MCSec =
static_cast<const MCSectionXCOFF *
>(&S);
589 assert(!SectionMap.
contains(MCSec) &&
"Cannot add a section twice.");
600 "An undefined csect should not get registered.");
601 CsectGroup &Group = getCsectGroup(MCSec);
602 Group.emplace_back(MCSec);
603 SectionMap[MCSec] = &Group.back();
606 std::unique_ptr<XCOFFSection> DwarfSec =
607 std::make_unique<XCOFFSection>(MCSec);
608 SectionMap[MCSec] = DwarfSec.get();
610 DwarfSectionEntry SecEntry(MCSec->
getName(),
612 std::move(DwarfSec));
613 DwarfSections.push_back(std::move(SecEntry));
618 for (
const MCSymbol &S :
Asm->symbols()) {
623 auto *XSym =
static_cast<const MCSymbolXCOFF *
>(&S);
624 const MCSectionXCOFF *ContainingCsect = getContainingCsect(XSym);
630 HasVisibility =
true;
634 UndefinedCsects.emplace_back(ContainingCsect);
635 SectionMap[ContainingCsect] = &UndefinedCsects.back();
651 "Expected containing csect to exist in map");
652 XCOFFSection *Csect = SectionMap[ContainingCsect];
654 assert(Csect->MCSec->
isCsect() &&
"only csect is supported now!");
655 Csect->Syms.emplace_back(XSym);
663 std::unique_ptr<CInfoSymInfo> &CISI = CInfoSymSection.Entry;
664 if (CISI && nameShouldBeInStringTable(CISI->Name))
665 Strings.
add(CISI->Name);
668 if (FileNames.empty())
669 FileNames.emplace_back(
".file", 0);
670 for (
const std::pair<std::string, size_t> &
F : FileNames) {
671 if (auxFileSymNameShouldBeInStringTable(
F.first))
672 Strings.
add(
F.first);
677 if (nameShouldBeInStringTable(
".file"))
678 Strings.
add(
".file");
679 StringRef Vers = CompilerVersion;
680 if (auxFileSymNameShouldBeInStringTable(Vers))
684 assignAddressesAndIndices(*Asm);
687void XCOFFWriter::recordRelocation(
const MCFragment &
F,
const MCFixup &
Fixup,
688 MCValue Target,
uint64_t &FixedValue) {
689 auto getIndex = [
this](
const MCSymbol *Sym,
690 const MCSectionXCOFF *ContainingCsect) {
694 auto It = SymbolIndexMap.
find(Sym);
695 return It != SymbolIndexMap.
end()
700 auto getVirtualAddress =
702 const MCSectionXCOFF *ContainingSect) ->
uint64_t {
704 if (ContainingSect->isDwarfSect())
705 return Asm->getSymbolOffset(*Sym);
709 return SectionMap[ContainingSect]->Address;
713 return SectionMap[ContainingSect]->Address +
Asm->getSymbolOffset(*Sym);
719 std::tie(
Type, SignAndSize) = TargetObjectWriter->getRelocTypeAndSignSize(
722 const MCSectionXCOFF *SymASec =
723 getContainingCsect(
static_cast<const MCSymbolXCOFF *
>(SymA));
725 "Expected containing csect to exist in map.");
727 assert((
Fixup.getOffset() <= MaxRawDataSize -
Asm->getFragmentOffset(
F)) &&
728 "Fragment offset + fixup offset is overflowed.");
729 uint32_t FixupOffsetInCsect =
Asm->getFragmentOffset(
F) +
Fixup.getOffset();
731 const uint32_t
Index = getIndex(SymA, SymASec);
732 if (
Type == XCOFF::RelocationType::R_POS ||
733 Type == XCOFF::RelocationType::R_TLS ||
734 Type == XCOFF::RelocationType::R_TLS_LE ||
735 Type == XCOFF::RelocationType::R_TLS_IE ||
736 Type == XCOFF::RelocationType::R_TLS_LD)
739 FixedValue = getVirtualAddress(SymA, SymASec) +
Target.getConstant();
740 else if (
Type == XCOFF::RelocationType::R_TLSM)
744 else if (
Type == XCOFF::RelocationType::R_TOC ||
745 Type == XCOFF::RelocationType::R_TOCL) {
756 int64_t TOCEntryOffset = SectionMap[SymASec]->Address -
757 TOCCsects.front().Address +
Target.getConstant();
774 if (
Type == XCOFF::RelocationType::R_TOC && !
isInt<16>(TOCEntryOffset))
777 FixedValue = TOCEntryOffset;
779 }
else if (
Type == XCOFF::RelocationType::R_RBR) {
780 auto *ParentSec =
static_cast<MCSectionXCOFF *
>(
F.getParent());
783 "Only XMC_PR csect may have the R_RBR relocation.");
788 SectionMap[ParentSec]->Address + FixupOffsetInCsect;
791 FixedValue = getVirtualAddress(SymA, SymASec) - BRInstrAddress +
798 MCFixupKindInfo
Info =
Asm->getBackend().getFixupKindInfo(
Fixup.getKind());
799 if (callOverflows(Info, FixedValue) && haveDifferentSections(
F, Target))
800 FixedValue = normalizeCallOffset(Info, FixedValue);
801 }
else if (
Type == XCOFF::RelocationType::R_REF) {
805 FixupOffsetInCsect = 0;
808 XCOFFRelocation Reloc = {
Index, FixupOffsetInCsect, SignAndSize,
Type};
809 auto *RelocationSec =
static_cast<MCSectionXCOFF *
>(
F.getParent());
811 "Expected containing csect to exist in map.");
812 SectionMap[RelocationSec]->Relocations.push_back(Reloc);
814 auto SymB =
static_cast<const MCSymbolXCOFF *
>(
Target.getSubSym());
820 const MCSectionXCOFF *SymBSec = getContainingCsect(SymB);
822 "Expected containing csect to exist in map.");
823 if (SymASec == SymBSec)
825 "relocation for paired relocatable term is not yet supported");
827 assert(
Type == XCOFF::RelocationType::R_POS &&
828 "SymA must be R_POS here if it's not opposite term or paired "
829 "relocatable term.");
830 const uint32_t IndexB = getIndex(SymB, SymBSec);
833 const uint8_t TypeB = XCOFF::RelocationType::R_NEG;
834 XCOFFRelocation RelocB = {IndexB, FixupOffsetInCsect, SignAndSize, TypeB};
835 SectionMap[RelocationSec]->Relocations.push_back(RelocB);
838 FixedValue -= getVirtualAddress(SymB, SymBSec);
841void XCOFFWriter::writeSections(
const MCAssembler &Asm) {
842 uint64_t CurrentAddressLocation = 0;
843 for (
const auto *Section : Sections)
844 writeSectionForControlSectionEntry(Asm, *Section, CurrentAddressLocation);
845 for (
const auto &DwarfSection : DwarfSections)
846 writeSectionForDwarfSectionEntry(Asm, DwarfSection, CurrentAddressLocation);
847 writeSectionForExceptionSectionEntry(Asm, ExceptionSection,
848 CurrentAddressLocation);
849 writeSectionForCInfoSymSectionEntry(Asm, CInfoSymSection,
850 CurrentAddressLocation);
853uint64_t XCOFFWriter::writeObject() {
858 finalizeSectionInfo();
862 writeAuxFileHeader();
863 writeSectionHeaderTable();
870 return W.OS.tell() - StartOffset;
873bool XCOFFWriter::nameShouldBeInStringTable(
const StringRef &SymbolName) {
877void XCOFFWriter::writeSymbolName(
const StringRef &SymbolName) {
879 if (nameShouldBeInStringTable(SymbolName)) {
881 W.write<uint32_t>(Strings.
getOffset(SymbolName));
890void XCOFFWriter::writeSymbolEntry(StringRef SymbolName,
uint64_t Value,
893 uint8_t NumberOfAuxEntries) {
896 W.write<uint32_t>(Strings.
getOffset(SymbolName));
898 writeSymbolName(SymbolName);
901 W.write<int16_t>(SectionNumber);
904 W.write<uint8_t>(NumberOfAuxEntries);
907void XCOFFWriter::writeSymbolAuxCsectEntry(
uint64_t SectionOrLength,
908 uint8_t SymbolAlignmentAndType,
910 W.write<uint32_t>(
is64Bit() ?
Lo_32(SectionOrLength) : SectionOrLength);
911 W.write<uint32_t>(0);
912 W.write<uint16_t>(0);
913 W.write<uint8_t>(SymbolAlignmentAndType);
916 W.write<uint32_t>(
Hi_32(SectionOrLength));
920 W.write<uint32_t>(0);
921 W.write<uint16_t>(0);
925bool XCOFFWriter::auxFileSymNameShouldBeInStringTable(
926 const StringRef &SymbolName) {
930void XCOFFWriter::writeAuxFileSymName(
const StringRef &SymbolName) {
932 if (auxFileSymNameShouldBeInStringTable(SymbolName)) {
934 W.write<uint32_t>(Strings.
getOffset(SymbolName));
944void XCOFFWriter::writeSymbolAuxFileEntry(StringRef &Name, uint8_t ftype) {
945 writeAuxFileSymName(Name);
946 W.write<uint8_t>(ftype);
954void XCOFFWriter::writeSymbolAuxDwarfEntry(
uint64_t LengthOfSectionPortion,
968void XCOFFWriter::writeSymbolEntryForCsectMemberLabel(
969 const Symbol &SymbolRef,
const XCOFFSection &CSectionRef,
970 int16_t SectionIndex,
uint64_t SymbolOffset) {
971 assert(SymbolOffset <= MaxRawDataSize - CSectionRef.Address &&
972 "Symbol address overflowed.");
974 auto Entry = ExceptionSection.ExceptionTable.find(SymbolRef.MCSym->
getName());
975 if (Entry != ExceptionSection.ExceptionTable.end()) {
976 writeSymbolEntry(SymbolRef.getSymbolTableName(),
977 CSectionRef.Address + SymbolOffset, SectionIndex,
981 is64Bit() ? SymbolRef.getVisibilityType()
982 : SymbolRef.getVisibilityType() | 0x0020,
983 SymbolRef.getStorageClass(),
984 (
is64Bit() && ExceptionSection.isDebugEnabled) ? 3 : 2);
985 if (
is64Bit() && ExceptionSection.isDebugEnabled) {
988 writeSymbolAuxExceptionEntry(
989 ExceptionSection.FileOffsetToData +
990 getExceptionOffset(
Entry->second.FunctionSymbol),
991 Entry->second.FunctionSize,
992 SymbolIndexMap[
Entry->second.FunctionSymbol] + 4);
996 writeSymbolAuxFunctionEntry(
997 ExceptionSection.FileOffsetToData +
998 getExceptionOffset(
Entry->second.FunctionSymbol),
999 Entry->second.FunctionSize, 0,
1000 (
is64Bit() && ExceptionSection.isDebugEnabled)
1001 ? SymbolIndexMap[
Entry->second.FunctionSymbol] + 4
1002 : SymbolIndexMap[
Entry->second.FunctionSymbol] + 3);
1004 writeSymbolEntry(SymbolRef.getSymbolTableName(),
1005 CSectionRef.Address + SymbolOffset, SectionIndex,
1006 SymbolRef.getVisibilityType(),
1007 SymbolRef.getStorageClass());
1009 writeSymbolAuxCsectEntry(CSectionRef.SymbolTableIndex,
XCOFF::XTY_LD,
1013void XCOFFWriter::writeSymbolEntryForDwarfSection(
1014 const XCOFFSection &DwarfSectionRef, int16_t SectionIndex) {
1017 writeSymbolEntry(DwarfSectionRef.getSymbolTableName(), 0,
1020 writeSymbolAuxDwarfEntry(DwarfSectionRef.Size);
1023void XCOFFWriter::writeSymbolEntryForControlSection(
1024 const XCOFFSection &CSectionRef, int16_t SectionIndex,
1026 writeSymbolEntry(CSectionRef.getSymbolTableName(), CSectionRef.Address,
1027 SectionIndex, CSectionRef.getVisibilityType(),
StorageClass);
1029 writeSymbolAuxCsectEntry(CSectionRef.Size, getEncodedType(CSectionRef.MCSec),
1033void XCOFFWriter::writeSymbolAuxFunctionEntry(uint32_t EntryOffset,
1034 uint32_t FunctionSize,
1036 uint32_t EndIndex) {
1040 W.write<uint32_t>(EntryOffset);
1041 W.write<uint32_t>(FunctionSize);
1044 W.write<uint32_t>(EndIndex);
1046 W.OS.write_zeros(1);
1049 W.OS.write_zeros(2);
1053void XCOFFWriter::writeSymbolAuxExceptionEntry(
uint64_t EntryOffset,
1054 uint32_t FunctionSize,
1055 uint32_t EndIndex) {
1056 assert(
is64Bit() &&
"Exception auxilliary entries are 64-bit only.");
1058 W.write<uint32_t>(FunctionSize);
1059 W.write<uint32_t>(EndIndex);
1060 W.OS.write_zeros(1);
1064void XCOFFWriter::writeFileHeader() {
1066 W.write<uint16_t>(SectionCount);
1067 W.write<int32_t>(0);
1070 W.write<uint16_t>(auxiliaryHeaderSize());
1071 W.write<uint16_t>(0);
1072 W.write<int32_t>(SymbolTableEntryCount);
1074 W.write<int32_t>(SymbolTableEntryCount);
1075 W.write<uint16_t>(auxiliaryHeaderSize());
1076 W.write<uint16_t>(0);
1080void XCOFFWriter::writeAuxFileHeader() {
1081 if (!auxiliaryHeaderSize())
1083 W.write<uint16_t>(0);
1088 W.write<uint32_t>(Sections[0]->Size);
1089 W.write<uint32_t>(Sections[1]->Size);
1090 W.write<uint32_t>(Sections[2]->Size);
1091 W.write<uint32_t>(0);
1092 W.write<uint32_t>(Sections[0]->Address);
1093 W.write<uint32_t>(Sections[1]->Address);
1096void XCOFFWriter::writeSectionHeader(
const SectionEntry *Sec) {
1100 if (Sec->Index == SectionEntry::UninitializedIndex)
1111 writeWord((IsDwarf || IsOvrflo) ? 0 : Sec->Address);
1115 writeWord(Sec->FileOffsetToRelocations);
1119 W.write<uint32_t>(Sec->RelocationCount);
1120 W.write<uint32_t>(0);
1121 W.write<int32_t>(Sec->Flags);
1122 W.OS.write_zeros(4);
1128 W.write<uint16_t>(Sec->RelocationCount);
1130 ? Sec->RelocationCount
1132 W.write<int32_t>(Sec->Flags);
1136void XCOFFWriter::writeSectionHeaderTable() {
1137 for (
const auto *CsectSec : Sections)
1139 for (
const auto &DwarfSec : DwarfSections)
1141 for (
const auto &OverflowSec : OverflowSections)
1143 if (hasExceptionSection())
1145 if (CInfoSymSection.Entry)
1149void XCOFFWriter::writeRelocation(XCOFFRelocation Reloc,
1150 const XCOFFSection &Section) {
1155 assert(
Section.MCSec->isDwarfSect() &&
"unsupport section type!");
1158 W.write<uint32_t>(Reloc.SymbolTableIndex);
1159 W.write<uint8_t>(Reloc.SignAndSize);
1160 W.write<uint8_t>(Reloc.Type);
1163void XCOFFWriter::writeRelocations() {
1164 for (
auto *Section : Sections) {
1165 if (
Section->Index == SectionEntry::UninitializedIndex)
1169 for (
auto *Group :
Section->Groups) {
1173 for (XCOFFSection &Csect : *Group) {
1175 const XCOFFRelocation &
B) {
1176 return A.FixupOffsetInCsect < B.FixupOffsetInCsect;
1179 for (
const auto Reloc : Csect.Relocations)
1180 writeRelocation(Reloc, Csect);
1185 for (
const auto &DwarfSection : DwarfSections)
1186 for (
const auto &Reloc : DwarfSection.DwarfSect->Relocations)
1187 writeRelocation(Reloc, *DwarfSection.DwarfSect);
1190void XCOFFWriter::writeSymbolTable(MCAssembler &Asm) {
1192 StringRef Vers = CompilerVersion;
1194 for (
const std::pair<std::string, size_t> &
F : FileNames) {
1197 StringRef FileName =
F.first;
1219 int NumberOfFileAuxEntries = 1;
1221 ++NumberOfFileAuxEntries;
1222 writeSymbolEntry(
".file", 0, XCOFF::ReservedSectionNum::N_DEBUG,
1224 NumberOfFileAuxEntries);
1230 if (CInfoSymSection.Entry)
1231 writeSymbolEntry(CInfoSymSection.Entry->Name, CInfoSymSection.Entry->Offset,
1232 CInfoSymSection.Index,
1236 for (
const auto &Csect : UndefinedCsects) {
1237 writeSymbolEntryForControlSection(Csect, XCOFF::ReservedSectionNum::N_UNDEF,
1241 for (
const auto *Section : Sections) {
1242 if (
Section->Index == SectionEntry::UninitializedIndex)
1246 for (
const auto *Group :
Section->Groups) {
1250 const int16_t SectionIndex =
Section->Index;
1251 for (
const auto &Csect : *Group) {
1253 writeSymbolEntryForControlSection(Csect, SectionIndex,
1256 for (
const auto &Sym : Csect.Syms)
1257 writeSymbolEntryForCsectMemberLabel(
1258 Sym, Csect, SectionIndex,
Asm.getSymbolOffset(*(Sym.MCSym)));
1263 for (
const auto &DwarfSection : DwarfSections)
1264 writeSymbolEntryForDwarfSection(*DwarfSection.DwarfSect,
1265 DwarfSection.Index);
1268void XCOFFWriter::finalizeRelocationInfo(SectionEntry *Sec,
uint64_t RelCount) {
1277 SecEntry.RelocationCount = Sec->Index;
1281 SecEntry.Address = RelCount;
1282 SecEntry.Index = ++SectionCount;
1283 OverflowSections.push_back(std::move(SecEntry));
1289 Sec->RelocationCount = RelCount;
1293void XCOFFWriter::calcOffsetToRelocations(SectionEntry *Sec,
1295 if (!Sec->RelocationCount)
1298 Sec->FileOffsetToRelocations = RawPointer;
1303 for (
auto &OverflowSec : OverflowSections) {
1304 if (OverflowSec.RelocationCount ==
static_cast<uint32_t
>(Sec->Index)) {
1305 RelocationSizeInSec =
1310 OverflowSec.FileOffsetToRelocations = Sec->FileOffsetToRelocations;
1313 assert(RelocationSizeInSec &&
"Overflow section header doesn't exist.");
1315 RelocationSizeInSec = Sec->RelocationCount *
1320 RawPointer += RelocationSizeInSec;
1321 if (RawPointer > MaxRawDataSize)
1325void XCOFFWriter::finalizeSectionInfo() {
1326 for (
auto *Section : Sections) {
1327 if (
Section->Index == SectionEntry::UninitializedIndex)
1332 for (
const auto *Group :
Section->Groups) {
1336 for (
auto &Csect : *Group)
1337 RelCount += Csect.Relocations.size();
1339 finalizeRelocationInfo(Section, RelCount);
1342 for (
auto &DwarfSection : DwarfSections)
1343 finalizeRelocationInfo(&DwarfSection,
1344 DwarfSection.DwarfSect->Relocations.size());
1352 auxiliaryHeaderSize();
1355 for (
auto *Sec : Sections) {
1356 if (Sec->Index == SectionEntry::UninitializedIndex || Sec->IsVirtual)
1359 RawPointer = Sec->advanceFileOffset(MaxRawDataSize, RawPointer);
1362 if (!DwarfSections.empty()) {
1363 RawPointer += PaddingsBeforeDwarf;
1364 for (auto &DwarfSection : DwarfSections) {
1365 RawPointer = DwarfSection.advanceFileOffset(MaxRawDataSize, RawPointer);
1369 if (hasExceptionSection())
1370 RawPointer = ExceptionSection.advanceFileOffset(MaxRawDataSize, RawPointer);
1372 if (CInfoSymSection.Entry)
1373 RawPointer = CInfoSymSection.advanceFileOffset(MaxRawDataSize, RawPointer);
1375 for (
auto *Sec : Sections) {
1376 if (Sec->Index != SectionEntry::UninitializedIndex)
1377 calcOffsetToRelocations(Sec, RawPointer);
1380 for (
auto &DwarfSec : DwarfSections)
1381 calcOffsetToRelocations(&DwarfSec, RawPointer);
1385 if (SymbolTableEntryCount)
1386 SymbolTableOffset = RawPointer;
1389void XCOFFWriter::addExceptionEntry(
const MCSymbol *Symbol,
1390 const MCSymbol *
Trap,
unsigned LanguageCode,
1391 unsigned ReasonCode,
unsigned FunctionSize,
1396 ExceptionSection.isDebugEnabled =
true;
1397 auto Entry = ExceptionSection.ExceptionTable.find(
Symbol->getName());
1398 if (Entry != ExceptionSection.ExceptionTable.end()) {
1399 Entry->second.Entries.push_back(
1400 ExceptionTableEntry(
Trap, LanguageCode, ReasonCode));
1403 ExceptionInfo NewEntry;
1404 NewEntry.FunctionSymbol =
Symbol;
1405 NewEntry.FunctionSize = FunctionSize;
1406 NewEntry.Entries.push_back(
1407 ExceptionTableEntry(
Trap, LanguageCode, ReasonCode));
1408 ExceptionSection.ExceptionTable.insert(
1409 std::pair<const StringRef, ExceptionInfo>(
Symbol->getName(), NewEntry));
1412unsigned XCOFFWriter::getExceptionSectionSize() {
1413 unsigned EntryNum = 0;
1415 for (
const auto &TableEntry : ExceptionSection.ExceptionTable)
1418 EntryNum += TableEntry.second.Entries.size() + 1;
1424unsigned XCOFFWriter::getExceptionOffset(
const MCSymbol *Symbol) {
1425 unsigned EntryNum = 0;
1426 for (
const auto &TableEntry : ExceptionSection.ExceptionTable) {
1427 if (Symbol == TableEntry.second.FunctionSymbol)
1429 EntryNum += TableEntry.second.Entries.size() + 1;
1435void XCOFFWriter::addCInfoSymEntry(StringRef Name, StringRef
Metadata) {
1436 assert(!CInfoSymSection.Entry &&
"Multiple entries are not supported");
1437 CInfoSymSection.addEntry(
1438 std::make_unique<CInfoSymInfo>(
Name.str(),
Metadata.str()));
1441void XCOFFWriter::assignAddressesAndIndices(MCAssembler &Asm) {
1444 uint32_t SymbolTableIndex =
1445 (2 + (CompilerVersion.empty() ? 0 : 1)) * FileNames.size();
1447 if (CInfoSymSection.Entry)
1451 for (
auto &Csect : UndefinedCsects) {
1454 Csect.SymbolTableIndex = SymbolTableIndex;
1457 SymbolTableIndex += 2;
1465 int32_t SectionIndex = 1;
1466 bool HasTDataSection =
false;
1468 for (
auto *Section : Sections) {
1469 const bool IsEmpty =
1471 [](
const CsectGroup *Group) { return Group->empty(); });
1475 if (SectionIndex > MaxSectionIndex)
1477 Section->Index = SectionIndex++;
1480 bool SectionAddressSet =
false;
1484 HasTDataSection =
true;
1491 for (
auto *Group :
Section->Groups) {
1495 for (
auto &Csect : *Group) {
1496 const MCSectionXCOFF *MCSec = Csect.MCSec;
1498 Csect.Size =
Asm.getSectionAddressSize(*MCSec);
1499 Address = Csect.Address + Csect.Size;
1500 Csect.SymbolTableIndex = SymbolTableIndex;
1503 SymbolTableIndex += 2;
1505 for (
auto &Sym : Csect.Syms) {
1506 bool hasExceptEntry =
false;
1508 ExceptionSection.ExceptionTable.find(Sym.MCSym->
getName());
1509 if (Entry != ExceptionSection.ExceptionTable.end()) {
1510 hasExceptEntry =
true;
1511 for (
auto &TrapEntry :
Entry->second.Entries) {
1512 TrapEntry.TrapAddress =
Asm.getSymbolOffset(*(Sym.MCSym)) +
1513 TrapEntry.Trap->getOffset();
1516 Sym.SymbolTableIndex = SymbolTableIndex;
1517 SymbolIndexMap[Sym.MCSym] = Sym.SymbolTableIndex;
1522 SymbolTableIndex += 2;
1523 if (hasExceptionSection() && hasExceptEntry) {
1524 if (
is64Bit() && ExceptionSection.isDebugEnabled)
1525 SymbolTableIndex += 2;
1527 SymbolTableIndex += 1;
1532 if (!SectionAddressSet) {
1533 Section->Address = Group->front().Address;
1534 SectionAddressSet =
true;
1549 if (!DwarfSections.empty())
1550 PaddingsBeforeDwarf =
1552 (*DwarfSections.begin()).DwarfSect->MCSec->getAlign()) -
1555 DwarfSectionEntry *LastDwarfSection =
nullptr;
1556 for (
auto &DwarfSection : DwarfSections) {
1557 assert((SectionIndex <= MaxSectionIndex) &&
"Section index overflow!");
1559 XCOFFSection &DwarfSect = *DwarfSection.DwarfSect;
1560 const MCSectionXCOFF *MCSec = DwarfSect.MCSec;
1563 DwarfSection.Index = SectionIndex++;
1567 DwarfSect.SymbolTableIndex = SymbolTableIndex;
1570 SymbolTableIndex += 2;
1576 DwarfSection.Address = DwarfSect.Address =
1581 DwarfSection.Size = DwarfSect.Size =
Asm.getSectionAddressSize(*MCSec);
1583 Address = DwarfSection.Address + DwarfSection.Size;
1585 if (LastDwarfSection)
1586 LastDwarfSection->MemorySize =
1587 DwarfSection.Address - LastDwarfSection->Address;
1588 LastDwarfSection = &DwarfSection;
1590 if (LastDwarfSection) {
1593 Address =
alignTo(LastDwarfSection->Address + LastDwarfSection->Size,
1594 DefaultSectionAlign);
1595 LastDwarfSection->MemorySize =
Address - LastDwarfSection->Address;
1597 if (hasExceptionSection()) {
1598 ExceptionSection.Index = SectionIndex++;
1600 ExceptionSection.Address = 0;
1601 ExceptionSection.Size = getExceptionSectionSize();
1602 Address += ExceptionSection.Size;
1606 if (CInfoSymSection.Entry) {
1607 CInfoSymSection.Index = SectionIndex++;
1609 CInfoSymSection.Address = 0;
1610 Address += CInfoSymSection.Size;
1614 SymbolTableEntryCount = SymbolTableIndex;
1617void XCOFFWriter::writeSectionForControlSectionEntry(
1618 const MCAssembler &Asm,
const CsectSectionEntry &CsectEntry,
1619 uint64_t &CurrentAddressLocation) {
1621 if (CsectEntry.Index == SectionEntry::UninitializedIndex)
1628 assert(((CurrentAddressLocation <= CsectEntry.Address) ||
1631 "CurrentAddressLocation should be less than or equal to section "
1632 "address if the section is not TData or TBSS.");
1634 CurrentAddressLocation = CsectEntry.Address;
1639 if (CsectEntry.IsVirtual) {
1640 CurrentAddressLocation += CsectEntry.Size;
1644 for (
const auto &Group : CsectEntry.Groups) {
1645 for (
const auto &Csect : *Group) {
1646 if (uint32_t PaddingSize = Csect.Address - CurrentAddressLocation)
1647 W.OS.write_zeros(PaddingSize);
1649 Asm.writeSectionData(
W.OS, Csect.MCSec);
1650 CurrentAddressLocation = Csect.Address + Csect.Size;
1658 CsectEntry.Address + CsectEntry.Size - CurrentAddressLocation) {
1659 W.OS.write_zeros(PaddingSize);
1660 CurrentAddressLocation += PaddingSize;
1664void XCOFFWriter::writeSectionForDwarfSectionEntry(
1665 const MCAssembler &Asm,
const DwarfSectionEntry &DwarfEntry,
1666 uint64_t &CurrentAddressLocation) {
1670 assert(CurrentAddressLocation <= DwarfEntry.Address &&
1671 "CurrentAddressLocation should be less than or equal to section "
1674 if (
uint64_t PaddingSize = DwarfEntry.Address - CurrentAddressLocation)
1675 W.OS.write_zeros(PaddingSize);
1677 if (DwarfEntry.Size)
1678 Asm.writeSectionData(
W.OS, DwarfEntry.DwarfSect->MCSec);
1680 CurrentAddressLocation = DwarfEntry.Address + DwarfEntry.Size;
1684 uint32_t
Mod = CurrentAddressLocation % DefaultSectionAlign;
1685 uint32_t TailPaddingSize =
Mod ? DefaultSectionAlign -
Mod : 0;
1686 if (TailPaddingSize)
1687 W.OS.write_zeros(TailPaddingSize);
1689 CurrentAddressLocation += TailPaddingSize;
1692void XCOFFWriter::writeSectionForExceptionSectionEntry(
1693 const MCAssembler &Asm, ExceptionSectionEntry &ExceptionEntry,
1694 uint64_t &CurrentAddressLocation) {
1695 for (
const auto &TableEntry : ExceptionEntry.ExceptionTable) {
1698 W.write<uint32_t>(SymbolIndexMap[TableEntry.second.FunctionSymbol]);
1701 W.OS.write_zeros(4);
1703 W.OS.write_zeros(2);
1704 for (
auto &TrapEntry : TableEntry.second.Entries) {
1706 W.write<uint8_t>(TrapEntry.Lang);
1707 W.write<uint8_t>(TrapEntry.Reason);
1711 CurrentAddressLocation += getExceptionSectionSize();
1714void XCOFFWriter::writeSectionForCInfoSymSectionEntry(
1715 const MCAssembler &Asm, CInfoSymSectionEntry &CInfoSymEntry,
1716 uint64_t &CurrentAddressLocation) {
1717 if (!CInfoSymSection.Entry)
1720 constexpr int WordSize =
sizeof(uint32_t);
1721 std::unique_ptr<CInfoSymInfo> &CISI = CInfoSymEntry.Entry;
1722 const std::string &
Metadata = CISI->Metadata;
1732 while (Index + WordSize <=
Metadata.size()) {
1735 W.write<uint32_t>(NextWord);
1740 if (CISI->paddingSize()) {
1741 std::array<uint8_t, WordSize> LastWord = {0};
1742 ::memcpy(LastWord.data(),
Metadata.data() + Index,
Metadata.size() - Index);
1746 CurrentAddressLocation += CISI->size();
1752uint8_t getEncodedType(
const MCSectionXCOFF *Sec) {
1757 uint8_t EncodedAlign = Log2Align << 3;
1763std::unique_ptr<MCObjectWriter>
1766 return std::make_unique<XCOFFWriter>(std::move(MOTW), OS);
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void writeSymbolTable(raw_ostream &Out, object::Archive::Kind Kind, bool Deterministic, ArrayRef< MemberData > Members, StringRef StringTable, uint64_t MembersOffset, unsigned NumSyms, uint64_t PrevMemberOffset=0, uint64_t NextMemberOffset=0, bool Is64Bit=false)
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static void writeWord(support::endian::Writer &W, bool Is64Bit, uint64_t Val)
static unsigned getCPUType(const MachOObjectFile &O)
PowerPC TLS Dynamic Call Fixup
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
static bool is64Bit(const char *name)
iterator find(const_arg_type_t< KeyT > Val)
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
MCSection * getParent() const
virtual void reset()
lifetime management
StringRef getSymbolTableName() const
std::optional< XCOFF::DwarfSectionSubtypeFlags > getDwarfSubtypeFlags() const
XCOFF::StorageClass getStorageClass() const
XCOFF::StorageMappingClass getMappingClass() const
MCSymbolXCOFF * getQualNameSymbol() const
XCOFF::SymbolType getCSectType() const
StringRef getName() const
XCOFF::VisibilityType getVisibilityType() const
StringRef getSymbolTableName() const
LLVM_ABI MCSectionXCOFF * getRepresentedCsect() const
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
StringRef getName() const
getName - Get the symbol name.
MCFragment * getFragment() const
SectionEntry - represents a section emitted into memory by the dynamic linker.
SectionEntry(StringRef name, uint8_t *address, size_t size, size_t allocationSize, uintptr_t objAddress)
constexpr bool empty() const
Check if the string is empty.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
LLVM_ABI bool ends_with_insensitive(StringRef Suffix) const
Check if this string ends with the given Suffix, ignoring case.
Utility for building string tables with deduplicated suffixes.
LLVM_ABI size_t getOffset(CachedHashStringRef S) const
Get the offest of a string in the string table.
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority=0)
Add a string to the builder.
LLVM_ABI void write(raw_ostream &OS) const
LLVM_ABI void finalize()
Analyze the strings and build the final table.
An abstract base class for streams implementations that also support a pwrite operation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
LLVM_ABI void writeSectionHeader(support::endian::Writer &W, bool Is64Bit, uint32_t Name, uint32_t Type, uint64_t Flags, uint64_t Address, uint64_t Offset, uint64_t Size, uint32_t Link, uint32_t Info, uint64_t Alignment, uint64_t EntrySize)
Write a single ELF section header entry (Elf32_Shdr or Elf64_Shdr).
C::iterator addEntry(C &Container, StringRef InstallName)
constexpr size_t RelocationSerializationSize32
LLVM_ABI XCOFF::CFileCpuId getCpuID(StringRef CPU)
constexpr size_t ExceptionSectionEntrySize64
constexpr size_t RelocationSerializationSize64
constexpr size_t ExceptionSectionEntrySize32
constexpr size_t FileHeaderSize64
constexpr size_t SectionHeaderSize64
constexpr size_t AuxFileEntNameSize
@ AUX_SECT
Identifies a SECT auxiliary entry.
@ AUX_FILE
Identifies a file auxiliary entry.
@ AUX_EXCEPT
Identifies an exception auxiliary entry.
@ AUX_FCN
Identifies a function auxiliary entry.
@ AUX_CSECT
Identifies a csect auxiliary entry.
@ TB_Fortran
Fortran language.
@ TB_CPLUSPLUS
C++ language.
VisibilityType
Values for visibility as they would appear when encoded in the high 4 bits of the 16-bit unsigned n_t...
constexpr size_t NameSize
constexpr uint16_t RelocOverflow
constexpr size_t AuxFileHeaderSizeShort
@ XFT_FN
Specifies the source-file name.
@ XFT_CV
Specifies the compiler version number.
constexpr size_t FileHeaderSize32
StorageMappingClass
Storage Mapping Class definitions.
@ XMC_TE
Symbol mapped at the end of TOC.
@ XMC_TC0
TOC Anchor for TOC Addressability.
@ XMC_DS
Descriptor csect.
@ XMC_TL
Initialized thread-local variable.
@ XMC_RO
Read Only Constant.
@ XMC_TD
Scalar data item in the TOC.
@ XMC_UL
Uninitialized thread-local variable.
@ XMC_BS
BSS class (uninitialized static internal)
@ XMC_TC
General TOC item.
constexpr size_t SectionHeaderSize32
constexpr size_t FileNamePadSize
@ XTY_CM
Common csect definition. For uninitialized storage.
@ XTY_SD
Csect definition for initialized storage.
@ XTY_LD
Label definition.
@ XTY_ER
External reference.
support::ulittle32_t Word
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
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.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
unsigned Log2(Align A)
Returns the log2 of the alignment.
LLVM_ABI std::unique_ptr< MCObjectWriter > createXCOFFObjectWriter(std::unique_ptr< MCXCOFFObjectTargetWriter > MOTW, raw_pwrite_stream &OS)
LLVM_ABI Error write(DWPWriter &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue, raw_pwrite_stream *OS=nullptr)
Implement std::hash so that hash_code can be used in STL containers.