File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ struct LibPrespecializedData {
48
48
const LibPrespecializedData<InProcess> *getLibPrespecializedData ();
49
49
Metadata *getLibPrespecializedMetadata (const TypeContextDescriptor *description,
50
50
const void *const *arguments);
51
+ void libPrespecializedImageLoaded ();
51
52
52
53
} // namespace swift
53
54
Original file line number Diff line number Diff line change 16
16
#include " swift/Runtime/EnvironmentVariables.h"
17
17
#include " swift/Runtime/Metadata.h"
18
18
19
+ #include < atomic>
20
+
19
21
#if SWIFT_STDLIB_HAS_DLADDR && __has_include(<dlfcn.h>)
20
22
#include < dlfcn.h>
21
23
#define USE_DLOPEN 1
27
29
28
30
using namespace swift ;
29
31
32
+ static std::atomic<bool > disablePrespecializedMetadata = false ;
33
+
30
34
static const LibPrespecializedData<InProcess> *findLibPrespecialized () {
31
35
if (!runtime::environment::SWIFT_DEBUG_ENABLE_LIB_PRESPECIALIZED ())
32
36
return nullptr ;
@@ -91,10 +95,23 @@ static bool hasNonTypeGenericArguments(const TypeContextDescriptor *description)
91
95
92
96
static bool disableForValidation = false ;
93
97
98
+ void
99
+ swift::libPrespecializedImageLoaded () {
100
+ #if DYLD_GET_SWIFT_PRESPECIALIZED_DATA_DEFINED
101
+ // A newly loaded image might have caused us to load images that are
102
+ // overriding images in the shared cache. If we do that, turn off
103
+ // prespecialized metadata.
104
+ if (dyld_shared_cache_some_image_overridden ())
105
+ disablePrespecializedMetadata.store (true , std::memory_order_release);
106
+ #endif
107
+ }
108
+
94
109
Metadata *
95
110
swift::getLibPrespecializedMetadata (const TypeContextDescriptor *description,
96
111
const void *const *arguments) {
97
- if (disableForValidation)
112
+ if (SWIFT_UNLIKELY (
113
+ disableForValidation
114
+ || disablePrespecializedMetadata.load (std::memory_order_acquire)))
98
115
return nullptr ;
99
116
100
117
auto *data = getLibPrespecializedData ();
Original file line number Diff line number Diff line change 29
29
#include " swift/Runtime/Debug.h"
30
30
#include " swift/Runtime/EnvironmentVariables.h"
31
31
#include " swift/Runtime/HeapObject.h"
32
+ #include " swift/Runtime/LibPrespecialized.h"
32
33
#include " swift/Runtime/Metadata.h"
33
34
#include " swift/Strings.h"
34
35
#include " swift/Threading/Mutex.h"
@@ -347,6 +348,8 @@ void swift::addImageTypeMetadataRecordBlockCallbackUnsafe(
347
348
assert (recordsSize % sizeof (TypeMetadataRecord) == 0
348
349
&& " weird-sized type metadata section?!" );
349
350
351
+ libPrespecializedImageLoaded ();
352
+
350
353
// If we have a section, enqueue the type metadata for lookup.
351
354
auto recordBytes = reinterpret_cast <const char *>(records);
352
355
auto recordsBegin
You can’t perform that action at this time.
0 commit comments