diff options
author | Chris Bieneman <beanz@apple.com> | 2016-05-17 19:44:06 +0000 |
---|---|---|
committer | Chris Bieneman <beanz@apple.com> | 2016-05-17 19:44:06 +0000 |
commit | 0865cea8c3a792334cf48d286df3a6fc0731065d (patch) | |
tree | 89b9f30ce6679a8f058066369c92b663b90dddb6 /include | |
parent | 293233a0481de66a477d22d1e234893b8c4388b4 (diff) |
Reapply r269782 "[obj2yaml] [yaml2obj] Support for MachO load command structures""
This adds support for all the MachO *_command structures. The load_command payloads still are not represented, but that will come next.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269808 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/ObjectYAML/MachOYAML.h | 61 | ||||
-rw-r--r-- | include/llvm/Support/MachO.def | 45 | ||||
-rw-r--r-- | include/llvm/Support/MachO.h | 7 |
3 files changed, 101 insertions, 12 deletions
diff --git a/include/llvm/ObjectYAML/MachOYAML.h b/include/llvm/ObjectYAML/MachOYAML.h index 726b4241a91..21558f00cc0 100644 --- a/include/llvm/ObjectYAML/MachOYAML.h +++ b/include/llvm/ObjectYAML/MachOYAML.h @@ -35,19 +35,18 @@ struct FileHeader { struct LoadCommand { virtual ~LoadCommand(); - MachO::LoadCommandType cmd; - uint32_t cmdsize; + llvm::MachO::macho_load_command Data; }; struct Object { FileHeader Header; - std::vector<std::unique_ptr<LoadCommand>> LoadCommands; + std::vector<LoadCommand> LoadCommands; }; } // namespace llvm::MachOYAML } // namespace llvm -LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::MachOYAML::LoadCommand>) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::LoadCommand) namespace llvm { namespace yaml { @@ -60,12 +59,11 @@ template <> struct MappingTraits<MachOYAML::Object> { static void mapping(IO &IO, MachOYAML::Object &Object); }; -template <> struct MappingTraits<std::unique_ptr<MachOYAML::LoadCommand>> { - static void mapping(IO &IO, - std::unique_ptr<MachOYAML::LoadCommand> &LoadCommand); +template <> struct MappingTraits<MachOYAML::LoadCommand> { + static void mapping(IO &IO, MachOYAML::LoadCommand &LoadCommand); }; -#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \ +#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \ io.enumCase(value, #LCName, MachO::LCName); template <> struct ScalarEnumerationTraits<MachO::LoadCommandType> { @@ -74,7 +72,52 @@ template <> struct ScalarEnumerationTraits<MachO::LoadCommandType> { } }; -#undef HANDLE_LOAD_COMMAND +// This trait is used for 16-byte chars in Mach structures used for strings +typedef char char_16[16]; + +template <> struct ScalarTraits<char_16> { + static void output(const char_16 &Val, void *, llvm::raw_ostream &Out); + + static StringRef input(StringRef Scalar, void *, char_16 &Val); + static bool mustQuote(StringRef S); +}; + +// This trait is used for UUIDs. It reads and writes them matching otool's +// formatting style. +typedef uint8_t uuid_t[16]; + +template <> struct ScalarTraits<uuid_t> { + static void output(const uuid_t &Val, void *, llvm::raw_ostream &Out); + + static StringRef input(StringRef Scalar, void *, uuid_t &Val); + static bool mustQuote(StringRef S); +}; + +// Load Command struct mapping traits + +#define LOAD_COMMAND_STRUCT(LCStruct) \ + template <> struct MappingTraits<MachO::LCStruct> { \ + static void mapping(IO &IO, MachO::LCStruct &LoadCommand); \ + }; + +#include "llvm/Support/MachO.def" + +// Extra structures used by load commands +template <> struct MappingTraits<MachO::dylib> { + static void mapping(IO &IO, MachO::dylib &LoadCommand); +}; + +template <> struct MappingTraits<MachO::fvmlib> { + static void mapping(IO &IO, MachO::fvmlib &LoadCommand); +}; + +template <> struct MappingTraits<MachO::section> { + static void mapping(IO &IO, MachO::section &LoadCommand); +}; + +template <> struct MappingTraits<MachO::section_64> { + static void mapping(IO &IO, MachO::section_64 &LoadCommand); +}; } // namespace llvm::yaml diff --git a/include/llvm/Support/MachO.def b/include/llvm/Support/MachO.def index 8827a60ca16..9ca6440dd82 100644 --- a/include/llvm/Support/MachO.def +++ b/include/llvm/Support/MachO.def @@ -11,9 +11,7 @@ // //,,,----------------------------------------------------------------------,,,// -#ifndef HANDLE_LOAD_COMMAND -#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) -#endif +#ifdef HANDLE_LOAD_COMMAND HANDLE_LOAD_COMMAND(LC_SEGMENT, 0x00000001u, segment_command) HANDLE_LOAD_COMMAND(LC_SYMTAB, 0x00000002u, symtab_command) @@ -65,3 +63,44 @@ HANDLE_LOAD_COMMAND(LC_LINKER_OPTION, 0x0000002Du, linker_option_command) HANDLE_LOAD_COMMAND(LC_LINKER_OPTIMIZATION_HINT, 0x0000002Eu, linkedit_data_command) HANDLE_LOAD_COMMAND(LC_VERSION_MIN_TVOS, 0x0000002Fu, version_min_command) HANDLE_LOAD_COMMAND(LC_VERSION_MIN_WATCHOS, 0x00000030u, version_min_command) + +#endif + +#ifdef LOAD_COMMAND_STRUCT + +LOAD_COMMAND_STRUCT(dyld_info_command) +LOAD_COMMAND_STRUCT(dylib_command) +LOAD_COMMAND_STRUCT(dylinker_command) +LOAD_COMMAND_STRUCT(dysymtab_command) +LOAD_COMMAND_STRUCT(encryption_info_command) +LOAD_COMMAND_STRUCT(encryption_info_command_64) +LOAD_COMMAND_STRUCT(entry_point_command) +LOAD_COMMAND_STRUCT(fvmfile_command) +LOAD_COMMAND_STRUCT(fvmlib_command) +LOAD_COMMAND_STRUCT(ident_command) +LOAD_COMMAND_STRUCT(linkedit_data_command) +LOAD_COMMAND_STRUCT(linker_option_command) +LOAD_COMMAND_STRUCT(load_command) +LOAD_COMMAND_STRUCT(prebind_cksum_command) +LOAD_COMMAND_STRUCT(prebound_dylib_command) +LOAD_COMMAND_STRUCT(routines_command) +LOAD_COMMAND_STRUCT(routines_command_64) +LOAD_COMMAND_STRUCT(rpath_command) +LOAD_COMMAND_STRUCT(segment_command) +LOAD_COMMAND_STRUCT(segment_command_64) +LOAD_COMMAND_STRUCT(source_version_command) +LOAD_COMMAND_STRUCT(sub_client_command) +LOAD_COMMAND_STRUCT(sub_framework_command) +LOAD_COMMAND_STRUCT(sub_library_command) +LOAD_COMMAND_STRUCT(sub_umbrella_command) +LOAD_COMMAND_STRUCT(symseg_command) +LOAD_COMMAND_STRUCT(symtab_command) +LOAD_COMMAND_STRUCT(thread_command) +LOAD_COMMAND_STRUCT(twolevel_hints_command) +LOAD_COMMAND_STRUCT(uuid_command) +LOAD_COMMAND_STRUCT(version_min_command) + +#endif + +#undef HANDLE_LOAD_COMMAND +#undef LOAD_COMMAND_STRUCT diff --git a/include/llvm/Support/MachO.h b/include/llvm/Support/MachO.h index 7b00cb66652..3dd161b4a7c 100644 --- a/include/llvm/Support/MachO.h +++ b/include/llvm/Support/MachO.h @@ -1677,6 +1677,13 @@ namespace llvm { const uint32_t x86_EXCEPTION_STATE_COUNT = sizeof(x86_exception_state_t) / sizeof(uint32_t); + // Define a union of all load command structs + #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data; + + union macho_load_command { + #include "llvm/Support/MachO.def" + }; + } // end namespace MachO } // end namespace llvm |