[mach-o] generate LC_DATA_IN_CODE in final linked images
authorNick Kledzik <kledzik@apple.com>
Tue, 28 Oct 2014 22:21:10 +0000 (22:21 +0000)
committerNick Kledzik <kledzik@apple.com>
Tue, 28 Oct 2014 22:21:10 +0000 (22:21 +0000)
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.

llvm-svn: 220827

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

index 275060d..543b60f 100644 (file)
@@ -415,6 +415,12 @@ uint32_t MachOFileLayout::loadCommandsSize(uint32_t &count) {
     ++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::writeLoadCommands() {
       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::writeLinkEditContent() {
     writeLazyBindingInfo();
     // TODO: add weak binding info
     writeExportInfo();
+    writeDataInCodeInfo();
     writeSymbolTable();
   }
 }
index 8fa9f2c..29b483e 100644 (file)
@@ -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