diff options
author | Jim Grosbach <grosbach@apple.com> | 2014-03-18 22:09:05 +0000 |
---|---|---|
committer | Jim Grosbach <grosbach@apple.com> | 2014-03-18 22:09:05 +0000 |
commit | 448334a738408b08b9472f7ec15cc331f108e7bf (patch) | |
tree | 81f42e7bd67948b0eb8b56dad265a591d0aa533c /llvm/lib/MC/MachObjectWriter.cpp | |
parent | 79f91c595dc5eba449f3313e88ea0f2761566074 (diff) | |
download | bcm5719-llvm-448334a738408b08b9472f7ec15cc331f108e7bf.tar.gz bcm5719-llvm-448334a738408b08b9472f7ec15cc331f108e7bf.zip |
Darwin: Add assembler directives to create version-min load commands.
Allow object files to be tagged with a version-min load command for iOS
or MacOSX.
Teach macho-dump to understand the version-min load commands for
testcases.
rdar://11337778
llvm-svn: 204190
Diffstat (limited to 'llvm/lib/MC/MachObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/MachObjectWriter.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index b3b593d3154..ff55c978d6a 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -737,6 +737,8 @@ IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, void MachObjectWriter::WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) { unsigned NumSections = Asm.size(); + const MCAssembler::VersionMinInfoType &VersionInfo = + Layout.getAssembler().getVersionMinInfo(); // The section data starts after the header, the segment load command (and // section headers) and the symbol table. @@ -745,6 +747,12 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm, sizeof(MachO::segment_command_64) + NumSections * sizeof(MachO::section_64): sizeof(MachO::segment_command) + NumSections * sizeof(MachO::section); + // Add the deployment target version info load command size, if used. + if (VersionInfo.Major != 0) { + ++NumLoadCommands; + LoadCommandsSize += sizeof(MachO::version_min_command); + } + // Add the data-in-code load command size, if used. unsigned NumDataRegions = Asm.getDataRegions().size(); if (NumDataRegions) { @@ -817,6 +825,20 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm, RelocTableEnd += NumRelocs * sizeof(MachO::any_relocation_info); } + // Write out the deployment target information, if it's available. + if (VersionInfo.Major != 0) { + assert(VersionInfo.Update < 256 && "unencodable update target version"); + assert(VersionInfo.Minor < 256 && "unencodable minor target version"); + assert(VersionInfo.Major < 65536 && "unencodable major target version"); + uint32_t EncodedVersion = VersionInfo.Update | (VersionInfo.Minor << 8) | + (VersionInfo.Major << 16); + Write32(VersionInfo.Kind == MCVM_OSXVersionMin ? MachO::LC_VERSION_MIN_MACOSX : + MachO::LC_VERSION_MIN_IPHONEOS); + Write32(sizeof(MachO::version_min_command)); + Write32(EncodedVersion); + Write32(0); // reserved. + } + // Write the data-in-code load command, if used. uint64_t DataInCodeTableEnd = RelocTableEnd + NumDataRegions * 8; if (NumDataRegions) { |