[lld] r315954 - COFF: Add resource files to linkrepro instead of the cvtres object file.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 16 16:15:04 PDT 2017
Author: pcc
Date: Mon Oct 16 16:15:04 2017
New Revision: 315954
URL: http://llvm.org/viewvc/llvm-project?rev=315954&view=rev
Log:
COFF: Add resource files to linkrepro instead of the cvtres object file.
Now that we have our own implementation of cvtres, we can add resource
files directly to the linkrepro.
Differential Revision: https://reviews.llvm.org/D38974
Added:
lld/trunk/test/COFF/linkrepro-res.test
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/Driver.h
lld/trunk/COFF/DriverUtils.cpp
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=315954&r1=315953&r2=315954&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Mon Oct 16 16:15:04 2017
@@ -113,16 +113,15 @@ MemoryBufferRef LinkerDriver::takeBuffer
void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> MB,
bool WholeArchive) {
MemoryBufferRef MBRef = takeBuffer(std::move(MB));
+ FilePaths.push_back(MBRef.getBufferIdentifier());
// File type is detected by contents, not by file extension.
- file_magic Magic = identify_magic(MBRef.getBuffer());
- if (Magic == file_magic::windows_resource) {
+ switch (identify_magic(MBRef.getBuffer())) {
+ case file_magic::windows_resource:
Resources.push_back(MBRef);
- return;
- }
+ break;
- FilePaths.push_back(MBRef.getBufferIdentifier());
- if (Magic == file_magic::archive) {
+ case file_magic::archive:
if (WholeArchive) {
std::unique_ptr<Archive> File =
check(Archive::create(MBRef),
@@ -133,19 +132,21 @@ void LinkerDriver::addBuffer(std::unique
return;
}
Symtab->addFile(make<ArchiveFile>(MBRef));
- return;
- }
+ break;
- if (Magic == file_magic::bitcode) {
+ case file_magic::bitcode:
Symtab->addFile(make<BitcodeFile>(MBRef));
- return;
- }
+ break;
- if (Magic == file_magic::coff_cl_gl_object)
+ case file_magic::coff_cl_gl_object:
error(MBRef.getBufferIdentifier() + ": is not a native COFF file. "
"Recompile without /GL");
- else
+ break;
+
+ default:
Symtab->addFile(make<ObjFile>(MBRef));
+ break;
+ }
}
void LinkerDriver::enqueuePath(StringRef Path, bool WholeArchive) {
@@ -1078,7 +1079,7 @@ void LinkerDriver::link(ArrayRef<const c
// WindowsResource to convert resource files to a regular COFF file,
// then link the resulting file normally.
if (!Resources.empty())
- addBuffer(convertResToCOFF(Resources), false);
+ Symtab->addFile(make<ObjFile>(convertResToCOFF(Resources)));
if (Tar)
Tar->append("response.txt",
Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=315954&r1=315953&r2=315954&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Mon Oct 16 16:15:04 2017
@@ -169,10 +169,8 @@ void assignExportOrdinals();
// incompatible objects.
void checkFailIfMismatch(StringRef Arg);
-// Convert Windows resource files (.res files) to a .obj file
-// using cvtres.exe.
-std::unique_ptr<MemoryBuffer>
-convertResToCOFF(const std::vector<MemoryBufferRef> &MBs);
+// Convert Windows resource files (.res files) to a .obj file.
+MemoryBufferRef convertResToCOFF(const std::vector<MemoryBufferRef> &MBs);
void runMSVCLinker(std::string Rsp, ArrayRef<StringRef> Objects);
Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=315954&r1=315953&r2=315954&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Mon Oct 16 16:15:04 2017
@@ -639,10 +639,8 @@ void checkFailIfMismatch(StringRef Arg)
Config->MustMatch[K] = V;
}
-// Convert Windows resource files (.res files) to a .obj file
-// using cvtres.exe.
-std::unique_ptr<MemoryBuffer>
-convertResToCOFF(const std::vector<MemoryBufferRef> &MBs) {
+// Convert Windows resource files (.res files) to a .obj file.
+MemoryBufferRef convertResToCOFF(const std::vector<MemoryBufferRef> &MBs) {
object::WindowsResourceParser Parser;
for (MemoryBufferRef MB : MBs) {
@@ -658,7 +656,10 @@ convertResToCOFF(const std::vector<Memor
llvm::object::writeWindowsResourceCOFF(Config->Machine, Parser);
if (!E)
fatal(errorToErrorCode(E.takeError()), "failed to write .res to COFF");
- return std::move(E.get());
+
+ MemoryBufferRef MBRef = **E;
+ make<std::unique_ptr<MemoryBuffer>>(std::move(*E)); // take ownership
+ return MBRef;
}
// Run MSVC link.exe for given in-memory object files.
Added: lld/trunk/test/COFF/linkrepro-res.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/linkrepro-res.test?rev=315954&view=auto
==============================================================================
--- lld/trunk/test/COFF/linkrepro-res.test (added)
+++ lld/trunk/test/COFF/linkrepro-res.test Mon Oct 16 16:15:04 2017
@@ -0,0 +1,12 @@
+# REQUIRES: x86, shell
+
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir/build
+# RUN: cd %t.dir/build
+# RUN: lld-link %p/Inputs/resource.res /subsystem:console /machine:x64 \
+# RUN: /entry:__ImageBase /linkrepro:. /out:%t.exe
+# RUN: tar xf repro.tar
+# RUN: diff %p/Inputs/resource.res repro/%:p/Inputs/resource.res
+# RUN: FileCheck %s --check-prefix=RSP < repro/response.txt
+
+# RSP: resource.res
More information about the llvm-commits
mailing list