[lld] r259746 - Add support for the source_version cmdline option.
Pete Cooper via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 3 18:45:24 PST 2016
Author: pete
Date: Wed Feb 3 20:45:23 2016
New Revision: 259746
URL: http://llvm.org/viewvc/llvm-project?rev=259746&view=rev
Log:
Add support for the source_version cmdline option.
This is of the form A.B.C.D.E and to match ld64's behaviour, is
always output to files, even when the version is 0.
rdar://problem/24472630
Modified:
lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
lld/trunk/lib/Driver/DarwinLdDriver.cpp
lld/trunk/lib/Driver/DarwinLdOptions.td
lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
Modified: lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h?rev=259746&r1=259745&r2=259746&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h Wed Feb 3 20:45:23 2016
@@ -169,6 +169,9 @@ public:
uint32_t sdkVersion() const { return _sdkVersion; }
void setSdkVersion(uint64_t v) { _sdkVersion = v; }
+ uint64_t sourceVersion() const { return _sourceVersion; }
+ void setSourceVersion(uint64_t v) { _sourceVersion = v; }
+
uint32_t swiftVersion() const { return _swiftVersion; }
/// \brief Checks whether a given path on the filesystem exists.
@@ -371,6 +374,10 @@ public:
/// bits are xxxx.yy.zz. Largest number is 65535.255.255
static bool parsePackedVersion(StringRef str, uint32_t &result);
+ /// Construct 64-bit value from string "A.B.C.D.E" where
+ /// bits are aaaa.bb.cc.dd.ee. Largest number is 16777215.1023.1023.1023.1023
+ static bool parsePackedVersion(StringRef str, uint64_t &result);
+
void finalizeInputFiles() override;
std::error_code handleLoadedFile(File &file) override;
@@ -424,6 +431,7 @@ private:
OS _os;
uint32_t _osMinVersion;
uint32_t _sdkVersion = 0;
+ uint64_t _sourceVersion = 0;
uint64_t _pageZeroSize;
uint64_t _pageSize;
uint64_t _baseAddress;
Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=259746&r1=259745&r2=259746&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Wed Feb 3 20:45:23 2016
@@ -812,6 +812,17 @@ bool DarwinLdDriver::parse(llvm::ArrayRe
ctx.setSdkVersion(ctx.osMinVersion());
}
+ // Handle source_version
+ if (llvm::opt::Arg *arg = parsedArgs.getLastArg(OPT_source_version)) {
+ uint64_t version = 0;
+ if (MachOLinkingContext::parsePackedVersion(arg->getValue(),
+ version)) {
+ diagnostics << "error: malformed source_version value\n";
+ return false;
+ }
+ ctx.setSourceVersion(version);
+ }
+
// Handle stack_size
if (llvm::opt::Arg *stackSize = parsedArgs.getLastArg(OPT_stack_size)) {
uint64_t stackSizeVal;
Modified: lld/trunk/lib/Driver/DarwinLdOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdOptions.td?rev=259746&r1=259745&r2=259746&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdOptions.td (original)
+++ lld/trunk/lib/Driver/DarwinLdOptions.td Wed Feb 3 20:45:23 2016
@@ -36,6 +36,9 @@ def ios_simulator_version_min : Separate
def sdk_version : Separate<["-"], "sdk_version">,
MetaVarName<"<version>">,
HelpText<"SDK version">, Group<grp_opts>;
+def source_version : Separate<["-"], "source_version">,
+ MetaVarName<"<version>">,
+ HelpText<"Source version">, Group<grp_opts>;
def version_load_command : Flag<["-"], "version_load_command">,
HelpText<"Force generation of a version load command">, Group<grp_opts>;
def no_version_load_command : Flag<["-"], "no_version_load_command">,
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=259746&r1=259745&r2=259746&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Wed Feb 3 20:45:23 2016
@@ -76,6 +76,35 @@ bool MachOLinkingContext::parsePackedVer
return false;
}
+bool MachOLinkingContext::parsePackedVersion(StringRef str, uint64_t &result) {
+ result = 0;
+
+ if (str.empty())
+ return false;
+
+ SmallVector<StringRef, 5> parts;
+ llvm::SplitString(str, parts, ".");
+
+ uint64_t num;
+ if (llvm::getAsUnsignedInteger(parts[0], 10, num))
+ return true;
+ if (num > 0xFFFFFF)
+ return true;
+ result = num << 40;
+
+ unsigned Shift = 30;
+ for (StringRef str : llvm::makeArrayRef(parts).slice(1)) {
+ if (llvm::getAsUnsignedInteger(str, 10, num))
+ return true;
+ if (num > 0x3FF)
+ return true;
+ result |= (num << Shift);
+ Shift -= 10;
+ }
+
+ return false;
+}
+
MachOLinkingContext::ArchInfo MachOLinkingContext::_s_archInfos[] = {
{ "x86_64", arch_x86_64, true, CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL },
{ "i386", arch_x86, true, CPU_TYPE_I386, CPU_SUBTYPE_X86_ALL },
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp?rev=259746&r1=259745&r2=259746&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp Wed Feb 3 20:45:23 2016
@@ -467,6 +467,10 @@ uint32_t MachOFileLayout::loadCommandsSi
++count;
}
+ // Add LC_SOURCE_VERSION
+ size += sizeof(source_version_command);
+ ++count;
+
// If main executable add LC_MAIN
if (_file.fileType == llvm::MachO::MH_EXECUTE) {
size += sizeof(entry_point_command);
@@ -915,6 +919,17 @@ std::error_code MachOFileLayout::writeLo
// LC_VERSION_MIN_TVOS
writeVersionMinLoadCommand(_file, _swap, lc);
+ // Add LC_SOURCE_VERSION
+ {
+ source_version_command* sv = reinterpret_cast<source_version_command*>(lc);
+ sv->cmd = LC_SOURCE_VERSION;
+ sv->cmdsize = sizeof(source_version_command);
+ sv->version = _file.sourceVersion;
+ if (_swap)
+ swapStruct(*sv);
+ lc += sizeof(source_version_command);
+ }
+
// If main executable, add LC_MAIN.
if (_file.fileType == llvm::MachO::MH_EXECUTE) {
// Build LC_MAIN load command.
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=259746&r1=259745&r2=259746&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Wed Feb 3 20:45:23 2016
@@ -1285,6 +1285,7 @@ normalizedFromAtoms(const lld::File &ato
normFile.minOSVersionKind = util.minVersionCommandType();
normFile.sdkVersion = context.sdkVersion();
+ normFile.sourceVersion = context.sourceVersion();
if (context.generateVersionLoadCommand() &&
context.os() != MachOLinkingContext::OS::unknown)
More information about the llvm-commits
mailing list