The Wayback Machine - https://web.archive.org/web/20201221014628/https://github.com/microsoft/react-native-windows/pull/4115
Skip to content
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

Drop StdCall in favor of Cdecl for x86. #4115

Merged
merged 30 commits into from Feb 19, 2020
Merged

Conversation

@JunielKatarn
Copy link
Contributor

@JunielKatarn JunielKatarn commented Feb 18, 2020

Being built independently, React Native Windows doesn't need to be built with the __stdcall convention.
Moreover, many third-party dependencies are developed assuming __cdecl is used (i.e. OpenSSL).

  • Annotates all non-class-member (which use __thiscall) exported functions as __cdecl.
  • Switches to a non-forked OpenSSL build.
  • Resolves #4096.
Microsoft Reviewers: Open in CodeFlow
@JunielKatarn JunielKatarn requested a review from microsoft/jshost Feb 18, 2020
@JunielKatarn JunielKatarn requested a review from microsoft/react-native-windows-write as a code owner Feb 18, 2020
Copy link
Contributor

@NickGerleman NickGerleman left a comment

Patching upstream source and manually marking everything Office uses with cdecl is quite fragile, am I'm not convinced this touches everything we use in ReactCommon for example. This change also means me need to add more patches to React Native/Folly/Yoga, which we're trying hard to remove.

I'm personally against this change. If it's easy to miss new things, and adds fork debt, more repos to manage, etc, it seems to me like it's causing more damage than its fixing.

E.g. we upgrade Folly, RN, Yoga quite frequently, but don't do the same for OpenSSL.

Please let me know if I'm missing something. Would be interested in the opinions of others here as well.

.gitmodules Show resolved Hide resolved
@JunielKatarn
Copy link
Contributor Author

@JunielKatarn JunielKatarn commented Feb 18, 2020

WINAPIV

That would require adding more dependencies on Windows.h than needed.
I believe we should not add this complexity.

@JunielKatarn
Copy link
Contributor Author

@JunielKatarn JunielKatarn commented Feb 18, 2020

True. That's why things are like they are right now, but we have ended up facing the same issue by keeping __stdcall as the absolute default. I'll ping you offline to elaborate, for the concerns are on dependent projects and not directly on RNW.

@JunielKatarn is this in reference to the OpenSSL break?

Correct.
Also, OpenSSL is a sensitive dependency, so it's preferable to not patch it, even if other components need to be patched instead.

I'm aware of dependent software being potentially impacted.
I'll start testing these changes now.

@NikoAri
Copy link

@NikoAri NikoAri commented Feb 18, 2020

WINAPIV is declared inside of MinWinDef.h, not Windows.h

From quickly taking a look of contents of MinWinDef.h, it looks fairly small and self contained


In reply to: 587938026 [](ancestors = 587938026)

@JunielKatarn
Copy link
Contributor Author

@JunielKatarn JunielKatarn commented Feb 18, 2020

I believe we would also need to fork (and maintina) more React Native APIs in ReactCommon that we export, but this change doesn't seem to do that. E.g. the instance management stuff we call directly in devmain.

I will be testing this today.
Note, if these changes affect depending projects, we can partially revert this change by:

  • Going back to ReactWindows.OpenSSL.StdCall.Static.
  • Setting CallingConvention back to StdCall.

I'll merge this change after addressing feedback.

@NickGerleman
Copy link
Contributor

@NickGerleman NickGerleman commented Feb 18, 2020

@JunielKatarn apart from changing defs, do we need to change OpenSSL source at all, or just change compiler flags when producing the x86 binary?

I mentioned needing to patch more in ReactCommon, but as soon as we add all React, Yoga, and Folly sources exporting anything as patches, we're going back to near square one for Native deforking efforts, and people will almost definitely patch our code even note. I was just about to remove some of the last of the patches there.

Given we were going to remove the rest, would you be willing to take efforts to merge during upgrades, or build tooling we'll need to detect when these are out of date when we're pulling from master? Without exaggeration, this change has the potential to add engineer-months of extra effort in the future relative to changing only OpenSSL.

Either way, I agree with @kmelmon that this change has large enough implications that we should discuss with everyone involved. Checkin should be blocked until this happens.

@JunielKatarn
Copy link
Contributor Author

@JunielKatarn JunielKatarn commented Feb 18, 2020

@JunielKatarn apart from changing defs, do we need to change OpenSSL source at all, or just change compiler flags when producing the x86 binary?

@NickGerleman With this change, OpenSSL can be built "off the shelf" with not a single change to sources or compiler flags.
Package ReactWindows.OpenSSL.v141.Static already reflects this.

@NickGerleman
Copy link
Contributor

@NickGerleman NickGerleman commented Feb 19, 2020

I talked to @JunielKatarn offline. We shouldn't need to patch React Native functions, who are using "thiscall". Since there's not a sane way around this for OpenSSL this can make sense as a stopgap. @JunielKatarn will take on ownership of maintaining the patches during upgrades, and upstreaming them.

@msftbot
Copy link
Contributor

@msftbot msftbot bot commented Feb 19, 2020

Hello @JunielKatarn!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.
@msftbot msftbot bot merged commit 0a432a1 into microsoft:master Feb 19, 2020
23 checks passed
23 checks passed
PR Build #20200219..4 succeeded
Details
PR (Build and Pack Nuget) Build and Pack Nuget succeeded
Details
PR (Current (C#) PR ArmDebug) Current (C#) PR ArmDebug succeeded
Details
PR (Current (C#) PR X64DebugBundle) Current (C#) PR X64DebugBundle succeeded
Details
PR (Current (C#) PR X86Debug) Current (C#) PR X86Debug succeeded
Details
PR (Desktop PR X64Debug) Desktop PR X64Debug succeeded
Details
PR (Desktop PR X64Release) Desktop PR X64Release succeeded
Details
PR (Desktop PR X86Debug) Desktop PR X86Debug succeeded
Details
PR (Desktop PR X86Release) Desktop PR X86Release succeeded
Details
PR (E2E Test) E2E Test succeeded
Details
PR (Setup) Setup succeeded
Details
PR (Universal Other Projects PR X64Release) Universal Other Projects PR X64Release succeeded
Details
PR (Universal Other Projects PR X86Debug) Universal Other Projects PR X86Debug succeeded
Details
PR (Universal PR Arm64Release) Universal PR Arm64Release succeeded
Details
PR (Universal PR UnpatchedRNX86Debug) Universal PR UnpatchedRNX86Debug succeeded
Details
PR (Universal PR X64Debug) Universal PR X64Debug succeeded
Details
PR (Universal PR X86Release) Universal PR X86Release succeeded
Details
PR (Verify change files + lint) Verify change files + lint succeeded
Details
PR (Verify react-native init DebugCpp) Verify react-native init DebugCpp succeeded
Details
PR (Verify react-native init DebugCs) Verify react-native init DebugCs succeeded
Details
PR (Verify react-native init ReleaseCpp) Verify react-native init ReleaseCpp succeeded
Details
PR (Verify react-native init ReleaseCs) Verify react-native init ReleaseCs succeeded
Details
license/cla All CLA requirements met.
Details
NickGerleman added a commit to NickGerleman/react-native-windows that referenced this pull request Feb 19, 2020
This reverts commit 0a432a1.

The change has led to some breakage, and there is new information about
Office's needs for the change. Revert this change in master until we
have something fully working.
NickGerleman added a commit to NickGerleman/react-native-windows that referenced this pull request Feb 19, 2020
This reverts commit 0a432a1.

The change has led to some breakage, and there is new information about
Office's needs for the change. Revert this change in master until we
have something fully working.
msftbot bot pushed a commit that referenced this pull request Feb 19, 2020
* Revert "Drop StdCall in favor of Cdecl for x86. (#4115)"

This reverts commit 0a432a1.

The change has led to some breakage, and there is new information about
Office's needs for the change. Revert this change in master until we
have something fully working.

* Change files
@WillerZ
Copy link

@WillerZ WillerZ commented Feb 24, 2020

Folly isn't designed to be a DLL: it doesn't have an ABI, or versions.

The current groupthink internally is that if some project wants to make a folly DLL for their own reasons then it's OK for them to have the burden of choosing the calling convention with the appropriate /G flag and making sure they are using the same one consistently in their project.

@acoates-ms
Copy link
Collaborator

@acoates-ms acoates-ms commented Feb 24, 2020

Agreed. We should just wait for the work to remove folly from the API boundary before we switch the calling convention used inside react-native-windows back to normal.

@JunielKatarn
Copy link
Contributor Author

@JunielKatarn JunielKatarn commented Feb 24, 2020

Folly isn't designed to be a DLL: it doesn't have an ABI, or versions.

The current groupthink internally is that if some project wants to make a folly DLL for their own reasons then it's OK for them to have the burden of choosing the calling convention with the appropriate /G flag and making sure they are using the same one consistently in their project.

Problem is, we found a case where there are two projects (Say A which depends on B, and both depend on Folly, which is statically linked into B) that use different calling conventions.
Thus, whenever A calls into a Folly method, it will try to load it with a different calling convention, and we'll hit runtime crashes.

Annotating the proper calling convention would ensure whichever /G switch is used won't affect any consuming projects.
That said, if my team judges this as non-urgent, we can drop the subject for now.

@WillerZ
Copy link

@WillerZ WillerZ commented Feb 24, 2020

we found a case where there are two projects (Say A which depends on B, and both depend on Folly, which is statically linked into B) that use different calling conventions.

The model we expect here is for both A and B to statically link to folly and that neither of them should be exporting any folly symbols.

@JunielKatarn
Copy link
Contributor Author

@JunielKatarn JunielKatarn commented Feb 24, 2020

we found a case where there are two projects (Say A which depends on B, and both depend on Folly, which is statically linked into B) that use different calling conventions.

The model we expect here is for both A and B to statically link to folly and that neither of them should be exporting any folly symbols.

We'll look into that :)

@JunielKatarn JunielKatarn deleted the jurocha-ms:x86cdecl_f0 branch Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
7 participants
You can’t perform that action at this time.