summaryrefslogtreecommitdiff
path: root/lib/ObjectYAML/MachOYAML.cpp
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2016-05-19 20:54:43 +0000
committerChris Bieneman <beanz@apple.com>2016-05-19 20:54:43 +0000
commit09166ea25bee50c44b75a09b14c1e990fdc13996 (patch)
tree6613c222af04a097feb0cd00af33004dfbd41bcd /lib/ObjectYAML/MachOYAML.cpp
parentac5b9174b69b7ae5a3559a037615f758463cee0d (diff)
[obj2yaml] [yaml2obj] Support for MachO Load Command data
This re-applies r270115. Many of the MachO load commands can have data appended after the command structure. This data is frequently strings, but can actually be anything. This patch adds support for three optional fields on load command yaml descriptions. The new PayloadString YAML field is populated with the data after load commands known to have strings as extra data. The new ZeroPadBytes YAML field is a count of zero'd bytes after the end of the load command structure before the next command. This can apply anywhere in the file. MachO2YAML verifies that bytes are zero before populating this field, and YAML2MachO will add zero'd bytes. The new PayloadBytes YAML field stores all bytes after the end of the load command structure before the next command if they are non-zero. This is a catch all for all unhandled bytes. If MachO2Yaml populates PayloadBytes it will not populate ZeroPadBytes, instead zero'd bytes will be in the PayloadBytes structure. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270124 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ObjectYAML/MachOYAML.cpp')
-rw-r--r--lib/ObjectYAML/MachOYAML.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/ObjectYAML/MachOYAML.cpp b/lib/ObjectYAML/MachOYAML.cpp
index 2faefca432e..4111adefa76 100644
--- a/lib/ObjectYAML/MachOYAML.cpp
+++ b/lib/ObjectYAML/MachOYAML.cpp
@@ -96,6 +96,33 @@ void MappingTraits<MachOYAML::Object>::mapping(IO &IO,
IO.setContext(nullptr);
}
+template <typename StructType>
+void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand) {}
+
+template <>
+void mapLoadCommandData<MachO::segment_command>(
+ IO &IO, MachOYAML::LoadCommand &LoadCommand) {
+ IO.mapOptional("Sections", LoadCommand.Sections);
+}
+
+template <>
+void mapLoadCommandData<MachO::segment_command_64>(
+ IO &IO, MachOYAML::LoadCommand &LoadCommand) {
+ IO.mapOptional("Sections", LoadCommand.Sections);
+}
+
+template <>
+void mapLoadCommandData<MachO::dylib_command>(
+ IO &IO, MachOYAML::LoadCommand &LoadCommand) {
+ IO.mapOptional("PayloadString", LoadCommand.PayloadString);
+}
+
+template <>
+void mapLoadCommandData<MachO::dylinker_command>(
+ IO &IO, MachOYAML::LoadCommand &LoadCommand) {
+ IO.mapOptional("PayloadString", LoadCommand.PayloadString);
+}
+
void MappingTraits<MachOYAML::LoadCommand>::mapping(
IO &IO, MachOYAML::LoadCommand &LoadCommand) {
IO.mapRequired(
@@ -106,15 +133,14 @@ void MappingTraits<MachOYAML::LoadCommand>::mapping(
case MachO::LCName: \
MappingTraits<MachO::LCStruct>::mapping(IO, \
LoadCommand.Data.LCStruct##_data); \
+ mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand); \
break;
switch (LoadCommand.Data.load_command_data.cmd) {
#include "llvm/Support/MachO.def"
}
- if (LoadCommand.Data.load_command_data.cmd == MachO::LC_SEGMENT ||
- LoadCommand.Data.load_command_data.cmd == MachO::LC_SEGMENT_64) {
- IO.mapOptional("Sections", LoadCommand.Sections);
- }
+ IO.mapOptional("PayloadBytes", LoadCommand.PayloadBytes);
+ IO.mapOptional("ZeroPadBytes", LoadCommand.ZeroPadBytes, (uint64_t)0ull);
}
void MappingTraits<MachO::dyld_info_command>::mapping(