Skip to content

Initialize TSD on macOS even without Swift runtime #1695

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
Sep 14, 2018

Conversation

copumpkin
Copy link
Contributor

Without this, you get some really fun to debug segfaults at runtime because (among other things I assume) CFRunLoopGetCurrent queries TSD to avoid doing the heavier _CFRunLoopGet0 (which then sets the TSD to avoid later work). But if we don't initialize the TSD machinery, the _CFGetTSD function returns garbage and we never get a valid CFRunLoopRef.

cc @parkera @millenomi

For context, I have the standalone framework working just fine for most things, but was getting some really weird runtime crashes whenever someone used a CFRunLoop 😄

Without this, you get some really fun to debug segfaults at runtime
because (among other things I assume) CFRunLoopGetCurrent queries TSD
to avoid doing the heavier _CFRunLoopGet0 (which then sets the TSD to
avoid later work). But if we don't initialize the TSD machinery, the
_CFGetTSD function returns garbage and we never get a valid CFRunLoopRef
Copy link
Contributor

@millenomi millenomi left a comment

Choose a reason for hiding this comment

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

I need to double-check what effect it would have on Darwin CF but it looks okay to me for now.

@millenomi
Copy link
Contributor

@swift-ci please test

@copumpkin
Copy link
Contributor Author

Yeah, agree that this might not be the correct solution, but ultimately this was my thinking:

  1. TSD initialization is guarded by swift runtime
  2. CFRunLoop (and others) uses TSDs regardless of swift runtime

So for it to work properly, either I think either 1 or 2 need to change or we'll get garbage TSD behavior.

@parkera
Copy link
Contributor

parkera commented Sep 14, 2018

I think this is ok. Worst case we call pthread_once more than once.

@parkera parkera merged commit 71aaba2 into swiftlang:master Sep 14, 2018
@millenomi
Copy link
Contributor

Worst case, I may have a patch to conditionalize this on !DEPLOYMENT_RUNTIME_OBJC or similar.

@copumpkin
Copy link
Contributor Author

Now that you mention it, would you expect a build with DEPLOYMENT_RUNTIME_OBJC to work for this public version? I'm intrigued 😄

Also, thanks for merging!

@millenomi
Copy link
Contributor

I wouldn’t. !DEPLOYMENT_RUNTIME_OBJC (note the !) is in my limited rollout the “either Swift or standalone” flag.

@copumpkin
Copy link
Contributor Author

Cool, I won't waste time on it then 😄I was poking at it and saw quite a bit of missing stuff (symbols that are ostensibly from Foundation that actually come from CoreFoundation, etc.) in the public release and wasn't sure if that's intentional or not, but if it is I won't waste time reporting discrepancies in it.

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