[lld] r220827 - [mach-o] generate LC_DATA_IN_CODE in final linked images

Nick Kledzik kledzik at apple.com
Tue Oct 28 15:21:11 PDT 2014


Author: kledzik
Date: Tue Oct 28 17:21:10 2014
New Revision: 220827

URL: http://llvm.org/viewvc/llvm-project?rev=220827&view=rev
Log:
[mach-o] generate LC_DATA_IN_CODE in final linked images

lld was regenerating LC_DATA_IN_CODE in .o output files, but not into
final linked images.

Update test case to verify data-in-code info makes it into final linked images.

Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
    lld/trunk/test/mach-o/parse-data-in-code-armv7.yaml

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp?rev=220827&r1=220826&r2=220827&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp Tue Oct 28 17:21:10 2014
@@ -415,6 +415,12 @@ uint32_t MachOFileLayout::loadCommandsSi
     ++count;
   }
 
+  // Add LC_DATA_IN_CODE if needed
+  if (!_file.dataInCode.empty()) {
+    size += sizeof(linkedit_data_command);
+    ++count;
+  }
+
   return size;
 }
 
@@ -823,6 +829,17 @@ std::error_code MachOFileLayout::writeLo
       lc[sizeof(dylib_command)+dep.path.size()] = '\0';
       lc += size;
     }
+    // Add LC_DATA_IN_CODE if needed.
+    if (_dataInCodeSize != 0) {
+      linkedit_data_command* dl = reinterpret_cast<linkedit_data_command*>(lc);
+      dl->cmd      = LC_DATA_IN_CODE;
+      dl->cmdsize  = sizeof(linkedit_data_command);
+      dl->dataoff  = _startOfDataInCode;
+      dl->datasize = _dataInCodeSize;
+      if (_swap)
+        swapStruct(*dl);
+      lc += sizeof(linkedit_data_command);
+    }
   }
   return ec;
 }
@@ -1242,6 +1259,7 @@ void MachOFileLayout::writeLinkEditConte
     writeLazyBindingInfo();
     // TODO: add weak binding info
     writeExportInfo();
+    writeDataInCodeInfo();
     writeSymbolTable();
   }
 }

Modified: lld/trunk/test/mach-o/parse-data-in-code-armv7.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/parse-data-in-code-armv7.yaml?rev=220827&r1=220826&r2=220827&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-data-in-code-armv7.yaml (original)
+++ lld/trunk/test/mach-o/parse-data-in-code-armv7.yaml Tue Oct 28 17:21:10 2014
@@ -1,5 +1,7 @@
-# RUN: lld -flavor darwin -arch armv7 -r -print_atoms %s -o %t  | FileCheck %s \
-# RUN: && lld -flavor darwin -arch armv7 -r -print_atoms %t -o %t2  | FileCheck %s
+# RUN: lld -flavor darwin -arch armv7 -r -print_atoms %s -o %t  | FileCheck %s
+# RUN: lld -flavor darwin -arch armv7 -r -print_atoms %t -o %t2  | FileCheck %s
+# RUN: lld -flavor darwin -arch armv7 -dylib %s -o %t3.dylib %p/Inputs/libSystem.yaml \
+# RUN:   && llvm-objdump -macho -private-headers %t3.dylib | FileCheck --check-prefix=CHECK2 %s
 #
 # Test parsing LC_DATA_IN_CODE
 #
@@ -98,6 +100,10 @@ dataInCode:
 # CHECK:         offset:          20
 
 
+# CHECK2:      cmd LC_DATA_IN_CODE
+# CHECK2:  cmdsize 16
+# CHECK2: datasize 64
+
 
 #	.code	16
 #  .thumb_func	_foo_thumb





More information about the llvm-commits mailing list