LLVM 23.0.0git
DXContainer.cpp
Go to the documentation of this file.
1//===- DXContainer.cpp - DXContainer object file implementation -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "llvm/Object/Error.h"
12#include "llvm/Support/Endian.h"
15
16using namespace llvm;
17using namespace llvm::object;
18
22
23static bool readIsOutOfBounds(StringRef Buffer, const char *Src, size_t Size) {
24 return !Src || Size > static_cast<size_t>(Buffer.end() - Src);
25}
26
27template <typename T>
28static Error readStruct(StringRef Buffer, const char *Src, T &Struct) {
29 // Don't read before the beginning or past the end of the file
30 if (readIsOutOfBounds(Buffer, Src, sizeof(T)))
31 return parseFailed("Reading structure out of file bounds");
32
33 memcpy(&Struct, Src, sizeof(T));
34 // DXContainer is always little endian
36 Struct.swapBytes();
37 return Error::success();
38}
39
40template <typename T>
41static Error readInteger(StringRef Buffer, const char *Src, T &Val,
42 Twine Str = "structure") {
43 static_assert(std::is_integral_v<T>,
44 "Cannot call readInteger on non-integral type.");
45 // Don't read before the beginning or past the end of the file
46 if (readIsOutOfBounds(Buffer, Src, sizeof(T)))
47 return parseFailed(Twine("Reading ") + Str + " out of file bounds");
48
49 // The DXContainer offset table is comprised of uint32_t values but not padded
50 // to a 64-bit boundary. So Parts may start unaligned if there is an odd
51 // number of parts and part data itself is not required to be padded.
52 if (reinterpret_cast<uintptr_t>(Src) % alignof(T) != 0)
53 memcpy(reinterpret_cast<char *>(&Val), Src, sizeof(T));
54 else
55 Val = *reinterpret_cast<const T *>(Src);
56 // DXContainer is always little endian
59 return Error::success();
60}
61
62/// Read a null-terminated string at the position Src from Buffer, with maximum
63/// byte size of MaxSize (including the null-terminator). Advance Src by the
64/// number of bytes read.
65static Error readString(StringRef Buffer, const char *&Src, size_t MaxSize,
66 StringRef &Val, Twine Desc) {
67 if (readIsOutOfBounds(Buffer, Src, MaxSize))
68 return parseFailed(Desc + " is out of file bounds");
69
70 // Ensure that the null-terminator is somewhere within MaxSize bytes.
71 Buffer = Buffer.substr(Src - Buffer.data(), MaxSize);
72 size_t Length = Buffer.find('\0');
73 if (Length == Buffer.npos)
74 return parseFailed(Desc + " does not end with null-terminator");
75
76 Val = StringRef(Buffer.data(), Length);
77 Src += Length + 1;
78 return Error::success();
79}
80
81DXContainer::DXContainer(MemoryBufferRef O) : Data(O) {}
82
83Error DXContainer::parseHeader() {
84 if (Error Err = readStruct(Data.getBuffer(), Data.getBuffer().data(), Header))
85 return Err;
86 if (StringRef(reinterpret_cast<char *>(Header.Magic), 4) != "DXBC")
87 return parseFailed("Missing DXBC header magic");
88 return Error::success();
89}
90
91Error DXContainer::parseDXILHeader(dxbc::PartType PT, StringRef Part) {
92 bool IsDebug = dxbc::isDebugProgramPart(PT);
93 std::optional<DXILData> &DXIL = IsDebug ? this->DebugDXIL : this->DXIL;
94
95 if (DXIL)
96 return parseFailed(formatv("more than one {0} part is present in the file",
97 dxbc::getProgramPartName(IsDebug)));
98 const char *Current = Part.begin();
99 dxbc::ProgramHeader Header;
100 if (Error Err = readStruct(Part, Current, Header))
101 return Err;
102 Current += offsetof(dxbc::ProgramHeader, Bitcode) + Header.Bitcode.Offset;
103 DXIL.emplace(std::make_pair(Header, Current));
104 return Error::success();
105}
106
107Error DXContainer::parseDebugName(StringRef Part) {
108 if (DebugName)
109 return parseFailed("more than one ILDN part is present in the file");
110 const char *Current = Part.begin();
111 dxbc::DebugNameHeader Header;
112 if (Error Err = readStruct(Part, Current, Header))
113 return Err;
114 Current += sizeof(Header);
115
116 StringRef Name;
117 if (Error Err = readString(Part, Current, Header.NameLength + 1, Name,
118 "debug file name"))
119 return Err;
120 if (Name.size() != Header.NameLength)
121 return parseFailed("debug file name length mismatch");
122 DebugName.emplace(Header, Name.data());
123
124 return Error::success();
125}
126
127Error DXContainer::parseShaderFeatureFlags(StringRef Part) {
128 if (ShaderFeatureFlags)
129 return parseFailed("More than one SFI0 part is present in the file");
130 uint64_t FlagValue = 0;
131 if (Error Err = readInteger(Part, Part.begin(), FlagValue))
132 return Err;
133 ShaderFeatureFlags = FlagValue;
134 return Error::success();
135}
136
137Error DXContainer::parseHash(StringRef Part) {
138 if (Hash)
139 return parseFailed("More than one HASH part is present in the file");
140 dxbc::ShaderHash ReadHash;
141 if (Error Err = readStruct(Part, Part.begin(), ReadHash))
142 return Err;
143 Hash = ReadHash;
144 return Error::success();
145}
146
147Error DXContainer::parseRootSignature(StringRef Part) {
148 if (RootSignature)
149 return parseFailed("More than one RTS0 part is present in the file");
150 RootSignature = DirectX::RootSignature(Part);
151 if (Error Err = RootSignature->parse())
152 return Err;
153 return Error::success();
154}
155
156Error DXContainer::parsePSVInfo(StringRef Part) {
157 if (PSVInfo)
158 return parseFailed("More than one PSV0 part is present in the file");
159 PSVInfo = DirectX::PSVRuntimeInfo(Part);
160 // Parsing the PSVRuntime info occurs late because we need to read data from
161 // other parts first.
162 return Error::success();
163}
164
167 if (Error Err = readStruct(Part, Part.begin(), SigHeader))
168 return Err;
169 size_t Size = sizeof(dxbc::ProgramSignatureElement) * SigHeader.ParamCount;
170
171 if (Part.size() < Size + SigHeader.FirstParamOffset)
172 return parseFailed("Signature parameters extend beyond the part boundary");
173
174 Parameters.Data = Part.substr(SigHeader.FirstParamOffset, Size);
175
176 StringTableOffset = SigHeader.FirstParamOffset + static_cast<uint32_t>(Size);
177 StringTable = Part.substr(SigHeader.FirstParamOffset + Size);
178
179 for (const auto &Param : Parameters) {
180 if (Param.NameOffset < StringTableOffset)
181 return parseFailed("Invalid parameter name offset: name starts before "
182 "the first name offset");
183 if (Param.NameOffset - StringTableOffset > StringTable.size())
184 return parseFailed("Invalid parameter name offset: name starts after the "
185 "end of the part data");
186 }
187 return Error::success();
188}
189
190Error DXContainer::parseCompilerVersionInfo(StringRef Part) {
191 if (VersionInfo)
192 return parseFailed("more than one VERS part is present in the file");
193 const char *Current = Part.begin();
195 if (Error Err = readStruct(Part, Current, Header))
196 return Err;
197 Current += sizeof(Header);
198
200 return parseFailed("Incorrect shader compiler version flags combination");
201
202 StringRef CommitSha;
203 const char *Prev = Current;
204 if (Error Err = readString(Part, Current, Header.ContentSizeInBytes,
205 CommitSha, "CommitSha"))
206 return Err;
207 StringRef CustomVersionString;
208 if (Error Err = readString(Part, Current,
209 Header.ContentSizeInBytes - (Current - Prev),
210 CustomVersionString, "CustomVersionString"))
211 return Err;
212
213 VersionInfo.emplace();
214 VersionInfo->Parameters = Header;
215 VersionInfo->CommitSha = CommitSha;
216 VersionInfo->CustomVersionString = CustomVersionString;
217 return Error::success();
218}
219
220Error DXContainer::parsePartOffsets() {
221 uint32_t LastOffset =
222 sizeof(dxbc::Header) + (Header.PartCount * sizeof(uint32_t));
223 const char *Current = Data.getBuffer().data() + sizeof(dxbc::Header);
224 for (uint32_t Part = 0; Part < Header.PartCount; ++Part) {
225 uint32_t PartOffset;
226 if (Error Err = readInteger(Data.getBuffer(), Current, PartOffset))
227 return Err;
228 if (PartOffset < LastOffset)
229 return parseFailed(
230 formatv(
231 "Part offset for part {0} begins before the previous part ends",
232 Part)
233 .str());
234 Current += sizeof(uint32_t);
235 if (PartOffset >= Data.getBufferSize())
236 return parseFailed("Part offset points beyond boundary of the file");
237 // To prevent overflow when reading the part name, we subtract the part name
238 // size from the buffer size, rather than adding to the offset. Since the
239 // file header is larger than the part header we can't reach this code
240 // unless the buffer is at least as large as a part header, so this
241 // subtraction can't underflow.
242 if (PartOffset >= Data.getBufferSize() - sizeof(dxbc::PartHeader::Name))
243 return parseFailed("File not large enough to read part name");
244 PartOffsets.push_back(PartOffset);
245
246 dxbc::PartType PT =
247 dxbc::parsePartType(Data.getBuffer().substr(PartOffset, 4));
248 uint32_t PartDataStart = PartOffset + sizeof(dxbc::PartHeader);
249 uint32_t PartSize;
250 if (Error Err = readInteger(Data.getBuffer(),
251 Data.getBufferStart() + PartOffset + 4,
252 PartSize, "part size"))
253 return Err;
254 StringRef PartData = Data.getBuffer().substr(PartDataStart, PartSize);
255 LastOffset = PartOffset + PartSize;
256 switch (PT) {
257 case dxbc::PartType::DXIL:
258 case dxbc::PartType::ILDB:
259 if (Error Err = parseDXILHeader(PT, PartData))
260 return Err;
261 break;
262 case dxbc::PartType::ILDN:
263 if (Error Err = parseDebugName(PartData))
264 return Err;
265 break;
266 case dxbc::PartType::SFI0:
267 if (Error Err = parseShaderFeatureFlags(PartData))
268 return Err;
269 break;
270 case dxbc::PartType::HASH:
271 if (Error Err = parseHash(PartData))
272 return Err;
273 break;
274 case dxbc::PartType::PSV0:
275 if (Error Err = parsePSVInfo(PartData))
276 return Err;
277 break;
278 case dxbc::PartType::ISG1:
279 if (Error Err = InputSignature.initialize(PartData))
280 return Err;
281 break;
282 case dxbc::PartType::OSG1:
283 if (Error Err = OutputSignature.initialize(PartData))
284 return Err;
285 break;
286 case dxbc::PartType::PSG1:
287 if (Error Err = PatchConstantSignature.initialize(PartData))
288 return Err;
289 break;
291 break;
292 case dxbc::PartType::RTS0:
293 if (Error Err = parseRootSignature(PartData))
294 return Err;
295 break;
296 case dxbc::PartType::VERS:
297 if (Error Err = parseCompilerVersionInfo(PartData))
298 return Err;
299 break;
300 }
301 }
302
303 if (DXIL && DebugDXIL &&
304 DXIL->first.ShaderKind != DebugDXIL->first.ShaderKind)
305 return parseFailed(
306 "ILDB part shader kind does not match DXIL part shader kind");
307
308 // Fully parsing the PSVInfo requires knowing the shader kind which we read
309 // out of the program header in the DXIL part.
310 if (PSVInfo) {
311 std::optional<uint16_t> ShaderKind = getShaderKind();
312 if (!ShaderKind)
313 return parseFailed("cannot fully parse pipeline state validation "
314 "information without DXIL or ILDB part");
315 if (Error Err = PSVInfo->parse(*ShaderKind))
316 return Err;
317 }
318 return Error::success();
319}
320
322 DXContainer Container(Object);
323 if (Error Err = Container.parseHeader())
324 return std::move(Err);
325 if (Error Err = Container.parsePartOffsets())
326 return std::move(Err);
327 return Container;
328}
329
330void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
331 StringRef Buffer = Container.Data.getBuffer();
332 const char *Current = Buffer.data() + Offset;
333 // Offsets are validated during parsing, so all offsets in the container are
334 // valid and contain enough readable data to read a header.
335 cantFail(readStruct(Buffer, Current, IteratorState.Part));
336 IteratorState.Data =
337 StringRef(Current + sizeof(dxbc::PartHeader), IteratorState.Part.Size);
338 IteratorState.Offset = Offset;
339}
340
342 const char *Current = PartData.begin();
343
344 // Root Signature headers expects 6 integers to be present.
345 if (PartData.size() < 6 * sizeof(uint32_t))
346 return parseFailed(
347 "Invalid root signature, insufficient space for header.");
348
350 Current += sizeof(uint32_t);
351
352 NumParameters =
354 Current += sizeof(uint32_t);
355
356 RootParametersOffset =
358 Current += sizeof(uint32_t);
359
360 NumStaticSamplers =
362 Current += sizeof(uint32_t);
363
364 StaticSamplersOffset =
366 Current += sizeof(uint32_t);
367
369 Current += sizeof(uint32_t);
370
371 ParametersHeaders.Data = PartData.substr(
372 RootParametersOffset,
373 NumParameters * sizeof(dxbc::RTS0::v1::RootParameterHeader));
374
375 StaticSamplers.Stride = (Version <= 2)
378
379 StaticSamplers.Data = PartData.substr(StaticSamplersOffset,
380 static_cast<size_t>(NumStaticSamplers) *
381 StaticSamplers.Stride);
382
383 return Error::success();
384}
385
387 Triple::EnvironmentType ShaderStage = dxbc::getShaderStage(ShaderKind);
388
389 const char *Current = Data.begin();
390 if (Error Err = readInteger(Data, Current, Size))
391 return Err;
392 Current += sizeof(uint32_t);
393
394 StringRef PSVInfoData = Data.substr(sizeof(uint32_t), Size);
395
396 if (PSVInfoData.size() < Size)
397 return parseFailed(
398 "Pipeline state data extends beyond the bounds of the part");
399
400 using namespace dxbc::PSV;
401
402 const uint32_t PSVVersion = getVersion();
403
404 // Detect the PSVVersion by looking at the size field.
405 if (PSVVersion == 3) {
406 v3::RuntimeInfo Info;
407 if (Error Err = readStruct(PSVInfoData, Current, Info))
408 return Err;
410 Info.swapBytes(ShaderStage);
411 BasicInfo = Info;
412 } else if (PSVVersion == 2) {
413 v2::RuntimeInfo Info;
414 if (Error Err = readStruct(PSVInfoData, Current, Info))
415 return Err;
417 Info.swapBytes(ShaderStage);
418 BasicInfo = Info;
419 } else if (PSVVersion == 1) {
420 v1::RuntimeInfo Info;
421 if (Error Err = readStruct(PSVInfoData, Current, Info))
422 return Err;
424 Info.swapBytes(ShaderStage);
425 BasicInfo = Info;
426 } else if (PSVVersion == 0) {
427 v0::RuntimeInfo Info;
428 if (Error Err = readStruct(PSVInfoData, Current, Info))
429 return Err;
431 Info.swapBytes(ShaderStage);
432 BasicInfo = Info;
433 } else
434 return parseFailed(
435 "Cannot read PSV Runtime Info, unsupported PSV version.");
436
437 Current += Size;
438
439 uint32_t ResourceCount = 0;
440 if (Error Err = readInteger(Data, Current, ResourceCount))
441 return Err;
442 Current += sizeof(uint32_t);
443
444 if (ResourceCount > 0) {
445 if (Error Err = readInteger(Data, Current, Resources.Stride))
446 return Err;
447 Current += sizeof(uint32_t);
448
449 size_t BindingDataSize = Resources.Stride * ResourceCount;
450 Resources.Data = Data.substr(Current - Data.begin(), BindingDataSize);
451
452 if (Resources.Data.size() < BindingDataSize)
453 return parseFailed(
454 "Resource binding data extends beyond the bounds of the part");
455
456 Current += BindingDataSize;
457 } else
458 Resources.Stride = sizeof(v2::ResourceBindInfo);
459
460 // PSV version 0 ends after the resource bindings.
461 if (PSVVersion == 0)
462 return Error::success();
463
464 // String table starts at a 4-byte offset.
465 Current = reinterpret_cast<const char *>(
466 alignTo<4>(reinterpret_cast<uintptr_t>(Current)));
467
468 uint32_t StringTableSize = 0;
469 if (Error Err = readInteger(Data, Current, StringTableSize))
470 return Err;
471 if (StringTableSize % 4 != 0)
472 return parseFailed("String table misaligned");
473 Current += sizeof(uint32_t);
474 StringTable = StringRef(Current, StringTableSize);
475
476 Current += StringTableSize;
477
478 uint32_t SemanticIndexTableSize = 0;
479 if (Error Err = readInteger(Data, Current, SemanticIndexTableSize))
480 return Err;
481 Current += sizeof(uint32_t);
482
483 SemanticIndexTable.reserve(SemanticIndexTableSize);
484 for (uint32_t I = 0; I < SemanticIndexTableSize; ++I) {
485 uint32_t Index = 0;
486 if (Error Err = readInteger(Data, Current, Index))
487 return Err;
488 Current += sizeof(uint32_t);
489 SemanticIndexTable.push_back(Index);
490 }
491
492 uint8_t InputCount = getSigInputCount();
493 uint8_t OutputCount = getSigOutputCount();
494 uint8_t PatchOrPrimCount = getSigPatchOrPrimCount();
495
496 uint32_t ElementCount = InputCount + OutputCount + PatchOrPrimCount;
497
498 if (ElementCount > 0) {
499 if (Error Err = readInteger(Data, Current, SigInputElements.Stride))
500 return Err;
501 Current += sizeof(uint32_t);
502 // Assign the stride to all the arrays.
503 SigOutputElements.Stride = SigPatchOrPrimElements.Stride =
504 SigInputElements.Stride;
505
506 if (Data.end() - Current <
507 (ptrdiff_t)(ElementCount * SigInputElements.Stride))
508 return parseFailed(
509 "Signature elements extend beyond the size of the part");
510
511 size_t InputSize = SigInputElements.Stride * InputCount;
512 SigInputElements.Data = Data.substr(Current - Data.begin(), InputSize);
513 Current += InputSize;
514
515 size_t OutputSize = SigOutputElements.Stride * OutputCount;
516 SigOutputElements.Data = Data.substr(Current - Data.begin(), OutputSize);
517 Current += OutputSize;
518
519 size_t PSize = SigPatchOrPrimElements.Stride * PatchOrPrimCount;
520 SigPatchOrPrimElements.Data = Data.substr(Current - Data.begin(), PSize);
521 Current += PSize;
522 }
523
524 ArrayRef<uint8_t> OutputVectorCounts = getOutputVectorCounts();
525 uint8_t PatchConstOrPrimVectorCount = getPatchConstOrPrimVectorCount();
526 uint8_t InputVectorCount = getInputVectorCount();
527
528 auto maskDwordSize = [](uint8_t Vector) {
529 return (static_cast<uint32_t>(Vector) + 7) >> 3;
530 };
531
532 auto mapTableSize = [maskDwordSize](uint8_t X, uint8_t Y) {
533 return maskDwordSize(Y) * X * 4;
534 };
535
536 if (usesViewID()) {
537 for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) {
538 // The vector mask is one bit per component and 4 components per vector.
539 // We can compute the number of dwords required by rounding up to the next
540 // multiple of 8.
541 uint32_t NumDwords =
542 maskDwordSize(static_cast<uint32_t>(OutputVectorCounts[I]));
543 size_t NumBytes = NumDwords * sizeof(uint32_t);
544 OutputVectorMasks[I].Data = Data.substr(Current - Data.begin(), NumBytes);
545 Current += NumBytes;
546 }
547
548 if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0) {
549 uint32_t NumDwords = maskDwordSize(PatchConstOrPrimVectorCount);
550 size_t NumBytes = NumDwords * sizeof(uint32_t);
551 PatchOrPrimMasks.Data = Data.substr(Current - Data.begin(), NumBytes);
552 Current += NumBytes;
553 }
554 }
555
556 // Input/Output mapping table
557 for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) {
558 if (InputVectorCount == 0 || OutputVectorCounts[I] == 0)
559 continue;
560 uint32_t NumDwords = mapTableSize(InputVectorCount, OutputVectorCounts[I]);
561 size_t NumBytes = NumDwords * sizeof(uint32_t);
562 InputOutputMap[I].Data = Data.substr(Current - Data.begin(), NumBytes);
563 Current += NumBytes;
564 }
565
566 // Hull shader: Input/Patch mapping table
567 if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0 &&
568 InputVectorCount > 0) {
569 uint32_t NumDwords =
570 mapTableSize(InputVectorCount, PatchConstOrPrimVectorCount);
571 size_t NumBytes = NumDwords * sizeof(uint32_t);
572 InputPatchMap.Data = Data.substr(Current - Data.begin(), NumBytes);
573 Current += NumBytes;
574 }
575
576 // Domain Shader: Patch/Output mapping table
577 if (ShaderStage == Triple::Domain && PatchConstOrPrimVectorCount > 0 &&
578 OutputVectorCounts[0] > 0) {
579 uint32_t NumDwords =
580 mapTableSize(PatchConstOrPrimVectorCount, OutputVectorCounts[0]);
581 size_t NumBytes = NumDwords * sizeof(uint32_t);
582 PatchOutputMap.Data = Data.substr(Current - Data.begin(), NumBytes);
583 Current += NumBytes;
584 }
585
586 return Error::success();
587}
588
590 if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
591 return P->SigInputElements;
592 if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
593 return P->SigInputElements;
594 if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
595 return P->SigInputElements;
596 return 0;
597}
598
600 if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
601 return P->SigOutputElements;
602 if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
603 return P->SigOutputElements;
604 if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
605 return P->SigOutputElements;
606 return 0;
607}
608
610 if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
611 return P->SigPatchOrPrimElements;
612 if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
613 return P->SigPatchOrPrimElements;
614 if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
615 return P->SigPatchOrPrimElements;
616 return 0;
617}
618
619class DXNotSupportedError : public ErrorInfo<DXNotSupportedError> {
620public:
621 static char ID;
622
623 DXNotSupportedError(StringRef S) : FeatureString(S) {}
624
625 void log(raw_ostream &OS) const override {
626 OS << "DXContainer does not support " << FeatureString;
627 }
628
629 std::error_code convertToErrorCode() const override {
630 return inconvertibleErrorCode();
631 }
632
633private:
634 StringRef FeatureString;
635};
636
638
639Expected<section_iterator>
643
647
652
654 llvm_unreachable("DXContainer does not support symbols");
655}
658 llvm_unreachable("DXContainer does not support symbols");
659}
660
665
667 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
668 if (It == Parts.end())
669 return;
670
671 ++It;
672 Sec.p = reinterpret_cast<uintptr_t>(It);
673}
674
677 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
678 return StringRef(It->Part.getName());
679}
680
682 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
683 return It->Offset;
684}
685
687 return (Sec.p - reinterpret_cast<uintptr_t>(Parts.begin())) /
688 sizeof(PartIterator);
689}
690
692 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
693 return It->Data.size();
694}
697 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
698 return ArrayRef<uint8_t>(It->Data.bytes_begin(), It->Data.size());
699}
700
704
706 return false;
707}
708
710 return false;
711}
712
714 return false;
715}
716
718 return false;
719}
720
722 return false;
723}
724
729
734
736 llvm_unreachable("DXContainer does not support relocations");
737}
738
740 llvm_unreachable("DXContainer does not support relocations");
741}
742
747
749 llvm_unreachable("DXContainer does not support relocations");
750}
751
753 DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
754 llvm_unreachable("DXContainer does not support relocations");
755}
756
758 DataRefImpl Sec;
759 Sec.p = reinterpret_cast<uintptr_t>(Parts.begin());
760 return section_iterator(SectionRef(Sec, this));
761}
763 DataRefImpl Sec;
764 Sec.p = reinterpret_cast<uintptr_t>(Parts.end());
765 return section_iterator(SectionRef(Sec, this));
766}
767
769
771 return "DirectX Container";
772}
773
775
779
784
789
792 auto ExC = DXContainer::create(Object);
793 if (!ExC)
794 return ExC.takeError();
795 std::unique_ptr<DXContainerObjectFile> Obj(new DXContainerObjectFile(*ExC));
796 return std::move(Obj);
797}
#define X(NUM, ENUM, NAME)
Definition ELF.h:853
write Write Bitcode
#define offsetof(TYPE, MEMBER)
#define I(x, y, z)
Definition MD5.cpp:57
#define T
static Error readString(StringRef Buffer, const char *&Src, size_t MaxSize, StringRef &Val, Twine Desc)
Read a null-terminated string at the position Src from Buffer, with maximum byte size of MaxSize (inc...
static Error parseFailed(const Twine &Msg)
static Error readStruct(StringRef Buffer, const char *Src, T &Struct)
static bool readIsOutOfBounds(StringRef Buffer, const char *Src, size_t Size)
static Error readInteger(StringRef Buffer, const char *Src, T &Val, Twine Str="structure")
#define P(N)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
DXNotSupportedError(StringRef S)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
Base class for user error types.
Definition Error.h:354
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:591
iterator begin() const
Definition StringRef.h:114
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
iterator end() const
Definition StringRef.h:116
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition StringRef.h:290
Manages the enabling and disabling of subtarget specific features.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Definition Twine.cpp:17
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
uint64_t getRelocationOffset(DataRefImpl Rel) const override
uint64_t getSectionSize(DataRefImpl Sec) const override
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Triple::ArchType getArch() const override
bool isSectionCompressed(DataRefImpl Sec) const override
section_iterator section_end() const override
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
uint64_t getSectionIndex(DataRefImpl Sec) const override
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
uint64_t getSectionAddress(DataRefImpl Sec) const override
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
section_iterator section_begin() const override
bool isSectionVirtual(DataRefImpl Sec) const override
void moveRelocationNext(DataRefImpl &Rel) const override
relocation_iterator section_rel_end(DataRefImpl Sec) const override
void moveSectionNext(DataRefImpl &Sec) const override
bool isSectionData(DataRefImpl Sec) const override
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
StringRef getFileFormatName() const override
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
uint64_t getRelocationType(DataRefImpl Rel) const override
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
bool isSectionBSS(DataRefImpl Sec) const override
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
bool isSectionText(DataRefImpl Sec) const override
Expected< SubtargetFeatures > getFeatures() const override
Expected< StringRef > getSymbolName(DataRefImpl) const override
static LLVM_ABI Expected< DXContainer > create(MemoryBufferRef Object)
ArrayRef< uint8_t > getOutputVectorCounts() const
LLVM_ABI uint8_t getSigInputCount() const
LLVM_ABI uint8_t getSigPatchOrPrimCount() const
LLVM_ABI Error parse(uint16_t ShaderKind)
LLVM_ABI uint8_t getSigOutputCount() const
LLVM_ABI Error initialize(StringRef Part)
static Expected< std::unique_ptr< DXContainerObjectFile > > createDXContainerObjectFile(MemoryBufferRef Object)
friend class RelocationRef
Definition ObjectFile.h:289
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI PartType parsePartType(StringRef S)
Triple::EnvironmentType getShaderStage(uint32_t Kind)
Definition DXContainer.h:47
bool isDebugProgramPart(PartType PT)
bool isValidCompilerVersionFlags(uint32_t V)
const char * getProgramPartName(bool IsDebug)
static Error parseFailed(const Twine &Msg)
content_iterator< SectionRef > section_iterator
Definition ObjectFile.h:49
content_iterator< RelocationRef > relocation_iterator
Definition ObjectFile.h:79
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Definition Endian.h:60
constexpr bool IsBigEndianHost
void swapByteOrder(T &Value)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
@ Length
Definition DWP.cpp:558
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
Op::Description Desc
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
Use this type to describe the size and type of a DXIL container part.
Definition DXContainer.h:99