Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lld/MachO/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ struct DeferredFile {
};
using DeferredFiles = std::vector<DeferredFile>;

#if LLVM_ENABLE_THREADS
class SerialBackgroundQueue {
std::deque<std::function<void()>> queue;
std::thread *running;
Expand Down Expand Up @@ -359,7 +360,6 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
(void)t;
}
};
#if LLVM_ENABLE_THREADS
{ // Create scope for waiting for the taskGroup
std::atomic_size_t index = 0;
llvm::parallel::TaskGroup taskGroup;
Expand All @@ -373,7 +373,6 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
}
});
}
#endif
#ifndef NDEBUG
auto dt = high_resolution_clock::now() - t0;
if (Process::GetEnv("LLD_MULTI_THREAD_PAGE"))
Expand All @@ -390,6 +389,7 @@ static void multiThreadedPageIn(const DeferredFiles &deferred) {
multiThreadedPageInBackground(files);
});
}
#endif

static InputFile *processFile(std::optional<MemoryBufferRef> buffer,
DeferredFiles *archiveContents, StringRef path,
Expand Down Expand Up @@ -1430,6 +1430,7 @@ static void createFiles(const InputArgList &args) {
}
}

#if LLVM_ENABLE_THREADS
if (config->readWorkers) {
multiThreadedPageIn(deferredFiles);

Expand All @@ -1447,6 +1448,7 @@ static void createFiles(const InputArgList &args) {
for (auto *archive : archives)
archive->addLazySymbols();
}
#endif
}

static void gatherInputSections() {
Expand Down Expand Up @@ -1834,13 +1836,18 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
}

if (auto *arg = args.getLastArg(OPT_read_workers)) {
#if LLVM_ENABLE_THREADS
StringRef v(arg->getValue());
unsigned workers = 0;
if (!llvm::to_integer(v, workers, 0))
error(arg->getSpelling() +
": expected a non-negative integer, but got '" + arg->getValue() +
"'");
config->readWorkers = workers;
#else
error(arg->getSpelling() +
": option unavailable because lld was not built with thread support");
#endif
}
if (auto *arg = args.getLastArg(OPT_threads_eq)) {
StringRef v(arg->getValue());
Expand Down
1 change: 1 addition & 0 deletions lld/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
llvm_canonicalize_cmake_booleans(
ENABLE_BACKTRACES
LLVM_ENABLE_THREADS
LLVM_ENABLE_ZLIB
LLVM_ENABLE_ZSTD
LLVM_ENABLE_LIBXML2
Expand Down
10 changes: 10 additions & 0 deletions lld/test/MachO/read-workers-no-thread-support.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# REQUIRES: x86 && !thread_support
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o

# RUN: not %lld --read-workers=1 %t.o -o /dev/null

# CHECK: error: --read-workers=: option unavailable because lld was built without thread support

.globl _main
_main:
ret
2 changes: 1 addition & 1 deletion lld/test/MachO/read-workers.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# REQUIRES: x86
# REQUIRES: x86 && thread_support
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o

## A non-negative integer is allowed.
Expand Down
3 changes: 3 additions & 0 deletions lld/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,6 @@
# ELF tests expect the default target for ld.lld to be ELF.
if config.ld_lld_default_mingw:
config.excludes.append("ELF")

if config.enable_threads:
config.available_features.add("thread_support")
1 change: 1 addition & 0 deletions lld/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@
config.build_examples = @LLVM_BUILD_EXAMPLES@
config.has_plugins = @LLVM_ENABLE_PLUGINS@
config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@
config.enable_threads = @LLVM_ENABLE_THREADS@

import lit.llvm
lit.llvm.initialize(lit_config, config)
Expand Down