summaryrefslogtreecommitdiffstats
path: root/lld
diff options
context:
space:
mode:
Diffstat (limited to 'lld')
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp18
-rw-r--r--lld/test/mach-o/parse-data-in-code-armv7.yaml10
2 files changed, 26 insertions, 2 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
index 275060d57ee..543b60fe8bc 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
@@ -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();
}
}
diff --git a/lld/test/mach-o/parse-data-in-code-armv7.yaml b/lld/test/mach-o/parse-data-in-code-armv7.yaml
index 8fa9f2ce1a3..29b483e7d72 100644
--- a/lld/test/mach-o/parse-data-in-code-armv7.yaml
+++ b/lld/test/mach-o/parse-data-in-code-armv7.yaml
@@ -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
OpenPOWER on IntegriCloud