Skip to content

Under VFE/WME, disable mangled accessors and disable LLVM MergeFunctions #39969

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

Conversation

kubamracek
Copy link
Contributor

Two fixes for problems under VFE/WME/CRR (Virtual Function Elimination, Witness Method Elimination, Conditional Runtime Records):

  1. Using type metadata accessors that use mangled name to reference types is problematic, because that hides a dependency/reference to the type from the compiler, as it's only a string-based runtime lookup. Let's disable mangled name accessors under WME/VFE/CRR.

  2. When using VFE/WME, calls that go via vtables/wtables are using the @llvm.type.checked.load intrinsic to make a load from the vtable/wtable and pass a string metadata as the type identifier. However, MergeFunctions doesn't account for the type identifier when deciding whether functions are equal -- this very likely warrants a bugfix in LLVM, but until it's ready, let's disable LLVM's MergeFunctions pass when VFE/WME is on.

@kubamracek kubamracek requested a review from eeckstein October 29, 2021 00:54
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@slavapestov
Copy link
Contributor

Symbolic references in mangled names should still be visible to the linker -- should we instead switch to using symbolic references even for cross-module references instead? Mangled names are a lot more compact than open-coded metadata access functions. CC @jckarter

@jckarter
Copy link
Contributor

I agree, if you're seeing missed references from symbolic references, we should fix that problem instead of disabling them. One class of things that is probably still invisible to mangled names, at least until @al45tair is finished with protocol conformance demangling. A technique we'd discussed to deal with issues like this, is to append artificial references to those runtime entities after the null terminator for the runtime-interpreted part of the mangled name, so e.g. if you have something like Dictionary<Foo, Bar> we'd emit the mangled name with a reference to the Foo: Hashable conformance descriptor after the null terminator.

@kubamracek kubamracek force-pushed the hermetic-seal-no-mergefunctions-no-mangled-accessors branch from 8b14cf2 to 690373e Compare October 29, 2021 19:51
@kubamracek
Copy link
Contributor Author

Agree that fixing the missing references from mangled references is the right solution, and I'll work on that. I would still like to propose to temporarily go forward with this change, as a temporary solution to unblock actually using VFE/WME. This PR fixes the only remaining blockers from using VFE/WME on the 'freestanding' stdlib build, and I'd argue that getting this configuration in place has immediate benefits (CI will start testing it so it won't regress).

Given that, I'm happy to sign up to actually fix the missing references, but I'd like to do that as a follow-up (very soon, let's plan for next week or so). Would that be acceptable, @jckarter, @slavapestov?

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test Windows platform

@kubamracek
Copy link
Contributor Author

Fixing LLVM MergeFunctions in https://reviews.llvm.org/D112870.

@kubamracek kubamracek merged commit d682049 into swiftlang:main Nov 1, 2021
@kubamracek kubamracek deleted the hermetic-seal-no-mergefunctions-no-mangled-accessors branch November 1, 2021 22:34
// (mis-merge) unrelated functions.
if (Opts.VirtualFunctionElimination || Opts.WitnessMethodElimination)
PMBuilder.MergeFunctions = false;

Copy link
Contributor

Choose a reason for hiding this comment

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

@kubamracek I believe you also have to disable the swift merge function pass (see createSwiftMergeFunctionsPass)

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