Skip to content

Commit f5885de

Browse files
[lld] Reject --read-workers when lld is built without thread support (#163925)
Also expand the #ifdef to remove unused code in this configuration. As suggested in #147134 (comment). I have also: * Expanded the error message to explain why it's not allowed. * Added a test for the error. * Marked the original test as unsupported when threads are disabled. Fixes issues we have had on Armv8 with threading disabled where this test would crash every so often. This change will hopefully be superseded by #157917, but that has been in review a long time and I want to make the bot stable again. I could just disable the test, but I'd like lld to function properly in general in the meantime too. Co-authored-by: John Holdsworth <github@johnholdsworth.com>
1 parent 89eef94 commit f5885de

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

lld/MachO/Driver.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ struct DeferredFile {
291291
};
292292
using DeferredFiles = std::vector<DeferredFile>;
293293

294+
#if LLVM_ENABLE_THREADS
294295
class SerialBackgroundQueue {
295296
std::deque<std::function<void()>> queue;
296297
std::thread *running;
@@ -359,7 +360,6 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
359360
(void)t;
360361
}
361362
};
362-
#if LLVM_ENABLE_THREADS
363363
{ // Create scope for waiting for the taskGroup
364364
std::atomic_size_t index = 0;
365365
llvm::parallel::TaskGroup taskGroup;
@@ -373,7 +373,6 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
373373
}
374374
});
375375
}
376-
#endif
377376
#ifndef NDEBUG
378377
auto dt = high_resolution_clock::now() - t0;
379378
if (Process::GetEnv("LLD_MULTI_THREAD_PAGE"))
@@ -390,6 +389,7 @@ static void multiThreadedPageIn(const DeferredFiles &deferred) {
390389
multiThreadedPageInBackground(files);
391390
});
392391
}
392+
#endif
393393

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

1433+
#if LLVM_ENABLE_THREADS
14331434
if (config->readWorkers) {
14341435
multiThreadedPageIn(deferredFiles);
14351436

@@ -1447,6 +1448,7 @@ static void createFiles(const InputArgList &args) {
14471448
for (auto *archive : archives)
14481449
archive->addLazySymbols();
14491450
}
1451+
#endif
14501452
}
14511453

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

18361838
if (auto *arg = args.getLastArg(OPT_read_workers)) {
1839+
#if LLVM_ENABLE_THREADS
18371840
StringRef v(arg->getValue());
18381841
unsigned workers = 0;
18391842
if (!llvm::to_integer(v, workers, 0))
18401843
error(arg->getSpelling() +
18411844
": expected a non-negative integer, but got '" + arg->getValue() +
18421845
"'");
18431846
config->readWorkers = workers;
1847+
#else
1848+
error(arg->getSpelling() +
1849+
": option unavailable because lld was not built with thread support");
1850+
#endif
18441851
}
18451852
if (auto *arg = args.getLastArg(OPT_threads_eq)) {
18461853
StringRef v(arg->getValue());

lld/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
llvm_canonicalize_cmake_booleans(
22
ENABLE_BACKTRACES
3+
LLVM_ENABLE_THREADS
34
LLVM_ENABLE_ZLIB
45
LLVM_ENABLE_ZSTD
56
LLVM_ENABLE_LIBXML2
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# REQUIRES: x86 && !thread_support
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
3+
4+
# RUN: not %lld --read-workers=1 %t.o -o /dev/null
5+
6+
# CHECK: error: --read-workers=: option unavailable because lld was built without thread support
7+
8+
.globl _main
9+
_main:
10+
ret

lld/test/MachO/read-workers.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# REQUIRES: x86
1+
# REQUIRES: x86 && thread_support
22
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
33

44
## A non-negative integer is allowed.

lld/test/lit.cfg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,6 @@
182182
# ELF tests expect the default target for ld.lld to be ELF.
183183
if config.ld_lld_default_mingw:
184184
config.excludes.append("ELF")
185+
186+
if config.enable_threads:
187+
config.available_features.add("thread_support")

lld/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@
2626
config.build_examples = @LLVM_BUILD_EXAMPLES@
2727
config.has_plugins = @LLVM_ENABLE_PLUGINS@
2828
config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@
29+
config.enable_threads = @LLVM_ENABLE_THREADS@
2930

3031
import lit.llvm
3132
lit.llvm.initialize(lit_config, config)

0 commit comments

Comments
 (0)