Skip to content

Commit dd4a0ba

Browse files
authored
Merge pull request swiftlang#33001 from xymus/swiftmodule-files-are-volatile
[Serialization] Load swiftmodule files as volatile to avoid mmap
2 parents f7820f5 + 0ede728 commit dd4a0ba

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,25 @@ std::error_code SerializedModuleLoaderBase::openModuleFile(
347347
}
348348

349349
// Actually load the file and error out if necessary.
350+
//
351+
// Use the default arguments except for IsVolatile. Force avoiding the use of
352+
// mmap to workaround issues on NFS when the swiftmodule file loaded changes
353+
// on disk while it's in use.
354+
//
355+
// In practice, a swiftmodule file can chane when a client uses a
356+
// swiftmodule file from a framework while the framework is recompiled and
357+
// installed over existing files. Or when many processes rebuild the same
358+
// module interface.
359+
//
360+
// We have seen these scenarios leading to deserialization errors that on
361+
// the surface look like memory corruption.
362+
//
363+
// rdar://63755989
350364
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ModuleOrErr =
351-
FS.getBufferForFile(ModulePath);
365+
FS.getBufferForFile(ModulePath,
366+
/*FileSize=*/-1,
367+
/*RequiresNullTerminator=*/true,
368+
/*IsVolatile=*/true);
352369
if (!ModuleOrErr)
353370
return ModuleOrErr.getError();
354371

0 commit comments

Comments
 (0)