51#define DEBUG_TYPE "WinCOFFObjectWriter"
55constexpr int OffsetLabelIntervalBits = 20;
59enum AuxiliaryType { ATWeakExternal, ATFile, ATSectionDefinition };
62 AuxiliaryType AuxType;
77 COFFSymbol *
Other =
nullptr;
78 COFFSection *Section =
nullptr;
82 COFFSymbol(
StringRef Name) : Name(Name) {}
86 int64_t getIndex()
const {
return Index; }
87 void setIndex(
int Value) {
95struct COFFRelocation {
97 COFFSymbol *Symb =
nullptr;
99 COFFRelocation() =
default;
104using relocations = std::vector<COFFRelocation>;
113 COFFSymbol *Symbol =
nullptr;
114 relocations Relocations;
116 COFFSection(
StringRef Name) : Name(std::string(Name)) {}
127 using symbols = std::vector<std::unique_ptr<COFFSymbol>>;
128 using sections = std::vector<std::unique_ptr<COFFSection>>;
142 section_map SectionMap;
143 symbol_map SymbolMap;
145 symbol_list WeakDefaults;
148 bool UseOffsetLabels =
false;
170 COFFSymbol *createSymbol(
StringRef Name);
171 COFFSymbol *getOrCreateCOFFSymbol(
const MCSymbol &Sym);
172 COFFSection *createSection(
StringRef Name);
176 COFFSymbol *getLinkedSymbol(
const MCSymbol &Symbol);
179 void SetSymbolName(COFFSymbol &S);
180 void SetSectionName(COFFSection &S);
182 bool isUninitializedData(
const COFFSection &S);
186 void WriteSymbol(
const COFFSymbol &S);
187 void WriteAuxiliarySymbols(
const COFFSymbol::AuxiliarySymbols &S);
188 void writeSectionHeaders();
191 void writeSection(
const COFFSection &Sec);
193 void createFileSymbols();
194 void setWeakDefaultNames();
195 void assignSectionNumbers();
196 void assignFileOffsets();
201 : TargetObjectWriter(
std::
move(MOTW)),
207 : TargetObjectWriter(
std::
move(MOTW)),
223void COFFSymbol::set_name_offset(uint32_t
Offset) {
234 Header.Machine = OWriter.TargetObjectWriter->getMachine();
242COFFSymbol *WinCOFFWriter::createSymbol(
StringRef Name) {
243 Symbols.push_back(std::make_unique<COFFSymbol>(Name));
244 return Symbols.back().get();
247COFFSymbol *WinCOFFWriter::getOrCreateCOFFSymbol(
const MCSymbol &Sym) {
248 COFFSymbol *&Ret = SymbolMap[&Sym];
250 Ret = createSymbol(Sym.
getName());
254COFFSection *WinCOFFWriter::createSection(
StringRef Name) {
255 Sections.emplace_back(std::make_unique<COFFSection>(Name));
256 return Sections.back().get();
295void WinCOFFWriter::defineSection(
const MCSectionCOFF &MCSec) {
306 COFFSymbol *COMDATSymbol = getOrCreateCOFFSymbol(*S);
307 if (COMDATSymbol->Section)
309 COMDATSymbol->Section =
Section;
316 Symbol->Aux[0].AuxType = ATSectionDefinition;
327 if (UseOffsetLabels) {
328 const uint32_t
Interval = 1 << OffsetLabelIntervalBits;
330 for (uint32_t Off =
Interval,
E = Asm->getSectionAddressSize(MCSec);
332 auto Name = (
"$L" + MCSec.
getName() +
"_" + Twine(
N++)).str();
333 COFFSymbol *
Label = createSymbol(Name);
337 Section->OffsetSymbols.push_back(Label);
344 if (Symbol.isCommon() && Symbol.isExternal())
345 return Symbol.getCommonSize();
348 if (!Asm.getSymbolOffset(Symbol, Res))
354COFFSymbol *WinCOFFWriter::getLinkedSymbol(
const MCSymbol &Symbol) {
362 auto &Aliasee =
static_cast<const MCSymbolCOFF &
>(SymRef->getSymbol());
363 if (Aliasee.isUndefined() || Aliasee.isExternal())
364 return getOrCreateCOFFSymbol(Aliasee);
371void WinCOFFWriter::defineSymbol(
const MCSymbolCOFF &MCSym) {
373 COFFSection *Sec =
nullptr;
374 MCSectionCOFF *MCSec =
nullptr;
376 MCSec =
static_cast<MCSectionCOFF *
>(
Base->getFragment()->
getParent());
377 Sec = SectionMap[MCSec];
383 COFFSymbol *Sym = getOrCreateCOFFSymbol(MCSym);
384 COFFSymbol *
Local =
nullptr;
385 if (
static_cast<const MCSymbolCOFF &
>(MCSym)
386 .getWeakExternalCharacteristics()) {
388 Sym->Section =
nullptr;
390 COFFSymbol *WeakDefault = getLinkedSymbol(MCSym);
392 std::string WeakName = (
".weak." + MCSym.
getName() +
".default").str();
393 WeakDefault = createSymbol(WeakName);
397 WeakDefault->Section = Sec;
398 WeakDefaults.insert(WeakDefault);
402 Sym->Other = WeakDefault;
406 memset(&Sym->Aux[0], 0,
sizeof(Sym->Aux[0]));
407 Sym->Aux[0].AuxType = ATWeakExternal;
408 Sym->Aux[0].Aux.WeakExternal.TagIndex = 0;
409 Sym->Aux[0].Aux.WeakExternal.Characteristics =
410 static_cast<const MCSymbolCOFF &
>(MCSym)
411 .getWeakExternalCharacteristics();
423 auto &SymbolCOFF =
static_cast<const MCSymbolCOFF &
>(MCSym);
424 Local->Data.Type = SymbolCOFF.getType();
425 Local->Data.StorageClass = SymbolCOFF.getClass();
440void WinCOFFWriter::SetSectionName(COFFSection &S) {
442 std::memcpy(S.Header.
Name, S.Name.c_str(), S.Name.size());
446 uint64_t StringTableEntry = Strings.
getOffset(S.Name);
451void WinCOFFWriter::SetSymbolName(COFFSymbol &S) {
453 S.set_name_offset(Strings.getOffset(S.Name));
455 std::memcpy(S.Data.
Name, S.Name.c_str(), S.Name.size());
458bool WinCOFFWriter::isUninitializedData(
const COFFSection &S) {
466void WinCOFFWriter::WriteFileHeader(
const COFF::header &Header) {
469 W.write<uint16_t>(0xFFFF);
471 W.write<uint16_t>(Header.Machine);
472 W.write<uint32_t>(Header.TimeDateStamp);
474 W.write<uint32_t>(0);
475 W.write<uint32_t>(0);
476 W.write<uint32_t>(0);
477 W.write<uint32_t>(0);
478 W.write<uint32_t>(Header.NumberOfSections);
479 W.write<uint32_t>(Header.PointerToSymbolTable);
480 W.write<uint32_t>(Header.NumberOfSymbols);
482 W.write<uint16_t>(Header.Machine);
483 W.write<uint16_t>(
static_cast<int16_t
>(Header.NumberOfSections));
484 W.write<uint32_t>(Header.TimeDateStamp);
485 W.write<uint32_t>(Header.PointerToSymbolTable);
486 W.write<uint32_t>(Header.NumberOfSymbols);
487 W.write<uint16_t>(Header.SizeOfOptionalHeader);
488 W.write<uint16_t>(Header.Characteristics);
492void WinCOFFWriter::WriteSymbol(
const COFFSymbol &S) {
494 W.write<uint32_t>(S.Data.
Value);
498 W.write<uint16_t>(
static_cast<int16_t
>(S.Data.
SectionNumber));
499 W.write<uint16_t>(S.Data.
Type);
502 WriteAuxiliarySymbols(S.Aux);
505void WinCOFFWriter::WriteAuxiliarySymbols(
506 const COFFSymbol::AuxiliarySymbols &S) {
507 for (
const AuxSymbol &i : S) {
510 W.write<uint32_t>(i.Aux.WeakExternal.TagIndex);
511 W.write<uint32_t>(i.Aux.WeakExternal.Characteristics);
512 W.OS.write_zeros(
sizeof(i.Aux.WeakExternal.unused));
517 W.OS.write(
reinterpret_cast<const char *
>(&i.Aux),
520 case ATSectionDefinition:
521 W.write<uint32_t>(i.Aux.SectionDefinition.Length);
522 W.write<uint16_t>(i.Aux.SectionDefinition.NumberOfRelocations);
523 W.write<uint16_t>(i.Aux.SectionDefinition.NumberOfLinenumbers);
524 W.write<uint32_t>(i.Aux.SectionDefinition.CheckSum);
525 W.write<uint16_t>(
static_cast<int16_t
>(i.Aux.SectionDefinition.Number));
526 W.OS << char(i.Aux.SectionDefinition.Selection);
527 W.OS.write_zeros(
sizeof(i.Aux.SectionDefinition.unused));
529 static_cast<int16_t
>(i.Aux.SectionDefinition.Number >> 16));
538void WinCOFFWriter::writeSectionHeaders() {
542 std::vector<COFFSection *> Arr;
543 for (
auto &Section : Sections)
545 llvm::sort(Arr, [](
const COFFSection *
A,
const COFFSection *
B) {
546 return A->Number <
B->Number;
549 for (
auto &Section : Arr) {
553 COFF::section &S =
Section->Header;
554 if (
Section->Relocations.size() >= 0xffff)
570 W.write<uint32_t>(
R.VirtualAddress);
571 W.write<uint32_t>(
R.SymbolTableIndex);
572 W.write<uint16_t>(
R.Type);
578uint32_t WinCOFFWriter::writeSectionContents(
const MCSection &MCSec) {
581 SmallVector<char, 128> Buf;
582 raw_svector_ostream VecOS(Buf);
583 Asm->writeSectionData(VecOS, &MCSec);
595void WinCOFFWriter::writeSection(
const COFFSection &Sec) {
596 if (Sec.Number == -1)
602 "Section::PointerToRawData is insane!");
604 uint32_t CRC = writeSectionContents(*Sec.MCSection);
607 COFFSymbol::AuxiliarySymbols &AuxSyms = Sec.Symbol->Aux;
608 assert(AuxSyms.
size() == 1 && AuxSyms[0].AuxType == ATSectionDefinition);
609 AuxSymbol &SecDef = AuxSyms[0];
611 }
else if (isUninitializedData(Sec)) {
613 writeSectionContents(*Sec.MCSection);
617 if (Sec.Relocations.empty()) {
619 "Section::PointerToRelocations is insane!");
624 "Section::PointerToRelocations is insane!");
626 if (Sec.Relocations.size() >= 0xffff) {
630 R.VirtualAddress = Sec.Relocations.size() + 1;
631 R.SymbolTableIndex = 0;
636 for (
const auto &Relocation : Sec.Relocations)
637 WriteRelocation(Relocation.Data);
641void WinCOFFWriter::createFileSymbols() {
642 for (
const std::pair<std::string, size_t> &It : OWriter.getFileNames()) {
644 const std::string &
Name = It.first;
646 unsigned Count = (
Name.size() + SymbolSize - 1) / SymbolSize;
648 COFFSymbol *
File = createSymbol(
".file");
655 for (
auto &Aux :
File->Aux) {
656 Aux.AuxType = ATFile;
658 if (
Length > SymbolSize) {
659 memcpy(&Aux.Aux,
Name.c_str() +
Offset, SymbolSize);
663 memset((
char *)&Aux.Aux +
Length, 0, SymbolSize -
Length);
672void WinCOFFWriter::setWeakDefaultNames() {
673 if (WeakDefaults.empty())
683 COFFSymbol *Unique =
nullptr;
684 for (
bool AllowComdat : {
false,
true}) {
685 for (
auto &Sym : Symbols) {
687 if (WeakDefaults.count(Sym.get()))
695 if (!AllowComdat && Sym->Section &&
707 for (
auto *Sym : WeakDefaults) {
708 Sym->Name.append(
".");
709 Sym->Name.append(Unique->Name);
714 return Section.Symbol->Aux[0].Aux.SectionDefinition.Selection ==
718void WinCOFFWriter::assignSectionNumbers() {
722 Section.Symbol->Data.SectionNumber =
I;
723 Section.Symbol->Aux[0].Aux.SectionDefinition.Number =
I;
730 for (
const std::unique_ptr<COFFSection> &Section : Sections)
733 for (
const std::unique_ptr<COFFSection> &Section : Sections)
739void WinCOFFWriter::assignFileOffsets() {
740 unsigned Offset = W.OS.tell();
745 for (
const auto &Section : *Asm) {
746 COFFSection *Sec = SectionMap[&
Section];
748 if (!Sec || Sec->Number == -1)
751 Sec->Header.
SizeOfRawData = Asm->getSectionAddressSize(Section);
753 if (!isUninitializedData(*Sec)) {
758 if (!Sec->Relocations.empty()) {
759 bool RelocationsOverflow = Sec->Relocations.size() >= 0xffff;
761 if (RelocationsOverflow) {
770 if (RelocationsOverflow) {
777 for (
auto &Relocation : Sec->Relocations) {
778 assert(Relocation.Symb->getIndex() != -1);
781 Relocation.Data.SymbolTableIndex = Relocation.Symb->getIndex();
787 "Section's symbol must have one aux!");
788 AuxSymbol &Aux = Sec->Symbol->Aux[0];
789 assert(Aux.AuxType == ATSectionDefinition &&
790 "Section's symbol's aux symbol must be a Section Definition!");
798 Header.PointerToSymbolTable =
Offset;
802 memset(&Header, 0,
sizeof(Header));
803 Header.Machine = OWriter.TargetObjectWriter->getMachine();
809 WeakDefaults.clear();
815 for (
const auto &Section : *Asm) {
823 for (
const MCSymbol &Symbol : Asm->symbols()) {
832 Header.NumberOfSections = Sections.size();
833 Header.NumberOfSymbols = 0;
834 if (Sections.size() > INT32_MAX)
836 "PE COFF object files can't have more than 2147483647 sections");
838 assignSectionNumbers();
843 assert(
Target.getAddSym() &&
"Relocation must reference a symbol!");
846 if (!
A.isRegistered()) {
847 getContext().reportError(
Fixup.getLoc(),
Twine(
"symbol '") +
A.getName() +
848 "' can not be undefined");
851 if (
A.isTemporary() &&
A.isUndefined()) {
852 getContext().reportError(
Fixup.getLoc(),
Twine(
"assembler label '") +
854 "' can not be undefined");
861 assert(SectionMap.contains(MCSec) &&
862 "Section must already have been defined in executePostLayoutBinding!");
864 COFFSection *Sec = SectionMap[MCSec];
866 if (!
B->getFragment()) {
867 getContext().reportError(
869 Twine(
"symbol '") +
B->getName() +
870 "' can not be undefined in a subtraction expression");
875 int64_t OffsetOfB = Asm->getSymbolOffset(*
B);
878 int64_t OffsetOfRelocation = Asm->getFragmentOffset(
F) +
Fixup.getOffset();
880 FixedValue = (OffsetOfRelocation - OffsetOfB) +
Target.getConstant();
882 FixedValue =
Target.getConstant();
885 COFFRelocation
Reloc;
887 Reloc.Data.SymbolTableIndex = 0;
888 Reloc.Data.VirtualAddress = Asm->getFragmentOffset(
F);
891 if (
A.isTemporary() && !SymbolMap[&
A]) {
894 SectionMap.contains(TargetSection) &&
895 "Section must already have been defined in executePostLayoutBinding!");
896 COFFSection *Section = SectionMap[TargetSection];
897 Reloc.Symb = Section->Symbol;
898 FixedValue += Asm->getSymbolOffset(
A);
903 if (UseOffsetLabels && !Section->OffsetSymbols.empty()) {
904 uint64_t LabelIndex = FixedValue >> OffsetLabelIntervalBits;
905 if (LabelIndex > 0) {
906 if (LabelIndex <= Section->OffsetSymbols.size())
907 Reloc.Symb = Section->OffsetSymbols[LabelIndex - 1];
909 Reloc.Symb = Section->OffsetSymbols.back();
910 FixedValue -=
Reloc.Symb->Data.Value;
915 SymbolMap.contains(&
A) &&
916 "Symbol must already have been defined in executePostLayoutBinding!");
917 Reloc.Symb = SymbolMap[&
A];
920 ++
Reloc.Symb->Relocations;
922 Reloc.Data.VirtualAddress +=
Fixup.getOffset();
923 Reloc.Data.Type = OWriter.TargetObjectWriter->getRelocType(
939 switch (
Reloc.Data.Type) {
971 FixedValue = FixedValue + 4;
980 if (OWriter.TargetObjectWriter->recordRelocation(
Fixup)) {
981 Sec->Relocations.push_back(
Reloc);
987 auto RelocPair =
Reloc;
989 Sec->Relocations.push_back(RelocPair);
995 std::time_t Now = time(
nullptr);
1002 uint64_t StartOffset = W.OS.tell();
1004 setWeakDefaultNames();
1006 createFileSymbols();
1008 for (
auto &Symbol : Symbols) {
1010 if (Symbol->Section)
1011 Symbol->Data.SectionNumber = Symbol->Section->Number;
1012 Symbol->setIndex(Header.NumberOfSymbols++);
1014 Symbol->Data.NumberOfAuxSymbols = Symbol->Aux.size();
1015 Header.NumberOfSymbols += Symbol->Data.NumberOfAuxSymbols;
1019 for (
const auto &S : Sections)
1021 Strings.add(S->
Name);
1022 for (
const auto &S : Symbols)
1024 Strings.add(S->
Name);
1028 for (
const auto &S : Sections)
1030 for (
auto &S : Symbols)
1034 for (
auto &Symbol : Symbols) {
1035 if (Symbol->Other) {
1036 assert(Symbol->getIndex() != -1);
1037 assert(Symbol->Aux.size() == 1 &&
"Symbol must contain one aux symbol!");
1038 assert(Symbol->Aux[0].AuxType == ATWeakExternal &&
1039 "Symbol's aux symbol must be a Weak External!");
1040 Symbol->Aux[0].Aux.WeakExternal.TagIndex = Symbol->Other->getIndex();
1045 for (
auto &Section : Sections) {
1046 if (Section->Symbol->Aux[0].Aux.SectionDefinition.Selection !=
1057 getContext().reportError(
1059 Twine(
" associative with sectionless symbol ") +
1064 const auto *AssocMCSec =
1066 assert(SectionMap.count(AssocMCSec));
1067 COFFSection *AssocSec = SectionMap[AssocMCSec];
1070 if (AssocSec->Number == -1)
1073 Section->Symbol->Aux[0].Aux.SectionDefinition.Number = AssocSec->Number;
1077 if (
Mode !=
DwoOnly && OWriter.getEmitAddrsigSection()) {
1080 for (
const MCSymbol *S : OWriter.AddrsigSyms) {
1089 assert(SectionMap.contains(TargetSection) &&
1090 "Section must already have been defined in "
1091 "executePostLayoutBinding!");
1092 encodeULEB128(SectionMap[TargetSection]->Symbol->getIndex(), OS);
1094 auto *Sec = getContext().getCOFFSection(
".llvm_addrsig",
1096 Sec->curFragList()->Tail->setVarContents(OS.
str());
1100 if (
Mode !=
DwoOnly && !OWriter.getCGProfile().empty()) {
1103 for (
const auto &CGPE : OWriter.getCGProfile()) {
1104 uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
1105 uint32_t ToIndex = CGPE.To->getSymbol().getIndex();
1110 auto *Sec = getContext().getCOFFSection(
".llvm.call-graph-profile",
1112 Sec->curFragList()->Tail->setVarContents(OS.
str());
1115 assignFileOffsets();
1119 if (OWriter.IncrementalLinkerCompatible) {
1120 Header.TimeDateStamp =
getTime();
1123 Header.TimeDateStamp = 0;
1127 WriteFileHeader(Header);
1128 writeSectionHeaders();
1131 sections::iterator
I = Sections.begin();
1132 sections::iterator IE = Sections.end();
1133 auto J = Asm->begin();
1134 auto JE = Asm->end();
1135 for (;
I != IE && J != JE; ++
I, ++J) {
1139 assert(J != JE && (**I).MCSection == &*J &&
"Wrong bound MCSection");
1144 for (std::unique_ptr<COFFSection> &Sec : Sections)
1147 assert(W.OS.tell() == Header.PointerToSymbolTable &&
1148 "Header::PointerToSymbolTable is insane!");
1151 for (
auto &Symbol : Symbols)
1152 if (Symbol->getIndex() != -1)
1153 WriteSymbol(*Symbol);
1156 Strings.write(W.OS);
1158 return W.OS.tell() - StartOffset;
1162 return SectionMap.at(&Section)->Number;
1172 IncrementalLinkerCompatible =
false;
1181 ObjWriter->setAssembler(
Asm);
1183 DwoWriter->setAssembler(
Asm);
1188 bool IsPCRel)
const {
1202 ObjWriter->executePostLayoutBinding();
1204 DwoWriter->executePostLayoutBinding();
1211 ObjWriter->recordRelocation(
F,
Fixup,
Target, FixedValue);
1220 uint64_t TotalSize = ObjWriter->writeObject();
1222 TotalSize += DwoWriter->writeObject();
1227 return ObjWriter->getSectionNumber(Section);
1231 : Machine(Machine_) {}
1234void MCWinCOFFObjectTargetWriter::anchor() {}
1241 return std::make_unique<WinCOFFObjectWriter>(std::move(MOTW), OS);
1247 return std::make_unique<WinCOFFObjectWriter>(std::move(MOTW), OS, DwoOS);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
std::pair< uint64_t, uint64_t > Interval
PowerPC TLS Dynamic Call Fixup
This file defines the SmallString class.
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
static uint64_t getSymbolValue(const MCSymbolCOFF &Symbol, const MCAssembler &Asm)
void write32le(void *P, uint32_t V)
static uint32_t getAlignment(const MCSectionCOFF &Sec)
static bool isAssociative(const COFFSection &Section)
static bool isDwoSection(const MCSection &Sec)
static std::time_t getTime()
Implements a dense probed hash-table based set.
Context object for machine code objects.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
MCSection * getParent() const
virtual void setAssembler(MCAssembler *A)
virtual void reset()
lifetime management
MCContext & getContext() const
This represents a section on Windows.
MCSymbol * getCOMDATSymbol() const
unsigned getCharacteristics() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
StringRef getName() const
MCSymbol * getBeginSymbol()
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
StringRef getName() const
getName - Get the symbol name.
bool isVariable() const
isVariable - Check if this is a variable symbol.
bool isRegistered() const
void setIndex(uint32_t Value) const
Set the (implementation defined) index.
uint32_t getIndex() const
Get the (implementation defined) index.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
MCFragment * getFragment() const
uint64_t getOffset() const
MCWinCOFFObjectTargetWriter(unsigned Machine_)
Represents a location in source code.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Utility for building string tables with deduplicated suffixes.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
void recordRelocation(const MCFragment &F, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) override
Record a relocation entry.
void reset() override
lifetime management
int getSectionNumber(const MCSection &Section) const
void setAssembler(MCAssembler *Asm) override
WinCOFFObjectWriter(std::unique_ptr< MCWinCOFFObjectTargetWriter > MOTW, raw_pwrite_stream &OS)
void executePostLayoutBinding() override
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
friend class WinCOFFWriter
uint64_t writeObject() override
Write the object file and returns the number of bytes written.
bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const override
void executePostLayoutBinding()
WinCOFFWriter(WinCOFFObjectWriter &OWriter, raw_pwrite_stream &OS, DwoMode Mode)
enum llvm::WinCOFFWriter::DwoMode Mode
void recordRelocation(const MCFragment &F, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)
void setAssembler(MCAssembler *A)
int getSectionNumber(const MCSection &Section) const
An abstract base class for streams implementations that also support a pwrite operation.
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_REL_MIPS_SECRELHI
@ IMAGE_FILE_MACHINE_UNKNOWN
@ IMAGE_FILE_MACHINE_AMD64
@ IMAGE_FILE_MACHINE_R4000
@ IMAGE_FILE_MACHINE_I386
@ IMAGE_FILE_MACHINE_ARMNT
@ IMAGE_SCN_ALIGN_64BYTES
@ IMAGE_SCN_ALIGN_128BYTES
@ IMAGE_SCN_ALIGN_256BYTES
@ IMAGE_SCN_ALIGN_1024BYTES
@ IMAGE_SCN_ALIGN_512BYTES
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_ALIGN_4096BYTES
@ IMAGE_SCN_ALIGN_8192BYTES
@ IMAGE_SCN_LNK_NRELOC_OVFL
@ IMAGE_SCN_ALIGN_16BYTES
@ IMAGE_SCN_ALIGN_32BYTES
@ IMAGE_SCN_ALIGN_2048BYTES
bool isAnyArm64(T Machine)
@ IMAGE_SYM_CLASS_EXTERNAL
External symbol.
@ IMAGE_SYM_CLASS_LABEL
Label.
@ IMAGE_SYM_CLASS_FILE
File name.
@ IMAGE_SYM_CLASS_NULL
No symbol.
@ IMAGE_SYM_CLASS_WEAK_EXTERNAL
Duplicate tag.
@ IMAGE_SYM_CLASS_STATIC
Static.
LLVM_ABI bool encodeSectionName(char *Out, uint64_t Offset)
Encode section name based on string table offset.
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ IMAGE_REL_ARM_BRANCH20T
@ IMAGE_REL_ARM_BRANCH24T
const int32_t MaxNumberOfSections16
static const char BigObjMagic[]
@ IMAGE_SYM_DTYPE_FUNCTION
A function that returns a base type.
@ SCT_COMPLEX_TYPE_SHIFT
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
void write32le(void *P, uint32_t V)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
std::unique_ptr< MCObjectWriter > createWinCOFFDwoObjectWriter(std::unique_ptr< MCWinCOFFObjectTargetWriter > MOTW, raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS)
FunctionAddr VTableAddr Count
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
std::unique_ptr< MCObjectWriter > createWinCOFFObjectWriter(std::unique_ptr< MCWinCOFFObjectTargetWriter > MOTW, raw_pwrite_stream &OS)
Construct a new Win COFF writer instance.
@ FK_SecRel_2
A two-byte section relative fixup.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Implement std::hash so that hash_code can be used in STL containers.
uint64_t value() const
This is a hole in the type system and should not be abused.
uint16_t NumberOfRelocations
uint16_t NumberOfLinenumbers
uint32_t PointerToRelocations
uint16_t NumberOfLineNumbers
uint32_t PointerToRawData
uint16_t NumberOfRelocations
uint32_t PointerToLineNumbers
uint8_t NumberOfAuxSymbols
Adapter to write values to a stream in a particular byte order.
AuxiliarySectionDefinition SectionDefinition