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>>;
132 using section_offset_map =
144 section_map SectionMap;
145 symbol_map SymbolMap;
146 section_offset_map SecRelSymbolMap;
148 symbol_list WeakDefaults;
151 bool UseOffsetLabels =
false;
152 unsigned SecRelSymbolCount = 0;
174 COFFSymbol *createSymbol(
StringRef Name);
176 COFFSymbol *getOrCreateCOFFSymbol(
const MCSymbol &Sym);
177 COFFSection *createSection(
StringRef Name);
181 COFFSymbol *getLinkedSymbol(
const MCSymbol &Symbol);
184 void SetSymbolName(COFFSymbol &S);
185 void SetSectionName(COFFSection &S);
187 bool isUninitializedData(
const COFFSection &S);
191 void WriteSymbol(
const COFFSymbol &S);
192 void WriteAuxiliarySymbols(
const COFFSymbol::AuxiliarySymbols &S);
193 void writeSectionHeaders();
196 void writeSection(
const COFFSection &Sec);
198 void createFileSymbols();
199 void setWeakDefaultNames();
200 void assignSectionNumbers();
201 void assignFileOffsets();
206 : TargetObjectWriter(
std::
move(MOTW)),
212 : TargetObjectWriter(
std::
move(MOTW)),
228void COFFSymbol::set_name_offset(uint32_t
Offset) {
239 Header.Machine = OWriter.TargetObjectWriter->getMachine();
247COFFSymbol *WinCOFFWriter::createSymbol(
StringRef Name) {
248 Symbols.push_back(std::make_unique<COFFSymbol>(Name));
249 return Symbols.back().get();
252COFFSymbol *WinCOFFWriter::getOrCreateCOFFSymbol(
const MCSymbol &Sym) {
253 COFFSymbol *&Ret = SymbolMap[&Sym];
255 Ret = createSymbol(Sym.
getName());
259COFFSymbol *WinCOFFWriter::getOrCreateSecRelSymbol(
const MCSymbol &Sym,
262 assert(SectionMap.contains(TargetSection) &&
263 "Section must already have been defined in executePostLayoutBinding!");
265 COFFSymbol *&Ret = SecRelSymbolMap[{TargetSection,
Offset}];
269 COFFSection *
Section = SectionMap[TargetSection];
272 Offset == Asm->getSymbolOffset(Sym))
276 (Twine(
"$L") +
Section->Name +
"_secrel_" + Twine(++SecRelSymbolCount))
279 Ret = createSymbol(Name);
286COFFSection *WinCOFFWriter::createSection(
StringRef Name) {
287 Sections.emplace_back(std::make_unique<COFFSection>(Name));
288 return Sections.back().get();
327void WinCOFFWriter::defineSection(
const MCSectionCOFF &MCSec) {
338 COFFSymbol *COMDATSymbol = getOrCreateCOFFSymbol(*S);
339 if (COMDATSymbol->Section)
341 COMDATSymbol->Section =
Section;
348 Symbol->Aux[0].AuxType = ATSectionDefinition;
359 if (UseOffsetLabels) {
360 const uint32_t
Interval = 1 << OffsetLabelIntervalBits;
362 for (uint32_t Off =
Interval,
E = Asm->getSectionAddressSize(MCSec);
364 auto Name = (
"$L" + MCSec.
getName() +
"_" + Twine(
N++)).str();
365 COFFSymbol *
Label = createSymbol(Name);
369 Section->OffsetSymbols.push_back(Label);
376 if (Symbol.isCommon() && Symbol.isExternal())
377 return Symbol.getCommonSize();
380 if (!Asm.getSymbolOffset(Symbol, Res))
386COFFSymbol *WinCOFFWriter::getLinkedSymbol(
const MCSymbol &Symbol) {
394 auto &Aliasee =
static_cast<const MCSymbolCOFF &
>(SymRef->getSymbol());
395 if (Aliasee.isUndefined() || Aliasee.isExternal())
396 return getOrCreateCOFFSymbol(Aliasee);
403void WinCOFFWriter::defineSymbol(
const MCSymbolCOFF &MCSym) {
405 COFFSection *Sec =
nullptr;
406 MCSectionCOFF *MCSec =
nullptr;
408 MCSec =
static_cast<MCSectionCOFF *
>(
Base->getFragment()->
getParent());
409 Sec = SectionMap[MCSec];
415 COFFSymbol *Sym = getOrCreateCOFFSymbol(MCSym);
416 COFFSymbol *
Local =
nullptr;
417 if (
static_cast<const MCSymbolCOFF &
>(MCSym)
418 .getWeakExternalCharacteristics()) {
420 Sym->Section =
nullptr;
422 COFFSymbol *WeakDefault = getLinkedSymbol(MCSym);
424 std::string WeakName = (
".weak." + MCSym.
getName() +
".default").str();
425 WeakDefault = createSymbol(WeakName);
429 WeakDefault->Section = Sec;
430 WeakDefaults.insert(WeakDefault);
434 Sym->Other = WeakDefault;
438 memset(&Sym->Aux[0], 0,
sizeof(Sym->Aux[0]));
439 Sym->Aux[0].AuxType = ATWeakExternal;
440 Sym->Aux[0].Aux.WeakExternal.TagIndex = 0;
441 Sym->Aux[0].Aux.WeakExternal.Characteristics =
442 static_cast<const MCSymbolCOFF &
>(MCSym)
443 .getWeakExternalCharacteristics();
455 auto &SymbolCOFF =
static_cast<const MCSymbolCOFF &
>(MCSym);
456 Local->Data.Type = SymbolCOFF.getType();
457 Local->Data.StorageClass = SymbolCOFF.getClass();
472void WinCOFFWriter::SetSectionName(COFFSection &S) {
474 std::memcpy(S.Header.
Name, S.Name.c_str(), S.Name.size());
478 uint64_t StringTableEntry = Strings.
getOffset(S.Name);
483void WinCOFFWriter::SetSymbolName(COFFSymbol &S) {
485 S.set_name_offset(Strings.getOffset(S.Name));
487 std::memcpy(S.Data.
Name, S.Name.c_str(), S.Name.size());
490bool WinCOFFWriter::isUninitializedData(
const COFFSection &S) {
498void WinCOFFWriter::WriteFileHeader(
const COFF::header &Header) {
501 W.write<uint16_t>(0xFFFF);
503 W.write<uint16_t>(Header.Machine);
504 W.write<uint32_t>(Header.TimeDateStamp);
506 W.write<uint32_t>(0);
507 W.write<uint32_t>(0);
508 W.write<uint32_t>(0);
509 W.write<uint32_t>(0);
510 W.write<uint32_t>(Header.NumberOfSections);
511 W.write<uint32_t>(Header.PointerToSymbolTable);
512 W.write<uint32_t>(Header.NumberOfSymbols);
514 W.write<uint16_t>(Header.Machine);
515 W.write<uint16_t>(
static_cast<int16_t
>(Header.NumberOfSections));
516 W.write<uint32_t>(Header.TimeDateStamp);
517 W.write<uint32_t>(Header.PointerToSymbolTable);
518 W.write<uint32_t>(Header.NumberOfSymbols);
519 W.write<uint16_t>(Header.SizeOfOptionalHeader);
520 W.write<uint16_t>(Header.Characteristics);
524void WinCOFFWriter::WriteSymbol(
const COFFSymbol &S) {
526 W.write<uint32_t>(S.Data.
Value);
530 W.write<uint16_t>(
static_cast<int16_t
>(S.Data.
SectionNumber));
531 W.write<uint16_t>(S.Data.
Type);
534 WriteAuxiliarySymbols(S.Aux);
537void WinCOFFWriter::WriteAuxiliarySymbols(
538 const COFFSymbol::AuxiliarySymbols &S) {
539 for (
const AuxSymbol &i : S) {
542 W.write<uint32_t>(i.Aux.WeakExternal.TagIndex);
543 W.write<uint32_t>(i.Aux.WeakExternal.Characteristics);
544 W.OS.write_zeros(
sizeof(i.Aux.WeakExternal.unused));
549 W.OS.write(
reinterpret_cast<const char *
>(&i.Aux),
552 case ATSectionDefinition:
553 W.write<uint32_t>(i.Aux.SectionDefinition.Length);
554 W.write<uint16_t>(i.Aux.SectionDefinition.NumberOfRelocations);
555 W.write<uint16_t>(i.Aux.SectionDefinition.NumberOfLinenumbers);
556 W.write<uint32_t>(i.Aux.SectionDefinition.CheckSum);
557 W.write<uint16_t>(
static_cast<int16_t
>(i.Aux.SectionDefinition.Number));
558 W.OS << char(i.Aux.SectionDefinition.Selection);
559 W.OS.write_zeros(
sizeof(i.Aux.SectionDefinition.unused));
561 static_cast<int16_t
>(i.Aux.SectionDefinition.Number >> 16));
570void WinCOFFWriter::writeSectionHeaders() {
574 std::vector<COFFSection *> Arr;
575 for (
auto &Section : Sections)
577 llvm::sort(Arr, [](
const COFFSection *
A,
const COFFSection *
B) {
578 return A->Number <
B->Number;
581 for (
auto &Section : Arr) {
585 COFF::section &S =
Section->Header;
586 if (
Section->Relocations.size() >= 0xffff)
602 W.write<uint32_t>(
R.VirtualAddress);
603 W.write<uint32_t>(
R.SymbolTableIndex);
604 W.write<uint16_t>(
R.Type);
610uint32_t WinCOFFWriter::writeSectionContents(
const MCSection &MCSec) {
614 raw_svector_ostream VecOS(Buf);
615 Asm->writeSectionData(VecOS, &MCSec);
627void WinCOFFWriter::writeSection(
const COFFSection &Sec) {
628 if (Sec.Number == -1)
634 "Section::PointerToRawData is insane!");
636 uint32_t CRC = writeSectionContents(*Sec.MCSection);
639 COFFSymbol::AuxiliarySymbols &AuxSyms = Sec.Symbol->Aux;
640 assert(AuxSyms.
size() == 1 && AuxSyms[0].AuxType == ATSectionDefinition);
641 AuxSymbol &SecDef = AuxSyms[0];
643 }
else if (isUninitializedData(Sec)) {
645 writeSectionContents(*Sec.MCSection);
649 if (Sec.Relocations.empty()) {
651 "Section::PointerToRelocations is insane!");
656 "Section::PointerToRelocations is insane!");
658 if (Sec.Relocations.size() >= 0xffff) {
662 R.VirtualAddress = Sec.Relocations.size() + 1;
663 R.SymbolTableIndex = 0;
668 for (
const auto &Relocation : Sec.Relocations)
669 WriteRelocation(Relocation.Data);
673void WinCOFFWriter::createFileSymbols() {
674 for (
const std::pair<std::string, size_t> &It : OWriter.getFileNames()) {
676 const std::string &
Name = It.first;
678 unsigned Count = (
Name.size() + SymbolSize - 1) / SymbolSize;
680 COFFSymbol *
File = createSymbol(
".file");
687 for (
auto &Aux :
File->Aux) {
688 Aux.AuxType = ATFile;
690 if (
Length > SymbolSize) {
691 memcpy(&Aux.Aux,
Name.c_str() +
Offset, SymbolSize);
695 memset((
char *)&Aux.Aux +
Length, 0, SymbolSize -
Length);
704void WinCOFFWriter::setWeakDefaultNames() {
705 if (WeakDefaults.empty())
715 COFFSymbol *Unique =
nullptr;
716 for (
bool AllowComdat : {
false,
true}) {
717 for (
auto &Sym : Symbols) {
719 if (WeakDefaults.count(Sym.get()))
727 if (!AllowComdat && Sym->Section &&
739 for (
auto *Sym : WeakDefaults) {
740 Sym->Name.append(
".");
741 Sym->Name.append(Unique->Name);
746 return Section.Symbol->Aux[0].Aux.SectionDefinition.Selection ==
750void WinCOFFWriter::assignSectionNumbers() {
754 Section.Symbol->Data.SectionNumber =
I;
755 Section.Symbol->Aux[0].Aux.SectionDefinition.Number =
I;
762 for (
const std::unique_ptr<COFFSection> &Section : Sections)
765 for (
const std::unique_ptr<COFFSection> &Section : Sections)
771void WinCOFFWriter::assignFileOffsets() {
772 unsigned Offset = W.OS.tell();
777 for (
const auto &Section : *Asm) {
778 COFFSection *Sec = SectionMap[&
Section];
780 if (!Sec || Sec->Number == -1)
783 Sec->Header.
SizeOfRawData = Asm->getSectionAddressSize(Section);
785 if (!isUninitializedData(*Sec)) {
790 if (!Sec->Relocations.empty()) {
791 bool RelocationsOverflow = Sec->Relocations.size() >= 0xffff;
793 if (RelocationsOverflow) {
802 if (RelocationsOverflow) {
809 for (
auto &Relocation : Sec->Relocations) {
810 assert(Relocation.Symb->getIndex() != -1);
813 Relocation.Data.SymbolTableIndex = Relocation.Symb->getIndex();
819 "Section's symbol must have one aux!");
820 AuxSymbol &Aux = Sec->Symbol->Aux[0];
821 assert(Aux.AuxType == ATSectionDefinition &&
822 "Section's symbol's aux symbol must be a Section Definition!");
830 Header.PointerToSymbolTable =
Offset;
834 memset(&Header, 0,
sizeof(Header));
835 Header.Machine = OWriter.TargetObjectWriter->getMachine();
841 SecRelSymbolMap.clear();
842 WeakDefaults.clear();
843 SecRelSymbolCount = 0;
849 for (
const auto &Section : *Asm) {
857 for (
const MCSymbol &Symbol : Asm->symbols()) {
866 Header.NumberOfSections = Sections.size();
867 Header.NumberOfSymbols = 0;
868 if (Sections.size() > INT32_MAX)
870 "PE COFF object files can't have more than 2147483647 sections");
872 assignSectionNumbers();
877 assert(
Target.getAddSym() &&
"Relocation must reference a symbol!");
880 if (!
A.isRegistered()) {
881 getContext().reportError(
Fixup.getLoc(),
Twine(
"symbol '") +
A.getName() +
882 "' can not be undefined");
885 if (
A.isTemporary() &&
A.isUndefined()) {
886 getContext().reportError(
Fixup.getLoc(),
Twine(
"assembler label '") +
888 "' can not be undefined");
895 assert(SectionMap.contains(MCSec) &&
896 "Section must already have been defined in executePostLayoutBinding!");
898 COFFSection *Sec = SectionMap[MCSec];
900 if (!
B->getFragment()) {
901 getContext().reportError(
903 Twine(
"symbol '") +
B->getName() +
904 "' can not be undefined in a subtraction expression");
909 int64_t OffsetOfB = Asm->getSymbolOffset(*
B);
912 int64_t OffsetOfRelocation = Asm->getFragmentOffset(
F) +
Fixup.getOffset();
914 FixedValue = (OffsetOfRelocation - OffsetOfB) +
Target.getConstant();
916 FixedValue =
Target.getConstant();
919 COFFRelocation
Reloc;
921 Reloc.Data.SymbolTableIndex = 0;
922 Reloc.Data.VirtualAddress = Asm->getFragmentOffset(
F);
923 Reloc.Data.Type = OWriter.TargetObjectWriter->getRelocType(
926 bool IsArm64SecRel12 =
false;
928 switch (
Reloc.Data.Type) {
932 IsArm64SecRel12 =
true;
937 bool NeedsSecRelSymbol =
false;
938 bool UseSectionSymbol =
A.isTemporary() && !SymbolMap.lookup(&
A);
940 if (IsArm64SecRel12 &&
A.isInSection()) {
941 uint64_t SecRelFixedValue = FixedValue;
942 if (UseSectionSymbol)
943 SecRelFixedValue += Asm->getSymbolOffset(
A);
944 NeedsSecRelSymbol = !
isUInt<12>(SecRelFixedValue);
945 SecRelSymbolOffset = Asm->getSymbolOffset(
A) + FixedValue;
948 if (NeedsSecRelSymbol) {
950 getContext().reportError(
Fixup.getLoc(),
951 "relocation addend out of range");
954 Reloc.Symb = getOrCreateSecRelSymbol(
A, SecRelSymbolOffset);
956 }
else if (UseSectionSymbol) {
959 SectionMap.contains(TargetSection) &&
960 "Section must already have been defined in executePostLayoutBinding!");
961 COFFSection *Section = SectionMap[TargetSection];
962 Reloc.Symb = Section->Symbol;
963 FixedValue += Asm->getSymbolOffset(
A);
968 if (UseOffsetLabels && !Section->OffsetSymbols.empty()) {
969 uint64_t LabelIndex = FixedValue >> OffsetLabelIntervalBits;
970 if (LabelIndex > 0) {
971 if (LabelIndex <= Section->OffsetSymbols.size())
972 Reloc.Symb = Section->OffsetSymbols[LabelIndex - 1];
974 Reloc.Symb = Section->OffsetSymbols.back();
975 FixedValue -=
Reloc.Symb->Data.Value;
980 SymbolMap.contains(&
A) &&
981 "Symbol must already have been defined in executePostLayoutBinding!");
982 Reloc.Symb = SymbolMap[&
A];
985 ++
Reloc.Symb->Relocations;
987 Reloc.Data.VirtualAddress +=
Fixup.getOffset();
1002 switch (
Reloc.Data.Type) {
1034 FixedValue = FixedValue + 4;
1043 if (OWriter.TargetObjectWriter->recordRelocation(
Fixup)) {
1044 Sec->Relocations.push_back(
Reloc);
1050 auto RelocPair =
Reloc;
1052 Sec->Relocations.push_back(RelocPair);
1058 std::time_t Now = time(
nullptr);
1065 uint64_t StartOffset = W.OS.tell();
1067 setWeakDefaultNames();
1069 createFileSymbols();
1071 for (
auto &Symbol : Symbols) {
1073 if (Symbol->Section)
1074 Symbol->Data.SectionNumber = Symbol->Section->Number;
1075 Symbol->setIndex(Header.NumberOfSymbols++);
1077 Symbol->Data.NumberOfAuxSymbols = Symbol->Aux.size();
1078 Header.NumberOfSymbols += Symbol->Data.NumberOfAuxSymbols;
1082 for (
const auto &S : Sections)
1084 Strings.add(S->
Name);
1085 for (
const auto &S : Symbols)
1087 Strings.add(S->
Name);
1091 for (
const auto &S : Sections)
1093 for (
auto &S : Symbols)
1097 for (
auto &Symbol : Symbols) {
1098 if (Symbol->Other) {
1099 assert(Symbol->getIndex() != -1);
1100 assert(Symbol->Aux.size() == 1 &&
"Symbol must contain one aux symbol!");
1101 assert(Symbol->Aux[0].AuxType == ATWeakExternal &&
1102 "Symbol's aux symbol must be a Weak External!");
1103 Symbol->Aux[0].Aux.WeakExternal.TagIndex = Symbol->Other->getIndex();
1108 for (
auto &Section : Sections) {
1109 if (Section->Symbol->Aux[0].Aux.SectionDefinition.Selection !=
1120 getContext().reportError(
1122 Twine(
" associative with sectionless symbol ") +
1127 const auto *AssocMCSec =
1129 assert(SectionMap.count(AssocMCSec));
1130 COFFSection *AssocSec = SectionMap[AssocMCSec];
1133 if (AssocSec->Number == -1)
1136 Section->Symbol->Aux[0].Aux.SectionDefinition.Number = AssocSec->Number;
1140 if (
Mode !=
DwoOnly && OWriter.getEmitAddrsigSection()) {
1143 for (
const MCSymbol *S : OWriter.AddrsigSyms) {
1152 assert(SectionMap.contains(TargetSection) &&
1153 "Section must already have been defined in "
1154 "executePostLayoutBinding!");
1155 encodeULEB128(SectionMap[TargetSection]->Symbol->getIndex(), OS);
1157 auto *Sec = getContext().getCOFFSection(
".llvm_addrsig",
1159 Sec->curFragList()->Tail->setVarContents(OS.
str());
1163 if (
Mode !=
DwoOnly && !OWriter.getCGProfile().empty()) {
1166 for (
const auto &CGPE : OWriter.getCGProfile()) {
1167 uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
1168 uint32_t ToIndex = CGPE.To->getSymbol().getIndex();
1173 auto *Sec = getContext().getCOFFSection(
".llvm.call-graph-profile",
1175 Sec->curFragList()->Tail->setVarContents(OS.
str());
1178 assignFileOffsets();
1182 if (OWriter.IncrementalLinkerCompatible) {
1183 Header.TimeDateStamp =
getTime();
1186 Header.TimeDateStamp = 0;
1190 WriteFileHeader(Header);
1191 writeSectionHeaders();
1194 sections::iterator
I = Sections.begin();
1195 sections::iterator IE = Sections.end();
1196 auto J = Asm->begin();
1197 auto JE = Asm->end();
1198 for (;
I != IE && J != JE; ++
I, ++J) {
1202 assert(J != JE && (**I).MCSection == &*J &&
"Wrong bound MCSection");
1207 for (std::unique_ptr<COFFSection> &Sec : Sections)
1210 assert(W.OS.tell() == Header.PointerToSymbolTable &&
1211 "Header::PointerToSymbolTable is insane!");
1214 for (
auto &Symbol : Symbols)
1215 if (Symbol->getIndex() != -1)
1216 WriteSymbol(*Symbol);
1219 Strings.write(W.OS);
1221 return W.OS.tell() - StartOffset;
1225 return SectionMap.at(&Section)->Number;
1235 IncrementalLinkerCompatible =
false;
1244 ObjWriter->setAssembler(
Asm);
1246 DwoWriter->setAssembler(
Asm);
1251 bool IsPCRel)
const {
1265 ObjWriter->executePostLayoutBinding();
1267 DwoWriter->executePostLayoutBinding();
1274 ObjWriter->recordRelocation(
F,
Fixup,
Target, FixedValue);
1283 uint64_t TotalSize = ObjWriter->writeObject();
1285 TotalSize += DwoWriter->writeObject();
1290 return ObjWriter->getSectionNumber(Section);
1294 : Machine(Machine_) {}
1297void MCWinCOFFObjectTargetWriter::anchor() {}
1304 return std::make_unique<WinCOFFObjectWriter>(std::move(MOTW), OS);
1310 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.
Represent a constant reference to a string, i.e.
std::string str() const
Get the contents as an std::string.
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.
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_REL_ARM64_SECREL_LOW12A
@ IMAGE_REL_ARM64_SECREL_HIGH12A
@ IMAGE_REL_ARM64_SECREL_LOW12L
@ 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.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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.
constexpr 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