diff options
| author | Pete Cooper <peter_cooper@apple.com> | 2016-01-19 19:46:41 +0000 |
|---|---|---|
| committer | Pete Cooper <peter_cooper@apple.com> | 2016-01-19 19:46:41 +0000 |
| commit | 0872e46c9d7e296fe3470cf1411e6c7fc49eee42 (patch) | |
| tree | a8f8997d0c18b00bb28ae222a86e34eaff68231b | |
| parent | d3112a5bcccfa0f93ab6c8bf5c45b65202b23573 (diff) | |
| download | bcm5719-llvm-0872e46c9d7e296fe3470cf1411e6c7fc49eee42.tar.gz bcm5719-llvm-0872e46c9d7e296fe3470cf1411e6c7fc49eee42.zip | |
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.
llvm-svn: 258173
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp | 35 | ||||
| -rw-r--r-- | lld/test/mach-o/objc-image-info-host-vs-simulator.yaml | 23 | ||||
| -rw-r--r-- | lld/test/mach-o/objc-image-info-simulator-vs-host.yaml | 23 |
3 files changed, 81 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 5fcc259a498..38c73d7a6be 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -1016,6 +1016,41 @@ std::error_code MachOLinkingContext::handleLoadedFile(File &file) { 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) { diff --git a/lld/test/mach-o/objc-image-info-host-vs-simulator.yaml b/lld/test/mach-o/objc-image-info-host-vs-simulator.yaml new file mode 100644 index 00000000000..f836a742327 --- /dev/null +++ b/lld/test/mach-o/objc-image-info-host-vs-simulator.yaml @@ -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 diff --git a/lld/test/mach-o/objc-image-info-simulator-vs-host.yaml b/lld/test/mach-o/objc-image-info-simulator-vs-host.yaml new file mode 100644 index 00000000000..c4f9bd58f96 --- /dev/null +++ b/lld/test/mach-o/objc-image-info-simulator-vs-host.yaml @@ -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 |

