[lld] r257964 - Add checking of differing swift versions in input files.
Pete Cooper via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 15 16:07:23 PST 2016
Author: pete
Date: Fri Jan 15 18:07:22 2016
New Revision: 257964
URL: http://llvm.org/viewvc/llvm-project?rev=257964&view=rev
Log:
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
Added:
lld/trunk/test/mach-o/Inputs/swift-version-1.yaml
lld/trunk/test/mach-o/objc-image-info-mismatched-swift-version.yaml
Modified:
lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
lld/trunk/lib/ReaderWriter/MachO/File.h
lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
Modified: lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h?rev=257964&r1=257963&r2=257964&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h Fri Jan 15 18:07:22 2016
@@ -398,6 +398,7 @@ private:
uint64_t _stackSize;
uint32_t _compatibilityVersion;
uint32_t _currentVersion;
+ uint32_t _swiftVersion;
StringRef _installName;
StringRefVector _rpaths;
bool _flatNamespace;
Modified: lld/trunk/lib/ReaderWriter/MachO/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/File.h?rev=257964&r1=257963&r2=257964&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/File.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/File.h Fri Jan 15 18:07:22 2016
@@ -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 {
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=257964&r1=257963&r2=257964&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Fri Jan 15 18:07:22 2016
@@ -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::han
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();
}
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=257964&r1=257963&r2=257964&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Fri Jan 15 18:07:22 2016
@@ -911,6 +911,9 @@ std::error_code parseObjCImageInfo(const
" 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();
}
Added: lld/trunk/test/mach-o/Inputs/swift-version-1.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/Inputs/swift-version-1.yaml?rev=257964&view=auto
==============================================================================
--- lld/trunk/test/mach-o/Inputs/swift-version-1.yaml (added)
+++ lld/trunk/test/mach-o/Inputs/swift-version-1.yaml Fri Jan 15 18:07:22 2016
@@ -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 ]
+...
Added: lld/trunk/test/mach-o/objc-image-info-mismatched-swift-version.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/objc-image-info-mismatched-swift-version.yaml?rev=257964&view=auto
==============================================================================
--- lld/trunk/test/mach-o/objc-image-info-mismatched-swift-version.yaml (added)
+++ lld/trunk/test/mach-o/objc-image-info-mismatched-swift-version.yaml Fri Jan 15 18:07:22 2016
@@ -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
More information about the llvm-commits
mailing list