Skip to content

[Runtime] Fix dyld call for Swift prespecialized data. #71201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/Runtime/LibPrespecialized.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct LibPrespecializedData {
}
};

LibPrespecializedData<InProcess> *getLibPrespecializedData();
const LibPrespecializedData<InProcess> *getLibPrespecializedData();
Metadata *getLibPrespecializedMetadata(const TypeContextDescriptor *description,
const void *const *arguments);

Expand Down
13 changes: 7 additions & 6 deletions stdlib/public/runtime/LibPrespecialized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

using namespace swift;

static LibPrespecializedData<InProcess> *findLibPrespecialized() {
static const LibPrespecializedData<InProcess> *findLibPrespecialized() {
if (!runtime::environment::SWIFT_DEBUG_ENABLE_LIB_PRESPECIALIZED())
return nullptr;

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

if (!dataPtr)
return nullptr;

auto *data = reinterpret_cast<LibPrespecializedData<InProcess> *>(dataPtr);
auto *data =
reinterpret_cast<const LibPrespecializedData<InProcess> *>(dataPtr);
if (data->majorVersion !=
LibPrespecializedData<InProcess>::currentMajorVersion)
return nullptr;

return data;
}

LibPrespecializedData<InProcess> *swift::getLibPrespecializedData() {
const LibPrespecializedData<InProcess> *swift::getLibPrespecializedData() {
return SWIFT_LAZY_CONSTANT(findLibPrespecialized());
}

Expand Down