mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
[BinaryFormat] Teach identify_magic about Tapi files.
Summary: Tapi files are YAML files that start with the !tapi tag. The only execption are TBD v1 files, which don't have a tag. In that case we have to scan a little further and check if the first key "archs" exists. This is the first patch in a series of patches to add libObject support for text-based dynamic library (.tbd) files. This patch is practically exactly the same as D37820, that was never pushed to master, and is needed for future commits related to reading tbd files for llvm-nm Reviewers: ributzka, steven_wu, bollu, espindola, jfb, shafik, jdoerfert Reviewed By: steven_wu Subscribers: dexonsmith, llvm-commits Tags: #llvm, #clang, #sanitizers, #lldb, #libc, #openmp Differential Revision: https://reviews.llvm.org/D66149 llvm-svn: 369579
This commit is contained in:
parent
ba49309583
commit
f188975fc7
@ -49,6 +49,7 @@ struct file_magic {
|
||||
xcoff_object_64, ///< 64-bit XCOFF object file
|
||||
wasm_object, ///< WebAssembly Object file
|
||||
pdb, ///< Windows PDB debug info file
|
||||
tapi_file, ///< Text-based Dynamic Library Stub file
|
||||
};
|
||||
|
||||
bool is_object() const { return V != unknown; }
|
||||
|
@ -210,6 +210,11 @@ file_magic llvm::identify_magic(StringRef Magic) {
|
||||
return file_magic::coff_object;
|
||||
break;
|
||||
|
||||
case 0x2d: // YAML '-'
|
||||
if (startswith(Magic, "--- !tapi") || startswith(Magic, "---\narchs:"))
|
||||
return file_magic::tapi_file;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -86,6 +86,9 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
|
||||
return errorCodeToError(object_error::invalid_file_type);
|
||||
case file_magic::minidump:
|
||||
return MinidumpFile::create(Buffer);
|
||||
case file_magic::tapi_file:
|
||||
// Placeholder until TAPI is supported for lib/Object
|
||||
return errorCodeToError(object_error::invalid_file_type);
|
||||
}
|
||||
llvm_unreachable("Unexpected Binary File Type");
|
||||
}
|
||||
|
@ -127,6 +127,8 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type) {
|
||||
case file_magic::pdb:
|
||||
case file_magic::minidump:
|
||||
return errorCodeToError(object_error::invalid_file_type);
|
||||
case file_magic::tapi_file:
|
||||
return errorCodeToError(object_error::invalid_file_type);
|
||||
case file_magic::elf:
|
||||
case file_magic::elf_relocatable:
|
||||
case file_magic::elf_executable:
|
||||
|
@ -53,6 +53,7 @@ SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type,
|
||||
case file_magic::windows_resource:
|
||||
case file_magic::pdb:
|
||||
case file_magic::minidump:
|
||||
case file_magic::tapi_file:
|
||||
return errorCodeToError(object_error::invalid_file_type);
|
||||
case file_magic::elf:
|
||||
case file_magic::elf_executable:
|
||||
|
@ -82,6 +82,8 @@ const char macho_dynamically_linked_shared_lib_stub[] =
|
||||
const char ms_dos_stub_broken[] = "\x4d\x5a\x20\x20";
|
||||
const char pdb[] = "Microsoft C/C++ MSF 7.00\r\n\x1a"
|
||||
"DS\x00\x00\x00";
|
||||
const char tapi_file[] = "--- !tapi-tbd-v1\n";
|
||||
const char tapi_file_tbd_v1[] = "---\narchs: [";
|
||||
|
||||
TEST_F(MagicTest, Magic) {
|
||||
struct type {
|
||||
@ -114,6 +116,9 @@ TEST_F(MagicTest, Magic) {
|
||||
DEFINE(pdb),
|
||||
{"ms_dos_stub_broken", ms_dos_stub_broken, sizeof(ms_dos_stub_broken),
|
||||
file_magic::unknown},
|
||||
DEFINE(tapi_file),
|
||||
{"tapi_file_tbd_v1", tapi_file_tbd_v1, sizeof(tapi_file_tbd_v1),
|
||||
file_magic::tapi_file},
|
||||
#undef DEFINE
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user