diff options
author | Nico Weber <nicolasweber@gmx.de> | 2018-08-01 19:00:49 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2018-08-01 19:00:49 +0000 |
commit | 11f14904d3c13342c4ecc0f4a408c3a98b087ddf (patch) | |
tree | 92d4a296e15140e89c79e42265e2d75e8c8b18ef | |
parent | 5ae08b858d511aa9ce4847e607a8db02200cfbaa (diff) | |
download | bcm5719-llvm-11f14904d3c13342c4ecc0f4a408c3a98b087ddf.tar.gz bcm5719-llvm-11f14904d3c13342c4ecc0f4a408c3a98b087ddf.zip |
lld-link: Remove /msvclto option
This was useful for LTO bringup in lld-link while lld couldn't write PDBs. Now
that it can, this should no longer be needed. Hopefully the flag is obscure
enough and recent enough, that nobody uses it – but if somebody should use it,
they should be able to just stop passing it and things should continue to work.
https://reviews.llvm.org/D50139
llvm-svn: 338615
-rw-r--r-- | lld/COFF/Driver.cpp | 132 | ||||
-rw-r--r-- | lld/COFF/Driver.h | 2 | ||||
-rw-r--r-- | lld/COFF/DriverUtils.cpp | 20 | ||||
-rw-r--r-- | lld/COFF/Options.td | 1 | ||||
-rw-r--r-- | lld/test/COFF/msvclto-archive.ll | 40 | ||||
-rw-r--r-- | lld/test/COFF/msvclto-order.ll | 25 | ||||
-rw-r--r-- | lld/test/COFF/msvclto.ll | 20 |
7 files changed, 0 insertions, 240 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index eefdb48bead..f4be29b1a6a 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -679,131 +679,6 @@ static void parseModuleDefs(StringRef Path) { } } -// A helper function for filterBitcodeFiles. -static bool needsRebuilding(MemoryBufferRef MB) { - // The MSVC linker doesn't support thin archives, so if it's a thin - // archive, we always need to rebuild it. - std::unique_ptr<Archive> File = - CHECK(Archive::create(MB), "Failed to read " + MB.getBufferIdentifier()); - if (File->isThin()) - return true; - - // Returns true if the archive contains at least one bitcode file. - for (MemoryBufferRef Member : getArchiveMembers(File.get())) - if (identify_magic(Member.getBuffer()) == file_magic::bitcode) - return true; - return false; -} - -// Opens a given path as an archive file and removes bitcode files -// from them if exists. This function is to appease the MSVC linker as -// their linker doesn't like archive files containing non-native -// object files. -// -// If a given archive doesn't contain bitcode files, the archive path -// is returned as-is. Otherwise, a new temporary file is created and -// its path is returned. -static Optional<std::string> -filterBitcodeFiles(StringRef Path, std::vector<std::string> &TemporaryFiles) { - std::unique_ptr<MemoryBuffer> MB = CHECK( - MemoryBuffer::getFile(Path, -1, false, true), "could not open " + Path); - MemoryBufferRef MBRef = MB->getMemBufferRef(); - file_magic Magic = identify_magic(MBRef.getBuffer()); - - if (Magic == file_magic::bitcode) - return None; - if (Magic != file_magic::archive) - return Path.str(); - if (!needsRebuilding(MBRef)) - return Path.str(); - - std::unique_ptr<Archive> File = - CHECK(Archive::create(MBRef), - MBRef.getBufferIdentifier() + ": failed to parse archive"); - - std::vector<NewArchiveMember> New; - for (MemoryBufferRef Member : getArchiveMembers(File.get())) - if (identify_magic(Member.getBuffer()) != file_magic::bitcode) - New.emplace_back(Member); - - if (New.empty()) - return None; - - log("Creating a temporary archive for " + Path + " to remove bitcode files"); - - SmallString<128> S; - if (std::error_code EC = sys::fs::createTemporaryFile( - "lld-" + sys::path::stem(Path), ".lib", S)) - fatal("cannot create a temporary file: " + EC.message()); - std::string Temp = S.str(); - TemporaryFiles.push_back(Temp); - - Error E = - llvm::writeArchive(Temp, New, /*WriteSymtab=*/true, Archive::Kind::K_GNU, - /*Deterministics=*/true, - /*Thin=*/false); - handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) { - error("failed to create a new archive " + S.str() + ": " + EI.message()); - }); - return Temp; -} - -// Create response file contents and invoke the MSVC linker. -void LinkerDriver::invokeMSVC(opt::InputArgList &Args) { - std::string Rsp = "/nologo\n"; - std::vector<std::string> Temps; - - // Write out archive members that we used in symbol resolution and pass these - // to MSVC before any archives, so that MSVC uses the same objects to satisfy - // references. - for (ObjFile *Obj : ObjFile::Instances) { - if (Obj->ParentName.empty()) - continue; - SmallString<128> S; - int Fd; - if (auto EC = sys::fs::createTemporaryFile( - "lld-" + sys::path::filename(Obj->ParentName), ".obj", Fd, S)) - fatal("cannot create a temporary file: " + EC.message()); - raw_fd_ostream OS(Fd, /*shouldClose*/ true); - OS << Obj->MB.getBuffer(); - Temps.push_back(S.str()); - Rsp += quote(S) + "\n"; - } - - for (auto *Arg : Args) { - switch (Arg->getOption().getID()) { - case OPT_linkrepro: - case OPT_lldmap: - case OPT_lldmap_file: - case OPT_lldsavetemps: - 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: { - if (Optional<StringRef> Path = doFindFile(Arg->getValue())) { - if (Optional<std::string> S = filterBitcodeFiles(*Path, Temps)) - Rsp += quote(*S) + "\n"; - continue; - } - Rsp += quote(Arg->getValue()) + "\n"; - break; - } - default: - Rsp += toString(*Arg) + "\n"; - } - } - - std::vector<StringRef> ObjFiles = Symtab->compileBitcodeFiles(); - runMSVCLinker(Rsp, ObjFiles); - - for (StringRef Path : Temps) - sys::fs::remove(Path); -} - void LinkerDriver::enqueueTask(std::function<void()> Task) { TaskQueue.push_back(std::move(Task)); } @@ -1474,13 +1349,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { if (errorCount()) return; - // 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)) { - invokeMSVC(Args); - return; - } - // Do LTO by compiling bitcode input files to a set of native COFF files then // link those files. Symtab->addCombinedLTOObjects(); diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h index 627e991a902..e1477667e3f 100644 --- a/lld/COFF/Driver.h +++ b/lld/COFF/Driver.h @@ -115,8 +115,6 @@ private: StringRef findDefaultEntry(); WindowsSubsystem inferSubsystem(); - void invokeMSVC(llvm::opt::InputArgList &Args); - void addBuffer(std::unique_ptr<MemoryBuffer> MB, bool WholeArchive); void addArchiveBuffer(MemoryBufferRef MBRef, StringRef SymName, StringRef ParentName); diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index c12e791f950..f7d8fe55390 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -713,26 +713,6 @@ MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> MBs) { return MBRef; } -// 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(std::string Rsp, ArrayRef<StringRef> Objects) { - // Write the in-memory object files to disk. - std::vector<TemporaryFile> Temps; - for (StringRef S : Objects) { - Temps.emplace_back("lto", "obj", S); - Rsp += quote(Temps.back().Path) + "\n"; - } - - log("link.exe " + Rsp); - - // Run MSVC link.exe. - Temps.emplace_back("lto", "rsp", Rsp); - Executor E("link.exe"); - E.add(Twine("@" + Temps.back().Path)); - E.run(); -} - // Create OptTable // Create prefix string literals used in Options.td diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td index 871bad8bd65..85367636dc8 100644 --- a/lld/COFF/Options.td +++ b/lld/COFF/Options.td @@ -145,7 +145,6 @@ def debug_symtab : F<"debug:symtab">; def export_all_symbols : F<"export-all-symbols">; def kill_at : F<"kill-at">; def lldmingw : F<"lldmingw">; -def msvclto : F<"msvclto">; def output_def : Joined<["/", "-"], "output-def:">; def pdb_source_path : P<"pdbsourcepath", "Base path used to make relative source file path absolute in PDB">; diff --git a/lld/test/COFF/msvclto-archive.ll b/lld/test/COFF/msvclto-archive.ll deleted file mode 100644 index f0953272102..00000000000 --- a/lld/test/COFF/msvclto-archive.ll +++ /dev/null @@ -1,40 +0,0 @@ -; REQUIRES: x86 -;; Make sure we re-create archive files to strip bitcode files. - -;; Do not create empty archives because the MSVC linker -;; doesn't support them. -; RUN: llvm-as -o %t.obj %s -; RUN: rm -f %t-main1.a -; RUN: llvm-ar cru %t-main1.a %t.obj -; 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-main1.a %t.dir/bitcode.obj /msvclto /out:%t.exe /opt:lldlto=1 /opt:icf \ -; RUN: /entry:main /verbose 2> %t.log || true -; RUN: FileCheck -check-prefix=BC %s < %t.log -; BC-NOT: Creating a temporary archive for - -; RUN: rm -f %t-main2.a -; RUN: llvm-ar cru %t-main2.a %t.dir/bitcode.obj -; RUN: lld-link %t.obj %t-main2.a /msvclto /out:%t.exe /opt:lldlto=1 /opt:icf \ -; RUN: /entry:main /verbose 2> %t.log || true -; RUN: FileCheck -check-prefix=OBJ %s < %t.log -; OBJ-NOT: Creating a temporary archive - -;; Make sure that we always rebuild thin archives because -;; the MSVC linker doesn't support thin archives. -; RUN: rm -f %t-main3.a -; RUN: llvm-ar cruT %t-main3.a %t.dir/bitcode.obj -; RUN: lld-link %t.obj %t-main3.a /msvclto /out:%t.exe /opt:lldlto=1 /opt:icf \ -; RUN: /entry:main /verbose 2> %t.log || true -; RUN: FileCheck -check-prefix=THIN %s < %t.log -; THIN: Creating a temporary archive - -target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-pc-windows-msvc" - -declare void @foo() - -define i32 @main() { - call void @foo() - ret i32 0 -} diff --git a/lld/test/COFF/msvclto-order.ll b/lld/test/COFF/msvclto-order.ll deleted file mode 100644 index 1758077fe74..00000000000 --- a/lld/test/COFF/msvclto-order.ll +++ /dev/null @@ -1,25 +0,0 @@ -; REQUIRES: x86 -; RUN: opt -thinlto-bc %s -o %t.obj -; RUN: llc -filetype=obj %S/Inputs/msvclto-order-a.ll -o %T/msvclto-order-a.obj -; RUN: llvm-ar crs %T/msvclto-order-a.lib %T/msvclto-order-a.obj -; RUN: llc -filetype=obj %S/Inputs/msvclto-order-b.ll -o %T/msvclto-order-b.obj -; RUN: llvm-ar crs %T/msvclto-order-b.lib %T/msvclto-order-b.obj -; RUN: lld-link /verbose /msvclto /out:%t.exe /entry:main %t.obj \ -; RUN: %T/msvclto-order-a.lib %T/msvclto-order-b.lib 2> %t.log || true -; RUN: FileCheck %s < %t.log - -; CHECK: : link.exe -; CHECK-NOT: .lib{{$}} -; CHECK: lld-msvclto-order-a{{.*}}.obj -; CHECK-NOT: lld-msvclto-order-b{{.*}}.obj -; CHECK: .lib{{$}} - -target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-pc-windows-msvc" - -declare void @foo() - -define i32 @main() { - call void @foo() - ret i32 0 -} diff --git a/lld/test/COFF/msvclto.ll b/lld/test/COFF/msvclto.ll deleted file mode 100644 index b29982737f1..00000000000 --- a/lld/test/COFF/msvclto.ll +++ /dev/null @@ -1,20 +0,0 @@ -; REQUIRES: x86 -; 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 2> %t.log || true -; RUN: FileCheck %s < %t.log - -; CHECK: /opt:icf /entry:main -; CHECK: /verbose - -target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-pc-windows-msvc" - -declare void @foo() - -define i32 @main() { - call void @foo() - ret i32 0 -} |