Skip to content

Commit e6453a3

Browse files
[Concurrency] Fix runtime isolated-conformance checks with static stdlib
Most of linkers pull object files from static archives only if any symbol from that object file is referenced, even if the object contains a ctor code. `Setup.cpp` didn't have any symbols referenced from other code, so it was not linked in when the concurrency runtime was linked in statically. This commit moves the ctor code to `Task.cpp` to ensure that it is always linked in.
1 parent 73530bf commit e6453a3

File tree

4 files changed

+54
-58
lines changed

4 files changed

+54
-58
lines changed

Runtimes/Core/Concurrency/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ add_library(swift_Concurrency
1616
ExecutorImpl.cpp
1717
ExecutorChecks.cpp
1818
GlobalExecutor.cpp
19-
Setup.cpp
2019
Task.cpp
2120
TaskAlloc.cpp
2221
TaskGroup.cpp

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ set(SWIFT_RUNTIME_CONCURRENCY_C_SOURCES
8484
Error.cpp
8585
ExecutorBridge.cpp
8686
ExecutorChecks.cpp
87-
Setup.cpp
8887
Task.cpp
8988
TaskAlloc.cpp
9089
TaskStatus.cpp

stdlib/public/Concurrency/Setup.cpp

Lines changed: 0 additions & 56 deletions
This file was deleted.

stdlib/public/Concurrency/Task.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,60 @@ static void swift_task_startOnMainActorImpl(AsyncTask* task) {
18741874
_swift_task_setCurrent(originalTask);
18751875
}
18761876

1877+
// ==== Load-time setup code ----------------------------------------------------
1878+
//
1879+
// The ctor below is placed here so that it must always be linked into the final
1880+
// image even if the libswift_Concurrency is linked in as a static library.
1881+
1882+
#if !SWIFT_CONCURRENCY_EMBEDDED
1883+
1884+
// Helper macros for figuring out the mangled name of a context descriptor.
1885+
#define DESCRIPTOR_MANGLING_SUFFIX_Structure Mn
1886+
#define DESCRIPTOR_MANGLING_SUFFIX_Class Mn
1887+
#define DESCRIPTOR_MANGLING_SUFFIX_Enum Mn
1888+
#define DESCRIPTOR_MANGLING_SUFFIX_Protocol Mp
1889+
1890+
#define DESCRIPTOR_MANGLING_SUFFIX_(X) X
1891+
#define DESCRIPTOR_MANGLING_SUFFIX(KIND) \
1892+
DESCRIPTOR_MANGLING_SUFFIX_(DESCRIPTOR_MANGLING_SUFFIX_##KIND)
1893+
1894+
#define DESCRIPTOR_MANGLING_(CHAR, SUFFIX) $sSc##CHAR##SUFFIX
1895+
#define DESCRIPTOR_MANGLING(CHAR, SUFFIX) DESCRIPTOR_MANGLING_(CHAR, SUFFIX)
1896+
1897+
// Declare context descriptors for all of the concurrency descriptors with
1898+
// standard manglings.
1899+
#define STANDARD_TYPE(KIND, MANGLING, TYPENAME)
1900+
#define STANDARD_TYPE_CONCURRENCY(KIND, MANGLING, TYPENAME) \
1901+
extern "C" const swift::ContextDescriptor DESCRIPTOR_MANGLING( \
1902+
MANGLING, DESCRIPTOR_MANGLING_SUFFIX(KIND));
1903+
#include "swift/Demangling/StandardTypesMangling.def"
1904+
1905+
// Defined in Swift, redeclared here so we can register it with the runtime.
1906+
extern "C" SWIFT_CC(swift)
1907+
bool _swift_task_isCurrentGlobalActor(
1908+
const swift::Metadata *, const swift::WitnessTable *);
1909+
1910+
// Register our type descriptors with standard manglings when the concurrency
1911+
// runtime is loaded. This allows the runtime to quickly resolve those standard
1912+
// manglings.
1913+
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN
1914+
__attribute__((constructor)) static void setupStandardConcurrencyDescriptors() {
1915+
static const swift::ConcurrencyStandardTypeDescriptors descriptors = {
1916+
#define STANDARD_TYPE(KIND, MANGLING, TYPENAME)
1917+
#define STANDARD_TYPE_CONCURRENCY(KIND, MANGLING, TYPENAME) \
1918+
&DESCRIPTOR_MANGLING(MANGLING, DESCRIPTOR_MANGLING_SUFFIX(KIND)),
1919+
#include "swift/Demangling/StandardTypesMangling.def"
1920+
};
1921+
_swift_registerConcurrencyRuntime(
1922+
&descriptors,
1923+
&_swift_task_isCurrentGlobalActor);
1924+
}
1925+
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END
1926+
1927+
#endif
1928+
1929+
// ==== Back-deploy hooks -------------------------------------------------------
1930+
18771931
#define OVERRIDE_TASK COMPATIBILITY_OVERRIDE
18781932

18791933
#ifdef SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT

0 commit comments

Comments
 (0)