diff options
author | Eric Beckmann <ecbeckmann@google.com> | 2017-07-05 19:04:33 +0000 |
---|---|---|
committer | Eric Beckmann <ecbeckmann@google.com> | 2017-07-05 19:04:33 +0000 |
commit | 0eafa581a3878c5fb52a513bb329fa82002e72da (patch) | |
tree | a9d93e77c93db71722fed0ba09b1bd745e1fa702 /lld/COFF/DriverUtils.cpp | |
parent | 36793a0ecf30a4382a1626ca8fdd76117b0c5945 (diff) | |
download | bcm5719-llvm-0eafa581a3878c5fb52a513bb329fa82002e72da.tar.gz bcm5719-llvm-0eafa581a3878c5fb52a513bb329fa82002e72da.zip |
Revert "Revert "Switch external cvtres.exe for llvm's own resource library.""
This reverts commit 165e578e47f1cd38191120aad23a9020fb5476dd.
Forgot to run tests on this.
llvm-svn: 307190
Diffstat (limited to 'lld/COFF/DriverUtils.cpp')
-rw-r--r-- | lld/COFF/DriverUtils.cpp | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index d4c72e7c1ca..1d2c8811386 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -21,6 +21,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Object/COFF.h" +#include "llvm/Object/WindowsResource.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/Option.h" @@ -595,40 +596,22 @@ void checkFailIfMismatch(StringRef Arg) { // using cvtres.exe. std::unique_ptr<MemoryBuffer> convertResToCOFF(const std::vector<MemoryBufferRef> &MBs) { - // Create an output file path. - TemporaryFile File("resource-file", "obj"); + object::WindowsResourceParser Parser; - // Execute cvtres.exe. - Executor E("cvtres.exe"); - E.add("/machine:" + machineToStr(Config->Machine)); - E.add("/readonly"); - E.add("/nologo"); - E.add("/out:" + Twine(File.Path)); - - // 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; - 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); + std::unique_ptr<object::Binary> Bin = check(object::createBinary(MB)); + object::WindowsResource *RF = dyn_cast<object::WindowsResource>(Bin.get()); + if (!RF) + fatal("cannot compile non-resource file as resource"); + if (auto EC = Parser.parse(RF)) + fatal(EC, "failed to parse .res file"); } - E.run(); - return File.getMemoryBuffer(); + Expected<std::unique_ptr<MemoryBuffer>> E = + llvm::object::writeWindowsResourceCOFF(Config->Machine, Parser); + if (!E) + fatal(errorToErrorCode(E.takeError()), "failed to write .res to COFF"); + return std::move(E.get()); } // Run MSVC link.exe for given in-memory object files. |