[LLD][COFF] Fix pdb loading when the path points to a removable device
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>
Fri, 28 Sep 2018 21:53:40 +0000 (21:53 +0000)
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>
Fri, 28 Sep 2018 21:53:40 +0000 (21:53 +0000)
Differential Revision: https://reviews.llvm.org/D52666

llvm-svn: 343366

lld/COFF/PDB.cpp

index e25fb4e..80f0219 100644 (file)
@@ -351,6 +351,12 @@ Expected<const CVIndexMap&> PDBLinker::mergeDebugT(ObjFile *File,
 
 static Expected<std::unique_ptr<pdb::NativeSession>>
 tryToLoadPDB(const GUID &GuidFromObj, StringRef TSPath) {
+  // Ensure the file exists before anything else. We want to return ENOENT,
+  // "file not found", even if the path points to a removable device (in which
+  // case the return message would be EAGAIN, "resource unavailable try again")
+  if (!llvm::sys::fs::exists(TSPath))
+    return errorCodeToError(std::error_code(ENOENT, std::generic_category()));
+
   ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getFile(
       TSPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false);
   if (!MBOrErr)