summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-11-15 21:25:20 +0000
committerRui Ueyama <ruiu@google.com>2016-11-15 21:25:20 +0000
commitc3dcf99441322c37eb3a7a013b92554622beb7a6 (patch)
tree905c3d9177c97334c31a1ce652f8e9d22f81b826
parent2a51748a5d0116bd8b54e0e99091574200cf6f11 (diff)
downloadbcm5719-llvm-c3dcf99441322c37eb3a7a013b92554622beb7a6.tar.gz
bcm5719-llvm-c3dcf99441322c37eb3a7a013b92554622beb7a6.zip
[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! llvm-svn: 287034
-rw-r--r--lld/COFF/DriverUtils.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index 7a1bf12d25b..c548bbac930 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -587,8 +587,29 @@ convertResToCOFF(const std::vector<MemoryBufferRef> &MBs) {
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();
}
OpenPOWER on IntegriCloud