[ELF] Reorder BitcodeFiles.empty() to call thinLTOCreateEmptyIndexFiles() in only one place

It makes the --plugin-opt=obj-path= and --plugin-opt=thinlto-index-only=
behavior more consistent - the files will be created in the
BitcodeFiles.empty() case, but I assume whether it behaves this way is
not required by anyone.

LTOObj->run() cannot run with empty BitcodeFiles. There would be an error:

    ld.lld: error: No available targets are compatible with triple ""

Differential Revision: https://reviews.llvm.org/D61635

llvm-svn: 360129
This commit is contained in:
Fangrui Song 2019-05-07 10:40:26 +00:00
parent c5ac14eef8
commit f3994e4dfa
3 changed files with 8 additions and 15 deletions

View File

@ -214,7 +214,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
// If LazyObjFile has not been added to link, emit empty index files.
// This is needed because this is what GNU gold plugin does and we have a
// distributed build system that depends on that behavior.
void elf::thinLTOCreateEmptyIndexFiles() {
static void thinLTOCreateEmptyIndexFiles() {
for (LazyObjFile *F : LazyObjFiles) {
if (F->AddedToLink || !isBitcode(F->MB))
continue;
@ -249,12 +249,13 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
Files[Task] = std::move(MB);
}));
checkError(LTOObj->run(
[&](size_t Task) {
return llvm::make_unique<lto::NativeObjectStream>(
llvm::make_unique<raw_svector_ostream>(Buf[Task]));
},
Cache));
if (!BitcodeFiles.empty())
checkError(LTOObj->run(
[&](size_t Task) {
return llvm::make_unique<lto::NativeObjectStream>(
llvm::make_unique<raw_svector_ostream>(Buf[Task]));
},
Cache));
// Emit empty index files for non-indexed files
for (StringRef S : ThinIndices) {

View File

@ -56,8 +56,6 @@ private:
std::unique_ptr<llvm::raw_fd_ostream> IndexFile;
llvm::DenseSet<StringRef> ThinIndices;
};
void thinLTOCreateEmptyIndexFiles();
} // namespace elf
} // namespace lld

View File

@ -115,12 +115,6 @@ template <class ELFT> void SymbolTable::addFile(InputFile *File) {
// Because all bitcode files that the program consists of are passed
// to the compiler at once, it can do whole-program optimization.
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
if (BitcodeFiles.empty()) {
if (Config->ThinLTOIndexOnly)
thinLTOCreateEmptyIndexFiles();
return;
}
// Compile bitcode files and replace bitcode symbols.
LTO.reset(new BitcodeCompiler);
for (BitcodeFile *F : BitcodeFiles)