summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2016-05-20 17:20:42 +0000
committerChris Bieneman <beanz@apple.com>2016-05-20 17:20:42 +0000
commitbe70933d3c12db14670ed086f26148917b9e993c (patch)
tree5d37fb4256dc4293101b63baaf53b7631477f0f5
parentc537c8a72b0fe3e31bbbb13d9170c30012dddcb4 (diff)
downloadbcm5719-llvm-be70933d3c12db14670ed086f26148917b9e993c.tar.gz
bcm5719-llvm-be70933d3c12db14670ed086f26148917b9e993c.zip
[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. llvm-svn: 270239
-rw-r--r--llvm/include/llvm/ObjectYAML/MachOYAML.h1
-rw-r--r--llvm/include/llvm/Support/YAMLTraits.h7
-rw-r--r--llvm/test/ObjectYAML/MachO/bogus_load_command.yaml51
3 files changed, 56 insertions, 3 deletions
diff --git a/llvm/include/llvm/ObjectYAML/MachOYAML.h b/llvm/include/llvm/ObjectYAML/MachOYAML.h
index cb29c6dcd62..c9eb48a24c5 100644
--- a/llvm/include/llvm/ObjectYAML/MachOYAML.h
+++ b/llvm/include/llvm/ObjectYAML/MachOYAML.h
@@ -95,6 +95,7 @@ template <> struct MappingTraits<MachOYAML::Section> {
template <> struct ScalarEnumerationTraits<MachO::LoadCommandType> {
static void enumeration(IO &io, MachO::LoadCommandType &value) {
#include "llvm/Support/MachO.def"
+ io.enumFallback<Hex32>(value);
}
};
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index b332bdde83a..6f38a94d91b 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -510,11 +510,11 @@ public:
template <typename FBT, typename T>
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<typename FBT::BaseType>(Val);
yamlize(*this, Res, true);
- Val = (uint64_t)Res;
+ Val = static_cast<T>(static_cast<typename FBT::BaseType>(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/llvm/test/ObjectYAML/MachO/bogus_load_command.yaml b/llvm/test/ObjectYAML/MachO/bogus_load_command.yaml
new file mode 100644
index 00000000000..4809f41df37
--- /dev/null
+++ b/llvm/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
OpenPOWER on IntegriCloud