Skip to content

Commit 0eafa58

Browse files
author
Eric Beckmann
committed
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
1 parent 36793a0 commit 0eafa58

File tree

12 files changed

+30
-61
lines changed

12 files changed

+30
-61
lines changed

lld/COFF/DriverUtils.cpp

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ADT/Optional.h"
2222
#include "llvm/ADT/StringSwitch.h"
2323
#include "llvm/Object/COFF.h"
24+
#include "llvm/Object/WindowsResource.h"
2425
#include "llvm/Option/Arg.h"
2526
#include "llvm/Option/ArgList.h"
2627
#include "llvm/Option/Option.h"
@@ -595,40 +596,22 @@ void checkFailIfMismatch(StringRef Arg) {
595596
// using cvtres.exe.
596597
std::unique_ptr<MemoryBuffer>
597598
convertResToCOFF(const std::vector<MemoryBufferRef> &MBs) {
598-
// Create an output file path.
599-
TemporaryFile File("resource-file", "obj");
599+
object::WindowsResourceParser Parser;
600600

601-
// Execute cvtres.exe.
602-
Executor E("cvtres.exe");
603-
E.add("/machine:" + machineToStr(Config->Machine));
604-
E.add("/readonly");
605-
E.add("/nologo");
606-
E.add("/out:" + Twine(File.Path));
607-
608-
// We must create new files because the memory buffers we have may have no
609-
// underlying file still existing on the disk.
610-
// It happens if it was created from a TemporaryFile, which usually delete
611-
// the file just after creating the MemoryBuffer.
612-
std::vector<TemporaryFile> ResFiles;
613-
ResFiles.reserve(MBs.size());
614601
for (MemoryBufferRef MB : MBs) {
615-
// We store the temporary file in a vector to avoid deletion
616-
// before running cvtres
617-
ResFiles.emplace_back("resource-file", "res");
618-
TemporaryFile& ResFile = ResFiles.back();
619-
// Write the content of the resource in a temporary file
620-
std::error_code EC;
621-
raw_fd_ostream OS(ResFile.Path, EC, sys::fs::F_None);
622-
if (EC)
623-
fatal(EC, "failed to open " + ResFile.Path);
624-
OS << MB.getBuffer();
625-
OS.close();
626-
627-
E.add(ResFile.Path);
602+
std::unique_ptr<object::Binary> Bin = check(object::createBinary(MB));
603+
object::WindowsResource *RF = dyn_cast<object::WindowsResource>(Bin.get());
604+
if (!RF)
605+
fatal("cannot compile non-resource file as resource");
606+
if (auto EC = Parser.parse(RF))
607+
fatal(EC, "failed to parse .res file");
628608
}
629609

630-
E.run();
631-
return File.getMemoryBuffer();
610+
Expected<std::unique_ptr<MemoryBuffer>> E =
611+
llvm::object::writeWindowsResourceCOFF(Config->Machine, Parser);
612+
if (!E)
613+
fatal(errorToErrorCode(E.takeError()), "failed to write .res to COFF");
614+
return std::move(E.get());
632615
}
633616

634617
// Run MSVC link.exe for given in-memory object files.

lld/test/COFF/def-name.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# REQUIRES: winres
2-
31
# RUN: rm -rf %t
42
# RUN: mkdir -p %t
53
# RUN: cd %t

lld/test/COFF/dll.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# REQUIRES: winres
2-
31
# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
42
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
53
# RUN: /export:mangled

lld/test/COFF/dllimport-gc.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# REQUIRES: winres
2-
31
# RUN: yaml2obj < %p/Inputs/export.yaml > %t-lib.obj
42
# RUN: lld-link /out:%t.dll /dll %t-lib.obj /implib:%t.lib /export:exportfn1
53

lld/test/COFF/manifestinput.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# REQUIRES: winres
1+
# REQUIRES: win_mt
22

33
# RUN: yaml2obj %p/Inputs/ret42.yaml > %t.obj
44
# RUN: lld-link /out:%t.exe /entry:main \

lld/test/COFF/noentry.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# REQUIRES: winres
2-
31
# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
42
# RUN: lld-link /out:%t.dll /dll %t.obj
53
# RUN: llvm-readobj -file-headers %t.dll | FileCheck -check-prefix=ENTRY %s

lld/test/COFF/out.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# REQUIRES: winres
21
# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
32

43
# RUN: mkdir -p %T/out/tmp

lld/test/COFF/resource.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# REQUIRES: winres
2-
31
# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
42
# RUN: lld-link /out:%t.exe /entry:main %t.obj %p/Inputs/resource.res
53

lld/test/lit.cfg

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ llvm_config_cmd.wait()
264264
# Set a fake constant version so that we get consitent output.
265265
config.environment['LLD_VERSION'] = 'LLD 1.0'
266266

267-
# Check if Windows resource file compiler exists.
268-
cvtres = lit.util.which('cvtres', config.environment['PATH'])
269-
rc = lit.util.which('rc', config.environment['PATH'])
270-
if cvtres and rc:
271-
config.available_features.add('winres')
267+
# Check if the mt.exe Microsoft utility exists.
268+
if lit.util.which('mt.exe', config.environment['PATH']):
269+
config.available_features.add('win_mt')

llvm/include/llvm/Object/WindowsResource.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@
4343
#include <map>
4444

4545
namespace llvm {
46-
4746
namespace object {
4847

4948
class WindowsResource;
5049

51-
enum class Machine { UNKNOWN, ARM, X64, X86 };
52-
5350
class ResourceEntryRef {
5451
public:
5552
Error moveNext(bool &End);

llvm/lib/Object/WindowsResource.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ class WindowsResourceCOFFWriter {
328328
std::unique_ptr<MemoryBuffer> OutputBuffer;
329329
char *BufferStart;
330330
uint64_t CurrentOffset = 0;
331-
Machine MachineType;
331+
COFF::MachineTypes MachineType;
332332
const WindowsResourceParser::TreeNode &Resources;
333333
const ArrayRef<std::vector<uint8_t>> Data;
334334
uint64_t FileSize;
@@ -350,6 +350,7 @@ WindowsResourceCOFFWriter::WindowsResourceCOFFWriter(
350350
: MachineType(MachineType), Resources(Parser.getTree()),
351351
Data(Parser.getData()), StringTable(Parser.getStringTable()) {
352352
performFileLayout();
353+
353354
OutputBuffer = MemoryBuffer::getNewMemBuffer(FileSize);
354355
}
355356

llvm/tools/llvm-cvtres/llvm-cvtres.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ int main(int argc_, const char *argv_[]) {
120120

121121
bool Verbose = InputArgs.hasArg(OPT_VERBOSE);
122122

123-
Machine MachineType;
123+
COFF::MachineTypes MachineType;
124124

125125
if (InputArgs.hasArg(OPT_MACHINE)) {
126126
std::string MachineString = InputArgs.getLastArgValue(OPT_MACHINE).upper();
127-
MachineType = StringSwitch<Machine>(MachineString)
128-
.Case("ARM", Machine::ARM)
129-
.Case("X64", Machine::X64)
130-
.Case("X86", Machine::X86)
131-
.Default(Machine::UNKNOWN);
132-
if (MachineType == Machine::UNKNOWN)
127+
MachineType = StringSwitch<COFF::MachineTypes>(MachineString)
128+
.Case("ARM", COFF::IMAGE_FILE_MACHINE_ARMNT)
129+
.Case("X64", COFF::IMAGE_FILE_MACHINE_AMD64)
130+
.Case("X86", COFF::IMAGE_FILE_MACHINE_I386)
131+
.Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
132+
if (MachineType == COFF::IMAGE_FILE_MACHINE_UNKNOWN)
133133
reportError("Unsupported machine architecture");
134134
} else {
135135
if (Verbose)
136136
outs() << "Machine architecture not specified; assumed X64.\n";
137-
MachineType = Machine::X64;
137+
MachineType = COFF::IMAGE_FILE_MACHINE_AMD64;
138138
}
139139

140140
std::vector<std::string> InputFiles = InputArgs.getAllArgValues(OPT_INPUT);
@@ -155,10 +155,10 @@ int main(int argc_, const char *argv_[]) {
155155
if (Verbose) {
156156
outs() << "Machine: ";
157157
switch (MachineType) {
158-
case Machine::ARM:
158+
case COFF::IMAGE_FILE_MACHINE_ARMNT:
159159
outs() << "ARM\n";
160160
break;
161-
case Machine::X86:
161+
case COFF::IMAGE_FILE_MACHINE_I386:
162162
outs() << "X86\n";
163163
break;
164164
default:
@@ -207,6 +207,7 @@ int main(int argc_, const char *argv_[]) {
207207
std::copy(OutputBuffer->getBufferStart(), OutputBuffer->getBufferEnd(),
208208
FileBuffer->getBufferStart());
209209
error(FileBuffer->commit());
210+
210211
if (Verbose) {
211212
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(OutputFile);
212213
if (!BinaryOrErr)

0 commit comments

Comments
 (0)