mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-16 20:41:44 +00:00
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. llvm-svn: 307227
This commit is contained in:
parent
81979b038f
commit
f6090b620e
@ -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.
|
||||
|
@ -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
|
||||
|
@ -1,3 +1,5 @@
|
||||
# REQUIRES: winres
|
||||
|
||||
# RUN: rm -rf %t
|
||||
# RUN: mkdir -p %t
|
||||
# RUN: cd %t
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 \
|
||||
|
@ -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
|
||||
|
@ -1,3 +1,4 @@
|
||||
# REQUIRES: winres
|
||||
# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
|
||||
|
||||
# RUN: mkdir -p %T/out/tmp
|
||||
|
@ -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
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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);
|
||||
|
@ -350,7 +350,6 @@ WindowsResourceCOFFWriter::WindowsResourceCOFFWriter(
|
||||
: MachineType(MachineType), Resources(Parser.getTree()),
|
||||
Data(Parser.getData()), StringTable(Parser.getStringTable()) {
|
||||
performFileLayout();
|
||||
|
||||
OutputBuffer = MemoryBuffer::getNewMemBuffer(FileSize);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user