From 54ce2958490fb41d5c8522e176e5bead0d0f310e Mon Sep 17 00:00:00 2001 From: Nick Kledzik Date: Tue, 28 Oct 2014 22:21:10 +0000 Subject: [PATCH] [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. llvm-svn: 220827 --- .../MachO/MachONormalizedFileBinaryWriter.cpp | 18 ++++++++++++++++++ lld/test/mach-o/parse-data-in-code-armv7.yaml | 10 ++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp index 275060d..543b60f 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(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 8fa9f2c..29b483e 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 -- 2.7.4