mirror of
https://github.com/intel/llvm.git
synced 2026-02-08 00:14:21 +08:00
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
This commit is contained in:
@@ -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) {
|
||||
|
||||
23
lld/test/mach-o/objc-image-info-host-vs-simulator.yaml
Normal file
23
lld/test/mach-o/objc-image-info-host-vs-simulator.yaml
Normal file
@@ -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
|
||||
23
lld/test/mach-o/objc-image-info-simulator-vs-host.yaml
Normal file
23
lld/test/mach-o/objc-image-info-simulator-vs-host.yaml
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user