[serialization] Reject loading a module with the wrong case.

Due to case-insensitive filesystems, "import foundation" can result in the
overlay module for Foundation being loaded. Everything is confused later on
because the (wrong) module name is used in manglings, leading to all sorts
of issues.

This is not the right fix for the problem, because a user really is allowed
to have modules named "foundation" and "FOUNDATION" and "Foundation" coexisting
on their system. To do that we'll want to check the actual case of a
.framework bundle or .swiftmodule file on disk and make sure it matches before
even trying to load the file. But this is a good sanity check anyway.

rdar://problem/15632996

Swift SVN r22818
This commit is contained in:
Jordan Rose
2014-10-17 21:48:03 +00:00
parent c371dd49dd
commit 5aa27cea08
8 changed files with 46 additions and 7 deletions

View File

@@ -504,7 +504,8 @@ ModuleFile::ModuleFile(
case CONTROL_BLOCK_ID: {
cursor.EnterSubBlock(CONTROL_BLOCK_ID);
ModuleStatus err = validateControlBlock(cursor, scratch).first;
ModuleStatus err;
std::tie(err, Name) = validateControlBlock(cursor, scratch);
if (err != ModuleStatus::Valid) {
error(err);
return;
@@ -746,6 +747,11 @@ bool ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc) {
assert(!FileContext && "already associated with an AST module");
FileContext = file;
if (file->getParentModule()->Name.str() != Name) {
error(ModuleStatus::NameMismatch);
return false;
}
ASTContext &ctx = getContext();
bool missingDependency = false;
for (auto &dependency : Dependencies) {
@@ -1091,8 +1097,7 @@ ModuleFile::collectLinkLibraries(Module::LinkLibraryCallback callback) const {
for (auto &lib : LinkLibraries)
callback(lib);
if (Bits.IsFramework)
callback(LinkLibrary(FileContext->getParentModule()->Name.str(),
LibraryKind::Framework));
callback(LinkLibrary(Name, LibraryKind::Framework));
}
void ModuleFile::getTopLevelDecls(SmallVectorImpl<Decl *> &results) {