llvm.org GIT mirror llvm / 87a4920
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369579 91177308-0d34-0410-b5e6-96231b3b80d8 Cyndy Ishida 25 days ago
6 changed file(s) with 17 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
4848 xcoff_object_64, ///< 64-bit XCOFF object file
4949 wasm_object, ///< WebAssembly Object file
5050 pdb, ///< Windows PDB debug info file
51 tapi_file, ///< Text-based Dynamic Library Stub file
5152 };
5253
5354 bool is_object() const { return V != unknown; }
209209 return file_magic::coff_object;
210210 break;
211211
212 case 0x2d: // YAML '-'
213 if (startswith(Magic, "--- !tapi") || startswith(Magic, "---\narchs:"))
214 return file_magic::tapi_file;
215 break;
216
212217 default:
213218 break;
214219 }
8585 return errorCodeToError(object_error::invalid_file_type);
8686 case file_magic::minidump:
8787 return MinidumpFile::create(Buffer);
88 case file_magic::tapi_file:
89 // Placeholder until TAPI is supported for lib/Object
90 return errorCodeToError(object_error::invalid_file_type);
8891 }
8992 llvm_unreachable("Unexpected Binary File Type");
9093 }
126126 case file_magic::pdb:
127127 case file_magic::minidump:
128128 return errorCodeToError(object_error::invalid_file_type);
129 case file_magic::tapi_file:
130 return errorCodeToError(object_error::invalid_file_type);
129131 case file_magic::elf:
130132 case file_magic::elf_relocatable:
131133 case file_magic::elf_executable:
5252 case file_magic::windows_resource:
5353 case file_magic::pdb:
5454 case file_magic::minidump:
55 case file_magic::tapi_file:
5556 return errorCodeToError(object_error::invalid_file_type);
5657 case file_magic::elf:
5758 case file_magic::elf_executable:
8181 const char ms_dos_stub_broken[] = "\x4d\x5a\x20\x20";
8282 const char pdb[] = "Microsoft C/C++ MSF 7.00\r\n\x1a"
8383 "DS\x00\x00\x00";
84 const char tapi_file[] = "--- !tapi-tbd-v1\n";
85 const char tapi_file_tbd_v1[] = "---\narchs: [";
8486
8587 TEST_F(MagicTest, Magic) {
8688 struct type {
113115 DEFINE(pdb),
114116 {"ms_dos_stub_broken", ms_dos_stub_broken, sizeof(ms_dos_stub_broken),
115117 file_magic::unknown},
118 DEFINE(tapi_file),
119 {"tapi_file_tbd_v1", tapi_file_tbd_v1, sizeof(tapi_file_tbd_v1),
120 file_magic::tapi_file},
116121 #undef DEFINE
117122 };
118123