[Runtime] Add function_cast, switch from std::bit_cast.
Function types aren't always trivially copyable, e.g. with address-discriminated signed pointers on ARM64e. Introduce a function_cast helper and use that instead.
@swift-ci please test
Manually stripping and re-signing would be pretty annoying and error-prone. What if we implement function_cast in terms of bit_cast when there's no ptrauth, and implement it with reinterpret_cast only when __has_feature(ptrauth_calls)? Or to make the condition directly address the problem, only when the types are not is_trivially_copyable.
Stripping and resigning is not allowed; pointer authentication is, in fact, actually supposed to do something.
Right, we'd really want to auth and re-sign. But doing that manually is still not an attractive prospect.
Seems that it's even simpler. The ptrauth annotation drops off the source once we're inside function_cast, so we can implement it as just an unconditional wrapper around std::bit_cast. I've updated the PR with this approach.
@compnerd Are you good with this new approach?
@swift-ci please test
@swift-ci please smoke test macos platform
@swift-ci please test