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

Compile OpenConsoleProxy without CRT #11610

Merged
3 commits merged into from
Oct 26, 2021
Merged

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Oct 25, 2021

After this commit OpenConsoleProxy will be built without a CRT.
This cuts down its binary size and DLL dependency bloat.
We hope that this fixes a COM server activation bug if the
user doesn't have a CRT installed globally on their system.

Fixes #11529

@lhecker lhecker requested a review from miniksa October 25, 2021 21:59
@ghost ghost added Area-DefApp Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. labels Oct 25, 2021
Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

If it works, I'm good.

@github-actions

This comment has been minimized.

@lhecker lhecker force-pushed the dev/lhecker/proxy-no-default-lib branch from 36772ef to 17526d6 Compare October 25, 2021 23:18
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lhecker lhecker force-pushed the dev/lhecker/proxy-no-default-lib branch from 17526d6 to 9ee9026 Compare October 25, 2021 23:27
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

// but we need one to compile IID_GENERIC_CHECK_IID.
// Luckily we only ever use memcmp for IIDs.
#pragma function(memcmp)
inline int memcmp(const IID* a, const IID* b, size_t count)
Copy link
Member

Choose a reason for hiding this comment

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

WOW. Clever, but scary. No way to ensure that we do not explode if a dependency creeps in!

Copy link
Member Author

@lhecker lhecker Oct 26, 2021

Choose a reason for hiding this comment

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

If we ever introduce another dependency on memcmp we could just write a generic one. It's fairly easy to write one, but I figured this one is a bit leaner (since it just delegates).

<AdditionalIncludeDirectories>..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CallingConvention>StdCall</CallingConvention>
<AdditionalIncludeDirectories>.;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CallingConvention Condition="'$(Platform)'!='ARM64'">StdCall</CallingConvention>
Copy link
Member

Choose a reason for hiding this comment

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

this should not break arm64 .... does it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The compiler was complaining on ARM64 that /Zg isn't a valid option actually so I silenced it.

Co-authored-by: Dustin L. Howett <[email protected]>
@DHowett DHowett added zPreview-Service-Queued-1.13 A floating label that tracks the current Preview version for servicing purposes. zStable-Service-Queued-1.12 A floating label that tracks the current Stable version for servicing purposes. labels Oct 26, 2021
@miniksa
Copy link
Member

miniksa commented Oct 26, 2021

Validated on ARM64 with https://dev.azure.com/microsoft/Dart/_build/results?buildId=40697594&view=results from this branch. It works now

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Oct 26, 2021
@ghost
Copy link

ghost commented Oct 26, 2021

Hello @DHowett!

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.

@ghost ghost merged commit def1bdd into main Oct 26, 2021
@ghost ghost deleted the dev/lhecker/proxy-no-default-lib branch October 26, 2021 19:08
@happybear88
Copy link

Hi! Sorry to crash your dev party, but what's CRT? I came from the now closed #11529, and I don't quite understand the assumption if the user doesn't have a CRT installed globally on their system.

11529 was repro on Windows 11 out of the box. What exactly did you expect to be installed globally that wasn't shipped with the OS? Also makes me wonder how it was tested.

Thanks,

@DHowett
Copy link
Member

DHowett commented Oct 26, 2021

Sure! So, the "CRT" is the C Runtime. It is distributed in the "Visual C++ Redistributable" package that you've probably seen on most of your computers.

That package includes a few DLLs: vcruntime140.dll, msvcp140.dll, and so on. Those DLLs provide support for the C and C++ programming languages. It's usually automatically installed when it's needed, but the way Terminal installs relies on a different mechanism for finding its DLLs.

They're also not installed by default on Windows. You can find it here, or wait for it to be installed by another piece of software.

Michael and Leonard tested on a fresh Windows 11 machine that could not launch Terminal by default.

The fix here is to not depend on those DLLs at all. "OpenConsoleProxy" is another DLL file that tells Windows how to activate Terminal, and it doesn't depend on anything from those DLLs. They were marked as "required" by mistake.

We did not find this in our own testing because all of our development computers have the Visual C++ Redistributable installed already, since it comes with so much other software (like Visual Studio!)

@zadjii-msft
Copy link
Member

Sorry, when we say CRT we mean the C Runtime Library. We didn't expect this dll to have a dependency on the CRT at all. That's what we get for re-using our build scripts for every project in our solution blindly 😅.

@happybear88
Copy link

@DHowett thanks, that's a perfect explanation

@happybear88
Copy link

happybear88 commented Oct 27, 2021

Hello! I do confirm that installing VC++ redist facilitates the expected behavior.

However, this only applies to non-elevated cmd / powershell. Their elevated instances still open as their own separate windows, regardless of whether an elevated WT is open or not (i.e. "windowingBehavior": "useExisting" has no effect on the behavior)

Is this the expected behavior? If not, please point to the existing issue, as I can't find it (tried this query and variants).

@zadjii-msft
Copy link
Member

Their elevated instances still open as their own separate window

Alas, that is by design. From #10276 (comment)

Unfortunately, this is by design right now. Due to a limitation in the app platform it is impossible for Terminal to be "discovered" as the handler when the application that needs a terminal is running elevated.

DHowett pushed a commit that referenced this pull request Dec 13, 2021
After this commit OpenConsoleProxy will be built without a CRT.
This cuts down its binary size and DLL dependency bloat.
We hope that this fixes a COM server activation bug if the
user doesn't have a CRT installed globally on their system.

Fixes #11529

(cherry picked from commit def1bdd)
DHowett pushed a commit that referenced this pull request Dec 13, 2021
After this commit OpenConsoleProxy will be built without a CRT.
This cuts down its binary size and DLL dependency bloat.
We hope that this fixes a COM server activation bug if the
user doesn't have a CRT installed globally on their system.

Fixes #11529

(cherry picked from commit def1bdd)
@DHowett DHowett removed zStable-Service-Queued-1.12 A floating label that tracks the current Stable version for servicing purposes. zPreview-Service-Queued-1.13 A floating label that tracks the current Preview version for servicing purposes. labels Dec 13, 2021
@ghost
Copy link

ghost commented Dec 14, 2021

🎉Windows Terminal Preview v1.12.3472.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Dec 14, 2021

🎉Windows Terminal v1.11.3471.0 has been released which incorporates this pull request.:tada:

Handy links:

DHowett added a commit that referenced this pull request Jun 9, 2022
ghost pushed a commit that referenced this pull request Jun 9, 2022
When #13160 introduced a new interface to the IConsoleHandoff idl, it
changed midl's RPC proxy stub lookup algorithm from a direct GUID
comparison to an unrolled binary search. Now, that would ordinarily not
be a problem...

However, in #11610, we took a shortcut and replaced `memcmp` -- used
only by RPC for GUID comparison -- with a direct GUID-only equality
comparator. This worked totally fine, and ordinarily would not be a
problem...

The unrolled binary search unfortunately _relies on memcmp's contract_:
it uses memcmp to match against a fully sorted set. Our memcmp only
returned 0 or 1 (equal or not), and it knew nothing about ordering.

When a package that contains a PackagedCOM proxy stub is installed, it
is selected as the primary proxy stub for any interfaces it can proxy.
After all, interfaces are immutable, so it doesn't matter whose proxy
you're using. Now, given that we installed a *broken* proxy... *all*
IIDs that got whacked by our memcmp issue broke for every consumer.

To fix it: instead of implementing memcmp ourselves, we're just going to
take a page out of WinAppSDK's book and link this binary using the
"Hybrid CRT" model. It will statically link any parts of the STL it uses
(none) and dynamically link the ucrt (which is guaranteed to be present
on Windows.)

Sure, the binary size goes up from 8k to 24k, but... the cost is never
having to worry about this again.

Closes #13251
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-DefApp AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Default Terminal" mysteriously doesn't work at all - boots up the vintage console instead
5 participants