[PATCH] D37820: [BinaryFormat] Teach identify_magic about Tapi files.
Juergen Ributzka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 12:03:20 PDT 2017
ributzka created this revision.
Herald added subscribers: aheejin, hiraditya, dschuff, jfb.
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.
https://reviews.llvm.org/D37820
Files:
llvm/include/llvm/BinaryFormat/Magic.h
llvm/lib/BinaryFormat/Magic.cpp
llvm/lib/Object/Binary.cpp
llvm/lib/Object/ObjectFile.cpp
llvm/lib/Object/SymbolicFile.cpp
llvm/unittests/BinaryFormat/TestFileMagic.cpp
Index: llvm/unittests/BinaryFormat/TestFileMagic.cpp
===================================================================
--- llvm/unittests/BinaryFormat/TestFileMagic.cpp
+++ llvm/unittests/BinaryFormat/TestFileMagic.cpp
@@ -81,6 +81,8 @@
const char macho_dynamically_linked_shared_lib_stub[] =
"\xfe\xed\xfa\xce........\x00\x00\x00\x09............";
const char ms_dos_stub_broken[] = "\x4d\x5a\x20\x20";
+const char tapi_file[] = "--- !tapi-tbd-v1\n";
+const char tapi_file_tbd_v1[] = "---\narchs: [";
TEST_F(MagicTest, Magic) {
struct type {
@@ -112,6 +114,9 @@
DEFINE(windows_resource),
{"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
};
Index: llvm/lib/Object/SymbolicFile.cpp
===================================================================
--- llvm/lib/Object/SymbolicFile.cpp
+++ llvm/lib/Object/SymbolicFile.cpp
@@ -52,6 +52,7 @@
case file_magic::coff_cl_gl_object:
case file_magic::macho_universal_binary:
case file_magic::windows_resource:
+ case file_magic::tapi_file:
return errorCodeToError(object_error::invalid_file_type);
case file_magic::elf:
case file_magic::elf_executable:
Index: llvm/lib/Object/ObjectFile.cpp
===================================================================
--- llvm/lib/Object/ObjectFile.cpp
+++ llvm/lib/Object/ObjectFile.cpp
@@ -92,6 +92,7 @@
case file_magic::archive:
case file_magic::macho_universal_binary:
case file_magic::windows_resource:
+ case file_magic::tapi_file:
return errorCodeToError(object_error::invalid_file_type);
case file_magic::elf:
case file_magic::elf_relocatable:
Index: llvm/lib/Object/Binary.cpp
===================================================================
--- llvm/lib/Object/Binary.cpp
+++ llvm/lib/Object/Binary.cpp
@@ -77,6 +77,7 @@
return WindowsResource::createWindowsResource(Buffer);
case file_magic::unknown:
case file_magic::coff_cl_gl_object:
+ case file_magic::tapi_file:
// Unrecognized object file format.
return errorCodeToError(object_error::invalid_file_type);
}
Index: llvm/lib/BinaryFormat/Magic.cpp
===================================================================
--- llvm/lib/BinaryFormat/Magic.cpp
+++ llvm/lib/BinaryFormat/Magic.cpp
@@ -196,6 +196,10 @@
return file_magic::coff_object;
break;
+ case 0x2d: // Tapi File '-'
+ if (startswith(Magic, "---\narchs:") || startswith(Magic, "--- !tapi"))
+ return file_magic::tapi_file;
+
default:
break;
}
Index: llvm/include/llvm/BinaryFormat/Magic.h
===================================================================
--- llvm/include/llvm/BinaryFormat/Magic.h
+++ llvm/include/llvm/BinaryFormat/Magic.h
@@ -45,7 +45,8 @@
coff_import_library, ///< COFF import library
pecoff_executable, ///< PECOFF executable file
windows_resource, ///< Windows compiled resource file (.res)
- wasm_object ///< WebAssembly Object file
+ wasm_object, ///< WebAssembly Object file
+ tapi_file, ///< Text-based Dynamic Library Stub file
};
bool is_object() const { return V != unknown; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37820.115092.patch
Type: text/x-patch
Size: 3316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170913/fa6db12f/attachment.bin>
More information about the llvm-commits
mailing list