Skip to content

Commit fae9d73

Browse files
yxsamliuGZGavinZhao
authored andcommitted
Part 2 (LLVM): Reland "[HIP] Support compressing device binary"
Original PR: llvm#67162 The commit was reverted due to UB detected by santizer: https://lab.llvm.org/buildbot/#/builders/238/builds/5955 clang/lib/Driver/OffloadBundler.cpp:1012:25: runtime error: load of misaligned address 0xaaaae2d90e7c for type 'const uint64_t' (aka 'const unsigned long'), which requires 8 byte alignment It was fixed by using memcpy instead of dereferencing int* casted from unaligned char*. Note from committer: The original patch is splitted into two parts, one only for clang, and the other only for LLVM. This is to allow easier packaging for Nix. Signed-off-by: Gavin Zhao <[email protected]>
1 parent baff627 commit fae9d73

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

llvm/include/llvm/BinaryFormat/Magic.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,21 @@ struct file_magic {
4242
macho_universal_binary, ///< Mach-O universal binary
4343
macho_file_set, ///< Mach-O file set binary
4444
minidump, ///< Windows minidump file
45-
coff_cl_gl_object, ///< Microsoft cl.exe's intermediate code file
46-
coff_object, ///< COFF object file
47-
coff_import_library, ///< COFF import library
48-
pecoff_executable, ///< PECOFF executable file
49-
windows_resource, ///< Windows compiled resource file (.res)
50-
xcoff_object_32, ///< 32-bit XCOFF object file
51-
xcoff_object_64, ///< 64-bit XCOFF object file
52-
wasm_object, ///< WebAssembly Object file
53-
pdb, ///< Windows PDB debug info file
54-
tapi_file, ///< Text-based Dynamic Library Stub file
55-
cuda_fatbinary, ///< CUDA Fatbinary object file
56-
offload_binary, ///< LLVM offload object file
57-
dxcontainer_object, ///< DirectX container file
45+
coff_cl_gl_object, ///< Microsoft cl.exe's intermediate code file
46+
coff_object, ///< COFF object file
47+
coff_import_library, ///< COFF import library
48+
pecoff_executable, ///< PECOFF executable file
49+
windows_resource, ///< Windows compiled resource file (.res)
50+
xcoff_object_32, ///< 32-bit XCOFF object file
51+
xcoff_object_64, ///< 64-bit XCOFF object file
52+
wasm_object, ///< WebAssembly Object file
53+
pdb, ///< Windows PDB debug info file
54+
tapi_file, ///< Text-based Dynamic Library Stub file
55+
cuda_fatbinary, ///< CUDA Fatbinary object file
56+
offload_binary, ///< LLVM offload object file
57+
dxcontainer_object, ///< DirectX container file
58+
offload_bundle, ///< Clang offload bundle file
59+
offload_bundle_compressed, ///< Compressed clang offload bundle file
5860
};
5961

6062
bool is_object() const { return V != unknown; }

llvm/lib/BinaryFormat/Magic.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ file_magic llvm::identify_magic(StringRef Magic) {
8787
if (startswith(Magic, "BC\xC0\xDE"))
8888
return file_magic::bitcode;
8989
break;
90+
case 'C':
91+
if (startswith(Magic, "CCOB"))
92+
return file_magic::offload_bundle_compressed;
93+
break;
9094
case '!':
9195
if (startswith(Magic, "!<arch>\n") || startswith(Magic, "!<thin>\n"))
9296
return file_magic::archive;

llvm/lib/Object/Binary.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
8787
case file_magic::cuda_fatbinary:
8888
case file_magic::coff_cl_gl_object:
8989
case file_magic::dxcontainer_object:
90+
case file_magic::offload_bundle:
91+
case file_magic::offload_bundle_compressed:
9092
// Unrecognized object file format.
9193
return errorCodeToError(object_error::invalid_file_type);
9294
case file_magic::offload_binary:

llvm/lib/Object/ObjectFile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
154154
case file_magic::cuda_fatbinary:
155155
case file_magic::offload_binary:
156156
case file_magic::dxcontainer_object:
157+
case file_magic::offload_bundle:
158+
case file_magic::offload_bundle_compressed:
157159
return errorCodeToError(object_error::invalid_file_type);
158160
case file_magic::tapi_file:
159161
return errorCodeToError(object_error::invalid_file_type);

0 commit comments

Comments
 (0)