-
Notifications
You must be signed in to change notification settings - Fork 10.5k
IRGen: prevent WeakExternal on COFF #21780
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
We cannot use ExternalWeakLinkage on PE/COFF as the semantics for that do not exist. It is theoretically possible to emulate this by manually creating a default value for the symbol that evaluates to 0, but that requires adding a set of linker directives and variable definitions. Disable the weak linkage rather than generate an invalid module.
@swift-ci please test |
I'm really kinda torn on this change. I am half tempted to sink this into the |
Build failed |
Why are you getting weak-linkage symbols on Windows to begin with? That's pretty much an Apple specific feature. |
@jckarter because the frontend doesn't track the triple, SIL declarations will often get |
That doesn't sound right. Looking at the code, |
@jckarter - hmm, maybe I'm misunderstanding something, because my reading is that SILGen really just blindly assumes weak linkage is available...
Note that weak external linkage is also supported on ELF. |
Where are you seeing it get set unconditionally? I see:
It would be a bug for |
@jckarter - right, that seems to not take into account the object file format ... or is there a code path that I'm not finding that checks that? |
The object format isn't the point. |
Right, but that's what I'm not seeing, how does it actually account for the fact that everything may match but because it is windows, it should return
|
That's what we should figure out—why are we getting in this state to begin with? It shouldn't need any Windows-specific logic in the compiler because there's nothing in the Windows SDK that should ever be able to indicate a C definition is weak-linked because that concept doesn't exist on the platform. |
For instance, if it's coming from declarations marked |
Hmm, how do you get the target triple during the SIL parsing phase? |
It should be in the |
I don't think you should do anything trying to get those tests to run or error. Just mark them unsupported and move on. (Or separate out the parts that depend on weak linking, if they're mixed in with larger files.) We don't have any non-underscored user-visible features that would result in weak linking. |
Making the attribute error out would at least let the compiler help find all the test cases that need to be marked unsupported. There's a chance something else might be wrong too, so having an assertion in place in IRGen or somewhere else if we try to form a weak reference on a non-Darwin platform seems to me like a nice canary to have as well. |
Oh, I figured there was already an assertion and that that would be good enough, but I guess pushing the assertion up higher is reasonable. |
Okay, #21798 should take care of promoting this to a nice diagnostic rather than a crash, even with user input. |
We cannot use ExternalWeakLinkage on PE/COFF as the semantics for that
do not exist. It is theoretically possible to emulate this by manually
creating a default value for the symbol that evaluates to 0, but that
requires adding a set of linker directives and variable definitions.
Disable the weak linkage rather than generate an invalid module.
Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.
Resolves SR-NNNN.