[OffloadPackager] Use appropriate kind for LTO bitcode

Summary:
Currently we just check the extension to set the image kind. This
incorrectly labels the `.o` files created during LTO as object files.
This patch simply adds a check for the bitcode magic bytes instead.
This commit is contained in:
Joseph Huber 2022-07-04 17:32:47 -04:00
parent a4e2c1f762
commit b6178ccfe8
2 changed files with 8 additions and 2 deletions

View File

@ -1,5 +1,6 @@
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
BinaryFormat
Object
Support)

View File

@ -99,9 +99,14 @@ int main(int argc, const char **argv) {
llvm::MemoryBuffer::getFileOrSTDIN(KeyAndValue.getValue());
if (std::error_code EC = ObjectOrErr.getError())
return reportError(errorCodeToError(EC));
// Clang uses the '.o' suffix for LTO bitcode.
if (identify_magic((*ObjectOrErr)->getBuffer()) == file_magic::bitcode)
ImageBinary.TheImageKind = object::IMG_Bitcode;
else
ImageBinary.TheImageKind = getImageKind(
sys::path::extension(KeyAndValue.getValue()).drop_front());
ImageBinary.Image = std::move(*ObjectOrErr);
ImageBinary.TheImageKind = getImageKind(
sys::path::extension(KeyAndValue.getValue()).drop_front());
} else if (Key == "kind") {
ImageBinary.TheOffloadKind = getOffloadKind(KeyAndValue.getValue());
} else {