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 < Buffer.begin() || Src + Size > Buffer.end();
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 return readStruct(Data.getBuffer(), Data.getBuffer().data(), Header);
85}
86
87Error DXContainer::parseDXILHeader(dxbc::PartType PT, StringRef Part) {
88 bool IsDebug = dxbc::isDebugProgramPart(PT);
89 std::optional<DXILData> &DXIL = IsDebug ? this->DebugDXIL : this->DXIL;
90
91 if (DXIL)
92 return parseFailed(formatv("more than one {0} part is present in the file",
93 dxbc::getProgramPartName(IsDebug)));
94 const char *Current = Part.begin();
95 dxbc::ProgramHeader Header;
96 if (Error Err = readStruct(Part, Current, Header))
97 return Err;
98 Current += offsetof(dxbc::ProgramHeader, Bitcode) + Header.Bitcode.Offset;
99 DXIL.emplace(std::make_pair(Header, Current));
100 return Error::success();
101}
102
103Error DXContainer::parseDebugName(StringRef Part) {
104 if (DebugName)
105 return parseFailed("more than one ILDN part is present in the file");
106 const char *Current = Part.begin();
107 dxbc::DebugNameHeader Header;
108 if (Error Err = readStruct(Part, Current, Header))
109 return Err;
110 Current += sizeof(Header);
111
112 StringRef Name;
113 if (Error Err = readString(Part, Current, Header.NameLength + 1, Name,
114 "debug file name"))
115 return Err;
116 if (Name.size() != Header.NameLength)
117 return parseFailed("debug file name length mismatch");
118 DebugName.emplace(Header, Name.data());
119
120 return Error::success();
121}
122
123Error DXContainer::parseShaderFeatureFlags(StringRef Part) {
124 if (ShaderFeatureFlags)
125 return parseFailed("More than one SFI0 part is present in the file");
126 uint64_t FlagValue = 0;
127 if (Error Err = readInteger(Part, Part.begin(), FlagValue))
128 return Err;
129 ShaderFeatureFlags = FlagValue;
130 return Error::success();
131}
132
133Error DXContainer::parseHash(StringRef Part) {
134 if (Hash)
135 return parseFailed("More than one HASH part is present in the file");
136 dxbc::ShaderHash ReadHash;
137 if (Error Err = readStruct(Part, Part.begin(), ReadHash))
138 return Err;
139 Hash = ReadHash;
140 return Error::success();
141}
142
143Error DXContainer::parseRootSignature(StringRef Part) {
144 if (RootSignature)
145 return parseFailed("More than one RTS0 part is present in the file");
146 RootSignature = DirectX::RootSignature(Part);
147 if (Error Err = RootSignature->parse())
148 return Err;
149 return Error::success();
150}
151
152Error DXContainer::parsePSVInfo(StringRef Part) {
153 if (PSVInfo)
154 return parseFailed("More than one PSV0 part is present in the file");
155 PSVInfo = DirectX::PSVRuntimeInfo(Part);
156 // Parsing the PSVRuntime info occurs late because we need to read data from
157 // other parts first.
158 return Error::success();
159}
160
163 if (Error Err = readStruct(Part, Part.begin(), SigHeader))
164 return Err;
165 size_t Size = sizeof(dxbc::ProgramSignatureElement) * SigHeader.ParamCount;
166
167 if (Part.size() < Size + SigHeader.FirstParamOffset)
168 return parseFailed("Signature parameters extend beyond the part boundary");
169
170 Parameters.Data = Part.substr(SigHeader.FirstParamOffset, Size);
171
172 StringTableOffset = SigHeader.FirstParamOffset + static_cast<uint32_t>(Size);
173 StringTable = Part.substr(SigHeader.FirstParamOffset + Size);
174
175 for (const auto &Param : Parameters) {
176 if (Param.NameOffset < StringTableOffset)
177 return parseFailed("Invalid parameter name offset: name starts before "
178 "the first name offset");
179 if (Param.NameOffset - StringTableOffset > StringTable.size())
180 return parseFailed("Invalid parameter name offset: name starts after the "
181 "end of the part data");
182 }
183 return Error::success();
184}
185
186Error DXContainer::parseCompilerVersionInfo(StringRef Part) {
187 if (VersionInfo)
188 return parseFailed("more than one VERS part is present in the file");
189 const char *Current = Part.begin();
191 if (Error Err = readStruct(Part, Current, Header))
192 return Err;
193 Current += sizeof(Header);
194
196 return parseFailed("Incorrect shader compiler version flags combination");
197
198 StringRef CommitSha;
199 const char *Prev = Current;
200 if (Error Err = readString(Part, Current, Header.ContentSizeInBytes,
201 CommitSha, "CommitSha"))
202 return Err;
203 StringRef CustomVersionString;
204 if (Error Err = readString(Part, Current,
205 Header.ContentSizeInBytes - (Current - Prev),
206 CustomVersionString, "CustomVersionString"))
207 return Err;
208
209 VersionInfo.emplace();
210 VersionInfo->Parameters = Header;
211 VersionInfo->CommitSha = CommitSha;
212 VersionInfo->CustomVersionString = CustomVersionString;
213 return Error::success();
214}
215
216Error DXContainer::parsePartOffsets() {
217 uint32_t LastOffset =
218 sizeof(dxbc::Header) + (Header.PartCount * sizeof(uint32_t));
219 const char *Current = Data.getBuffer().data() + sizeof(dxbc::Header);
220 for (uint32_t Part = 0; Part < Header.PartCount; ++Part) {
221 uint32_t PartOffset;
222 if (Error Err = readInteger(Data.getBuffer(), Current, PartOffset))
223 return Err;
224 if (PartOffset < LastOffset)
225 return parseFailed(
226 formatv(
227 "Part offset for part {0} begins before the previous part ends",
228 Part)
229 .str());
230 Current += sizeof(uint32_t);
231 if (PartOffset >= Data.getBufferSize())
232 return parseFailed("Part offset points beyond boundary of the file");
233 // To prevent overflow when reading the part name, we subtract the part name
234 // size from the buffer size, rather than adding to the offset. Since the
235 // file header is larger than the part header we can't reach this code
236 // unless the buffer is at least as large as a part header, so this
237 // subtraction can't underflow.
238 if (PartOffset >= Data.getBufferSize() - sizeof(dxbc::PartHeader::Name))
239 return parseFailed("File not large enough to read part name");
240 PartOffsets.push_back(PartOffset);
241
242 dxbc::PartType PT =
243 dxbc::parsePartType(Data.getBuffer().substr(PartOffset, 4));
244 uint32_t PartDataStart = PartOffset + sizeof(dxbc::PartHeader);
245 uint32_t PartSize;
246 if (Error Err = readInteger(Data.getBuffer(),
247 Data.getBufferStart() + PartOffset + 4,
248 PartSize, "part size"))
249 return Err;
250 StringRef PartData = Data.getBuffer().substr(PartDataStart, PartSize);
251 LastOffset = PartOffset + PartSize;
252 switch (PT) {
253 case dxbc::PartType::DXIL:
254 case dxbc::PartType::ILDB:
255 if (Error Err = parseDXILHeader(PT, PartData))
256 return Err;
257 break;
258 case dxbc::PartType::ILDN:
259 if (Error Err = parseDebugName(PartData))
260 return Err;
261 break;
262 case dxbc::PartType::SFI0:
263 if (Error Err = parseShaderFeatureFlags(PartData))
264 return Err;
265 break;
266 case dxbc::PartType::HASH:
267 if (Error Err = parseHash(PartData))
268 return Err;
269 break;
270 case dxbc::PartType::PSV0:
271 if (Error Err = parsePSVInfo(PartData))
272 return Err;
273 break;
274 case dxbc::PartType::ISG1:
275 if (Error Err = InputSignature.initialize(PartData))
276 return Err;
277 break;
278 case dxbc::PartType::OSG1:
279 if (Error Err = OutputSignature.initialize(PartData))
280 return Err;
281 break;
282 case dxbc::PartType::PSG1:
283 if (Error Err = PatchConstantSignature.initialize(PartData))
284 return Err;
285 break;
287 break;
288 case dxbc::PartType::RTS0:
289 if (Error Err = parseRootSignature(PartData))
290 return Err;
291 break;
292 case dxbc::PartType::VERS:
293 if (Error Err = parseCompilerVersionInfo(PartData))
294 return Err;
295 break;
296 }
297 }
298
299 if (DXIL && DebugDXIL &&
300 DXIL->first.ShaderKind != DebugDXIL->first.ShaderKind)
301 return parseFailed(
302 "ILDB part shader kind does not match DXIL part shader kind");
303
304 // Fully parsing the PSVInfo requires knowing the shader kind which we read
305 // out of the program header in the DXIL part.
306 if (PSVInfo) {
307 std::optional<uint16_t> ShaderKind = getShaderKind();
308 if (!ShaderKind)
309 return parseFailed("cannot fully parse pipeline state validation "
310 "information without DXIL or ILDB part");
311 if (Error Err = PSVInfo->parse(*ShaderKind))
312 return Err;
313 }
314 return Error::success();
315}
316
318 DXContainer Container(Object);
319 if (Error Err = Container.parseHeader())
320 return std::move(Err);
321 if (Error Err = Container.parsePartOffsets())
322 return std::move(Err);
323 return Container;
324}
325
326void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
327 StringRef Buffer = Container.Data.getBuffer();
328 const char *Current = Buffer.data() + Offset;
329 // Offsets are validated during parsing, so all offsets in the container are
330 // valid and contain enough readable data to read a header.
331 cantFail(readStruct(Buffer, Current, IteratorState.Part));
332 IteratorState.Data =
333 StringRef(Current + sizeof(dxbc::PartHeader), IteratorState.Part.Size);
334 IteratorState.Offset = Offset;
335}
336
338 const char *Current = PartData.begin();
339
340 // Root Signature headers expects 6 integers to be present.
341 if (PartData.size() < 6 * sizeof(uint32_t))
342 return parseFailed(
343 "Invalid root signature, insufficient space for header.");
344
346 Current += sizeof(uint32_t);
347
348 NumParameters =
350 Current += sizeof(uint32_t);
351
352 RootParametersOffset =
354 Current += sizeof(uint32_t);
355
356 NumStaticSamplers =
358 Current += sizeof(uint32_t);
359
360 StaticSamplersOffset =
362 Current += sizeof(uint32_t);
363
365 Current += sizeof(uint32_t);
366
367 ParametersHeaders.Data = PartData.substr(
368 RootParametersOffset,
369 NumParameters * sizeof(dxbc::RTS0::v1::RootParameterHeader));
370
371 StaticSamplers.Stride = (Version <= 2)
374
375 StaticSamplers.Data = PartData.substr(StaticSamplersOffset,
376 static_cast<size_t>(NumStaticSamplers) *
377 StaticSamplers.Stride);
378
379 return Error::success();
380}
381
383 Triple::EnvironmentType ShaderStage = dxbc::getShaderStage(ShaderKind);
384
385 const char *Current = Data.begin();
386 if (Error Err = readInteger(Data, Current, Size))
387 return Err;
388 Current += sizeof(uint32_t);
389
390 StringRef PSVInfoData = Data.substr(sizeof(uint32_t), Size);
391
392 if (PSVInfoData.size() < Size)
393 return parseFailed(
394 "Pipeline state data extends beyond the bounds of the part");
395
396 using namespace dxbc::PSV;
397
398 const uint32_t PSVVersion = getVersion();
399
400 // Detect the PSVVersion by looking at the size field.
401 if (PSVVersion == 3) {
402 v3::RuntimeInfo Info;
403 if (Error Err = readStruct(PSVInfoData, Current, Info))
404 return Err;
406 Info.swapBytes(ShaderStage);
407 BasicInfo = Info;
408 } else if (PSVVersion == 2) {
409 v2::RuntimeInfo Info;
410 if (Error Err = readStruct(PSVInfoData, Current, Info))
411 return Err;
413 Info.swapBytes(ShaderStage);
414 BasicInfo = Info;
415 } else if (PSVVersion == 1) {
416 v1::RuntimeInfo Info;
417 if (Error Err = readStruct(PSVInfoData, Current, Info))
418 return Err;
420 Info.swapBytes(ShaderStage);
421 BasicInfo = Info;
422 } else if (PSVVersion == 0) {
423 v0::RuntimeInfo Info;
424 if (Error Err = readStruct(PSVInfoData, Current, Info))
425 return Err;
427 Info.swapBytes(ShaderStage);
428 BasicInfo = Info;
429 } else
430 return parseFailed(
431 "Cannot read PSV Runtime Info, unsupported PSV version.");
432
433 Current += Size;
434
435 uint32_t ResourceCount = 0;
436 if (Error Err = readInteger(Data, Current, ResourceCount))
437 return Err;
438 Current += sizeof(uint32_t);
439
440 if (ResourceCount > 0) {
441 if (Error Err = readInteger(Data, Current, Resources.Stride))
442 return Err;
443 Current += sizeof(uint32_t);
444
445 size_t BindingDataSize = Resources.Stride * ResourceCount;
446 Resources.Data = Data.substr(Current - Data.begin(), BindingDataSize);
447
448 if (Resources.Data.size() < BindingDataSize)
449 return parseFailed(
450 "Resource binding data extends beyond the bounds of the part");
451
452 Current += BindingDataSize;
453 } else
454 Resources.Stride = sizeof(v2::ResourceBindInfo);
455
456 // PSV version 0 ends after the resource bindings.
457 if (PSVVersion == 0)
458 return Error::success();
459
460 // String table starts at a 4-byte offset.
461 Current = reinterpret_cast<const char *>(
462 alignTo<4>(reinterpret_cast<uintptr_t>(Current)));
463
464 uint32_t StringTableSize = 0;
465 if (Error Err = readInteger(Data, Current, StringTableSize))
466 return Err;
467 if (StringTableSize % 4 != 0)
468 return parseFailed("String table misaligned");
469 Current += sizeof(uint32_t);
470 StringTable = StringRef(Current, StringTableSize);
471
472 Current += StringTableSize;
473
474 uint32_t SemanticIndexTableSize = 0;
475 if (Error Err = readInteger(Data, Current, SemanticIndexTableSize))
476 return Err;
477 Current += sizeof(uint32_t);
478
479 SemanticIndexTable.reserve(SemanticIndexTableSize);
480 for (uint32_t I = 0; I < SemanticIndexTableSize; ++I) {
481 uint32_t Index = 0;
482 if (Error Err = readInteger(Data, Current, Index))
483 return Err;
484 Current += sizeof(uint32_t);
485 SemanticIndexTable.push_back(Index);
486 }
487
488 uint8_t InputCount = getSigInputCount();
489 uint8_t OutputCount = getSigOutputCount();
490 uint8_t PatchOrPrimCount = getSigPatchOrPrimCount();
491
492 uint32_t ElementCount = InputCount + OutputCount + PatchOrPrimCount;
493
494 if (ElementCount > 0) {
495 if (Error Err = readInteger(Data, Current, SigInputElements.Stride))
496 return Err;
497 Current += sizeof(uint32_t);
498 // Assign the stride to all the arrays.
499 SigOutputElements.Stride = SigPatchOrPrimElements.Stride =
500 SigInputElements.Stride;
501
502 if (Data.end() - Current <
503 (ptrdiff_t)(ElementCount * SigInputElements.Stride))
504 return parseFailed(
505 "Signature elements extend beyond the size of the part");
506
507 size_t InputSize = SigInputElements.Stride * InputCount;
508 SigInputElements.Data = Data.substr(Current - Data.begin(), InputSize);
509 Current += InputSize;
510
511 size_t OutputSize = SigOutputElements.Stride * OutputCount;
512 SigOutputElements.Data = Data.substr(Current - Data.begin(), OutputSize);
513 Current += OutputSize;
514
515 size_t PSize = SigPatchOrPrimElements.Stride * PatchOrPrimCount;
516 SigPatchOrPrimElements.Data = Data.substr(Current - Data.begin(), PSize);
517 Current += PSize;
518 }
519
520 ArrayRef<uint8_t> OutputVectorCounts = getOutputVectorCounts();
521 uint8_t PatchConstOrPrimVectorCount = getPatchConstOrPrimVectorCount();
522 uint8_t InputVectorCount = getInputVectorCount();
523
524 auto maskDwordSize = [](uint8_t Vector) {
525 return (static_cast<uint32_t>(Vector) + 7) >> 3;
526 };
527
528 auto mapTableSize = [maskDwordSize](uint8_t X, uint8_t Y) {
529 return maskDwordSize(Y) * X * 4;
530 };
531
532 if (usesViewID()) {
533 for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) {
534 // The vector mask is one bit per component and 4 components per vector.
535 // We can compute the number of dwords required by rounding up to the next
536 // multiple of 8.
537 uint32_t NumDwords =
538 maskDwordSize(static_cast<uint32_t>(OutputVectorCounts[I]));
539 size_t NumBytes = NumDwords * sizeof(uint32_t);
540 OutputVectorMasks[I].Data = Data.substr(Current - Data.begin(), NumBytes);
541 Current += NumBytes;
542 }
543
544 if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0) {
545 uint32_t NumDwords = maskDwordSize(PatchConstOrPrimVectorCount);
546 size_t NumBytes = NumDwords * sizeof(uint32_t);
547 PatchOrPrimMasks.Data = Data.substr(Current - Data.begin(), NumBytes);
548 Current += NumBytes;
549 }
550 }
551
552 // Input/Output mapping table
553 for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) {
554 if (InputVectorCount == 0 || OutputVectorCounts[I] == 0)
555 continue;
556 uint32_t NumDwords = mapTableSize(InputVectorCount, OutputVectorCounts[I]);
557 size_t NumBytes = NumDwords * sizeof(uint32_t);
558 InputOutputMap[I].Data = Data.substr(Current - Data.begin(), NumBytes);
559 Current += NumBytes;
560 }
561
562 // Hull shader: Input/Patch mapping table
563 if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0 &&
564 InputVectorCount > 0) {
565 uint32_t NumDwords =
566 mapTableSize(InputVectorCount, PatchConstOrPrimVectorCount);
567 size_t NumBytes = NumDwords * sizeof(uint32_t);
568 InputPatchMap.Data = Data.substr(Current - Data.begin(), NumBytes);
569 Current += NumBytes;
570 }
571
572 // Domain Shader: Patch/Output mapping table
573 if (ShaderStage == Triple::Domain && PatchConstOrPrimVectorCount > 0 &&
574 OutputVectorCounts[0] > 0) {
575 uint32_t NumDwords =
576 mapTableSize(PatchConstOrPrimVectorCount, OutputVectorCounts[0]);
577 size_t NumBytes = NumDwords * sizeof(uint32_t);
578 PatchOutputMap.Data = Data.substr(Current - Data.begin(), NumBytes);
579 Current += NumBytes;
580 }
581
582 return Error::success();
583}
584
586 if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
587 return P->SigInputElements;
588 if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
589 return P->SigInputElements;
590 if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
591 return P->SigInputElements;
592 return 0;
593}
594
596 if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
597 return P->SigOutputElements;
598 if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
599 return P->SigOutputElements;
600 if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
601 return P->SigOutputElements;
602 return 0;
603}
604
606 if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
607 return P->SigPatchOrPrimElements;
608 if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
609 return P->SigPatchOrPrimElements;
610 if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
611 return P->SigPatchOrPrimElements;
612 return 0;
613}
614
615class DXNotSupportedError : public ErrorInfo<DXNotSupportedError> {
616public:
617 static char ID;
618
619 DXNotSupportedError(StringRef S) : FeatureString(S) {}
620
621 void log(raw_ostream &OS) const override {
622 OS << "DXContainer does not support " << FeatureString;
623 }
624
625 std::error_code convertToErrorCode() const override {
626 return inconvertibleErrorCode();
627 }
628
629private:
630 StringRef FeatureString;
631};
632
634
635Expected<section_iterator>
639
643
648
650 llvm_unreachable("DXContainer does not support symbols");
651}
654 llvm_unreachable("DXContainer does not support symbols");
655}
656
661
663 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
664 if (It == Parts.end())
665 return;
666
667 ++It;
668 Sec.p = reinterpret_cast<uintptr_t>(It);
669}
670
673 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
674 return StringRef(It->Part.getName());
675}
676
678 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
679 return It->Offset;
680}
681
683 return (Sec.p - reinterpret_cast<uintptr_t>(Parts.begin())) /
684 sizeof(PartIterator);
685}
686
688 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
689 return It->Data.size();
690}
693 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
694 return ArrayRef<uint8_t>(It->Data.bytes_begin(), It->Data.size());
695}
696
700
702 return false;
703}
704
706 return false;
707}
708
710 return false;
711}
712
714 return false;
715}
716
718 return false;
719}
720
725
730
732 llvm_unreachable("DXContainer does not support relocations");
733}
734
736 llvm_unreachable("DXContainer does not support relocations");
737}
738
743
745 llvm_unreachable("DXContainer does not support relocations");
746}
747
749 DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
750 llvm_unreachable("DXContainer does not support relocations");
751}
752
754 DataRefImpl Sec;
755 Sec.p = reinterpret_cast<uintptr_t>(Parts.begin());
756 return section_iterator(SectionRef(Sec, this));
757}
759 DataRefImpl Sec;
760 Sec.p = reinterpret_cast<uintptr_t>(Parts.end());
761 return section_iterator(SectionRef(Sec, this));
762}
763
765
767 return "DirectX Container";
768}
769
771
775
780
785
788 auto ExC = DXContainer::create(Object);
789 if (!ExC)
790 return ExC.takeError();
791 std::unique_ptr<DXContainerObjectFile> Obj(new DXContainerObjectFile(*ExC));
792 return std::move(Obj);
793}
#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