summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Beckmann <ecbeckmann@google.com>2017-07-05 18:59:16 +0000
committerEric Beckmann <ecbeckmann@google.com>2017-07-05 18:59:16 +0000
commit36793a0ecf30a4382a1626ca8fdd76117b0c5945 (patch)
treee3c196ab542f9db966975c2c57712afe77411a29
parent8cc9fd31e64981d2c1aaf71d7b05ea928ef499f6 (diff)
downloadbcm5719-llvm-36793a0ecf30a4382a1626ca8fdd76117b0c5945.tar.gz
bcm5719-llvm-36793a0ecf30a4382a1626ca8fdd76117b0c5945.zip
Revert "Switch external cvtres.exe for llvm's own resource library."
This reverts commit 600d52c278e123dd08bee24c1f00932b55add8de. This patch still seems to break CrWinClangLLD, reverting until I can find root problem. llvm-svn: 307189
-rw-r--r--lld/COFF/DriverUtils.cpp43
-rw-r--r--lld/test/COFF/def-name.test2
-rw-r--r--lld/test/COFF/dll.test2
-rw-r--r--lld/test/COFF/dllimport-gc.test2
-rw-r--r--lld/test/COFF/manifestinput.test2
-rw-r--r--lld/test/COFF/noentry.test2
-rw-r--r--lld/test/COFF/out.test1
-rw-r--r--lld/test/COFF/resource.test2
-rw-r--r--lld/test/lit.cfg8
-rw-r--r--llvm/include/llvm/Object/WindowsResource.h3
-rw-r--r--llvm/lib/Object/WindowsResource.cpp3
-rw-r--r--llvm/tools/llvm-cvtres/llvm-cvtres.cpp21
12 files changed, 61 insertions, 30 deletions
diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index 1d2c8811386..d4c72e7c1ca 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -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.
diff --git a/lld/test/COFF/def-name.test b/lld/test/COFF/def-name.test
index b971007eda3..c48424a1bff 100644
--- a/lld/test/COFF/def-name.test
+++ b/lld/test/COFF/def-name.test
@@ -1,3 +1,5 @@
+# REQUIRES: winres
+
# RUN: rm -rf %t
# RUN: mkdir -p %t
# RUN: cd %t
diff --git a/lld/test/COFF/dll.test b/lld/test/COFF/dll.test
index abd39f4eeb2..db4b4056552 100644
--- a/lld/test/COFF/dll.test
+++ b/lld/test/COFF/dll.test
@@ -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
diff --git a/lld/test/COFF/dllimport-gc.test b/lld/test/COFF/dllimport-gc.test
index d8523fbc7da..54ae773e793 100644
--- a/lld/test/COFF/dllimport-gc.test
+++ b/lld/test/COFF/dllimport-gc.test
@@ -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
diff --git a/lld/test/COFF/manifestinput.test b/lld/test/COFF/manifestinput.test
index 7fc37c98fc5..376d404d604 100644
--- a/lld/test/COFF/manifestinput.test
+++ b/lld/test/COFF/manifestinput.test
@@ -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 \
diff --git a/lld/test/COFF/noentry.test b/lld/test/COFF/noentry.test
index cc02c85e701..5e241e46e89 100644
--- a/lld/test/COFF/noentry.test
+++ b/lld/test/COFF/noentry.test
@@ -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
diff --git a/lld/test/COFF/out.test b/lld/test/COFF/out.test
index a7b56145996..67b2ef01b71 100644
--- a/lld/test/COFF/out.test
+++ b/lld/test/COFF/out.test
@@ -1,3 +1,4 @@
+# REQUIRES: winres
# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
# RUN: mkdir -p %T/out/tmp
diff --git a/lld/test/COFF/resource.test b/lld/test/COFF/resource.test
index 53242cdcb63..1d5219b0d9f 100644
--- a/lld/test/COFF/resource.test
+++ b/lld/test/COFF/resource.test
@@ -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
diff --git a/lld/test/lit.cfg b/lld/test/lit.cfg
index 83df50957be..486e83eb29e 100644
--- a/lld/test/lit.cfg
+++ b/lld/test/lit.cfg
@@ -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')
diff --git a/llvm/include/llvm/Object/WindowsResource.h b/llvm/include/llvm/Object/WindowsResource.h
index 844256478cf..1ef00e2909f 100644
--- a/llvm/include/llvm/Object/WindowsResource.h
+++ b/llvm/include/llvm/Object/WindowsResource.h
@@ -43,10 +43,13 @@
#include <map>
namespace llvm {
+
namespace object {
class WindowsResource;
+enum class Machine { UNKNOWN, ARM, X64, X86 };
+
class ResourceEntryRef {
public:
Error moveNext(bool &End);
diff --git a/llvm/lib/Object/WindowsResource.cpp b/llvm/lib/Object/WindowsResource.cpp
index f675a8389e6..7d1da37a634 100644
--- a/llvm/lib/Object/WindowsResource.cpp
+++ b/llvm/lib/Object/WindowsResource.cpp
@@ -328,7 +328,7 @@ private:
std::unique_ptr<MemoryBuffer> OutputBuffer;
char *BufferStart;
uint64_t CurrentOffset = 0;
- COFF::MachineTypes MachineType;
+ Machine MachineType;
const WindowsResourceParser::TreeNode &Resources;
const ArrayRef<std::vector<uint8_t>> Data;
uint64_t FileSize;
@@ -350,7 +350,6 @@ WindowsResourceCOFFWriter::WindowsResourceCOFFWriter(
: MachineType(MachineType), Resources(Parser.getTree()),
Data(Parser.getData()), StringTable(Parser.getStringTable()) {
performFileLayout();
-
OutputBuffer = MemoryBuffer::getNewMemBuffer(FileSize);
}
diff --git a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
index 36c15925e84..b331566d41c 100644
--- a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -120,21 +120,21 @@ int main(int argc_, const char *argv_[]) {
bool Verbose = InputArgs.hasArg(OPT_VERBOSE);
- COFF::MachineTypes MachineType;
+ Machine MachineType;
if (InputArgs.hasArg(OPT_MACHINE)) {
std::string MachineString = InputArgs.getLastArgValue(OPT_MACHINE).upper();
- MachineType = StringSwitch<COFF::MachineTypes>(MachineString)
- .Case("ARM", COFF::IMAGE_FILE_MACHINE_ARMNT)
- .Case("X64", COFF::IMAGE_FILE_MACHINE_AMD64)
- .Case("X86", COFF::IMAGE_FILE_MACHINE_I386)
- .Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
- if (MachineType == COFF::IMAGE_FILE_MACHINE_UNKNOWN)
+ MachineType = StringSwitch<Machine>(MachineString)
+ .Case("ARM", Machine::ARM)
+ .Case("X64", Machine::X64)
+ .Case("X86", Machine::X86)
+ .Default(Machine::UNKNOWN);
+ if (MachineType == Machine::UNKNOWN)
reportError("Unsupported machine architecture");
} else {
if (Verbose)
outs() << "Machine architecture not specified; assumed X64.\n";
- MachineType = COFF::IMAGE_FILE_MACHINE_AMD64;
+ MachineType = Machine::X64;
}
std::vector<std::string> InputFiles = InputArgs.getAllArgValues(OPT_INPUT);
@@ -155,10 +155,10 @@ int main(int argc_, const char *argv_[]) {
if (Verbose) {
outs() << "Machine: ";
switch (MachineType) {
- case COFF::IMAGE_FILE_MACHINE_ARMNT:
+ case Machine::ARM:
outs() << "ARM\n";
break;
- case COFF::IMAGE_FILE_MACHINE_I386:
+ case Machine::X86:
outs() << "X86\n";
break;
default:
@@ -207,7 +207,6 @@ int main(int argc_, const char *argv_[]) {
std::copy(OutputBuffer->getBufferStart(), OutputBuffer->getBufferEnd(),
FileBuffer->getBufferStart());
error(FileBuffer->commit());
-
if (Verbose) {
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(OutputFile);
if (!BinaryOrErr)
OpenPOWER on IntegriCloud