[lld] r259729 - Add support for -sdk_version cmdline option.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 3 15:39:05 PST 2016


Author: pete
Date: Wed Feb  3 17:39:05 2016
New Revision: 259729

URL: http://llvm.org/viewvc/llvm-project?rev=259729&view=rev
Log:
Add support for -sdk_version cmdline option.

This option is emitted in the min_version load commands.

Note, there's currently a difference in behaviour compared to ld64 in
that we emit a warning if we generate a min_version load command and
didn't give an sdk_version.  We need to decide what the correct behaviour
is here as its possible we want to emit an error and force clients to
provide the option.

Added:
    lld/trunk/test/mach-o/sdk-version-error.yaml
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/MachONormalizedFileFromAtoms.cpp
    lld/trunk/test/mach-o/version-min-load-command.yaml

Modified: lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h?rev=259729&r1=259728&r2=259729&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h Wed Feb  3 17:39:05 2016
@@ -166,6 +166,9 @@ public:
 
   uint32_t osMinVersion() const { return _osMinVersion; }
 
+  uint32_t sdkVersion() const { return _sdkVersion; }
+  void setSdkVersion(uint64_t v) { _sdkVersion = v; }
+
   uint32_t swiftVersion() const { return _swiftVersion; }
 
   /// \brief Checks whether a given path on the filesystem exists.
@@ -420,6 +423,7 @@ private:
   Arch _arch;
   OS _os;
   uint32_t _osMinVersion;
+  uint32_t _sdkVersion = 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=259729&r1=259728&r2=259729&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Wed Feb  3 17:39:05 2016
@@ -792,6 +792,26 @@ bool DarwinLdDriver::parse(llvm::ArrayRe
     }
   }
 
+  // Handle sdk_version
+  if (llvm::opt::Arg *arg = parsedArgs.getLastArg(OPT_sdk_version)) {
+    uint32_t sdkVersion = 0;
+    if (MachOLinkingContext::parsePackedVersion(arg->getValue(),
+                                                sdkVersion)) {
+      diagnostics << "error: malformed sdkVersion value\n";
+      return false;
+    }
+    ctx.setSdkVersion(sdkVersion);
+  } else if (ctx.generateVersionLoadCommand()) {
+    // If we don't have an sdk version, but were going to emit a load command
+    // with min_version, then we need to give an warning as we have no sdk
+    // version to put in that command.
+    // FIXME: We need to decide whether to make this an error.
+    diagnostics << "warning: -sdk_version is required when emitting "
+                   "min version load command.  "
+                   "Setting sdk version to match provided min version\n";
+    ctx.setSdkVersion(ctx.osMinVersion());
+  }
+
   // 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=259729&r1=259728&r2=259729&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdOptions.td (original)
+++ lld/trunk/lib/Driver/DarwinLdOptions.td Wed Feb  3 17:39:05 2016
@@ -33,6 +33,9 @@ def iphoneos_version_min : Separate<["-"
 def ios_simulator_version_min : Separate<["-"], "ios_simulator_version_min">,
      MetaVarName<"<version>">,
      HelpText<"Minimum iOS simulator version">, Group<grp_opts>;
+def sdk_version : Separate<["-"], "sdk_version">,
+     MetaVarName<"<version>">,
+     HelpText<"SDK 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/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=259729&r1=259728&r2=259729&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Wed Feb  3 17:39:05 2016
@@ -1248,7 +1248,7 @@ normalizedFromAtoms(const lld::File &ato
   normFile.minOSverson = context.osMinVersion();
   // FIXME: We need to get the SDK version from the system.  For now the min
   // OS version is better than nothing.
-  normFile.sdkVersion = context.osMinVersion();
+  normFile.sdkVersion = context.sdkVersion();
 
   if (context.generateVersionLoadCommand() &&
       context.os() != MachOLinkingContext::OS::unknown)

Added: lld/trunk/test/mach-o/sdk-version-error.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/sdk-version-error.yaml?rev=259729&view=auto
==============================================================================
--- lld/trunk/test/mach-o/sdk-version-error.yaml (added)
+++ lld/trunk/test/mach-o/sdk-version-error.yaml Wed Feb  3 17:39:05 2016
@@ -0,0 +1,22 @@
+# RUN: not lld -flavor darwin -arch x86_64 -sdk_version 10.blah %s -o %t 2>&1 | FileCheck %s --check-prefix=ERROR
+
+--- !mach-o
+arch:            x86_64
+file-type:       MH_OBJECT
+flags:           [ MH_SUBSECTIONS_VIA_SYMBOLS ]
+sections:
+  - segment:         __TEXT
+    section:         __text
+    type:            S_REGULAR
+    attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
+    address:         0x0000000000000000
+    content:         [ 0x00, 0x00, 0x00, 0x00 ]
+global-symbols:
+  - name:            _main
+    type:            N_SECT
+    scope:           [ N_EXT ]
+    sect:            1
+    value:           0x0000000000000000
+...
+
+# ERROR: malformed sdkVersion value
\ No newline at end of file

Modified: lld/trunk/test/mach-o/version-min-load-command.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/version-min-load-command.yaml?rev=259729&r1=259728&r2=259729&view=diff
==============================================================================
--- lld/trunk/test/mach-o/version-min-load-command.yaml (original)
+++ lld/trunk/test/mach-o/version-min-load-command.yaml Wed Feb  3 17:39:05 2016
@@ -1,9 +1,12 @@
 # RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t -dylib %p/Inputs/libSystem.yaml && llvm-objdump -private-headers %t | FileCheck %s
+# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t -dylib %p/Inputs/libSystem.yaml 2>&1 | FileCheck %s --check-prefix=WARNING
 # RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t -dylib %p/Inputs/libSystem.yaml -static -version_load_command && llvm-objdump -private-headers %t | FileCheck %s
 # RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t -dylib %p/Inputs/libSystem.yaml -no_version_load_command && llvm-objdump -private-headers %t | FileCheck %s --check-prefix=NO_VERSION_MIN
 # RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t -dylib %p/Inputs/libSystem.yaml -static -version_load_command -no_version_load_command && llvm-objdump -private-headers %t | FileCheck %s --check-prefix=NO_VERSION_MIN
 # RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t -dylib %p/Inputs/libSystem.yaml -static && llvm-objdump -private-headers %t | FileCheck %s --check-prefix=NO_VERSION_MIN
 
+# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -sdk_version 10.9 %s -o %t -dylib %p/Inputs/libSystem.yaml && llvm-objdump -private-headers %t | FileCheck %s --check-prefix=SDK_VERSION
+
 --- !mach-o
 arch:            x86_64
 file-type:       MH_OBJECT
@@ -29,4 +32,12 @@ global-symbols:
 # CHECK:   version 10.8
 # CHECK:   sdk 10.8
 
+# SDK_VERSION: Load command {{[0-9]*}}
+# SDK_VERSION:   cmd LC_VERSION_MIN_MACOSX
+# SDK_VERSION:   cmdsize 16
+# SDK_VERSION:   version 10.8
+# SDK_VERSION:   sdk 10.9
+
+# WARNING: warning: -sdk_version is required when emitting min version load command.  Setting sdk version to match provided min version
+
 # NO_VERSION_MIN-NOT: LC_VERSION_MIN_MACOSX




More information about the llvm-commits mailing list