[lld] r332527 - Add support for ThinLTO plugin option thinlto-object-suffix-replace
Rumeet Dhindsa via llvm-commits
llvm-commits at lists.llvm.org
Wed May 16 14:04:08 PDT 2018
Author: rdhindsa
Date: Wed May 16 14:04:08 2018
New Revision: 332527
URL: http://llvm.org/viewvc/llvm-project?rev=332527&view=rev
Log:
Add support for ThinLTO plugin option thinlto-object-suffix-replace
Differential Revision: https://reviews.llvm.org/D46608
Added:
lld/trunk/test/ELF/lto/thinlto-object-suffix-replace.ll
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/LTO.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=332527&r1=332526&r2=332527&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed May 16 14:04:08 2018
@@ -96,6 +96,7 @@ struct Configuration {
llvm::StringRef Sysroot;
llvm::StringRef ThinLTOCacheDir;
llvm::StringRef ThinLTOIndexOnlyArg;
+ std::pair<llvm::StringRef, llvm::StringRef> ThinLTOObjectSuffixReplace;
std::pair<llvm::StringRef, llvm::StringRef> ThinLTOPrefixReplace;
std::string Rpath;
std::vector<VersionDefinition> VersionDefinitions;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=332527&r1=332526&r2=332527&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed May 16 14:04:08 2018
@@ -813,6 +813,14 @@ void LinkerDriver::readConfigs(opt::Inpu
if (Config->ThinLTOPrefixReplace.second.empty())
error("thinlto-prefix-replace expects 'old;new' format, but got " +
S.substr(23));
+ } else if (S.startswith("thinlto-object-suffix-replace=")) {
+ std::tie(Config->ThinLTOObjectSuffixReplace.first,
+ Config->ThinLTOObjectSuffixReplace.second) =
+ S.substr(30).split(';');
+ if (Config->ThinLTOObjectSuffixReplace.second.empty())
+ error(
+ "thinlto-object-suffix-replace expects 'old;new' format, but got " +
+ S.substr(30));
} else if (!S.startswith("/") && !S.startswith("-fresolution=") &&
!S.startswith("-pass-through=") && !S.startswith("thinlto")) {
parseClangOption(S, Arg->getSpelling());
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=332527&r1=332526&r2=332527&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed May 16 14:04:08 2018
@@ -1032,9 +1032,13 @@ BitcodeFile::BitcodeFile(MemoryBufferRef
// this causes a collision which result in only one of the objects being
// taken into consideration at LTO time (which very likely causes undefined
// symbols later in the link stage).
+ std::string Path = MB.getBufferIdentifier().str();
+ if (Config->ThinLTOIndexOnly)
+ Path = updateSuffixInPath(MB.getBufferIdentifier());
+
MemoryBufferRef MBRef(
MB.getBuffer(),
- Saver.save(ArchiveName + MB.getBufferIdentifier() +
+ Saver.save(ArchiveName + Path +
(ArchiveName.empty() ? "" : utostr(OffsetInArchive))));
Obj = CHECK(lto::InputFile::create(MBRef), this);
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=332527&r1=332526&r2=332527&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Wed May 16 14:04:08 2018
@@ -355,6 +355,20 @@ inline bool isBitcode(MemoryBufferRef MB
return identify_magic(MB.getBuffer()) == llvm::file_magic::bitcode;
}
+inline std::string updateSuffixInPath(llvm::StringRef Path) {
+ if (Path.endswith(Config->ThinLTOObjectSuffixReplace.first)) {
+ size_t pos = Path.rfind(Config->ThinLTOObjectSuffixReplace.first);
+ std::string SuffixedPath =
+ (Path.str().substr(0, pos) +
+ Config->ThinLTOObjectSuffixReplace.second.str());
+ return SuffixedPath;
+ } else {
+ error("cannot find suffix " +
+ Config->ThinLTOObjectSuffixReplace.first.str());
+ return "";
+ }
+}
+
extern std::vector<BinaryFile *> BinaryFiles;
extern std::vector<BitcodeFile *> BitcodeFiles;
extern std::vector<LazyObjFile *> LazyObjFiles;
Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=332527&r1=332526&r2=332527&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Wed May 16 14:04:08 2018
@@ -266,7 +266,8 @@ std::vector<InputFile *> BitcodeCompiler
if (F->AddedToLink || !isBitcode(F->MB))
continue;
- std::string Path = getThinLTOOutputFile(F->getName());
+ std::string Path = updateSuffixInPath(getThinLTOOutputFile(F->getName()));
+
std::unique_ptr<raw_fd_ostream> OS = openFile(Path + ".thinlto.bc");
if (!OS)
continue;
Added: lld/trunk/test/ELF/lto/thinlto-object-suffix-replace.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/thinlto-object-suffix-replace.ll?rev=332527&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/thinlto-object-suffix-replace.ll (added)
+++ lld/trunk/test/ELF/lto/thinlto-object-suffix-replace.ll Wed May 16 14:04:08 2018
@@ -0,0 +1,51 @@
+; REQUIRES: x86
+
+; Test to make sure the thinlto-object-suffix-replace option is handled
+; correctly.
+
+; Generate bitcode file with summary, as well as a minimized bitcode without
+; the debug metadata for the thin link.
+; RUN: opt -thinlto-bc %s -thin-link-bitcode-file=%t1.thinlink.bc -o %t1.o
+
+; First perform the thin link on the normal bitcode file, and save the
+; resulting index.
+; RUN: ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only -shared %t1.o -o %t3
+; RUN: cp %t1.o.thinlto.bc %t1.o.thinlto.bc.orig
+
+; Next perform the thin link on the minimized bitcode file, and compare dump
+; of the resulting index to the above dump to ensure they are identical.
+; RUN: rm -f %t1.o.thinlto.bc
+; Make sure it isn't inadvertently using the regular bitcode file.
+; RUN: rm -f %t1.o
+; RUN: ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only \
+; RUN: --plugin-opt=thinlto-object-suffix-replace=".thinlink.bc;.o" \
+; RUN: -shared %t1.thinlink.bc -o %t3
+; RUN: diff %t1.o.thinlto.bc.orig %t1.o.thinlto.bc
+
+; Ensure lld generates error if object suffix replace option does not have 'old;new' format
+; RUN: rm -f %t1.o.thinlto.bc
+; RUN: not ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only \
+; RUN: --plugin-opt=thinlto-object-suffix-replace="abc:def" -shared %t1.thinlink.bc \
+; RUN: -o %t3 2>&1 | FileCheck %s --check-prefix=ERR1
+; ERR1: thinlto-object-suffix-replace expects 'old;new' format, but got abc:def
+
+; Ensure lld generates error if old suffix doesn't exist in file name
+; RUN: rm -f %t1.o
+; RUN: not ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only \
+; RUN: --plugin-opt=thinlto-object-suffix-replace=".abc;.o" -shared %t1.thinlink.bc \
+; RUN: -o %t3 2>&1 | FileCheck %s --check-prefix=ERR2
+; ERR2: cannot find suffix .abc
+
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @f() {
+entry:
+ ret void
+}
+
+!llvm.dbg.cu = !{}
+
+!1 = !{i32 2, !"Debug Info Version", i32 3}
+!llvm.module.flags = !{!1}
More information about the llvm-commits
mailing list