Skip to content

Commit ccdcf6f

Browse files
authored
Merge pull request #71201 from mikeash/libprespecialize-dyld-call-fix
[Runtime] Fix dyld call for Swift prespecialized data.
2 parents 01df0ca + ade4b8e commit ccdcf6f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

include/swift/Runtime/LibPrespecialized.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct LibPrespecializedData {
4545
}
4646
};
4747

48-
LibPrespecializedData<InProcess> *getLibPrespecializedData();
48+
const LibPrespecializedData<InProcess> *getLibPrespecializedData();
4949
Metadata *getLibPrespecializedMetadata(const TypeContextDescriptor *description,
5050
const void *const *arguments);
5151

stdlib/public/runtime/LibPrespecialized.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
using namespace swift;
2828

29-
static LibPrespecializedData<InProcess> *findLibPrespecialized() {
29+
static const LibPrespecializedData<InProcess> *findLibPrespecialized() {
3030
if (!runtime::environment::SWIFT_DEBUG_ENABLE_LIB_PRESPECIALIZED())
3131
return nullptr;
3232

33-
void *dataPtr = nullptr;
33+
const void *dataPtr = nullptr;
3434
#if USE_DLOPEN
3535
auto path = runtime::environment::SWIFT_DEBUG_LIB_PRESPECIALIZED_PATH();
3636
if (path && path[0]) {
@@ -41,29 +41,30 @@ static LibPrespecializedData<InProcess> *findLibPrespecialized() {
4141
dataPtr = dlsym(handle, LIB_PRESPECIALIZED_TOP_LEVEL_SYMBOL_NAME);
4242
}
4343
#if DYLD_GET_SWIFT_PRESPECIALIZED_DATA_DEFINED
44-
else {
44+
else if (SWIFT_RUNTIME_WEAK_CHECK(_dyld_get_swift_prespecialized_data)) {
4545
// Disable the prespecializations library if anything in the shared cache is
4646
// overridden. Eventually we want to be cleverer and only disable the
4747
// prespecializations that have been invalidated, but we'll start with the
4848
// simplest approach.
4949
if (!dyld_shared_cache_some_image_overridden())
50-
dataPtr = _dyld_get_swift_prespecialized_data();
50+
dataPtr = SWIFT_RUNTIME_WEAK_USE(_dyld_get_swift_prespecialized_data());
5151
}
5252
#endif
5353
#endif
5454

5555
if (!dataPtr)
5656
return nullptr;
5757

58-
auto *data = reinterpret_cast<LibPrespecializedData<InProcess> *>(dataPtr);
58+
auto *data =
59+
reinterpret_cast<const LibPrespecializedData<InProcess> *>(dataPtr);
5960
if (data->majorVersion !=
6061
LibPrespecializedData<InProcess>::currentMajorVersion)
6162
return nullptr;
6263

6364
return data;
6465
}
6566

66-
LibPrespecializedData<InProcess> *swift::getLibPrespecializedData() {
67+
const LibPrespecializedData<InProcess> *swift::getLibPrespecializedData() {
6768
return SWIFT_LAZY_CONSTANT(findLibPrespecialized());
6869
}
6970

0 commit comments

Comments
 (0)