Skip to content

Fix for Foundation on Android 6.0 #2815

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

Conversation

Molanda
Copy link
Contributor

@Molanda Molanda commented Jun 4, 2020

Foundation's Host.swift uses getifaddrs and freeifaddrs, which currently causes Android 6.0 or below to fail to link.

This PR changes these functions so they are called using dlsym, which allows Android 6.0 to link while providing full support on later versions of Android.

This is a replacement for PR #2439.

@compnerd
Copy link
Member

compnerd commented Jun 4, 2020

Does this not re-open the library each call and then lookup the symbol? That isn't the cheapest operation. Why not make the function a lazy static that will cache the value avoiding the dlopen/dlsym on subsequent calls?

@Molanda
Copy link
Contributor Author

Molanda commented Jun 4, 2020

No, RTLD_NOLOAD returns the shared instance of the library.

getifaddrs and freeifaddrs are only called once, the resulting data is cached, and _resolved is set to true. So there is no benefit to caching the function pointers in this case.

@compnerd
Copy link
Member

compnerd commented Jun 5, 2020

Ah, good point about the NOLOAD. I’m still worried that future changes may end up calling the function multiple times, looking up the symbol each time.

@Molanda
Copy link
Contributor Author

Molanda commented Jun 6, 2020

Understood. I updated the comment to capture your concern for any future changes.

@compnerd
Copy link
Member

@swift-ci please test

@compnerd
Copy link
Member

CC: @drodriguez

@drodriguez
Copy link
Contributor

I don't know why CI is not triggering. Someone else might need to trigger it.

@spevans
Copy link
Contributor

spevans commented Jun 27, 2020

@swift-ci please test

@Molanda
Copy link
Contributor Author

Molanda commented Jun 28, 2020

Looks like the Linux build failed for an unrelated reason...

/home/buildnode/jenkins/workspace/swift-corelibs-foundation-PR-Linux/swift-corelibs-libdispatch/src/swift/Block.swift:13:8: error: no such module 'CDispatch'

@spevans
Copy link
Contributor

spevans commented Jun 28, 2020

@swift-ci please test linux

@drodriguez drodriguez merged commit ad50bdf into swiftlang:master Jun 28, 2020
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.

4 participants