Skip to content

Commit 7be99e4

Browse files
authored
Merge pull request #37084 from kateinoigakukun/katei/share-fatalerror-concurrency
Rename duplicated `swift::fatalError` in `swiftRuntime` and `swift_Concurrency`. Both `swiftRuntime` and `swift_Concurrency` had `swift::fatalError` implementation, but it causes symbol conflict with the `-static-stdlib` flag. This patch removes one of the implementations in `swift_Concurrency` to avoid conflicts. Also added a test case to ensure that linking the Concurrency module with `-static-stdlib` works. This issue was found by SwiftWasm test cases.
2 parents 9c02fd1 + f2fe95e commit 7be99e4

File tree

15 files changed

+141
-17
lines changed

15 files changed

+141
-17
lines changed

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
4242
CheckedContinuation.swift
4343
GlobalExecutor.cpp
4444
Errors.swift
45+
Error.cpp
4546
Executor.swift
4647
AsyncCompactMapSequence.swift
4748
AsyncDropFirstSequence.swift

stdlib/public/Concurrency/Error.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===--- Error.cpp - Error handling support code --------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "Error.h"
14+
15+
// swift::fatalError is not exported from libswiftCore and not shared, so define another
16+
// internal function instead.
17+
SWIFT_NORETURN void swift::swift_Concurrency_fatalError(uint32_t flags, const char *format, ...) {
18+
abort();
19+
}

stdlib/public/Concurrency/Error.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===--- Error.h - Swift Concurrency error helpers --------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Error handling support.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_CONCURRENCY_ERRORS_H
18+
#define SWIFT_CONCURRENCY_ERRORS_H
19+
20+
#include "../SwiftShims/Visibility.h"
21+
#include <cstdint>
22+
#include <stdlib.h>
23+
24+
namespace swift {
25+
26+
SWIFT_NORETURN void swift_Concurrency_fatalError(uint32_t flags, const char *format, ...);
27+
28+
} // namespace swift
29+
30+
#endif

stdlib/public/Concurrency/GlobalExecutor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "swift/Runtime/Concurrency.h"
5858
#include "swift/Runtime/EnvironmentVariables.h"
5959
#include "TaskPrivate.h"
60+
#include "Error.h"
6061

6162
#include <dispatch/dispatch.h>
6263

@@ -267,7 +268,7 @@ static std::atomic<dispatch_queue_t> globalQueueCache[globalQueueCacheCount];
267268
static dispatch_queue_t getGlobalQueue(JobPriority priority) {
268269
size_t numericPriority = static_cast<size_t>(priority);
269270
if (numericPriority >= globalQueueCacheCount)
270-
fatalError(0, "invalid job priority %#zx");
271+
swift_Concurrency_fatalError(0, "invalid job priority %#zx");
271272

272273
auto *ptr = &globalQueueCache[numericPriority];
273274
auto queue = ptr->load(std::memory_order_relaxed);

stdlib/public/Concurrency/Mutex.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "Error.h"
14+
15+
#define SWIFT_FATAL_ERROR swift_Concurrency_fatalError
16+
1317
// Include the runtime's mutex support code.
1418
// FIXME: figure out some reasonable way to share this stuff
1519

1620
#include "../runtime/MutexPThread.cpp"
1721
#include "../runtime/MutexWin32.cpp"
18-
19-
SWIFT_NORETURN void swift::fatalError(uint32_t flags, const char *format, ...) {
20-
abort();
21-
}

stdlib/public/Concurrency/Task.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "TaskPrivate.h"
2626
#include "AsyncCall.h"
2727
#include "Debug.h"
28+
#include "Error.h"
2829

2930
#include <dispatch/dispatch.h>
3031

@@ -690,7 +691,7 @@ static void swift_task_future_waitImpl(OpaqueValue *result,
690691
return waitingTask->runInFullyEstablishedContext();
691692

692693
case FutureFragment::Status::Error:
693-
fatalError(0, "future reported an error, but wait cannot throw");
694+
swift_Concurrency_fatalError(0, "future reported an error, but wait cannot throw");
694695
}
695696
}
696697

stdlib/public/Concurrency/TaskAlloc.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "swift/Runtime/Concurrency.h"
2121
#include "swift/ABI/Task.h"
2222
#include "TaskPrivate.h"
23+
#include "Error.h"
24+
25+
#define SWIFT_FATAL_ERROR swift_Concurrency_fatalError
2326
#include "../runtime/StackAllocator.h"
2427
#include <stdlib.h>
2528

stdlib/public/runtime/MutexPThread.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
#endif
2121

2222
#if defined(_POSIX_THREADS) && !defined(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
23+
24+
// Notes: swift::fatalError is not shared between libswiftCore and libswift_Concurrency
25+
// and libswift_Concurrency uses swift_Concurrency_fatalError instead.
26+
#ifndef SWIFT_FATAL_ERROR
27+
#define SWIFT_FATAL_ERROR swift::fatalError
28+
#endif
29+
2330
#include "swift/Runtime/Mutex.h"
2431

2532
#include "swift/Runtime/Debug.h"
@@ -32,8 +39,8 @@ using namespace swift;
3239
do { \
3340
int errorcode = PThreadFunction; \
3441
if (errorcode != 0) { \
35-
fatalError(/* flags = */ 0, "'%s' failed with error '%s'(%d)\n", \
36-
#PThreadFunction, errorName(errorcode), errorcode); \
42+
SWIFT_FATAL_ERROR(/* flags = */ 0, "'%s' failed with error '%s'(%d)\n", \
43+
#PThreadFunction, errorName(errorcode), errorcode); \
3744
} \
3845
} while (false)
3946

@@ -44,8 +51,8 @@ using namespace swift;
4451
return true; \
4552
if (returnFalseOnEBUSY && errorcode == EBUSY) \
4653
return false; \
47-
fatalError(/* flags = */ 0, "'%s' failed with error '%s'(%d)\n", \
48-
#PThreadFunction, errorName(errorcode), errorcode); \
54+
SWIFT_FATAL_ERROR(/* flags = */ 0, "'%s' failed with error '%s'(%d)\n", \
55+
#PThreadFunction, errorName(errorcode), errorcode); \
4956
} while (false)
5057

5158
static const char *errorName(int errorcode) {

stdlib/public/runtime/MutexWin32.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#if defined(_WIN32)
19+
20+
// Notes: swift::fatalError is not shared between libswiftCore and libswift_Concurrency
21+
// and libswift_Concurrency uses swift_Concurrency_fatalError instead.
22+
#ifndef SWIFT_FATAL_ERROR
23+
#define SWIFT_FATAL_ERROR swift::fatalError
24+
#endif
25+
1926
#include "swift/Runtime/Mutex.h"
2027
#include "swift/Runtime/Debug.h"
2128

@@ -26,9 +33,9 @@ void ConditionPlatformHelper::wait(CONDITION_VARIABLE &condition,
2633
BOOL result = SleepConditionVariableSRW(&condition, &mutex, INFINITE, 0);
2734
if (!result) {
2835
DWORD errorcode = GetLastError();
29-
fatalError(/* flags = */ 0,
30-
"'SleepConditionVariableSRW()' failed with error code %d\n",
31-
errorcode);
36+
SWIFT_FATAL_ERROR(/* flags = */ 0,
37+
"'SleepConditionVariableSRW()' failed with error code %d\n",
38+
errorcode);
3239
}
3340
}
3441
#endif

stdlib/public/runtime/StackAllocator.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
#include "llvm/Support/Alignment.h"
1919
#include <cstddef>
2020

21+
// Notes: swift::fatalError is not shared between libswiftCore and libswift_Concurrency
22+
// and libswift_Concurrency uses swift_Concurrency_fatalError instead.
23+
#ifndef SWIFT_FATAL_ERROR
24+
#define SWIFT_FATAL_ERROR swift::fatalError
25+
#endif
26+
2127
namespace swift {
2228

2329
/// A bump-pointer allocator that obeys a stack discipline.
@@ -151,7 +157,7 @@ class StackAllocator {
151157
if (guardAllocations) {
152158
auto *endOfAllocation = (uintptr_t *)getAddr(currentOffset);
153159
if (endOfAllocation[-1] != magicEndOfAllocation)
154-
fatalError(0, "Buffer overflow in StackAllocator");
160+
SWIFT_FATAL_ERROR(0, "Buffer overflow in StackAllocator");
155161
for (auto *p = (uintptr_t *)allocation; p < endOfAllocation; ++p)
156162
*p = magicUninitialized;
157163
}
@@ -256,7 +262,7 @@ class StackAllocator {
256262

257263
~StackAllocator() {
258264
if (lastAllocation)
259-
fatalError(0, "not all allocations are deallocated");
265+
SWIFT_FATAL_ERROR(0, "not all allocations are deallocated");
260266
(void)freeAllSlabs(firstSlabIsPreallocated ? firstSlab->next : firstSlab);
261267
assert(getNumAllocatedSlabs() == 0);
262268
}
@@ -277,7 +283,7 @@ class StackAllocator {
277283
/// Deallocate memory \p ptr.
278284
void dealloc(void *ptr) {
279285
if (!lastAllocation || lastAllocation->getAllocatedMemory() != ptr)
280-
fatalError(0, "freed pointer was not the last allocation");
286+
SWIFT_FATAL_ERROR(0, "freed pointer was not the last allocation");
281287

282288
Allocation *prev = lastAllocation->previous;
283289
lastAllocation->slab->deallocate(lastAllocation);

0 commit comments

Comments
 (0)