Skip to content

DNM: stdlib: Add backward deployment versions for the dynamic-replacement runtime functions - version 2 #25360

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

Closed

Conversation

eeckstein
Copy link
Contributor

This will allow backward deployment to a swift 5.0 runtime.
It also needs a different mechanism to pass the "implicit" boolean parameter in the thread local storage: Instead storing it in a boolean field, we use bit 0 of the AccessSet Head.
This avoids changing the layout of the thread local storage and makes it compatible with the swift 5.0 runtime.

rdar://problem/51601233

This PR is another possibility to implement this feature. The first version is #25340

…runtime functions.

This will allow backward deployment to a swift 5.0 runtime.
It also needs a different mechanism to pass the "implicit" boolean parameter in the thread local storage: Instead storing it in a boolean field, we use bit 0 of the AccessSet Head.
This avoids changing the layout of the thread local storage and makes it compatible with the swift 5.0 runtime.

rdar://problem/51601233
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein requested a review from aschwaighofer June 11, 2019 19:52
};

__attribute__((visibility("hidden"), weak))
extern "C" char *swift_getFunctionReplacement(char **ReplFnPtr, char *CurrFn) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really wary about baking this into apps. These are pretty simple functions, which means there isn't much potential for breaking changes, but I'm paranoid that something would come up eventually.

Can we find a way to make these call the versions from libswiftCore.dylib if they exist? ARCLite accomplishes this using a terrifying technique that involves patching entries in the lazy pointer section at runtime. We could potentially do that, although it is scary.

Another option might be to use dlsym in these functions to try to find one in libswiftCore, and then call through to it if it exists. That would add a bit more overhead but it wouldn't be too horrible.

We could cut down on that overhead by having the static library include global variable function pointers that point to these functions, similar to how swift_retain etc. work. When code is compiled for older targets, have it call through the function pointers. The function pointers can point to something that decides whether to use the version from libswiftCore or the version here, then writes the appropriate function pointer back to the global variable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Andy pointed out that the current implementation would bake in the ABI of how we do things.

Jordan and I talked yesterday and he proposed marking the functions in the libswiftCore.dylib weak. Something like

libswiftCore.dylib:

__attribute__(weak) // or is that __attribute__(weak_import)
void *swift_getReplacement();

The compatibility archive can then check whether the weak symbols is bound and use it if it is otherwise fall back to a compatibility version. This way you always get the current implementation and only fall back if there is not implementation. The fallback does not become ABI this way.

libcompatdynrepl.a:

void *swift_getReplacement50() {
  if (swift_getReplacement)
    return swift_getReplacement()
  ... fallback implementation
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, this is like my dlsym idea except much better.

@aschwaighofer aschwaighofer changed the title stdlib: Add backward deployment versions for the dynamic-replacement runtime functions - version 2 DNM: stdlib: Add backward deployment versions for the dynamic-replacement runtime functions - version 2 Jun 12, 2019
@aschwaighofer
Copy link
Contributor

Follow-up as discussed: #25473

@eeckstein eeckstein deleted the backward-deployment-dr-v2 branch April 17, 2021 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants