diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 9c7de9d613d2..ede80c246533 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -49,7 +49,6 @@ static void checkError(Error E) { static std::unique_ptr createLTO() { lto::Config Conf; - lto::ThinBackend Backend; // LLD supports the new relocations. Conf.Options = InitTargetOptionsFromCodeGenFlags(); @@ -68,6 +67,9 @@ static std::unique_ptr createLTO() { checkError(Conf.addSaveTemps(std::string(Config->OutputFile) + ".", /*UseInputModulePath*/ true)); + lto::ThinBackend Backend; + if (Config->LtoJobs) + Backend = lto::createInProcessThinBackend(Config->LtoJobs); return llvm::make_unique(std::move(Conf), Backend, Config->LtoJobs); } diff --git a/lld/test/ELF/lto/Inputs/thinlto.ll b/lld/test/ELF/lto/Inputs/thinlto.ll new file mode 100644 index 000000000000..31c72ec4653a --- /dev/null +++ b/lld/test/ELF/lto/Inputs/thinlto.ll @@ -0,0 +1,7 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @g() { +entry: + ret void +} diff --git a/lld/test/ELF/lto/thinlto.ll b/lld/test/ELF/lto/thinlto.ll new file mode 100644 index 000000000000..98d4aff2f99c --- /dev/null +++ b/lld/test/ELF/lto/thinlto.ll @@ -0,0 +1,29 @@ +; Basic ThinLTO tests. +; RUN: llvm-as %s -o %t.o +; RUN: llvm-as %p/Inputs/thinlto.ll -o %t2.o + +; First force single-threaded mode +; RUN: ld.lld -save-temps --lto-jobs=1 -shared %t.o %t2.o -o %t +; RUN: llvm-nm %t.lto.o | FileCheck %s --check-prefix=NM + +; NM: T f +; NM: T g + +; Next force multi-threaded mode +; RUN: ld.lld -save-temps --lto-jobs=2 -shared %t.o %t2.o -o %t2 +; RUN: llvm-nm %t20.lto.o | FileCheck %s --check-prefix=NM1 +; RUN: llvm-nm %t21.lto.o | FileCheck %s --check-prefix=NM2 + +; NM1: T g +; NM2: T f + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @g(...) + +define void @f() { +entry: + call void (...) @g() + ret void +}