[lld] r307227 - Revert "Revert "Revert "Switch external cvtres.exe for llvm's own resource library."""

Eric Beckmann via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 5 16:46:06 PDT 2017


Author: ecbeckmann
Date: Wed Jul  5 16:46:06 2017
New Revision: 307227

URL: http://llvm.org/viewvc/llvm-project?rev=307227&view=rev
Log:
Revert "Revert "Revert "Switch external cvtres.exe for llvm's own resource library."""

This reverts commit ae21ee0b6cacbc1efaf4d42502e71da2f0eb45c3.

The initial revert was done in order to prevent ongoing errors on
chromium bots such as CrWinClangLLD.  However, this was done haphazardly
and I didn't realize there were test and compilation failures, so this
revert was reverted.  Now that those have been fixed, we can revert the
revert of the revert.

Modified:
    lld/trunk/COFF/DriverUtils.cpp
    lld/trunk/test/COFF/combined-resources.test
    lld/trunk/test/COFF/def-name.test
    lld/trunk/test/COFF/dll.test
    lld/trunk/test/COFF/dllimport-gc.test
    lld/trunk/test/COFF/manifestinput.test
    lld/trunk/test/COFF/noentry.test
    lld/trunk/test/COFF/out.test
    lld/trunk/test/COFF/resource.test
    lld/trunk/test/lit.cfg

Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Wed Jul  5 16:46:06 2017
@@ -21,7 +21,6 @@
 #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"
@@ -596,22 +595,40 @@ void checkFailIfMismatch(StringRef Arg)
 // using cvtres.exe.
 std::unique_ptr<MemoryBuffer>
 convertResToCOFF(const std::vector<MemoryBufferRef> &MBs) {
-  object::WindowsResourceParser Parser;
+  // Create an output file path.
+  TemporaryFile File("resource-file", "obj");
 
+  // 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) {
-    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");
+    // 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);
   }
 
-  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());
+  E.run();
+  return File.getMemoryBuffer();
 }
 
 // Run MSVC link.exe for given in-memory object files.

Modified: lld/trunk/test/COFF/combined-resources.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/combined-resources.test?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/test/COFF/combined-resources.test (original)
+++ lld/trunk/test/COFF/combined-resources.test Wed Jul  5 16:46:06 2017
@@ -4,6 +4,8 @@
 // > rc /fo combined-resources.res /nologo combined-resources.rc
 // > rc /fo combined-resources-2.res /nologo combined-resources-2.rc
 
+# REQUIRES: winres
+
 # RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
 # RUN: lld-link /out:%t.exe /entry:main %t.obj %p/Inputs/resource.res \
 # RUN:   %p/Inputs/combined-resources.res %p/Inputs/combined-resources-2.res

Modified: lld/trunk/test/COFF/def-name.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/def-name.test?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/test/COFF/def-name.test (original)
+++ lld/trunk/test/COFF/def-name.test Wed Jul  5 16:46:06 2017
@@ -1,3 +1,5 @@
+# REQUIRES: winres
+
 # RUN: rm -rf %t
 # RUN: mkdir -p %t
 # RUN: cd %t

Modified: lld/trunk/test/COFF/dll.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/dll.test?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/test/COFF/dll.test (original)
+++ lld/trunk/test/COFF/dll.test Wed Jul  5 16:46:06 2017
@@ -1,3 +1,5 @@
+# REQUIRES: winres
+
 # RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
 # RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
 # RUN:   /export:mangled

Modified: lld/trunk/test/COFF/dllimport-gc.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/dllimport-gc.test?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/test/COFF/dllimport-gc.test (original)
+++ lld/trunk/test/COFF/dllimport-gc.test Wed Jul  5 16:46:06 2017
@@ -1,3 +1,5 @@
+# REQUIRES: winres
+
 # RUN: yaml2obj < %p/Inputs/export.yaml > %t-lib.obj
 # RUN: lld-link /out:%t.dll /dll %t-lib.obj /implib:%t.lib /export:exportfn1
 

Modified: lld/trunk/test/COFF/manifestinput.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/manifestinput.test?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/test/COFF/manifestinput.test (original)
+++ lld/trunk/test/COFF/manifestinput.test Wed Jul  5 16:46:06 2017
@@ -1,4 +1,4 @@
-# REQUIRES: win_mt
+# REQUIRES: winres
 
 # RUN: yaml2obj %p/Inputs/ret42.yaml > %t.obj
 # RUN: lld-link /out:%t.exe /entry:main \

Modified: lld/trunk/test/COFF/noentry.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/noentry.test?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/test/COFF/noentry.test (original)
+++ lld/trunk/test/COFF/noentry.test Wed Jul  5 16:46:06 2017
@@ -1,3 +1,5 @@
+# REQUIRES: winres
+
 # RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
 # RUN: lld-link /out:%t.dll /dll %t.obj
 # RUN: llvm-readobj -file-headers %t.dll | FileCheck -check-prefix=ENTRY %s

Modified: lld/trunk/test/COFF/out.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/out.test?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/test/COFF/out.test (original)
+++ lld/trunk/test/COFF/out.test Wed Jul  5 16:46:06 2017
@@ -1,3 +1,4 @@
+# REQUIRES: winres
 # RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
 
 # RUN: mkdir -p %T/out/tmp

Modified: lld/trunk/test/COFF/resource.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/resource.test?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/test/COFF/resource.test (original)
+++ lld/trunk/test/COFF/resource.test Wed Jul  5 16:46:06 2017
@@ -1,3 +1,5 @@
+# REQUIRES: winres
+
 # RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
 # RUN: lld-link /out:%t.exe /entry:main %t.obj %p/Inputs/resource.res
 

Modified: lld/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/lit.cfg?rev=307227&r1=307226&r2=307227&view=diff
==============================================================================
--- lld/trunk/test/lit.cfg (original)
+++ lld/trunk/test/lit.cfg Wed Jul  5 16:46:06 2017
@@ -264,6 +264,8 @@ llvm_config_cmd.wait()
 # Set a fake constant version so that we get consitent output.
 config.environment['LLD_VERSION'] = 'LLD 1.0'
 
-# Check if the mt.exe Microsoft utility exists.
-if lit.util.which('mt.exe', config.environment['PATH']):
-    config.available_features.add('win_mt')
+# Check if Windows resource file compiler exists.
+cvtres = lit.util.which('cvtres', config.environment['PATH'])
+rc = lit.util.which('rc', config.environment['PATH'])
+if cvtres and rc:
+    config.available_features.add('winres')




More information about the llvm-commits mailing list