summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2016-01-16 00:07:22 +0000
committerPete Cooper <peter_cooper@apple.com>2016-01-16 00:07:22 +0000
commita014ffef87a537524811b041ea6b88bec14eee50 (patch)
treeaf97f4b4f89a3b0dab63529c801257e963a671e5
parent628bc3ec00e487daefb7399e48d6364e7449a09e (diff)
downloadbcm5719-llvm-a014ffef87a537524811b041ea6b88bec14eee50.tar.gz
bcm5719-llvm-a014ffef87a537524811b041ea6b88bec14eee50.zip
Add checking of differing swift versions in input files.
Swift versions are part of the objc image info section, and must match for all files linked which actually have an image info section llvm-svn: 257964
-rw-r--r--lld/include/lld/ReaderWriter/MachOLinkingContext.h1
-rw-r--r--lld/lib/ReaderWriter/MachO/File.h4
-rw-r--r--lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp11
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp3
-rw-r--r--lld/test/mach-o/Inputs/swift-version-1.yaml18
-rw-r--r--lld/test/mach-o/objc-image-info-mismatched-swift-version.yaml20
6 files changed, 57 insertions, 0 deletions
diff --git a/lld/include/lld/ReaderWriter/MachOLinkingContext.h b/lld/include/lld/ReaderWriter/MachOLinkingContext.h
index 22274f4f618..671f4515e77 100644
--- a/lld/include/lld/ReaderWriter/MachOLinkingContext.h
+++ b/lld/include/lld/ReaderWriter/MachOLinkingContext.h
@@ -398,6 +398,7 @@ private:
uint64_t _stackSize;
uint32_t _compatibilityVersion;
uint32_t _currentVersion;
+ uint32_t _swiftVersion;
StringRef _installName;
StringRefVector _rpaths;
bool _flatNamespace;
diff --git a/lld/lib/ReaderWriter/MachO/File.h b/lld/lib/ReaderWriter/MachO/File.h
index 24e042ed3b5..c95b2da989a 100644
--- a/lld/lib/ReaderWriter/MachO/File.h
+++ b/lld/lib/ReaderWriter/MachO/File.h
@@ -194,6 +194,9 @@ public:
MachOLinkingContext::OS OS() const { return _os; }
void setOS(MachOLinkingContext::OS os) { _os = os; }
+ uint32_t swiftVersion() const { return _swiftVersion; }
+ void setSwiftVersion(uint32_t v) { _swiftVersion = v; }
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const File *F) {
return F->kind() == File::kindMachObject;
@@ -234,6 +237,7 @@ private:
NameToAtom _undefAtoms;
MachOLinkingContext::Arch _arch = MachOLinkingContext::arch_unknown;
MachOLinkingContext::OS _os = MachOLinkingContext::OS::unknown;
+ uint32_t _swiftVersion = 0;
};
class MachODylibFile : public SharedLibraryFile {
diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
index c129e9e529c..6987f7afb06 100644
--- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
@@ -145,6 +145,7 @@ MachOLinkingContext::MachOLinkingContext()
_doNothing(false), _pie(false), _arch(arch_unknown), _os(OS::macOSX),
_osMinVersion(0), _pageZeroSize(0), _pageSize(4096), _baseAddress(0),
_stackSize(0), _compatibilityVersion(0), _currentVersion(0),
+ _swiftVersion(0),
_flatNamespace(false), _undefinedMode(UndefinedMode::error),
_deadStrippableDylib(false), _printAtoms(false), _testingFileUsage(false),
_keepPrivateExterns(false), _demangle(false), _archHandler(nullptr),
@@ -1015,6 +1016,16 @@ std::error_code MachOLinkingContext::handleLoadedFile(File &file) {
return make_dynamic_error_code(file.path() +
Twine(" cannot be linked due to incompatible operating systems"));
}
+
+ // 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) {
+ _swiftVersion = machoFile->swiftVersion();
+ } else if (machoFile->swiftVersion() &&
+ machoFile->swiftVersion() != _swiftVersion) {
+ // Swift versions are different.
+ return make_dynamic_error_code("different swift versions");
+ }
return std::error_code();
}
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
index 770b58b2270..78c930bac0f 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
@@ -911,6 +911,9 @@ std::error_code parseObjCImageInfo(const NormalizedFile &normalizedFile,
" in file " + file.path() +
" should have version=0");
+ uint32_t flags = read32(content.data() + 4, isBig);
+ file.setSwiftVersion((flags >> 8) & 0xFF);
+
return std::error_code();
}
diff --git a/lld/test/mach-o/Inputs/swift-version-1.yaml b/lld/test/mach-o/Inputs/swift-version-1.yaml
new file mode 100644
index 00000000000..1337d7a1324
--- /dev/null
+++ b/lld/test/mach-o/Inputs/swift-version-1.yaml
@@ -0,0 +1,18 @@
+# RUN: not lld -flavor darwin -arch x86_64 -r %s %p/Inputs/hello-world-x86_64.yaml 2>&1 | FileCheck %s
+
+--- !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, 0x01, 0x00, 0x00 ]
+...
diff --git a/lld/test/mach-o/objc-image-info-mismatched-swift-version.yaml b/lld/test/mach-o/objc-image-info-mismatched-swift-version.yaml
new file mode 100644
index 00000000000..efb7c319285
--- /dev/null
+++ b/lld/test/mach-o/objc-image-info-mismatched-swift-version.yaml
@@ -0,0 +1,20 @@
+# RUN: not lld -flavor darwin -arch x86_64 -r %s %p/Inputs/swift-version-1.yaml 2>&1 | FileCheck %s
+
+--- !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, 0x02, 0x00, 0x00 ]
+...
+
+# CHECK: different swift versions \ No newline at end of file
OpenPOWER on IntegriCloud