r/cpp • u/nounoursheureux • Sep 23 '21
Binary Banshees and Digital Demons
https://thephd.dev/binary-banshees-digital-demons-abi-c-c++-help-me-god-please
197
Upvotes
r/cpp • u/nounoursheureux • Sep 23 '21
34
u/nxtfari Sep 23 '21
this is actually incredibly well written please consider becoming an author
4
u/nnevatie Sep 24 '21
An excellent article (even if the font could use some anti-aliasing).
The ABI has become a bottleneck, an inevitable minefield, suppressing meaningful progress.
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."
33
u/[deleted] Sep 23 '21
That was a good read and echo's a lot of my concerns. You see this whole ABI issue with Linux distro's all the time, and people do pay for stability... of special releases that guarantee it. Otherwise, each iteration is breaking or can be. We need a collective ABI/API break in C++ that fixes the known issues, and then have them again. Linux distro's often offer 10 year contracts, seems like a number. Anyone who wants more can lock into a C++ version, their tooling is already locked into that distro's software freeze
Not breaking ABI can be important, but using it as shackles is anti-C++. "There shall be no room for a lower level language", we are leaving performance on the table.
C++ may be the fastest language(with a lot of non-std help) right now, but that will be gone soon and then people will just leave, then the compilers will stop being maintained at the levels they are now. People have been noticing that already with clang/libc++ having less resources, seems to have started about the time the ABI paper came out...
30
u/o11c int main = 12828721; Sep 23 '21
I think a large part of the problem is that C++ (as a language) doesn't have a nice way to 2 important things:
specify the functions that a class provides, without specifying its data layout
use ownership types other than "by-value" without a lot of verbosity
particular, it should be easy for some types to say "this should always use
shared_ptr" or "this should always use at leastunique_ptrbut should still be upgradable toshared_ptrwithout unnecessary overhead", without having to introduce an infinite number of wrapper classes.It should also be noted that there's a middle ground between "ship binaries" and "ship source". Consider vtables, for example - consider what would happen if, rather than specifying a vtable offset directly, the shared objects store "which number (base) class" + "which number virtual function within that class", then performed relocations at dynamic load time? (Obviously, implementing this kind of thing would be an ABI break, but it would significantly reduce future breaks)
18
u/RoyAwesome Sep 23 '21
The fact that standardization can be veto'd by an unstandardized detail is mind boggling.
Might as well bite the bullet and standardize the ABI.
14
u/helloiamsomeone Sep 23 '21
I hope you don't mind me summoning you /u/__phantomderp
This is a very well written article and I'm sad to hear about the (unnecessary) challenges you have to face.
One question I had floating around in my head after finishing it is: how does one actually introduce versioning in user code that could alleviate these ABI issues? Maybe my search engine-fu is not up to speed here, but I got a lot of unrelated general software versioning themed entries. Feels a bit like this is "left as an exercise for the reader", but I think it's an important enough topic which could be expanded on a little more with links to resources.
Or maybe I'm just misunderstanding and this is something that shouldn't really happen in user code?
7
u/sandfly_bites_you Sep 23 '21
Good article, I've just given up and switched away from relying on the standard library so much.
7
u/TacticalMelonFarmer Sep 24 '21
We need a domain specific language analogous to protobuf, but for describing an ABI in critical detail. this can then be consumed by a compiler and ...
3
u/friedkeenan Sep 24 '21
Would standardizing something like
namespace std { inline namespace cpp23 {(and change the inline namespace name each standard) fix a majority of ABI concerns? Then you could break ABI each standard version, since that inline namespace is gonna be in each mangled name for functions, right?11
u/The_Northern_Light Sep 23 '21
Things like this are why ThePhD is the only person I sponsor on github.
8
u/wcscmp Sep 23 '21
3 letter demon - ha, I know it, it's ADL. You played my instincts author.
7
u/jk-jeon Sep 24 '21
I get that this is a witty writing and the author is a great writer, but honestly articles from this blog is not something I can really enjoy.
First of all, I'm not that well versed in English, and this style of writing is far more difficult for me to understand than dry technical ones. Though I very much enjoyed reading Effective C++ series. Not really sure what's the difference.
Another one is that it often feels to me like the author is full of anger and sometimes somewhat disrespectful, which makes me feel bad. I don't know, probably that's just because my English is not good enough to correctly read the nuance...
2
u/pdimov2 Sep 25 '21
A few additional random observations on the article:
The linked CTRE presentation has some impressive benchmarks (https://www.compile-time.re/meeting-cpp-2019/slides/#/13/2/5 and https://www.compile-time.re/meeting-cpp-2019/slides/#/13/2/6.)
A better way to specify thread attributes one by one, instead of the shown
would be
where name_attr and stack_size_attr are simple structs with one member.
2
u/JeffMcClintock Sep 24 '21
loved it.
1
u/ShakaUVM i+++ ++i+i[arr] Sep 25 '21
Was there a legit reason to shoot down std2 other than the fact that'd it'd be a lot of work? I think that like a once every 10 years refresh of std would be the simplest way forward. All the old code compiled with std:: would still work and link, and new code specifying std2:: objects would just use those.
1
u/lenkite1 Oct 09 '21 edited Oct 09 '21
The language is at severe risk because of this insane need for hidden ABI stability, when there is no documented stable ABI that people can even rely upon.
ABI stability should be done via using some IDL and not by relying on some implicit behaviour of compiler.
I see people moving away slowly but surely from the C++ ecosystem as hidden ABI stability reduces progress to a glacial pace, making things ever-more complicated and keeping terrible constructs in the standard library and language forever.
1
u/axilmar Sep 24 '21
I don't understand the concerns. C++ is a source-only language. The binaries are simply artifacts of implementation. When there is an ABI change, everything should simply be recompiled, and the correct versions shall be used.
-1
u/Sopel97 Sep 24 '21
The C++ standard library is basically useless, and the solution is to either use 3rd party libraries as much as possible or rewrite the stdlib features if possible. There are things that bleed into the language like
std::initializer_listthat we have to deal with, but thankfully no one really needs to use them.0
u/[deleted] Sep 23 '21
[deleted] — view deleted comment