Lines Matching refs:CP
144 static bool layoutOptionalHeader(COFFParser &CP) { in layoutOptionalHeader() argument
145 if (!CP.isPE()) in layoutOptionalHeader()
147 unsigned PEHeaderSize = CP.is64Bit() ? sizeof(object::pe32plus_header) in layoutOptionalHeader()
149 CP.Obj.Header.SizeOfOptionalHeader = in layoutOptionalHeader()
161 static bool layoutCOFF(COFFParser &CP) { in layoutCOFF() argument
164 CP.SectionTableStart = in layoutCOFF()
165 CP.getHeaderSize() + CP.Obj.Header.SizeOfOptionalHeader; in layoutCOFF()
166 if (CP.isPE()) in layoutCOFF()
167 CP.SectionTableStart += DOSStubSize + sizeof(COFF::PEMagic); in layoutCOFF()
168 CP.SectionTableSize = COFF::SectionSize * CP.Obj.Sections.size(); in layoutCOFF()
171 CP.SectionTableStart + CP.SectionTableSize; in layoutCOFF()
174 for (COFFYAML::Section &S : CP.Obj.Sections) { in layoutCOFF()
177 CurrentSectionDataOffset, CP.isPE() ? CP.getFileAlignment() : 4); in layoutCOFF()
179 if (CP.isPE()) in layoutCOFF()
181 RoundUpToAlignment(S.Header.SizeOfRawData, CP.getFileAlignment()); in layoutCOFF()
200 for (std::vector<COFFYAML::Symbol>::iterator i = CP.Obj.Symbols.begin(), in layoutCOFF()
201 e = CP.Obj.Symbols.end(); in layoutCOFF()
212 (i->File.size() + CP.getSymbolSize() - 1) / CP.getSymbolSize(); in layoutCOFF()
222 CP.Obj.Header.NumberOfSections = CP.Obj.Sections.size(); in layoutCOFF()
223 CP.Obj.Header.NumberOfSymbols = NumberOfSymbols; in layoutCOFF()
224 if (NumberOfSymbols > 0 || CP.StringTable.size() > 4) in layoutCOFF()
225 CP.Obj.Header.PointerToSymbolTable = SymbolTableStart; in layoutCOFF()
227 CP.Obj.Header.PointerToSymbolTable = 0; in layoutCOFF()
229 *reinterpret_cast<support::ulittle32_t *>(&CP.StringTable[0]) in layoutCOFF()
230 = CP.StringTable.size(); in layoutCOFF()
288 static uint32_t initializeOptionalHeader(COFFParser &CP, uint16_t Magic, T Header) { in initializeOptionalHeader() argument
291 Header->SectionAlignment = CP.Obj.OptionalHeader->Header.SectionAlignment; in initializeOptionalHeader()
292 Header->FileAlignment = CP.Obj.OptionalHeader->Header.FileAlignment; in initializeOptionalHeader()
296 CP.SectionTableStart + CP.SectionTableSize, Header->FileAlignment); in initializeOptionalHeader()
300 for (const COFFYAML::Section &S : CP.Obj.Sections) { in initializeOptionalHeader()
319 CP.Obj.OptionalHeader->Header.AddressOfEntryPoint; // RVA in initializeOptionalHeader()
320 Header->ImageBase = CP.Obj.OptionalHeader->Header.ImageBase; in initializeOptionalHeader()
322 CP.Obj.OptionalHeader->Header.MajorOperatingSystemVersion; in initializeOptionalHeader()
324 CP.Obj.OptionalHeader->Header.MinorOperatingSystemVersion; in initializeOptionalHeader()
326 CP.Obj.OptionalHeader->Header.MajorImageVersion; in initializeOptionalHeader()
328 CP.Obj.OptionalHeader->Header.MinorImageVersion; in initializeOptionalHeader()
330 CP.Obj.OptionalHeader->Header.MajorSubsystemVersion; in initializeOptionalHeader()
332 CP.Obj.OptionalHeader->Header.MinorSubsystemVersion; in initializeOptionalHeader()
335 Header->Subsystem = CP.Obj.OptionalHeader->Header.Subsystem; in initializeOptionalHeader()
336 Header->DLLCharacteristics = CP.Obj.OptionalHeader->Header.DLLCharacteristics; in initializeOptionalHeader()
337 Header->SizeOfStackReserve = CP.Obj.OptionalHeader->Header.SizeOfStackReserve; in initializeOptionalHeader()
338 Header->SizeOfStackCommit = CP.Obj.OptionalHeader->Header.SizeOfStackCommit; in initializeOptionalHeader()
339 Header->SizeOfHeapReserve = CP.Obj.OptionalHeader->Header.SizeOfHeapReserve; in initializeOptionalHeader()
340 Header->SizeOfHeapCommit = CP.Obj.OptionalHeader->Header.SizeOfHeapCommit; in initializeOptionalHeader()
345 static bool writeCOFF(COFFParser &CP, raw_ostream &OS) { in writeCOFF() argument
346 if (CP.isPE()) { in writeCOFF()
369 if (CP.useBigObj()) { in writeCOFF()
373 << binary_le(CP.Obj.Header.Machine) in writeCOFF()
374 << binary_le(CP.Obj.Header.TimeDateStamp); in writeCOFF()
380 << binary_le(CP.Obj.Header.NumberOfSections) in writeCOFF()
381 << binary_le(CP.Obj.Header.PointerToSymbolTable) in writeCOFF()
382 << binary_le(CP.Obj.Header.NumberOfSymbols); in writeCOFF()
384 OS << binary_le(CP.Obj.Header.Machine) in writeCOFF()
385 << binary_le(static_cast<int16_t>(CP.Obj.Header.NumberOfSections)) in writeCOFF()
386 << binary_le(CP.Obj.Header.TimeDateStamp) in writeCOFF()
387 << binary_le(CP.Obj.Header.PointerToSymbolTable) in writeCOFF()
388 << binary_le(CP.Obj.Header.NumberOfSymbols) in writeCOFF()
389 << binary_le(CP.Obj.Header.SizeOfOptionalHeader) in writeCOFF()
390 << binary_le(CP.Obj.Header.Characteristics); in writeCOFF()
392 if (CP.isPE()) { in writeCOFF()
393 if (CP.is64Bit()) { in writeCOFF()
395 initializeOptionalHeader(CP, COFF::PE32Header::PE32_PLUS, &PEH); in writeCOFF()
399 uint32_t BaseOfData = initializeOptionalHeader(CP, COFF::PE32Header::PE32, &PEH); in writeCOFF()
404 CP.Obj.OptionalHeader->DataDirectories) { in writeCOFF()
417 assert(OS.tell() == CP.SectionTableStart); in writeCOFF()
419 for (std::vector<COFFYAML::Section>::iterator i = CP.Obj.Sections.begin(), in writeCOFF()
420 e = CP.Obj.Sections.end(); in writeCOFF()
433 assert(OS.tell() == CP.SectionTableStart + CP.SectionTableSize); in writeCOFF()
437 for (std::vector<COFFYAML::Symbol>::iterator I = CP.Obj.Symbols.begin(), in writeCOFF()
438 E = CP.Obj.Symbols.end(); in writeCOFF()
445 for (const COFFYAML::Section &S : CP.Obj.Sections) { in writeCOFF()
463 for (std::vector<COFFYAML::Symbol>::const_iterator i = CP.Obj.Symbols.begin(), in writeCOFF()
464 e = CP.Obj.Symbols.end(); in writeCOFF()
468 if (CP.useBigObj()) in writeCOFF()
482 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size); in writeCOFF()
489 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size); in writeCOFF()
494 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size); in writeCOFF()
496 unsigned SymbolSize = CP.getSymbolSize(); in writeCOFF()
513 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size); in writeCOFF()
519 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size); in writeCOFF()
523 if (CP.Obj.Header.PointerToSymbolTable) in writeCOFF()
524 OS.write(&CP.StringTable[0], CP.StringTable.size()); in writeCOFF()
536 COFFParser CP(Doc); in yaml2coff() local
537 if (!CP.parse()) { in yaml2coff()
542 if (!layoutOptionalHeader(CP)) { in yaml2coff()
546 if (!layoutCOFF(CP)) { in yaml2coff()
550 if (!writeCOFF(CP, Out)) { in yaml2coff()