diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1401,8 +1401,12 @@ config->mllvmOpts.emplace_back(arg->getValue()); } + config->threadCount = parallel::strategy.compute_thread_count(); + // --threads= takes a positive integer and provides the default value for - // --thinlto-jobs=. + // --thinlto-jobs=. If unspecified, cap the number of threads since + // overhead outweighs optimization for used parallel algorithms for the + // non-LTO parts. if (auto *arg = args.getLastArg(OPT_threads)) { StringRef v(arg->getValue()); unsigned threads = 0; @@ -1411,10 +1415,11 @@ arg->getValue() + "'"); parallel::strategy = hardware_concurrency(threads); config->thinLTOJobs = v; + } else if (config->threadCount > 8) { + parallel::strategy = hardware_concurrency(8); } if (auto *arg = args.getLastArg(OPT_thinlto_jobs_eq)) config->thinLTOJobs = arg->getValue(); - config->threadCount = parallel::strategy.compute_thread_count(); if (config->ltoPartitions == 0) error("--lto-partitions: number of threads must be > 0");