LLVM 23.0.0git
OffloadBundle.cpp
Go to the documentation of this file.
1//===- OffloadBundle.cpp - Utilities for offload bundles---*- C++ -*-===//
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/IR/Module.h"
14#include "llvm/Object/Archive.h"
15#include "llvm/Object/Binary.h"
16#include "llvm/Object/COFF.h"
18#include "llvm/Object/Error.h"
23#include "llvm/Support/Timer.h"
24
25using namespace llvm;
26using namespace llvm::object;
27
28static TimerGroup OffloadBundlerTimerGroup("Offload Bundler Timer Group",
29 "Timer group for offload bundler");
30
31// Extract an Offload bundle (usually a Offload Bundle) from a fat_bin
32// section.
34 StringRef FileName,
36
37 size_t Offset = 0;
38 size_t NextbundleStart = 0;
39 StringRef Magic;
40 std::unique_ptr<MemoryBuffer> Buffer;
41
42 // There could be multiple offloading bundles stored at this section.
43 while ((NextbundleStart != StringRef::npos) &&
44 (Offset < Contents.getBuffer().size())) {
45 Buffer =
47 /*RequiresNullTerminator=*/false);
48
49 if (identify_magic((*Buffer).getBuffer()) ==
51 Magic = "CCOB";
52 // Decompress this bundle first.
53 NextbundleStart = (*Buffer).getBuffer().find(Magic, Magic.size());
54 if (NextbundleStart == StringRef::npos)
55 NextbundleStart = (*Buffer).getBuffer().size();
56
59 (*Buffer).getBuffer().take_front(NextbundleStart), FileName,
60 false);
61 if (std::error_code EC = CodeOrErr.getError())
62 return createFileError(FileName, EC);
63
64 Expected<std::unique_ptr<MemoryBuffer>> DecompressedBufferOrErr =
65 CompressedOffloadBundle::decompress(**CodeOrErr, nullptr);
66 if (!DecompressedBufferOrErr)
67 return createStringError("failed to decompress input: " +
68 toString(DecompressedBufferOrErr.takeError()));
69
70 auto FatBundleOrErr = OffloadBundleFatBin::create(
71 **DecompressedBufferOrErr, Offset, FileName, true);
72 if (!FatBundleOrErr)
73 return FatBundleOrErr.takeError();
74
75 // Add current Bundle to list.
76 Bundles.emplace_back(std::move(**FatBundleOrErr));
77
78 } else if (identify_magic((*Buffer).getBuffer()) ==
80 // Create the OffloadBundleFatBin object. This will also create the Bundle
81 // Entry list info.
82 auto FatBundleOrErr = OffloadBundleFatBin::create(
83 *Buffer, SectionOffset + Offset, FileName);
84 if (!FatBundleOrErr)
85 return FatBundleOrErr.takeError();
86
87 // Add current Bundle to list.
88 Bundles.emplace_back(std::move(**FatBundleOrErr));
89
90 Magic = "__CLANG_OFFLOAD_BUNDLE__";
91 NextbundleStart = (*Buffer).getBuffer().find(Magic, Magic.size());
92 }
93
94 if (NextbundleStart != StringRef::npos)
95 Offset += NextbundleStart;
96 }
97
98 return Error::success();
99}
100
102 uint64_t SectionOffset) {
103 uint64_t NumOfEntries = 0;
104
106
107 // Read the Magic String first.
108 StringRef Magic;
109 if (auto EC = Reader.readFixedString(Magic, 24))
111
112 // Read the number of Code Objects (Entries) in the current Bundle.
113 if (auto EC = Reader.readInteger(NumOfEntries))
115
116 NumberOfEntries = NumOfEntries;
117
118 // For each Bundle Entry (code object).
119 for (uint64_t I = 0; I < NumOfEntries; I++) {
120 uint64_t EntrySize;
121 uint64_t EntryOffset;
122 uint64_t EntryIDSize;
123 StringRef EntryID;
124
125 if (Error Err = Reader.readInteger(EntryOffset))
126 return Err;
127
128 if (Error Err = Reader.readInteger(EntrySize))
129 return Err;
130
131 if (Error Err = Reader.readInteger(EntryIDSize))
132 return Err;
133
134 if (Error Err = Reader.readFixedString(EntryID, EntryIDSize))
135 return Err;
136
137 auto Entry = std::make_unique<OffloadBundleEntry>(
138 EntryOffset + SectionOffset, EntrySize, EntryIDSize, EntryID);
139
140 Entries.push_back(*Entry);
141 }
142
143 return Error::success();
144}
145
148 StringRef FileName, bool Decompress) {
149 if (Buf.getBufferSize() < 24)
151
152 // Check for magic bytes.
154 (identify_magic(Buf.getBuffer()) !=
157
158 std::unique_ptr<OffloadBundleFatBin> TheBundle(
159 new OffloadBundleFatBin(Buf, FileName));
160
161 // Read the Bundle Entries.
162 Error Err =
163 TheBundle->readEntries(Buf.getBuffer(), Decompress ? 0 : SectionOffset);
164 if (Err)
165 return Err;
166
167 return std::move(TheBundle);
168}
169
171 // This will extract all entries in the Bundle.
172 for (OffloadBundleEntry &Entry : Entries) {
173
174 if (Entry.Size == 0)
175 continue;
176
177 // create output file name. Which should be
178 // <fileName>-offset<Offset>-size<Size>.co"
179 std::string Str = getFileName().str() + "-offset" + itostr(Entry.Offset) +
180 "-size" + itostr(Entry.Size) + ".co";
181 if (Error Err = object::extractCodeObject(Source, Entry.Offset, Entry.Size,
182 StringRef(Str)))
183 return Err;
184 }
185
186 return Error::success();
187}
188
191 // Ignore unsupported object formats.
192 if (!Obj.isELF() && !Obj.isCOFF())
193 return Error::success();
194
195 // Iterate through Sections until we find an offload_bundle section.
196 for (SectionRef Sec : Obj.sections()) {
197 Expected<StringRef> Buffer = Sec.getContents();
198 if (!Buffer)
199 return Buffer.takeError();
200
201 // If it does not start with the reserved suffix, just skip this section.
203 (llvm::identify_magic(*Buffer) ==
205
206 uint64_t SectionOffset = 0;
207 if (Obj.isELF()) {
208 SectionOffset = ELFSectionRef(Sec).getOffset();
209 } else if (Obj.isCOFF()) // TODO: add COFF Support.
211 "COFF object files not supported");
212
213 MemoryBufferRef Contents(*Buffer, Obj.getFileName());
214 if (Error Err = extractOffloadBundle(Contents, SectionOffset,
215 Obj.getFileName(), Bundles))
216 return Err;
217 }
218 }
219 return Error::success();
220}
221
223 int64_t Size, StringRef OutputFileName) {
225 FileOutputBuffer::create(OutputFileName, Size);
226
227 if (!BufferOrErr)
228 return BufferOrErr.takeError();
229
230 Expected<MemoryBufferRef> InputBuffOrErr = Source.getMemoryBufferRef();
231 if (Error Err = InputBuffOrErr.takeError())
232 return Err;
233
234 std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
235 std::copy(InputBuffOrErr->getBufferStart() + Offset,
236 InputBuffOrErr->getBufferStart() + Offset + Size,
237 Buf->getBufferStart());
238 if (Error E = Buf->commit())
239 return E;
240
241 return Error::success();
242}
243
245 int64_t Size, StringRef OutputFileName) {
247 FileOutputBuffer::create(OutputFileName, Size);
248 if (!BufferOrErr)
249 return BufferOrErr.takeError();
250
251 std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
252 std::copy(Buffer.getBufferStart() + Offset,
253 Buffer.getBufferStart() + Offset + Size, Buf->getBufferStart());
254
255 return Buf->commit();
256}
257
258// given a file name, offset, and size, extract data into a code object file,
259// into file "<SourceFile>-offset<Offset>-size<Size>.co".
261 // create a URI object
264 if (!UriOrErr)
265 return UriOrErr.takeError();
266
267 OffloadBundleURI &Uri = **UriOrErr;
268 std::string OutputFile = Uri.FileName.str();
269 OutputFile +=
270 "-offset" + itostr(Uri.Offset) + "-size" + itostr(Uri.Size) + ".co";
271
272 // Create an ObjectFile object from uri.file_uri.
273 auto ObjOrErr = ObjectFile::createObjectFile(Uri.FileName);
274 if (!ObjOrErr)
275 return ObjOrErr.takeError();
276
277 auto Obj = ObjOrErr->getBinary();
278 if (Error Err =
279 object::extractCodeObject(*Obj, Uri.Offset, Uri.Size, OutputFile))
280 return Err;
281
282 return Error::success();
283}
284
285// Utility function to format numbers with commas.
286static std::string formatWithCommas(unsigned long long Value) {
287 std::string Num = std::to_string(Value);
288 int InsertPosition = Num.length() - 3;
289 while (InsertPosition > 0) {
290 Num.insert(InsertPosition, ",");
291 InsertPosition -= 3;
292 }
293 return Num;
294}
295
296Expected<std::unique_ptr<MemoryBuffer>>
299 raw_ostream *VerboseStream) {
301 return createStringError("compression not supported.");
302 Timer HashTimer("Hash Calculation Timer", "Hash calculation time",
304 if (VerboseStream)
305 HashTimer.startTimer();
306 MD5 Hash;
307 MD5::MD5Result Result;
308 Hash.update(Input.getBuffer());
309 Hash.final(Result);
310 uint64_t TruncatedHash = Result.low();
311 if (VerboseStream)
312 HashTimer.stopTimer();
313
314 SmallVector<uint8_t, 0> CompressedBuffer;
315 auto BufferUint8 = ArrayRef<uint8_t>(
316 reinterpret_cast<const uint8_t *>(Input.getBuffer().data()),
317 Input.getBuffer().size());
318 Timer CompressTimer("Compression Timer", "Compression time",
320 if (VerboseStream)
321 CompressTimer.startTimer();
322 compression::compress(P, BufferUint8, CompressedBuffer);
323 if (VerboseStream)
324 CompressTimer.stopTimer();
325
326 uint16_t CompressionMethod = static_cast<uint16_t>(P.format);
327
328 // Store sizes in 64-bit variables first.
329 uint64_t UncompressedSize64 = Input.getBuffer().size();
330 uint64_t TotalFileSize64;
331
332 // Calculate total file size based on version.
333 if (Version == 2) {
334 // For V2, ensure the sizes don't exceed 32-bit limit.
335 if (UncompressedSize64 > std::numeric_limits<uint32_t>::max())
336 return createStringError("uncompressed size (%llu) exceeds version 2 "
337 "unsigned 32-bit integer limit",
338 UncompressedSize64);
339 TotalFileSize64 = MagicNumber.size() + sizeof(uint32_t) + sizeof(Version) +
340 sizeof(CompressionMethod) + sizeof(uint32_t) +
341 sizeof(TruncatedHash) + CompressedBuffer.size();
342 if (TotalFileSize64 > std::numeric_limits<uint32_t>::max())
343 return createStringError("total file size (%llu) exceeds version 2 "
344 "unsigned 32-bit integer limit",
345 TotalFileSize64);
346
347 } else { // Version 3.
348 TotalFileSize64 = MagicNumber.size() + sizeof(uint64_t) + sizeof(Version) +
349 sizeof(CompressionMethod) + sizeof(uint64_t) +
350 sizeof(TruncatedHash) + CompressedBuffer.size();
351 }
352
353 SmallVector<char, 0> FinalBuffer;
354 raw_svector_ostream OS(FinalBuffer);
355 OS << MagicNumber;
356 OS.write(reinterpret_cast<const char *>(&Version), sizeof(Version));
357 OS.write(reinterpret_cast<const char *>(&CompressionMethod),
358 sizeof(CompressionMethod));
359
360 // Write size fields according to version.
361 if (Version == 2) {
362 uint32_t TotalFileSize32 = static_cast<uint32_t>(TotalFileSize64);
363 uint32_t UncompressedSize32 = static_cast<uint32_t>(UncompressedSize64);
364 OS.write(reinterpret_cast<const char *>(&TotalFileSize32),
365 sizeof(TotalFileSize32));
366 OS.write(reinterpret_cast<const char *>(&UncompressedSize32),
367 sizeof(UncompressedSize32));
368 } else { // Version 3.
369 OS.write(reinterpret_cast<const char *>(&TotalFileSize64),
370 sizeof(TotalFileSize64));
371 OS.write(reinterpret_cast<const char *>(&UncompressedSize64),
372 sizeof(UncompressedSize64));
373 }
374
375 OS.write(reinterpret_cast<const char *>(&TruncatedHash),
376 sizeof(TruncatedHash));
377 OS.write(reinterpret_cast<const char *>(CompressedBuffer.data()),
378 CompressedBuffer.size());
379
380 if (VerboseStream) {
381 auto MethodUsed = P.format == compression::Format::Zstd ? "zstd" : "zlib";
382 double CompressionRate =
383 static_cast<double>(UncompressedSize64) / CompressedBuffer.size();
384 double CompressionTimeSeconds = CompressTimer.getTotalTime().getWallTime();
385 double CompressionSpeedMBs =
386 (UncompressedSize64 / (1024.0 * 1024.0)) / CompressionTimeSeconds;
387 *VerboseStream << "Compressed bundle format version: " << Version << "\n"
388 << "Total file size (including headers): "
389 << formatWithCommas(TotalFileSize64) << " bytes\n"
390 << "Compression method used: " << MethodUsed << "\n"
391 << "Compression level: " << P.level << "\n"
392 << "Binary size before compression: "
393 << formatWithCommas(UncompressedSize64) << " bytes\n"
394 << "Binary size after compression: "
395 << formatWithCommas(CompressedBuffer.size()) << " bytes\n"
396 << "Compression rate: " << format("%.2lf", CompressionRate)
397 << "\n"
398 << "Compression ratio: "
399 << format("%.2lf%%", 100.0 / CompressionRate) << "\n"
400 << "Compression speed: "
401 << format("%.2lf MB/s", CompressionSpeedMBs) << "\n"
402 << "Truncated MD5 hash: " << format_hex(TruncatedHash, 16)
403 << "\n";
404 }
405
407 StringRef(FinalBuffer.data(), FinalBuffer.size()));
408}
409
410// Use packed structs to avoid padding, such that the structs map the serialized
411// format.
446
447// Helper method to get header size based on version.
448static size_t getHeaderSize(uint16_t Version) {
449 switch (Version) {
450 case 1:
452 case 2:
454 case 3:
456 default:
457 llvm_unreachable("Unsupported version");
458 }
459}
460
461Expected<CompressedOffloadBundle::CompressedBundleHeader>
465
467 std::memcpy(&Header, Blob.data(), std::min(Blob.size(), sizeof(Header)));
468
469 CompressedBundleHeader Normalized;
470 Normalized.Version = Header.Common.Version;
471
472 size_t RequiredSize = getHeaderSize(Normalized.Version);
473
474 if (Blob.size() < RequiredSize)
475 return createStringError("compressed bundle header size too small");
476
477 switch (Normalized.Version) {
478 case 1:
479 Normalized.UncompressedFileSize = Header.V1.UncompressedFileSize;
480 Normalized.Hash = Header.V1.Hash;
481 break;
482 case 2:
483 Normalized.FileSize = Header.V2.FileSize;
484 Normalized.UncompressedFileSize = Header.V2.UncompressedFileSize;
485 Normalized.Hash = Header.V2.Hash;
486 break;
487 case 3:
488 Normalized.FileSize = Header.V3.FileSize;
489 Normalized.UncompressedFileSize = Header.V3.UncompressedFileSize;
490 Normalized.Hash = Header.V3.Hash;
491 break;
492 default:
493 return createStringError("unknown compressed bundle version");
494 }
495
496 // Determine compression format.
497 switch (Header.Common.Method) {
498 case static_cast<uint16_t>(compression::Format::Zlib):
499 case static_cast<uint16_t>(compression::Format::Zstd):
500 Normalized.CompressionFormat =
501 static_cast<compression::Format>(Header.Common.Method);
502 break;
503 default:
504 return createStringError("unknown compressing method");
505 }
506
507 return Normalized;
508}
509
512 raw_ostream *VerboseStream) {
513 StringRef Blob = Input.getBuffer();
514
515 // Check minimum header size (using V1 as it's the smallest).
518
520 if (VerboseStream)
521 *VerboseStream << "Uncompressed bundle\n";
523 }
524
527 if (!HeaderOrErr)
528 return HeaderOrErr.takeError();
529
530 const CompressedBundleHeader &Normalized = *HeaderOrErr;
531 unsigned ThisVersion = Normalized.Version;
532 size_t HeaderSize = getHeaderSize(ThisVersion);
533
534 compression::Format CompressionFormat = Normalized.CompressionFormat;
535
536 size_t TotalFileSize = Normalized.FileSize.value_or(0);
537 size_t UncompressedSize = Normalized.UncompressedFileSize;
538 auto StoredHash = Normalized.Hash;
539
540 Timer DecompressTimer("Decompression Timer", "Decompression time",
542 if (VerboseStream)
543 DecompressTimer.startTimer();
544
545 SmallVector<uint8_t, 0> DecompressedData;
546 StringRef CompressedData =
547 Blob.substr(HeaderSize, TotalFileSize - HeaderSize);
548
549 if (Error DecompressionError = compression::decompress(
550 CompressionFormat, arrayRefFromStringRef(CompressedData),
551 DecompressedData, UncompressedSize))
552 return createStringError("could not decompress embedded file contents: " +
553 toString(std::move(DecompressionError)));
554
555 if (VerboseStream) {
556 DecompressTimer.stopTimer();
557
558 double DecompressionTimeSeconds =
559 DecompressTimer.getTotalTime().getWallTime();
560
561 // Recalculate MD5 hash for integrity check.
562 Timer HashRecalcTimer("Hash Recalculation Timer", "Hash recalculation time",
564 HashRecalcTimer.startTimer();
565 MD5 Hash;
566 MD5::MD5Result Result;
567 Hash.update(ArrayRef<uint8_t>(DecompressedData));
568 Hash.final(Result);
569 uint64_t RecalculatedHash = Result.low();
570 HashRecalcTimer.stopTimer();
571 bool HashMatch = (StoredHash == RecalculatedHash);
572
573 double CompressionRate =
574 static_cast<double>(UncompressedSize) / CompressedData.size();
575 double DecompressionSpeedMBs =
576 (UncompressedSize / (1024.0 * 1024.0)) / DecompressionTimeSeconds;
577
578 *VerboseStream << "Compressed bundle format version: " << ThisVersion
579 << "\n";
580 if (ThisVersion >= 2)
581 *VerboseStream << "Total file size (from header): "
582 << formatWithCommas(TotalFileSize) << " bytes\n";
583 *VerboseStream
584 << "Decompression method: "
585 << (CompressionFormat == compression::Format::Zlib ? "zlib" : "zstd")
586 << "\n"
587 << "Size before decompression: "
588 << formatWithCommas(CompressedData.size()) << " bytes\n"
589 << "Size after decompression: " << formatWithCommas(UncompressedSize)
590 << " bytes\n"
591 << "Compression rate: " << format("%.2lf", CompressionRate) << "\n"
592 << "Compression ratio: " << format("%.2lf%%", 100.0 / CompressionRate)
593 << "\n"
594 << "Decompression speed: "
595 << format("%.2lf MB/s", DecompressionSpeedMBs) << "\n"
596 << "Stored hash: " << format_hex(StoredHash, 16) << "\n"
597 << "Recalculated hash: " << format_hex(RecalculatedHash, 16) << "\n"
598 << "Hashes match: " << (HashMatch ? "Yes" : "No") << "\n";
599 }
600
601 return MemoryBuffer::getMemBufferCopy(toStringRef(DecompressedData));
602}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_PACKED_END
Definition Compiler.h:555
#define LLVM_PACKED_START
Definition Compiler.h:554
Module.h This file contains the declarations for the Module class.
#define I(x, y, z)
Definition MD5.cpp:57
static LLVM_PACKED_END size_t getHeaderSize(uint16_t Version)
Error extractOffloadBundle(MemoryBufferRef Contents, uint64_t SectionOffset, StringRef FileName, SmallVectorImpl< OffloadBundleFatBin > &Bundles)
static std::string formatWithCommas(unsigned long long Value)
static TimerGroup OffloadBundlerTimerGroup("Offload Bundler Timer Group", "Timer group for offload bundler")
#define P(N)
The Input class is used to parse a yaml document into in-memory structs and vectors.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Provides read only access to a subclass of BinaryStream.
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
LLVM_ABI Error readFixedString(StringRef &Dest, uint32_t Length)
Read a Length byte string into Dest.
Represents either an error or a value T.
Definition ErrorOr.h:56
std::error_code getError() const
Definition ErrorOr.h:152
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
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
static LLVM_ABI Expected< std::unique_ptr< FileOutputBuffer > > create(StringRef FilePath, size_t Size, unsigned Flags=0)
Factory method to create an OutputBuffer object which manages a read/write buffer of the specified si...
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition MD5.cpp:188
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition MD5.cpp:233
size_t getBufferSize() const
const char * getBufferStart() const
StringRef getBuffer() const
This interface provides simple read-only access to a block of memory, and provides simple methods for...
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
static constexpr size_t npos
Definition StringRef.h:57
std::string str() const
str - Get the contents as an std::string.
Definition StringRef.h:225
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:573
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:611
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:146
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:140
double getWallTime() const
Definition Timer.h:45
The TimerGroup class is used to group together related timers into a single report that is printed wh...
Definition Timer.h:191
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition Timer.h:87
LLVM_ABI void stopTimer()
Stop the timer.
Definition Timer.cpp:159
LLVM_ABI void startTimer()
Start the timer running.
Definition Timer.cpp:150
TimeRecord getTotalTime() const
Return the duration for which this timer has been running.
Definition Timer.h:145
LLVM Value Representation.
Definition Value.h:75
static llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > decompress(const llvm::MemoryBuffer &Input, raw_ostream *VerboseStream=nullptr)
static llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input, uint16_t Version, raw_ostream *VerboseStream=nullptr)
This class is the base class for all object file types.
Definition ObjectFile.h:231
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
LLVM_ABI Error readEntries(StringRef Section, uint64_t SectionOffset)
OffloadBundleFatBin(MemoryBufferRef Source, StringRef File, bool Decompress=false)
LLVM_ABI Error extractBundle(const ObjectFile &Source)
static LLVM_ABI Expected< std::unique_ptr< OffloadBundleFatBin > > create(MemoryBufferRef, uint64_t SectionOffset, StringRef FileName, bool Decompress=false)
This is a value type class that represents a single section in the list of sections in the object fil...
Definition ObjectFile.h:83
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI bool isAvailable()
LLVM_ABI bool isAvailable()
LLVM_ABI Error decompress(DebugCompressionType T, ArrayRef< uint8_t > Input, uint8_t *Output, size_t UncompressedSize)
LLVM_ABI void compress(Params P, ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &Output)
LLVM_ABI Error extractCodeObject(const ObjectFile &Source, int64_t Offset, int64_t Size, StringRef OutputFileName)
Extract code object memory from the given Source object file at Offset and of Size,...
LLVM_ABI Error extractOffloadBundleByURI(StringRef URIstr)
Extracts an Offload Bundle Entry given by URI.
LLVM_ABI Error extractOffloadBundleFatBinary(const ObjectFile &Obj, SmallVectorImpl< OffloadBundleFatBin > &Bundles)
Extracts fat binary in binary clang-offload-bundler format from object Obj and return it in Bundles.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
LLVM_ABI file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition Magic.cpp:33
@ Offset
Definition DWP.cpp:532
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition Error.h:1399
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:302
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition Format.h:191
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:129
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition Error.cpp:107
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
std::string itostr(int64_t X)
@ offload_bundle
Clang offload bundle file.
Definition Magic.h:60
@ offload_bundle_compressed
Compressed clang offload bundle file.
Definition Magic.h:61
static llvm::Expected< CompressedBundleHeader > tryParse(llvm::StringRef)
Bundle entry in binary clang-offload-bundler format.
static Expected< std::unique_ptr< OffloadBundleURI > > createOffloadBundleURI(StringRef Str, UriTypeT Type)