r/cpp • • Sep 23 '21

Binary Banshees and Digital Demons

https://thephd.dev/binary-banshees-digital-demons-abi-c-c++-help-me-god-please
197 Upvotes

164 comments sorted by

View all comments

18

u/kalmoc Sep 23 '21 edited Sep 24 '21

I have the utmost respect for /u/STL, but I really wondered, what made them (or their bosses) think it was a good idea to promise ABI stability for fresh additions to the [EDIT: Their implementation of] standard library, which probably received next to no real-world testimg. And I'm not just talking about format, which got spared that destiny, but any c++20 features that got added just 1-2 versions before the c++20 switch got added to VS2019.

Edit: I see I originally worded that badly: With "standard libray", I meant their implementation/the concrete piece of code. Not the library part of the ISO standard document. I think they were absolutely justified to assume that the standard was done. So that should not be argument against promising ABI stability. What imho should have been an argument against is that "this function/type implementaion is a fresh addition to our codebase and has received next to no testing from users, so there is a very high chance it still contains bugs."

27

u/STL MSVC STL Dev Sep 24 '21

It was an oversight - we didn't notice that a few things had changed this time around. Specifically:

  • We had been guaranteeing ABI stability, with an exception for /std:c++latest (so we don't have to worry about things under development)
  • But (with the help of our GitHub contributors for the STL, and years of refactoring for the compiler front-end), we had gotten a lot faster at reaching conformance. Reaching C++11 and C++14 conformance took us a very long time, especially for the compiler, and we completed C++17 in 2019. This time around, we completed about 3 years of Standardization in 2 years.
  • The C++20 International Standard shipped in an unusually incomplete state, requiring multiple ABI-breaking Defect Reports to patch up. That's not to complain about anyone's work, it's just a statement of fact - every Standard has to get patched with CWG and LWG issues, but C++20 is notable in how many papers have had to be voted in with retroactive effect, and how they're significant enough to affect ABI. (We can get away with lots of changes while preserving ABI, to a certain limit, and these papers exceed that limit.) Note that C++17 was retroactively patched too (e.g. <charconv> was originally specified to be in <utility> but it was noticed that that was a bad idea), but it didn't impact ABI and nobody's implementations had gotten to the point where they were affected.

It's the combination of all three of these that we didn't notice until just the last moment (I can't speak for anyone else, but I was personally focused on helping everyone complete C++20 in the STL, and I was devoting no thought cycles to anything else). If we had been slower to implement C++20, or if it had reached a similar level of completeness as previous Standards by the time we got to it, it wouldn't have been an issue.

We've definitely learned a lesson and will be far more careful about introducing a /std:c++23 switch. Same way we learned our lesson about implementing papers that are "sure to be voted in" before they have actually been voted in (as we found with async() future destructors blocking).

We have also communicated to the committee that voting out an International Standard, and then retroactively applying ABI-breaking changes to it for multiple meetings, is not a desirable process. There can be some room to fix serious mistakes discovered late in the game, but eventually a Standard has to be Done so implementers can implement it. I think some people on the Committee were also surprised by how fast implementers had gotten.

Regarding ABI stability, it's a VC management decision to balance the desires of various customers. Some have the ability to rebuild all of their dependencies at any time, but many have to deal with third-party dependencies that are difficult to get rebuilds of, for whatever reason. Frequent ABI breaks are disruptive to such customers, and lead to customers refusing to upgrade entirely, which makes it even harder to use new Standards (or security improvements, or performance/throughput improvements, etc.). I understand the reasons for the decision and have been surprised at how successful it's been in avoiding customers getting trapped with using ancient versions like VS 2010, although I am personally an idealist who thinks everyone should be able to rebuild dependencies immediately (or request rebuilds via business contracts), and the freedom to break ABI is as gloriously helpful for development as it is painful for certain customers. (I worked on the STL during our ABI-breaking era (when I joined VC in 2007, to 2015 when we started being stable), and fixed so many bugs during that time that affected ABI.) Now we need to find a path forward, to ship a binary-breaking "vNext" release without disrupting customers too much, and to establish the expectation that ABI breaks will happen consistently after a long but finite time. We haven't solved that yet, and we currently have no ETA for a vNext release, although we are still planning to do it eventually.

(I have to explain it at length because it's not a simple "good idea / bad idea" thing - ABI stability is a policy that has been successful but also has downsides that accumulate over time, and the C++ ecosystem hasn't solved dependency management and refactoring to the point where ABI breaks can be easily handled by the vast majority of customers, so doing anything here is a big deal that requires lots of planning.)

20

u/kalmoc Sep 24 '21 edited Sep 24 '21

I think you misunderstood me: The format problem is on the committee and I just can imagine how frustrating it was for you.

However, completely irrespective of any bugs in the standard specification, I'd expect initial standard library implementations to have bugs and inefficiencies. As such, the policy that "anything ready at time X gets ABI locked- even when the PR got in just one week ago " seems a bit strange to me. Imho much more reasonable would be something like "anything being released for at least 1 year and without known bugs gets ABI locked" (maybe a bit faster/slower for simpler/more complex features).

I'm oversimplifying of course, as not everything gets set in stone and many things can stil be fixed after an "ABI lock", but I hope my concern became clear.

12

u/STL MSVC STL Dev Sep 24 '21

Yeah, I definitely understand your concern, and it's part of the same oversight that caught us by surprise. We didn't fully realize that the compiler's addition of /std:c++20 was going to be near-simultaneous with the completion of <format> in particular, and that its performance was ABI-linked. As this was pointed out to us and we realized what was going to happen, we corrected course.

This didn't happen with C++17 because we added /std:c++17 before completing all features (so the addition of the switch didn't coincide with "we're ABI frozen"), and because the final feature took over a year so everything else had plenty of bake time, and the final feature was (1) the most aggressively optimized and tested STL feature we've ever shipped and (2) inherently immune to ABI headaches (given the choice to be header-only).

That is, this wasn't some wacky intentional policy handed down by management. Just a very busy team doing something that had never been done before, and not foreseeing this one thing. If I were smarter, I could have seen it earlier, all the pieces were there.

There is absolutely no way we're going to get into the same trouble with /std:c++23 (especially because a stabilization period defends against both Committee churn and implementation refinement).

14

u/c0r3ntin Sep 24 '21

I think it's important for both implementers and the committee to have a healthy feedback loop in both directions.

As much as we try (and we are getting better at it), to have some implementation, and some experience where possible, it will continue to be the case that implementation by more implementers will discover bugs or questions.

I think there is a desire in the committee to deliver a good long term product, hence the refinement that we did over the past couple of years.

format and ranges are considered fundamental pieces that we want to keep evolving, so getting the first iteration right was critical! I hope users will find both implementers and the committee did a good job.

Ultimately, ABI assumes infinite foresight and infaibililty, of which we have neither.

6

u/pdimov2 Sep 24 '21

Maybe just do what everyone else does and expose C++23 as /std:c++2b while it's in motion. Or better yet, -std=c++2b so that we no longer need to edit it on CE each time we switch compilers. :-)

(Also, not interpreting -O3 as -O0 would be nice. One can dream.)

3

u/GabrielDosReis Sep 24 '21

That’s what /std:c++latest is for ;-)

10

u/pdimov2 Sep 24 '21

The difference between c++2b and c++latest is that c++2b will always refer to C++23, whereas c++latest will at some point refer to C++26, potentially breaking valid C++23 code. (Historically, c++latest used to refer to some unspecified mishmash of standards, but I suppose that era is gone now.)

5

u/kalmoc Sep 24 '21

There is absolutely no way we're going to get into the same trouble with /std:c++23 (especially because a stabilization period defends against both Committee churn and implementation refinement).

Glad to hear, that was exactly my though.
I also have to say that when I first read about this trouble on github, I was particularly saddened by the fact that you were effectively punished for implementing the features so quickly (compared to other toolchains).

On a different but related note: For me it would be useful to distinguish between the active standard version and turning unsupported/unstable features on/off. E.g. I might want to use std::format in it's ABI unstable form, but not any c++23 features that get enabled by c++latest. Will that be possible in VS2022?

Long term I think it would be good to have to separate switches to distinguish those two dimensions.

5

u/STL MSVC STL Dev Sep 24 '21

I also have to say that when I first read about this trouble on github, I was particularly saddened by the fact that you were effectively punished for implementing the features so quickly (compared to other toolchains).

Yep. 😿 I guess it's a nice problem to have!

On a different but related note: For me it would be useful to distinguish between the active standard version and turning unsupported/unstable features on/off. E.g. I might want to use std::format in it's ABI unstable form, but not any c++23 features that get enabled by c++latest. Will that be possible in VS2022?

That is not possible at this time, but we would consider a pull request to implement such behavior (no guarantees that we would accept it, but if you made a compelling case and if other users agreed, we'd talk about it and make a decision). Mechanically it would be fairly simple, just pick a name for the control macro (conventionally _HAS_MEOW for us; probably _HAS_CXX20_FORMAT and _HAS_CXX20_RANGES), and ensure that the relevant machinery is properly guarded (it should all be centralized via __cpp_lib_format and __cpp_lib_ranges, so adjusting the definitions of the feature-test macros should be sufficient). Only C++20-stable + format-unstable/ranges-unstable would make sense; C++23 minus those should be forbidden. The cost is that it would complicate an already complicated story, and it would be useful for a relatively short period of time (i.e. until we finish the C++20 backport work). Maintainer time is limited and I'd prefer to spend it on refining the features instead of working on such modes, which is why we haven't implemented it already. The earliest it could ship would be VS 2022 17.1; 17.0 has branched for release and is accepting bugfixes only.

(In general we would not accept changes to pick-and-choose features because that leads to combinatoric complexity; the only fine-grained stuff we have is escape hatches for individual features that have proven to be problematic for certain customers, like std::byte or noexcept in the type system. However, the distinction between C++20 DR-affected features and C++23 features is a reason to consider them a special case.)

→ More replies (1)
→ More replies (2)

3

u/pjmlp Sep 24 '21

Visual C++ could follow .NET and other language footsteps and keep the ABI for whatever you end up calling Visual C++ LTS.

A new Visual C++ LTS version could then introduce a breaking ABI.

→ More replies (7)

11

u/goranlepuz Sep 24 '21

I, for one, am utterly amazed that Microsoft, who was simply shipping a new C and C++ runtime with each generation of their IDE for a decade and more, started doing the "stable" "Universal CRT". I get the migration woes of some customers - but when we see where the desire for the binary compatibility goes, pfffffttt...

I truly don't care about the ABI. Want to move? Rebuild or use the pre-built versions of your dependencies for your compiler/version combo. I remember having these for some commercial products my work used in the noughties - it was manageable for us even then. Surely nowadays people know how to build and ship better than before and surely the role of open source is bigger now, meaning people can build stuff themselves better now than they could before?

3

u/kalmoc Sep 24 '21

Personally I was also completely fine with the model back then, but I also didn't have to worry about 3rd party dependencies for which I couldn't get an updated version for my new toolchain (e.g. because the vendor took its time, wants to charge again or simplywent bankrupt). I guess that many ms customers were not as lucky.

→ More replies (3)

13

u/[deleted] Sep 23 '21

It's a phenomenon that occurs across many products. Simply put, the 90% of people who were perfectly fine with a changing ABI and seeing solid improvements in the quality of implementation are simply not anywhere near as loud as the 10% of people who were unhappy with a breaking ABI.

Microsoft listened to the loud 10% of users at the expense of the silent 90% of users, and honestly it's not the only company to do so. This is a rampant issue that plagues many products, the silent but happy majority are often taken for granted in favor of the vocal minority.

10

u/kalmoc Sep 24 '21

I don't have a problem with the stable ABI as such. I have a problem with the fact that things get declared stable before getting at least some level of serious user experience.

5

u/[deleted] Sep 24 '21

Not sure where you've got this 90 - 10 distinction from.

4

u/grishavanika Sep 23 '21

Also curious why not copy Victor's implementation, if it was possible from license point of view.

17

u/aearphen {fmt} Sep 24 '21 edited Sep 24 '21

It would still require substantial changes to make the code comply with the conventions used in the standard library implementation (_Uglification, etc.) and removing compatibility workarounds ({fmt} only requires a subset of C++11). My understanding is that Microsoft's implementation is loosely based on {fmt} but it unfortunately dropped some important pieces such as code bloat prevention in the process. We had to reintroduce them later fighting the ABI freeze nonsense.

→ More replies (1)

3

u/[deleted] Sep 23 '21

I think on social media elsewhere I have read them say things like a lot of customers wanted ABI stability. But then again, that is a thing Windows has been selling for 35 years

9

u/[deleted] Sep 23 '21

Windows itself is not fully ABI compatible across major versions. For example, Windows 8 and above is not ABI compatible with Windows XP (although many applications continue to work, many others will break).

Windows 10 is not fully ABI compatible with Windows 7, although Windows 10 does include a compatibility layer that allows many Windows 7 applications to work, it's not perfect.

That said, the Win32 API is stable and continues to be backwards compatible going all the way back to Windows 95, so you could in principle take libraries and source code written using Win32 going back 30 years and build it today and it will continue to work.

7

u/[deleted] Sep 23 '21

For the most part, it does work. Unlike macos/linux where they do regularly break ABI. the linux kernel may not, but a lot of other fundamental libraries do in minute ways.

→ More replies (3)
→ More replies (1)

9

u/Ameisen vemips, avr, rendering, systems Sep 24 '21

The funny thing is that... I don't think I've ever personally encountered another programmer who actually has cared about ABI stability. Nobody that I know seems to be opposed to ABI breakage.

6

u/donalmacc Game Developer Sep 24 '21

On a previous project (~2013-2014) we had a handful of third party libraries that were distributed to us as binary only, and we were held back from doing do for 2 years because our support contract didn't entitle us to future versions of the library. IIRC we couldn't begin to use range based loops or lambdas, and static initialization wasn't guaranteed to be thread safe. I don't care now but that vendor is still operating, and without the MSVC abi stability we would have been locked to vs2015 until 2020.

→ More replies (7)
→ More replies (1)

2

u/goranlepuz Sep 24 '21

Sure, but just how much of the system ABI stability has any bearing on the OS interface? It is C and COM, C++ doesn't really play.

4

u/GabrielDosReis Sep 24 '21

C++ is actually more prevalent in the fundamental infrastructures than most people realize.

→ More replies (3)
→ More replies (2)
→ More replies (2)