[lld] r287034 - [COFF] Fix manifest resource file creation on Windows.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 15 13:25:20 PST 2016


Author: ruiu
Date: Tue Nov 15 15:25:20 2016
New Revision: 287034

URL: http://llvm.org/viewvc/llvm-project?rev=287034&view=rev
Log:
[COFF] Fix manifest resource file creation on Windows.

createManifestRes was generating a MemoryBuffer from a TemporaryFile,
keeping the data but removing the file, before passing the file path
to CVTRES.exe, leading to the following error:

  CVTRES : fatal error CVT1101: cannot open 'C:\Users\user\AppData\
  Local\Temp\lld-output-resource-bfee19.res' for reading

With this, we instead create a new TemporaryFile before passing it to cvtres.

Patch from Rudy Pons!

Modified:
    lld/trunk/COFF/DriverUtils.cpp

Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=287034&r1=287033&r2=287034&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Tue Nov 15 15:25:20 2016
@@ -587,8 +587,29 @@ convertResToCOFF(const std::vector<Memor
   E.add("/readonly");
   E.add("/nologo");
   E.add("/out:" + Twine(File.Path));
-  for (MemoryBufferRef MB : MBs)
-    E.add(MB.getBufferIdentifier());
+
+  // We must create new files because the memory buffers we have may have no
+  // underlying file still existing on the disk.
+  // It happens if it was created from a TemporaryFile, which usually delete
+  // the file just after creating the MemoryBuffer.
+  std::vector<TemporaryFile> ResFiles;
+  ResFiles.reserve(MBs.size());
+  for (MemoryBufferRef MB : MBs) {
+    // We store the temporary file in a vector to avoid deletion
+    // before running cvtres
+    ResFiles.emplace_back("resource-file", "res");
+    TemporaryFile& ResFile = ResFiles.back();
+    // Write the content of the resource in a temporary file
+    std::error_code EC;
+    llvm::raw_fd_ostream OS(ResFile.Path, EC, sys::fs::F_None);
+    if (EC)
+      fatal(EC, "failed to open " + ResFile.Path);
+    OS << MB.getBuffer();
+    OS.close();
+
+    E.add(ResFile.Path);
+  }
+
   E.run();
   return File.getMemoryBuffer();
 }




More information about the llvm-commits mailing list