[lld] r295913 - Fix /msvclto.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 22 16:26:42 PST 2017
Author: ruiu
Date: Wed Feb 22 18:26:42 2017
New Revision: 295913
URL: http://llvm.org/viewvc/llvm-project?rev=295913&view=rev
Log:
Fix /msvclto.
Previously, bitcode files in library paths were passed to the MSVC linker.
This patch strips them.
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/Driver.h
lld/trunk/COFF/DriverUtils.cpp
lld/trunk/test/COFF/msvclto.ll
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=295913&r1=295912&r2=295913&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Feb 22 18:26:42 2017
@@ -422,6 +422,46 @@ static std::string getMapFile(const opt:
return (OutFile.substr(0, OutFile.rfind('.')) + ".map").str();
}
+static bool isBitcodeFile(StringRef Path) {
+ std::unique_ptr<MemoryBuffer> MB = check(
+ MemoryBuffer::getFile(Path, -1, false, true), "could not open " + Path);
+ StringRef Buf = MB->getBuffer();
+ return sys::fs::identify_magic(Buf) == sys::fs::file_magic::bitcode;
+}
+
+// Create response file contents and invoke the MSVC linker.
+void LinkerDriver::invokeMSVC(opt::InputArgList &Args) {
+ std::string Rsp = "/nologo ";
+
+ for (auto *Arg : Args) {
+ switch (Arg->getOption().getID()) {
+ case OPT_linkrepro:
+ case OPT_lldmap:
+ case OPT_lldmap_file:
+ case OPT_msvclto:
+ // LLD-specific options are stripped.
+ break;
+ case OPT_opt:
+ if (!StringRef(Arg->getValue()).startswith("lld"))
+ Rsp += toString(Arg) + " ";
+ break;
+ case OPT_INPUT:
+ // Bitcode files are stripped as they've been compiled to
+ // native object files.
+ if (Optional<StringRef> Path = doFindFile(Arg->getValue()))
+ if (isBitcodeFile(*Path))
+ break;
+ Rsp += quote(Arg->getValue()) + " ";
+ break;
+ default:
+ Rsp += toString(Arg) + " ";
+ }
+ }
+
+ std::vector<StringRef> ObjectFiles = Symtab.compileBitcodeFiles();
+ runMSVCLinker(Rsp, ObjectFiles);
+}
+
void LinkerDriver::enqueueTask(std::function<void()> Task) {
TaskQueue.push_back(std::move(Task));
}
@@ -820,8 +860,7 @@ void LinkerDriver::link(ArrayRef<const c
// If /msvclto is given, we use the MSVC linker to link LTO output files.
// This is useful because MSVC link.exe can generate complete PDBs.
if (Args.hasArg(OPT_msvclto)) {
- std::vector<StringRef> ObjectFiles = Symtab.compileBitcodeFiles();
- runMSVCLinker(Args, ObjectFiles);
+ invokeMSVC(Args);
exit(0);
}
Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=295913&r1=295912&r2=295913&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Wed Feb 22 18:26:42 2017
@@ -107,6 +107,8 @@ private:
StringRef findDefaultEntry();
WindowsSubsystem inferSubsystem();
+ void invokeMSVC(llvm::opt::InputArgList &Args);
+
MemoryBufferRef takeBuffer(std::unique_ptr<MemoryBuffer> MB);
void addBuffer(std::unique_ptr<MemoryBuffer> MB);
void addArchiveBuffer(MemoryBufferRef MBRef, StringRef SymName,
@@ -178,7 +180,7 @@ void checkFailIfMismatch(StringRef Arg);
std::unique_ptr<MemoryBuffer>
convertResToCOFF(const std::vector<MemoryBufferRef> &MBs);
-void runMSVCLinker(llvm::opt::InputArgList &Args, ArrayRef<StringRef> Objects);
+void runMSVCLinker(std::string Rsp, ArrayRef<StringRef> Objects);
// Create enum with OPT_xxx values for each option in Options.td
enum {
Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=295913&r1=295912&r2=295913&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Wed Feb 22 18:26:42 2017
@@ -626,48 +626,15 @@ convertResToCOFF(const std::vector<Memor
return File.getMemoryBuffer();
}
-static bool isBitcodeFile(StringRef Path) {
- std::unique_ptr<MemoryBuffer> MB = check(
- MemoryBuffer::getFile(Path, -1, false, true), "could not open " + Path);
- StringRef Buf = MB->getBuffer();
- return sys::fs::identify_magic(Buf) == sys::fs::file_magic::bitcode;
-}
-
// Run MSVC link.exe for given in-memory object files.
// Command line options are copied from those given to LLD.
// This is for the /msvclto option.
-void runMSVCLinker(opt::InputArgList &Args, ArrayRef<StringRef> Objects) {
+void runMSVCLinker(std::string Rsp, ArrayRef<StringRef> Objects) {
// Write the in-memory object files to disk.
std::vector<TemporaryFile> Temps;
- for (StringRef S : Objects)
+ for (StringRef S : Objects) {
Temps.emplace_back("lto", "obj", S);
-
- // Create a response file.
- std::string Rsp = "/nologo ";
- for (TemporaryFile &T : Temps)
- Rsp += quote(T.Path) + " ";
-
- for (auto *Arg : Args) {
- switch (Arg->getOption().getID()) {
- case OPT_linkrepro:
- case OPT_lldmap:
- case OPT_lldmap_file:
- case OPT_msvclto:
- // LLD-specific options are stripped.
- break;
- case OPT_opt:
- if (!StringRef(Arg->getValue()).startswith("lld"))
- Rsp += toString(Arg) + " ";
- break;
- case OPT_INPUT:
- // Bitcode files are stripped as they've been compiled to
- // native object files.
- if (!isBitcodeFile(Arg->getValue()))
- Rsp += quote(Arg->getValue()) + " ";
- break;
- default:
- Rsp += toString(Arg) + " ";
- }
+ Rsp += quote(Temps.back().Path) + " ";
}
log("link.exe " + Rsp);
Modified: lld/trunk/test/COFF/msvclto.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/msvclto.ll?rev=295913&r1=295912&r2=295913&view=diff
==============================================================================
--- lld/trunk/test/COFF/msvclto.ll (original)
+++ lld/trunk/test/COFF/msvclto.ll Wed Feb 22 18:26:42 2017
@@ -1,6 +1,7 @@
-; RUN: llvm-as -o %t1.obj %s
-; RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t2.obj %p/Inputs/msvclto.s
-; RUN: lld-link %t1.obj %t2.obj /msvclto /out:%t.exe /opt:lldlto=1 /opt:icf \
+; RUN: llvm-as -o %t.obj %s
+; RUN: mkdir -p %t.dir
+; RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t.dir/bitcode.obj %p/Inputs/msvclto.s
+; RUN: lld-link %t.obj %t.dir/bitcode.obj /msvclto /out:%t.exe /opt:lldlto=1 /opt:icf \
; RUN: /entry:main /verbose > %t.log || true
; RUN: FileCheck %s < %t.log
More information about the llvm-commits
mailing list