Do not call exit() directly from lld.

Our promise is that as long as there's no fatal error (i.e. broken
file is given to the linker), our main function returns to the caller.
So we can't use exit() in the regular code path.

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

llvm-svn: 331690
This commit is contained in:
Rui Ueyama 2018-05-07 22:11:34 +00:00
parent d54f1c2fed
commit 554adb2e97
3 changed files with 12 additions and 2 deletions

View File

@ -1265,10 +1265,18 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
for (auto *Arg : Args.filtered(OPT_wrap))
Symtab->addSymbolWrap<ELFT>(Arg->getValue());
// Do link-time optimization if given files are LLVM bitcode files.
// This compiles bitcode files into real object files.
Symtab->addCombinedLTOObject<ELFT>();
if (errorCount())
return;
// If -thinlto-index-only is given, we should create only "index
// files" and not object files. Index file creation is already done
// in addCombinedLTOObject, so we are done if that's the case.
if (Config->ThinLTOIndexOnly)
return;
// Apply symbol renames for -wrap.
Symtab->applySymbolWrap();

View File

@ -282,7 +282,9 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
// ThinLTO with index only option is required to generate only the index
// files. After that, we exit from linker and ThinLTO backend runs in a
// distributed environment.
exit(0);
if (IndexFile)
IndexFile->close();
return {};
}
for (std::unique_ptr<MemoryBuffer> &File : Files)

View File

@ -37,7 +37,7 @@
; RUN: rm -f %t4.o.thinlto.bc
; RUN: touch %t4.o.thinlto.bc
; RUN: chmod 400 %t4.o.thinlto.bc
; RUN: ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only -shared %t.o %t4.o -o %t5 2>&1 | FileCheck %s --check-prefix=ERR
; RUN: not ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only -shared %t.o %t4.o -o %t5 2>&1 | FileCheck %s --check-prefix=ERR
; ERR: cannot open {{.*}}4.o.thinlto.bc: {{P|p}}ermission denied
; Ensure lld doesn't generates index files when thinlto-index-only is not enabled