[lld] r258173 - Set the objc constraint on the context based on the parsed files.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 19 11:46:43 PST 2016


Author: pete
Date: Tue Jan 19 13:46:41 2016
New Revision: 258173

URL: http://llvm.org/viewvc/llvm-project?rev=258173&view=rev
Log:
Set the objc constraint on the context based on the parsed files.

Like arch, os, etc, when we know we are going to use a file, we check
that the file has compatible objc constraints to the context, throw
appropriate errors where that is not the case, and hopefully set the
objc constraints on the context for use later.

Added 2 tests to ensure that we don't have incompatibilities between
host and simulator code as both will get x86 based architectures.

Added:
    lld/trunk/test/mach-o/objc-image-info-host-vs-simulator.yaml
    lld/trunk/test/mach-o/objc-image-info-simulator-vs-host.yaml
Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=258173&r1=258172&r2=258173&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Tue Jan 19 13:46:41 2016
@@ -1016,6 +1016,41 @@ std::error_code MachOLinkingContext::han
               Twine(" cannot be linked due to incompatible operating systems"));
   }
 
+  // Check that if the objc info exists, that it is compatible with the target
+  // OS.
+  switch (machoFile->objcConstraint()) {
+    case objc_unknown:
+      // The file is not compiled with objc, so skip the checks.
+      break;
+    case objc_gc_only:
+    case objc_supports_gc:
+      llvm_unreachable("GC support should already have thrown an error");
+    case objc_retainReleaseForSimulator:
+      // The file is built with simulator objc, so make sure that the context
+      // is also building with simulator support.
+      if (_os != OS::iOS_simulator)
+        return make_dynamic_error_code(file.path() +
+          Twine(" cannot be linked.  It contains ObjC built for the simulator"
+                " while we are linking a non-simulator target"));
+      assert((_objcConstraint == objc_unknown ||
+              _objcConstraint == objc_retainReleaseForSimulator) &&
+             "Must be linking with retain/release for the simulator");
+      _objcConstraint = objc_retainReleaseForSimulator;
+      break;
+    case objc_retainRelease:
+      // The file is built without simulator objc, so make sure that the
+      // context is also building without simulator support.
+      if (_os == OS::iOS_simulator)
+        return make_dynamic_error_code(file.path() +
+          Twine(" cannot be linked.  It contains ObjC built for a non-simulator"
+                " target while we are linking a simulator target"));
+      assert((_objcConstraint == objc_unknown ||
+              _objcConstraint == objc_retainRelease) &&
+             "Must be linking with retain/release for a non-simulator target");
+      _objcConstraint = objc_retainRelease;
+      break;
+  }
+
   // Check that the swift version of the context matches that of the file.
   // Also set the swift version of the context if it didn't have one.
   if (!_swiftVersion) {

Added: lld/trunk/test/mach-o/objc-image-info-host-vs-simulator.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/objc-image-info-host-vs-simulator.yaml?rev=258173&view=auto
==============================================================================
--- lld/trunk/test/mach-o/objc-image-info-host-vs-simulator.yaml (added)
+++ lld/trunk/test/mach-o/objc-image-info-host-vs-simulator.yaml Tue Jan 19 13:46:41 2016
@@ -0,0 +1,23 @@
+# RUN: not lld -flavor darwin -arch x86_64 -r %s 2>&1 | FileCheck %s
+
+# The file is built for the host, but the objc image info flags are for
+# the simulator.
+
+--- !mach-o
+arch:            x86_64
+file-type:       MH_OBJECT
+flags:           [ MH_SUBSECTIONS_VIA_SYMBOLS ]
+compat-version:  0.0
+current-version: 0.0
+has-UUID:        false
+OS:              unknown
+sections:
+  - segment:         __DATA
+    section:         __objc_imageinfo
+    type:            S_REGULAR
+    attributes:      [ S_ATTR_NO_DEAD_STRIP ]
+    address:         0x0000000000000100
+    content:         [ 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00 ]
+...
+
+# CHECK: {{.*}} cannot be linked.  It contains ObjC built for the simulator while we are linking a non-simulator target
\ No newline at end of file

Added: lld/trunk/test/mach-o/objc-image-info-simulator-vs-host.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/objc-image-info-simulator-vs-host.yaml?rev=258173&view=auto
==============================================================================
--- lld/trunk/test/mach-o/objc-image-info-simulator-vs-host.yaml (added)
+++ lld/trunk/test/mach-o/objc-image-info-simulator-vs-host.yaml Tue Jan 19 13:46:41 2016
@@ -0,0 +1,23 @@
+# RUN: not lld -flavor darwin -ios_simulator_version_min 5.0 -arch x86_64 -r %s 2>&1 | FileCheck %s
+
+# The file is built for the simulator, but the objc image info flags are for
+# the host.
+
+--- !mach-o
+arch:            x86_64
+file-type:       MH_OBJECT
+flags:           [ MH_SUBSECTIONS_VIA_SYMBOLS ]
+compat-version:  0.0
+current-version: 0.0
+has-UUID:        false
+OS:              unknown
+sections:
+  - segment:         __DATA
+    section:         __objc_imageinfo
+    type:            S_REGULAR
+    attributes:      [ S_ATTR_NO_DEAD_STRIP ]
+    address:         0x0000000000000100
+    content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
+...
+
+# CHECK: {{.*}} cannot be linked.  It contains ObjC built for a non-simulator target while we are linking a simulator target
\ No newline at end of file




More information about the llvm-commits mailing list