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

1 //===- lib/MC/MachObjectWriter.cpp - Mach-O File Writer -------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
83 return Symbol->getName() < RHS.Symbol->getName(); in operator <()
96 return getSectionAddress(Fragment->getParent()) + in getFragmentAddress()
106 return C->getValue(); in getSymbolAddress()
109 if (!S.getVariableValue()->evaluateAsRelocatable(Target, &Asm, nullptr)) in getSymbolAddress()
114 if (Target.getSymA() && Target.getSymA()->getSymbol().isUndefined()) in getSymbolAddress()
116 Target.getSymA()->getSymbol().getName() + "'"); in getSymbolAddress()
117 if (Target.getSymB() && Target.getSymB()->getSymbol().isUndefined()) in getSymbolAddress()
119 Target.getSymB()->getSymbol().getName() + "'"); in getSymbolAddress()
123 Address += getSymbolAddress(Target.getSymA()->getSymbol(), Asm); in getSymbolAddress()
125 Address += getSymbolAddress(Target.getSymB()->getSymbol(), Asm); in getSymbolAddress()
129 return getSectionAddress(S.getFragment()->getParent()) + in getSymbolAddress()
136 unsigned Next = cast<MCSectionMachO>(Sec)->getLayoutOrder() + 1; in getPaddingSize()
147 // Non-temporary labels should always be visible to the linker. in isSymbolLinkerVisible()
166 // Non-linker visible symbols in sections which can't be atomized have no in getAtom()
169 *S.getFragment()->getParent())) in getAtom()
173 return S.getFragment()->getAtom(); in getAtom()
191 W.write<uint32_t>(is64Bit() ? MachO::MH_MAGIC_64 : MachO::MH_MAGIC); in writeHeader()
193 W.write<uint32_t>(TargetObjectWriter->getCPUType()); in writeHeader()
194 W.write<uint32_t>(TargetObjectWriter->getCPUSubtype()); in writeHeader()
196 W.write<uint32_t>(Type); in writeHeader()
197 W.write<uint32_t>(NumLoadCommands); in writeHeader()
198 W.write<uint32_t>(LoadCommandsSize); in writeHeader()
199 W.write<uint32_t>(Flags); in writeHeader()
201 W.write<uint32_t>(0); // reserved in writeHeader()
203 assert(W.OS.tell() - Start == (is64Bit() ? sizeof(MachO::mach_header_64) in writeHeader()
210 W.OS.write_zeros(Size - Str.size()); in writeWithPadding()
213 /// writeSegmentLoadCommand - Write a segment load command.
230 W.write<uint32_t>(is64Bit() ? MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT); in writeSegmentLoadCommand()
231 W.write<uint32_t>(SegmentLoadCommandSize + in writeSegmentLoadCommand()
237 W.write<uint64_t>(VMAddr); // vmaddr in writeSegmentLoadCommand()
238 W.write<uint64_t>(VMSize); // vmsize in writeSegmentLoadCommand()
239 W.write<uint64_t>(SectionDataStartOffset); // file offset in writeSegmentLoadCommand()
240 W.write<uint64_t>(SectionDataSize); // file size in writeSegmentLoadCommand()
242 W.write<uint32_t>(VMAddr); // vmaddr in writeSegmentLoadCommand()
243 W.write<uint32_t>(VMSize); // vmsize in writeSegmentLoadCommand()
244 W.write<uint32_t>(SectionDataStartOffset); // file offset in writeSegmentLoadCommand()
245 W.write<uint32_t>(SectionDataSize); // file size in writeSegmentLoadCommand()
248 W.write<uint32_t>(MaxProt); in writeSegmentLoadCommand()
250 W.write<uint32_t>(InitProt); in writeSegmentLoadCommand()
251 W.write<uint32_t>(NumSections); in writeSegmentLoadCommand()
252 W.write<uint32_t>(0); // flags in writeSegmentLoadCommand()
254 assert(W.OS.tell() - Start == SegmentLoadCommandSize); in writeSegmentLoadCommand()
280 W.write<uint64_t>(VMAddr); // address in writeSection()
281 W.write<uint64_t>(SectionSize); // size in writeSection()
283 W.write<uint32_t>(VMAddr); // address in writeSection()
284 W.write<uint32_t>(SectionSize); // size in writeSection()
287 W.write<uint32_t>(FileOffset); in writeSection()
289 W.write<uint32_t>(Log2(Section.getAlign())); in writeSection()
292 W.write<uint32_t>(NumRelocations ? RelocationsStart : 0); in writeSection()
293 W.write<uint32_t>(NumRelocations); in writeSection()
294 W.write<uint32_t>(Flags); in writeSection()
295 W.write<uint32_t>(IndirectSymBase.lookup(&Sec)); // reserved1 in writeSection()
296 W.write<uint32_t>(Section.getStubSize()); // reserved2 in writeSection()
298 W.write<uint32_t>(0); // reserved3 in writeSection()
300 assert(W.OS.tell() - Start == in writeSection()
313 W.write<uint32_t>(MachO::LC_SYMTAB); in writeSymtabLoadCommand()
314 W.write<uint32_t>(sizeof(MachO::symtab_command)); in writeSymtabLoadCommand()
315 W.write<uint32_t>(SymbolOffset); in writeSymtabLoadCommand()
316 W.write<uint32_t>(NumSymbols); in writeSymtabLoadCommand()
317 W.write<uint32_t>(StringTableOffset); in writeSymtabLoadCommand()
318 W.write<uint32_t>(StringTableSize); in writeSymtabLoadCommand()
320 assert(W.OS.tell() - Start == sizeof(MachO::symtab_command)); in writeSymtabLoadCommand()
336 W.write<uint32_t>(MachO::LC_DYSYMTAB); in writeDysymtabLoadCommand()
337 W.write<uint32_t>(sizeof(MachO::dysymtab_command)); in writeDysymtabLoadCommand()
338 W.write<uint32_t>(FirstLocalSymbol); in writeDysymtabLoadCommand()
339 W.write<uint32_t>(NumLocalSymbols); in writeDysymtabLoadCommand()
340 W.write<uint32_t>(FirstExternalSymbol); in writeDysymtabLoadCommand()
341 W.write<uint32_t>(NumExternalSymbols); in writeDysymtabLoadCommand()
342 W.write<uint32_t>(FirstUndefinedSymbol); in writeDysymtabLoadCommand()
343 W.write<uint32_t>(NumUndefinedSymbols); in writeDysymtabLoadCommand()
344 W.write<uint32_t>(0); // tocoff in writeDysymtabLoadCommand()
345 W.write<uint32_t>(0); // ntoc in writeDysymtabLoadCommand()
346 W.write<uint32_t>(0); // modtaboff in writeDysymtabLoadCommand()
347 W.write<uint32_t>(0); // nmodtab in writeDysymtabLoadCommand()
348 W.write<uint32_t>(0); // extrefsymoff in writeDysymtabLoadCommand()
349 W.write<uint32_t>(0); // nextrefsyms in writeDysymtabLoadCommand()
350 W.write<uint32_t>(IndirectSymbolOffset); in writeDysymtabLoadCommand()
351 W.write<uint32_t>(NumIndirectSymbols); in writeDysymtabLoadCommand()
352 W.write<uint32_t>(0); // extreloff in writeDysymtabLoadCommand()
353 W.write<uint32_t>(0); // nextrel in writeDysymtabLoadCommand()
354 W.write<uint32_t>(0); // locreloff in writeDysymtabLoadCommand()
355 W.write<uint32_t>(0); // nlocrel in writeDysymtabLoadCommand()
357 assert(W.OS.tell() - Start == sizeof(MachO::dysymtab_command)); in writeDysymtabLoadCommand()
373 while (S->isVariable()) { in findAliasedSymbol()
374 const MCExpr *Value = S->getVariableValue(); in findAliasedSymbol()
378 S = &Ref->getSymbol(); in findAliasedSymbol()
385 const auto &Data = cast<MCSymbolMachO>(*Symbol); in writeNlist() local
397 SectionIndex = AliaseeInfo->SectionIndex; in writeNlist()
399 // FIXME: Should this update Data as well? in writeNlist()
402 // Set the N_TYPE bits. See <mach-o/nlist.h>. in writeNlist()
405 if (IsAlias && Symbol->isUndefined()) in writeNlist()
407 else if (Symbol->isUndefined()) in writeNlist()
409 else if (Symbol->isAbsolute()) in writeNlist()
416 if (Data.isPrivateExtern()) in writeNlist()
420 if (Data.isExternal() || (!IsAlias && Symbol->isUndefined())) in writeNlist()
424 if (IsAlias && Symbol->isUndefined()) in writeNlist()
425 Address = AliaseeInfo->StringIndex; in writeNlist()
426 else if (Symbol->isDefined()) in writeNlist()
428 else if (Symbol->isCommon()) { in writeNlist()
431 Address = Symbol->getCommonSize(); in writeNlist()
436 W.write<uint32_t>(MSD.StringIndex); in writeNlist()
440 // The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc' in writeNlist()
444 W.write<uint16_t>(cast<MCSymbolMachO>(Symbol)->getEncodedFlags(EncodeAsAltEntry)); in writeNlist()
446 W.write<uint64_t>(Address); in writeNlist()
448 W.write<uint32_t>(Address); in writeNlist()
457 W.write<uint32_t>(Type); in writeLinkeditLoadCommand()
458 W.write<uint32_t>(sizeof(MachO::linkedit_data_command)); in writeLinkeditLoadCommand()
459 W.write<uint32_t>(DataOffset); in writeLinkeditLoadCommand()
460 W.write<uint32_t>(DataSize); in writeLinkeditLoadCommand()
462 assert(W.OS.tell() - Start == sizeof(MachO::linkedit_data_command)); in writeLinkeditLoadCommand()
481 W.write<uint32_t>(MachO::LC_LINKER_OPTION); in writeLinkerOptionsLoadCommand()
482 W.write<uint32_t>(Size); in writeLinkerOptionsLoadCommand()
483 W.write<uint32_t>(Options.size()); in writeLinkerOptionsLoadCommand()
486 // Write each string, including the null byte. in writeLinkerOptionsLoadCommand()
495 assert(W.OS.tell() - Start == Size); in writeLinkerOptionsLoadCommand()
499 // Target is (LHS - RHS + cst). in isFixupTargetValid()
500 // We don't support the form where LHS is null: -RHS + cst in isFixupTargetValid()
516 TargetObjectWriter->recordRelocation(this, Asm, Fragment, Fixup, Target, in recordRelocation()
543 // Bind non-lazy symbol pointers first. in bindIndirectSymbols()
572 cast<MCSymbolMachO>(ISD.Symbol)->setReferenceTypeUndefinedLazy(true); in bindIndirectSymbols()
576 /// computeSymbolTable - Compute the symbol table data
597 // Build the symbol arrays but only for non-local symbols. in computeSymbolTable()
603 // Ignore non-linker visible symbols. in computeSymbolTable()
627 // Now add the data for local symbols. in computeSymbolTable()
629 // Ignore non-linker visible symbols. in computeSymbolTable()
659 Entry.Symbol->setIndex(Index++); in computeSymbolTable()
667 unsigned Index = Rel.Sym->getIndex(); in computeSymbolTable()
696 StartAddress = alignTo(StartAddress, Sec->getAlign()); in computeSectionAddresses()
710 // Create symbol data for any indirect symbols. in executePostLayoutBinding()
722 // - addr(atom(B)) - offset(B) in isSymbolRefDifferenceFullyResolvedImpl()
724 // addr(atom(A)) - addr(atom(B)) == 0. in isSymbolRefDifferenceFullyResolvedImpl()
739 // If the file isn't using sub-sections-via-symbols, we can make the in isSymbolRefDifferenceFullyResolvedImpl()
746 (!SA.isTemporary() && FB.getAtom() != SA.getFragment()->getAtom() && in isSymbolRefDifferenceFullyResolvedImpl()
758 return SA.getFragment()->getAtom() == FB.getAtom(); in isSymbolRefDifferenceFullyResolvedImpl()
773 Asm.getContext().getObjectFileInfo()->getAddrSigSection(); in populateAddrSigSection()
776 if (!S->isRegistered()) in populateAddrSigSection()
787 auto NumBytesWritten = [&] { return W.OS.tell() - StartOffset; }; in writeObject()
798 auto &Frag = cast<MCDataFragment>(*CGProfileSection->begin()); in writeObject()
802 uint32_t FromIndex = CGPE.From->getSymbol().getIndex(); in writeObject()
803 uint32_t ToIndex = CGPE.To->getSymbol().getIndex(); in writeObject()
804 support::endian::write(OS, FromIndex, W.Endian); in writeObject()
805 support::endian::write(OS, ToIndex, W.Endian); in writeObject()
806 support::endian::write(OS, CGPE.Count, W.Endian); in writeObject()
810 unsigned NumSections = Asm.end() - Asm.begin(); in writeObject()
812 // The section data starts after the header, the segment load command (and in writeObject()
836 // Add the data-in-code load command size, if used. in writeObject()
866 // Compute the total size of the section data, as well as its file size and vm in writeObject()
888 // The section data is padded to pointer size bytes. in writeObject()
895 // Write the prolog, starting with the header and load command... in writeObject()
930 // Write out the deployment target information, if it's available. in writeObject()
933 auto EncodeVersion = [](VersionTuple V) -> uint32_t { in writeObject()
949 W.write<uint32_t>(MachO::LC_BUILD_VERSION); in writeObject()
950 W.write<uint32_t>(sizeof(MachO::build_version_command)); in writeObject()
951 W.write<uint32_t>(VersionInfo.TypeOrPlatform.Platform); in writeObject()
952 W.write<uint32_t>(EncodedVersion); in writeObject()
953 W.write<uint32_t>(SDKVersion); in writeObject()
954 W.write<uint32_t>(0); // Empty tools list. in writeObject()
958 W.write<uint32_t>(LCType); in writeObject()
959 W.write<uint32_t>(sizeof(MachO::version_min_command)); in writeObject()
960 W.write<uint32_t>(EncodedVersion); in writeObject()
961 W.write<uint32_t>(SDKVersion); in writeObject()
969 // Write the data-in-code load command, if used. in writeObject()
978 // Write the loh load command, if used. in writeObject()
984 // Write the symbol table load command, if used. in writeObject()
998 // If used, the indirect symbols are written after the section data. in writeObject()
1002 // The symbol table is written after the indirect symbol data. in writeObject()
1019 // Write the linker options load commands. in writeObject()
1023 // Write the actual section data. in writeObject()
1031 // Write the extra padding. in writeObject()
1034 // Write the relocation entries. in writeObject()
1036 // Write the section relocation entries, in reverse order to match 'as' in writeObject()
1040 W.write<uint32_t>(Rel.MRE.r_word0); in writeObject()
1041 W.write<uint32_t>(Rel.MRE.r_word1); in writeObject()
1045 // Write out the data-in-code region payload, if there is one. in writeObject()
1046 for (DataRegionData Data : DataRegions) { in writeObject() local
1047 uint64_t Start = getSymbolAddress(*Data.Start, Asm); in writeObject()
1049 if (Data.End) in writeObject()
1050 End = getSymbolAddress(*Data.End, Asm); in writeObject()
1052 report_fatal_error("Data region not terminated"); in writeObject()
1054 LLVM_DEBUG(dbgs() << "data in code region-- kind: " << Data.Kind in writeObject()
1055 << " start: " << Start << "(" << Data.Start->getName() in writeObject()
1056 << ")" << " end: " << End << "(" << Data.End->getName() in writeObject()
1057 << ")" << " size: " << End - Start << "\n"); in writeObject()
1058 W.write<uint32_t>(Start); in writeObject()
1059 W.write<uint16_t>(End - Start); in writeObject()
1060 W.write<uint16_t>(Data.Kind); in writeObject()
1063 // Write out the loh commands, if there is one. in writeObject()
1072 assert(W.OS.tell() - Start == LOHSize); in writeObject()
1075 // Write the symbol table data, if used. in writeObject()
1077 // Write the indirect symbol entries. in writeObject()
1079 // Indirect symbols in the non-lazy symbol pointer section have some in writeObject()
1085 if (ISD.Symbol->isDefined() && !ISD.Symbol->isExternal()) { in writeObject()
1087 if (ISD.Symbol->isAbsolute()) in writeObject()
1089 W.write<uint32_t>(Flags); in writeObject()
1094 W.write<uint32_t>(ISD.Symbol->getIndex()); in writeObject()
1099 // Write the symbol table entries. in writeObject()
1105 // Write the string table. in writeObject()
1106 StringTable.write(W.OS); in writeObject()