summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
diff options
context:
space:
mode:
authorEric Beckmann <ecbeckmann@google.com>2017-06-16 21:13:24 +0000
committerEric Beckmann <ecbeckmann@google.com>2017-06-16 21:13:24 +0000
commitd135e8c039757a839ab5c4f75dd7ca2eb82ae9f3 (patch)
treee298ac6fafb4ac1feee45b296891a4f8f7762f76 /llvm/tools/llvm-cvtres/llvm-cvtres.cpp
parent6bc14c65ad3e237cfb034ed569358f40e3b45318 (diff)
downloadbcm5719-llvm-d135e8c039757a839ab5c4f75dd7ca2eb82ae9f3.tar.gz
bcm5719-llvm-d135e8c039757a839ab5c4f75dd7ca2eb82ae9f3.zip
Switch external cvtres.exe for llvm's own resource library.
In this patch, I flip the switch in DriverUtils from using the external cvtres.exe tool to using the Windows Resource library in llvm. I also fixed a bug where .rsrc sections were marked as discardable memory and therefore were placed in the wrong order in the final PE. Furthermore, I modified WindowsResource to write the coff directly to a memory buffer instead of to file, also had it use the machine types already declared in COFF.h instead creating my own enum. Finally, I flipped the switch to allow all unit tests that had previously run only on windows due to a winres dependency to run cross-platform. Reviewers: zturner, ruiu Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D34265 llvm-svn: 305592
Diffstat (limited to 'llvm/tools/llvm-cvtres/llvm-cvtres.cpp')
-rw-r--r--llvm/tools/llvm-cvtres/llvm-cvtres.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
index 1e463399a59..4aaf455fa45 100644
--- a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -114,21 +114,21 @@ int main(int argc_, const char *argv_[]) {
bool Verbose = InputArgs.hasArg(OPT_VERBOSE);
- Machine MachineType;
+ COFF::MachineTypes MachineType;
if (InputArgs.hasArg(OPT_MACHINE)) {
std::string MachineString = InputArgs.getLastArgValue(OPT_MACHINE).upper();
- MachineType = StringSwitch<Machine>(MachineString)
- .Case("ARM", Machine::ARM)
- .Case("X64", Machine::X64)
- .Case("X86", Machine::X86)
- .Default(Machine::UNKNOWN);
- if (MachineType == Machine::UNKNOWN)
+ 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)
reportError("Unsupported machine architecture");
} else {
if (Verbose)
outs() << "Machine architecture not specified; assumed X64.\n";
- MachineType = Machine::X64;
+ MachineType = COFF::IMAGE_FILE_MACHINE_AMD64;
}
std::vector<std::string> InputFiles = InputArgs.getAllArgValues(OPT_INPUT);
@@ -149,10 +149,10 @@ int main(int argc_, const char *argv_[]) {
if (Verbose) {
outs() << "Machine: ";
switch (MachineType) {
- case Machine::ARM:
+ case COFF::IMAGE_FILE_MACHINE_ARMNT:
outs() << "ARM\n";
break;
- case Machine::X86:
+ case COFF::IMAGE_FILE_MACHINE_I386:
outs() << "X86\n";
break;
default:
@@ -196,8 +196,17 @@ int main(int argc_, const char *argv_[]) {
Parser.printTree(errs());
}
- error(
- llvm::object::writeWindowsResourceCOFF(OutputFile, MachineType, Parser));
+ std::unique_ptr<MemoryBuffer> OutputBuffer;
+ error(llvm::object::writeWindowsResourceCOFF(OutputBuffer, MachineType,
+ Parser));
+ auto FileOrErr =
+ FileOutputBuffer::create(OutputFile, OutputBuffer->getBufferSize());
+ if (!FileOrErr)
+ reportError(OutputFile, FileOrErr.getError());
+ std::unique_ptr<FileOutputBuffer> FileBuffer = std::move(*FileOrErr);
+ std::copy(OutputBuffer->getBufferStart(), OutputBuffer->getBufferEnd(),
+ FileBuffer->getBufferStart());
+ error(FileBuffer->commit());
if (Verbose) {
Expected<object::OwningBinary<object::Binary>> BinaryOrErr =
OpenPOWER on IntegriCloud