From 9b28a4559eb5c1f61501422c916469cc8f611fad Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Tue, 9 Feb 2016 02:10:39 +0000 Subject: Add cmdline options for LC_DATA_IN_CODE load command. Also added the defaults for whether to generate this load command, which the cmdline options are able to override. There was also a difference to ld64 which is fixed here in that ld64 will generate an empty data in code command if requested. rdar://problem/24472630 llvm-svn: 260191 --- .../MachO/MachONormalizedFileBinaryWriter.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp') diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp index d85920f7e19..34c48a500b9 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp @@ -288,7 +288,7 @@ MachOFileLayout::MachOFileLayout(const NormalizedFile &file) _endOfLoadCommands += sizeof(linkedit_data_command); _countOfLoadCommands++; } - if (!_file.dataInCode.empty()) { + if (_file.generateDataInCodeLoadCommand) { _endOfLoadCommands += sizeof(linkedit_data_command); _countOfLoadCommands++; } @@ -463,8 +463,9 @@ uint32_t MachOFileLayout::loadCommandsSize(uint32_t &count) { ++count; } - // Add LC_DATA_IN_CODE if needed - if (!_file.dataInCode.empty()) { + // Add LC_DATA_IN_CODE if requested. Note, we do encode zero length entries. + // FIXME: Zero length entries is only to match ld64. Should we change this? + if (_file.generateDataInCodeLoadCommand) { size += sizeof(linkedit_data_command); ++count; } @@ -810,8 +811,8 @@ std::error_code MachOFileLayout::writeLoadCommands() { lc += sizeof(linkedit_data_command); } - // Add LC_DATA_IN_CODE if needed. - if (_dataInCodeSize != 0) { + // Add LC_DATA_IN_CODE if requested. + if (_file.generateDataInCodeLoadCommand) { linkedit_data_command* dl = reinterpret_cast(lc); dl->cmd = LC_DATA_IN_CODE; dl->cmdsize = sizeof(linkedit_data_command); @@ -993,8 +994,8 @@ std::error_code MachOFileLayout::writeLoadCommands() { lc += sizeof(linkedit_data_command); } - // Add LC_DATA_IN_CODE if needed. - if (_dataInCodeSize != 0) { + // Add LC_DATA_IN_CODE if requested. + if (_file.generateDataInCodeLoadCommand) { linkedit_data_command* dl = reinterpret_cast(lc); dl->cmd = LC_DATA_IN_CODE; dl->cmdsize = sizeof(linkedit_data_command); -- cgit v1.2.3