[llvm] r278985 - [macho2yaml] Don't write empty linkedit data

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 17 14:46:04 PDT 2016


Author: cbieneman
Date: Wed Aug 17 16:46:04 2016
New Revision: 278985

URL: http://llvm.org/viewvc/llvm-project?rev=278985&view=rev
Log:
[macho2yaml] Don't write empty linkedit data

Since I stopped writing empty export tries it causes LinkEdit to potentially be completely empty which results in invalid yaml being generated.

To prevent this we skip linkedit data if it is empty.

Modified:
    llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h
    llvm/trunk/lib/ObjectYAML/MachOYAML.cpp
    llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml

Modified: llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h?rev=278985&r1=278984&r2=278985&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h Wed Aug 17 16:46:04 2016
@@ -100,6 +100,8 @@ struct LinkEditData {
   MachOYAML::ExportEntry ExportTrie;
   std::vector<NListEntry> NameList;
   std::vector<StringRef> StringTable;
+
+  bool isEmpty() const;
 };
 
 struct Object {

Modified: llvm/trunk/lib/ObjectYAML/MachOYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/MachOYAML.cpp?rev=278985&r1=278984&r2=278985&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/MachOYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/MachOYAML.cpp Wed Aug 17 16:46:04 2016
@@ -22,6 +22,10 @@ namespace llvm {
 
 MachOYAML::LoadCommand::~LoadCommand() {}
 
+bool MachOYAML::LinkEditData::isEmpty() const {
+  return 0 == RebaseOpcodes.size() + BindOpcodes.size() + WeakBindOpcodes.size() + LazyBindOpcodes.size() + ExportTrie.Children.size() + NameList.size() + StringTable.size();
+}
+
 namespace yaml {
 
 void ScalarTraits<char_16>::output(const char_16 &Val, void *,
@@ -95,7 +99,8 @@ void MappingTraits<MachOYAML::Object>::m
   IO.mapTag("!mach-o", true);
   IO.mapRequired("FileHeader", Object.Header);
   IO.mapOptional("LoadCommands", Object.LoadCommands);
-  IO.mapOptional("LinkEditData", Object.LinkEdit);
+  if(!Object.LinkEdit.isEmpty() || !IO.outputting())
+    IO.mapOptional("LinkEditData", Object.LinkEdit);
 
   if (IO.getContext() == &Object)
     IO.setContext(nullptr);

Modified: llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml?rev=278985&r1=278984&r2=278985&view=diff
==============================================================================
--- llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml (original)
+++ llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml Wed Aug 17 16:46:04 2016
@@ -49,3 +49,4 @@ LoadCommands:
 #CHECK:       - 0x0A
 #CHECK:       - 0x0B
 #CHECK:       - 0x0C
+#CHECK-NOT: LinkEditData:




More information about the llvm-commits mailing list