From 54530096e514cbeb78782dc8111dbf356b8e6aff Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Fri, 20 May 2016 17:20:42 +0000 Subject: [PATCH] [obj2yaml][yaml2obj] Adding enumFallback for MachO load commands This adds support for handling unknown load commands, and a bogus_load_command tests. Unknown or unsupported load commands can be specified in YAML by their hex value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270239 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ObjectYAML/MachOYAML.h | 1 + include/llvm/Support/YAMLTraits.h | 7 +-- test/ObjectYAML/MachO/bogus_load_command.yaml | 51 +++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 test/ObjectYAML/MachO/bogus_load_command.yaml diff --git a/include/llvm/ObjectYAML/MachOYAML.h b/include/llvm/ObjectYAML/MachOYAML.h index cb29c6dcd62..c9eb48a24c5 100644 --- a/include/llvm/ObjectYAML/MachOYAML.h +++ b/include/llvm/ObjectYAML/MachOYAML.h @@ -95,6 +95,7 @@ template <> struct MappingTraits { template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, MachO::LoadCommandType &value) { #include "llvm/Support/MachO.def" + io.enumFallback(value); } }; diff --git a/include/llvm/Support/YAMLTraits.h b/include/llvm/Support/YAMLTraits.h index b332bdde83a..6f38a94d91b 100644 --- a/include/llvm/Support/YAMLTraits.h +++ b/include/llvm/Support/YAMLTraits.h @@ -510,11 +510,11 @@ public: template void enumFallback(T &Val) { - if ( matchEnumFallback() ) { + if (matchEnumFallback()) { // FIXME: Force integral conversion to allow strong typedefs to convert. - FBT Res = (uint64_t)Val; + FBT Res = static_cast(Val); yamlize(*this, Res, true); - Val = (uint64_t)Res; + Val = static_cast(static_cast(Res)); } } @@ -1168,6 +1168,7 @@ private: bool operator==(const _base &rhs) const { return value == rhs; } \ bool operator<(const _type &rhs) const { return value < rhs.value; } \ _base value; \ + typedef _base BaseType; \ }; /// diff --git a/test/ObjectYAML/MachO/bogus_load_command.yaml b/test/ObjectYAML/MachO/bogus_load_command.yaml new file mode 100644 index 00000000000..4809f41df37 --- /dev/null +++ b/test/ObjectYAML/MachO/bogus_load_command.yaml @@ -0,0 +1,51 @@ +# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s + +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x01000007 + cpusubtype: 0x80000003 + filetype: 0x00000002 + ncmds: 2 + sizeofcmds: 56 + flags: 0x00218085 + reserved: 0x00000000 +LoadCommands: + - cmd: 0xDEADBEEF + cmdsize: 32 + ZeroPadBytes: 24 + - cmd: 0xDEADBEEF + cmdsize: 24 + PayloadBytes: + - 0x01 + - 0x02 + - 0x03 + - 0x04 + - 0x05 + - 0x06 + - 0x07 + - 0x08 + - 0x09 + - 0x0A + - 0x0B + - 0x0C +... + +#CHECK: - cmd: 0xDEADBEEF +#CHECK: cmdsize: 32 +#CHECK: ZeroPadBytes: +#CHECK: - cmd: 0xDEADBEEF +#CHECK: cmdsize: 24 +#CHECK: PayloadBytes: +#CHECK: - 0x01 +#CHECK: - 0x02 +#CHECK: - 0x03 +#CHECK: - 0x04 +#CHECK: - 0x05 +#CHECK: - 0x06 +#CHECK: - 0x07 +#CHECK: - 0x08 +#CHECK: - 0x09 +#CHECK: - 0x0A +#CHECK: - 0x0B +#CHECK: - 0x0C