Lines Matching +full:write +full:- +full:data

1 //===- llvm/MC/WinCOFFObjectWriter.cpp ------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
72 COFF::symbol Data = {}; member in __anon3870acaf0111::COFFSymbol
92 MC->setIndex(static_cast<uint32_t>(Value)); in setIndex()
96 // This class contains staging data for a COFF relocation entry.
98 COFF::relocation Data; member
216 //------------------------------------------------------------------------------
223 write32le(Data.Name + 0, 0); in set_name_offset()
224 write32le(Data.Name + 4, Offset); in set_name_offset()
227 //------------------------------------------------------------------------------
233 Header.Machine = OWriter.TargetObjectWriter->getMachine(); in WinCOFFWriter()
235 // limited range for the immediate offset (+/- 1 MB); create extra offset in WinCOFFWriter()
237 // non-temporary symbol that is close enough. in WinCOFFWriter()
249 Ret = createSymbol(Symbol->getName()); in GetOrCreateCOFFSymbol()
292 /// This function takes a section data object from the assembler
298 Section->Symbol = Symbol; in defineSection()
300 Symbol->Section = Section; in defineSection()
301 Symbol->Data.StorageClass = COFF::IMAGE_SYM_CLASS_STATIC; in defineSection()
307 if (COMDATSymbol->Section) in defineSection()
309 COMDATSymbol->Section = Section; in defineSection()
314 Symbol->Aux.resize(1); in defineSection()
315 Symbol->Aux[0] = {}; in defineSection()
316 Symbol->Aux[0].AuxType = ATSectionDefinition; in defineSection()
317 Symbol->Aux[0].Aux.SectionDefinition.Selection = MCSec.getSelection(); in defineSection()
320 Section->Header.Characteristics = MCSec.getCharacteristics(); in defineSection()
321 Section->Header.Characteristics |= getAlignment(MCSec); in defineSection()
324 Section->MCSection = &MCSec; in defineSection()
334 Label->Section = Section; in defineSection()
335 Label->Data.StorageClass = COFF::IMAGE_SYM_CLASS_LABEL; in defineSection()
336 Label->Data.Value = Off; in defineSection()
337 Section->OffsetSymbols.push_back(Label); in defineSection()
362 const MCSymbol &Aliasee = SymRef->getSymbol(); in getLinkedSymbol()
369 /// This function takes a symbol data object from the assembler
376 if (Base && Base->getFragment()) { in defineSymbol()
377 MCSec = cast<MCSectionCOFF>(Base->getFragment()->getParent()); in defineSymbol()
387 Sym->Data.StorageClass = COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL; in defineSymbol()
388 Sym->Section = nullptr; in defineSymbol()
395 WeakDefault->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE; in defineSymbol()
397 WeakDefault->Section = Sec; in defineSymbol()
402 Sym->Other = WeakDefault; in defineSymbol()
405 Sym->Aux.resize(1); in defineSymbol()
406 memset(&Sym->Aux[0], 0, sizeof(Sym->Aux[0])); in defineSymbol()
407 Sym->Aux[0].AuxType = ATWeakExternal; in defineSymbol()
408 Sym->Aux[0].Aux.WeakExternal.TagIndex = 0; // Filled in later in defineSymbol()
409 Sym->Aux[0].Aux.WeakExternal.Characteristics = in defineSymbol()
413 Sym->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE; in defineSymbol()
415 Sym->Section = Sec; in defineSymbol()
420 Local->Data.Value = getSymbolValue(MCSym, Asm); in defineSymbol()
423 Local->Data.Type = SymbolCOFF.getType(); in defineSymbol()
424 Local->Data.StorageClass = SymbolCOFF.getClass(); in defineSymbol()
427 if (Local->Data.StorageClass == COFF::IMAGE_SYM_CLASS_NULL) { in defineSymbol()
431 Local->Data.StorageClass = IsExternal ? COFF::IMAGE_SYM_CLASS_EXTERNAL in defineSymbol()
436 Sym->MC = &MCSym; in defineSymbol()
454 std::memcpy(S.Data.Name, S.Name.c_str(), S.Name.size()); in SetSymbolName()
458 return (S->Header.Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA) == in IsPhysicalSection()
462 //------------------------------------------------------------------------------
467 W.write<uint16_t>(COFF::IMAGE_FILE_MACHINE_UNKNOWN); in WriteFileHeader()
468 W.write<uint16_t>(0xFFFF); in WriteFileHeader()
469 W.write<uint16_t>(COFF::BigObjHeader::MinBigObjectVersion); in WriteFileHeader()
470 W.write<uint16_t>(Header.Machine); in WriteFileHeader()
471 W.write<uint32_t>(Header.TimeDateStamp); in WriteFileHeader()
472 W.OS.write(COFF::BigObjMagic, sizeof(COFF::BigObjMagic)); in WriteFileHeader()
473 W.write<uint32_t>(0); in WriteFileHeader()
474 W.write<uint32_t>(0); in WriteFileHeader()
475 W.write<uint32_t>(0); in WriteFileHeader()
476 W.write<uint32_t>(0); in WriteFileHeader()
477 W.write<uint32_t>(Header.NumberOfSections); in WriteFileHeader()
478 W.write<uint32_t>(Header.PointerToSymbolTable); in WriteFileHeader()
479 W.write<uint32_t>(Header.NumberOfSymbols); in WriteFileHeader()
481 W.write<uint16_t>(Header.Machine); in WriteFileHeader()
482 W.write<uint16_t>(static_cast<int16_t>(Header.NumberOfSections)); in WriteFileHeader()
483 W.write<uint32_t>(Header.TimeDateStamp); in WriteFileHeader()
484 W.write<uint32_t>(Header.PointerToSymbolTable); in WriteFileHeader()
485 W.write<uint32_t>(Header.NumberOfSymbols); in WriteFileHeader()
486 W.write<uint16_t>(Header.SizeOfOptionalHeader); in WriteFileHeader()
487 W.write<uint16_t>(Header.Characteristics); in WriteFileHeader()
492 W.OS.write(S.Data.Name, COFF::NameSize); in WriteSymbol()
493 W.write<uint32_t>(S.Data.Value); in WriteSymbol()
495 W.write<uint32_t>(S.Data.SectionNumber); in WriteSymbol()
497 W.write<uint16_t>(static_cast<int16_t>(S.Data.SectionNumber)); in WriteSymbol()
498 W.write<uint16_t>(S.Data.Type); in WriteSymbol()
499 W.OS << char(S.Data.StorageClass); in WriteSymbol()
500 W.OS << char(S.Data.NumberOfAuxSymbols); in WriteSymbol()
509 W.write<uint32_t>(i.Aux.WeakExternal.TagIndex); in WriteAuxiliarySymbols()
510 W.write<uint32_t>(i.Aux.WeakExternal.Characteristics); in WriteAuxiliarySymbols()
513 W.OS.write_zeros(COFF::Symbol32Size - COFF::Symbol16Size); in WriteAuxiliarySymbols()
516 W.OS.write(reinterpret_cast<const char *>(&i.Aux), in WriteAuxiliarySymbols()
520 W.write<uint32_t>(i.Aux.SectionDefinition.Length); in WriteAuxiliarySymbols()
521 W.write<uint16_t>(i.Aux.SectionDefinition.NumberOfRelocations); in WriteAuxiliarySymbols()
522 W.write<uint16_t>(i.Aux.SectionDefinition.NumberOfLinenumbers); in WriteAuxiliarySymbols()
523 W.write<uint32_t>(i.Aux.SectionDefinition.CheckSum); in WriteAuxiliarySymbols()
524 W.write<uint16_t>(static_cast<int16_t>(i.Aux.SectionDefinition.Number)); in WriteAuxiliarySymbols()
527 W.write<uint16_t>( in WriteAuxiliarySymbols()
530 W.OS.write_zeros(COFF::Symbol32Size - COFF::Symbol16Size); in WriteAuxiliarySymbols()
536 // Write the section header.
545 return A->Number < B->Number; in writeSectionHeaders()
549 if (Section->Number == -1) in writeSectionHeaders()
552 COFF::section &S = Section->Header; in writeSectionHeaders()
553 if (Section->Relocations.size() >= 0xffff) in writeSectionHeaders()
555 W.OS.write(S.Name, COFF::NameSize); in writeSectionHeaders()
556 W.write<uint32_t>(S.VirtualSize); in writeSectionHeaders()
557 W.write<uint32_t>(S.VirtualAddress); in writeSectionHeaders()
558 W.write<uint32_t>(S.SizeOfRawData); in writeSectionHeaders()
559 W.write<uint32_t>(S.PointerToRawData); in writeSectionHeaders()
560 W.write<uint32_t>(S.PointerToRelocations); in writeSectionHeaders()
561 W.write<uint32_t>(S.PointerToLineNumbers); in writeSectionHeaders()
562 W.write<uint16_t>(S.NumberOfRelocations); in writeSectionHeaders()
563 W.write<uint16_t>(S.NumberOfLineNumbers); in writeSectionHeaders()
564 W.write<uint32_t>(S.Characteristics); in writeSectionHeaders()
569 W.write<uint32_t>(R.VirtualAddress); in WriteRelocation()
570 W.write<uint32_t>(R.SymbolTableIndex); in WriteRelocation()
571 W.write<uint16_t>(R.Type); in WriteRelocation()
574 // Write MCSec's contents. What this function does is essentially
580 // to CRC the data before we dump it into the object file. in writeSectionContents()
585 // Write the section contents to the object file. in writeSectionContents()
591 JC.update(ArrayRef(reinterpret_cast<uint8_t *>(Buf.data()), Buf.size())); in writeSectionContents()
596 if (Sec.Number == -1) in writeSection()
599 // Write the section contents. in writeSection()
607 COFFSymbol::AuxiliarySymbols &AuxSyms = Sec.Symbol->Aux; in writeSection()
613 // Write relocations for this section. in writeSection()
624 // In case of overflow, write actual relocation count as first in writeSection()
634 WriteRelocation(Relocation.Data); in writeSection()
643 unsigned Count = (Name.size() + SymbolSize - 1) / SymbolSize; in createFileSymbols()
646 File->Data.SectionNumber = COFF::IMAGE_SYM_DEBUG; in createFileSymbols()
647 File->Data.StorageClass = COFF::IMAGE_SYM_CLASS_FILE; in createFileSymbols()
648 File->Aux.resize(Count); in createFileSymbols()
652 for (auto &Aux : File->Aux) { in createFileSymbols()
657 Length = Length - SymbolSize; in createFileSymbols()
660 memset((char *)&Aux.Aux + Length, 0, SymbolSize - Length); in createFileSymbols()
676 // for a defined extern symbol, that isn't comdat - that should be unique in setWeakDefaultNames()
687 if (Sym->Data.StorageClass != COFF::IMAGE_SYM_CLASS_EXTERNAL) in setWeakDefaultNames()
690 if (!Sym->Section && Sym->Data.SectionNumber != COFF::IMAGE_SYM_ABSOLUTE) in setWeakDefaultNames()
692 if (!AllowComdat && Sym->Section && in setWeakDefaultNames()
693 Sym->Section->Header.Characteristics & COFF::IMAGE_SCN_LNK_COMDAT) in setWeakDefaultNames()
705 Sym->Name.append("."); in setWeakDefaultNames()
706 Sym->Name.append(Unique->Name); in setWeakDefaultNames()
711 return Section.Symbol->Aux[0].Aux.SectionDefinition.Selection == in isAssociative()
719 Section.Symbol->Data.SectionNumber = I; in assignSectionNumbers()
720 Section.Symbol->Aux[0].Aux.SectionDefinition.Number = I; in assignSectionNumbers()
745 if (!Sec || Sec->Number == -1) in assignFileOffsets()
748 Sec->Header.SizeOfRawData = Asm.getSectionAddressSize(Section); in assignFileOffsets()
751 Sec->Header.PointerToRawData = Offset; in assignFileOffsets()
752 Offset += Sec->Header.SizeOfRawData; in assignFileOffsets()
755 if (!Sec->Relocations.empty()) { in assignFileOffsets()
756 bool RelocationsOverflow = Sec->Relocations.size() >= 0xffff; in assignFileOffsets()
761 Sec->Header.NumberOfRelocations = 0xffff; in assignFileOffsets()
763 Sec->Header.NumberOfRelocations = Sec->Relocations.size(); in assignFileOffsets()
765 Sec->Header.PointerToRelocations = Offset; in assignFileOffsets()
772 Offset += COFF::RelocationSize * Sec->Relocations.size(); in assignFileOffsets()
774 for (auto &Relocation : Sec->Relocations) { in assignFileOffsets()
775 assert(Relocation.Symb->getIndex() != -1); in assignFileOffsets()
776 Relocation.Data.SymbolTableIndex = Relocation.Symb->getIndex(); in assignFileOffsets()
780 assert(Sec->Symbol->Aux.size() == 1 && in assignFileOffsets()
782 AuxSymbol &Aux = Sec->Symbol->Aux[0]; in assignFileOffsets()
785 Aux.Aux.SectionDefinition.Length = Sec->Header.SizeOfRawData; in assignFileOffsets()
787 Sec->Header.NumberOfRelocations; in assignFileOffsets()
789 Sec->Header.NumberOfLineNumbers; in assignFileOffsets()
797 Header.Machine = OWriter.TargetObjectWriter->getMachine(); in reset()
818 // Define non-temporary or temporary static (private-linkage) symbols in executePostLayoutBinding()
830 const MCSymbol &A = Target.getSymA()->getSymbol(); in recordRelocation()
844 MCSection *MCSec = Fragment->getParent(); in recordRelocation()
854 const MCSymbol *B = &SymB->getSymbol(); in recordRelocation()
855 if (!B->getFragment()) { in recordRelocation()
858 Twine("symbol '") + B->getName() + in recordRelocation()
870 FixedValue = (OffsetOfRelocation - OffsetOfB) + Target.getConstant(); in recordRelocation()
877 Reloc.Data.SymbolTableIndex = 0; in recordRelocation()
878 Reloc.Data.VirtualAddress = Asm.getFragmentOffset(*Fragment); in recordRelocation()
887 Reloc.Symb = Section->Symbol; in recordRelocation()
893 if (UseOffsetLabels && !Section->OffsetSymbols.empty()) { in recordRelocation()
896 if (LabelIndex <= Section->OffsetSymbols.size()) in recordRelocation()
897 Reloc.Symb = Section->OffsetSymbols[LabelIndex - 1]; in recordRelocation()
899 Reloc.Symb = Section->OffsetSymbols.back(); in recordRelocation()
900 FixedValue -= Reloc.Symb->Data.Value; in recordRelocation()
910 ++Reloc.Symb->Relocations; in recordRelocation()
912 Reloc.Data.VirtualAddress += Fixup.getOffset(); in recordRelocation()
913 Reloc.Data.Type = OWriter.TargetObjectWriter->getRelocType( in recordRelocation()
919 Reloc.Data.Type == COFF::IMAGE_REL_AMD64_REL32) || in recordRelocation()
921 Reloc.Data.Type == COFF::IMAGE_REL_I386_REL32) || in recordRelocation()
923 Reloc.Data.Type == COFF::IMAGE_REL_ARM_REL32) || in recordRelocation()
925 Reloc.Data.Type == COFF::IMAGE_REL_ARM64_REL32)) in recordRelocation()
929 switch (Reloc.Data.Type) { in recordRelocation()
940 // pre-ARMv7, which implicitly rules it out of ARMNT (it would be valid in recordRelocation()
970 if (OWriter.TargetObjectWriter->recordRelocation(Fixup)) in recordRelocation()
971 Sec->Relocations.push_back(Reloc); in recordRelocation()
999 if (Symbol->Section) in writeObject()
1000 Symbol->Data.SectionNumber = Symbol->Section->Number; in writeObject()
1001 Symbol->setIndex(Header.NumberOfSymbols++); in writeObject()
1003 Symbol->Data.NumberOfAuxSymbols = Symbol->Aux.size(); in writeObject()
1004 Header.NumberOfSymbols += Symbol->Data.NumberOfAuxSymbols; in writeObject()
1009 if (S->Name.size() > COFF::NameSize) in writeObject()
1010 Strings.add(S->Name); in writeObject()
1012 if (S->Name.size() > COFF::NameSize) in writeObject()
1013 Strings.add(S->Name); in writeObject()
1024 if (Symbol->Other) { in writeObject()
1025 assert(Symbol->getIndex() != -1); in writeObject()
1026 assert(Symbol->Aux.size() == 1 && "Symbol must contain one aux symbol!"); in writeObject()
1027 assert(Symbol->Aux[0].AuxType == ATWeakExternal && in writeObject()
1029 Symbol->Aux[0].Aux.WeakExternal.TagIndex = Symbol->Other->getIndex(); in writeObject()
1035 if (Section->Symbol->Aux[0].Aux.SectionDefinition.Selection != in writeObject()
1039 const MCSectionCOFF &MCSec = *Section->MCSection; in writeObject()
1045 if (!AssocMCSym->isInSection()) { in writeObject()
1049 AssocMCSym->getName()); in writeObject()
1053 const auto *AssocMCSec = cast<MCSectionCOFF>(&AssocMCSym->getSection()); in writeObject()
1058 if (AssocSec->Number == -1) in writeObject()
1061 Section->Symbol->Aux[0].Aux.SectionDefinition.Number = AssocSec->Number; in writeObject()
1068 auto *Frag = cast<MCDataFragment>(Sec->curFragList()->Head); in writeObject()
1069 raw_svector_ostream OS(Frag->getContents()); in writeObject()
1071 if (!S->isRegistered()) in writeObject()
1073 if (!S->isTemporary()) { in writeObject()
1074 encodeULEB128(S->getIndex(), OS); in writeObject()
1078 MCSection *TargetSection = &S->getSection(); in writeObject()
1082 encodeULEB128(SectionMap[TargetSection]->Symbol->getIndex(), OS); in writeObject()
1086 // Create the contents of the .llvm.call-graph-profile section. in writeObject()
1089 ".llvm.call-graph-profile", COFF::IMAGE_SCN_LNK_REMOVE); in writeObject()
1090 auto *Frag = cast<MCDataFragment>(Sec->curFragList()->Head); in writeObject()
1091 raw_svector_ostream OS(Frag->getContents()); in writeObject()
1093 uint32_t FromIndex = CGPE.From->getSymbol().getIndex(); in writeObject()
1094 uint32_t ToIndex = CGPE.To->getSymbol().getIndex(); in writeObject()
1095 support::endian::write(OS, FromIndex, W.Endian); in writeObject()
1096 support::endian::write(OS, ToIndex, W.Endian); in writeObject()
1097 support::endian::write(OS, CGPE.Count, W.Endian); in writeObject()
1112 // Write it all to disk... in writeObject()
1129 // Write section contents. in writeObject()
1136 // Write a symbol table. in writeObject()
1138 if (Symbol->getIndex() != -1) in writeObject()
1141 // Write a string table, which completes the entire COFF file. in writeObject()
1142 Strings.write(W.OS); in writeObject()
1144 return W.OS.tell() - StartOffset; in writeObject()
1147 //------------------------------------------------------------------------------
1155 ObjWriter->reset(); in reset()
1157 DwoWriter->reset(); in reset()
1177 ObjWriter->executePostLayoutBinding(Asm); in executePostLayoutBinding()
1179 DwoWriter->executePostLayoutBinding(Asm); in executePostLayoutBinding()
1186 assert(!isDwoSection(*Fragment->getParent()) && in recordRelocation()
1188 ObjWriter->recordRelocation(Asm, Fragment, Fixup, Target, FixedValue); in recordRelocation()
1192 uint64_t TotalSize = ObjWriter->writeObject(Asm); in writeObject()
1194 TotalSize += DwoWriter->writeObject(Asm); in writeObject()
1204 //------------------------------------------------------------------------------