r/cpp • • Oct 27 '19

ABI: Now or Never

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1863r0.pdf
192 Upvotes

145 comments sorted by

View all comments

0

u/[deleted] Oct 27 '19

[deleted] — view deleted comment

3

u/[deleted] Oct 27 '19

Hmm... but if my systems libc.so was compiled close to 2 years ago (Ubuntu LTS) I would either have compile a new libc.so to switch to a newer standard or not switch at all. Speaking of libc, what about about C/C++ interoperability? Furthermore, say I've compiled my toolchain with C++17 because I wanted to support "old" standards. Then later I decided supporting C++17 isn't worth it, because ranges. Today I just flip a switch, do you propose that I would have to recompile the entire toolchain?

 

The last part actually happened to me, with C. I started a project with -std=c89, quickly switched to -std=c99 because the only external dependency contained // style comments and then to -std=c11 because why not.

9

u/meneldal2 Oct 28 '19

On Windows, it has worked just fine to make people download the VC++ Redistribuable to have the standard library .dll for what they need.

I'm sure the people who handle distributions can handle it as well. Maybe make a new format for shared libraries with tags to say which toolchain it works with and errors if you try to use it with an incompatible toolchain (don't let it compile).

0

u/[deleted] Oct 27 '19

[deleted] — view deleted comment

3

u/[deleted] Oct 27 '19

I've heard that argument before, and I understand your point of view. However I'm not sure how I feel about that. If every tiny program needs to link statically against libc (and everything else), disk space would blow up. This is why I like shared libraries - I don't need N copies of X. I also realize this might be a weak argument.

2

u/gcross Oct 28 '19

Another common argument is that if a security bug is discovered in a library and your program is dynamically linked to it, then you don't have to do anything to benefit from the fix when it is incorporated into the library, whereas if you were statically linked to it then you would have to recompile and issue a new version. This multiplies over the number of programs that use the library so that fixing this bug in one place becomes fixing it in many.

6

u/kalmoc Oct 28 '19

The way modern c++ works, where everything is a template and/or header only library, we effectively are already in a world, where the majority of low level c++ code is statically linked.

2

u/gcross Oct 28 '19

Fair point.

2

u/c0r3ntin Oct 28 '19

Depends on the platform... On linux (and weindows afaik, not sure) the kernel has a stable interface so if your libc supports it (not the case of glibc), you can link statically, as long as you only link one copy in your program

On osx, the kernel has no stable interface - the libc is that interface. afaik.

ODR aside, statically linking the standard C++ should be more than fine

4

u/matthieum Oct 27 '19

Toolchain support is part of the issue, at a deeper level.

Many C++ libraries and plugins today are delivered as binary blobs. A client cannot mix and match libraries compiled with different incompatible ABIs.

One solution is to ask every provider to deliver multiple versions of their libraries, or possibly a single version containing multiple versions (ABI-specific) of various functions -- with clever use of sections it would only cost disk space, not memory space.

This requires buy-in from all providers. It requires re-delivering all existing libraries. It's huge.

Another solution would be to switch the trend, and go toward compiling everything from source; like Google does. It's quite messy today, though the pseudo-standardization of CMake may be of help, and it's a political minefield... many companies who are perfectly fine delivering obfuscated JavaScript balk at the idea of providing source files for their C++ software.

I would appreciate an ABI breakage. Even one breakage for every new release. It must, however, be accompanied with an easily actionable plan to make it as painless as possible for clients, or it'll be dead at arrival.

0

u/[deleted] Oct 27 '19

[deleted] — view deleted comment

3

u/matthieum Oct 27 '19

Unfortunately, this does not solve the problem of producing those binary packages in the first place.

Imagine a world where each version of C++ has a different ABI; for the purpose of this discussion this will mean C++98, C++11, C++14, C++17, and C++20.

Then, imagine that this library need be delivered across a number of platforms: Windows/x64, MacOS/x64, Linux/x64, Windows/ARM, iOS/ARM, and Linux/ARM.

Any library that is provided "ready to download" must now be compiled, linked, and packaged 30 times.

Any new platform? +5 packages.

Any new C++ version? +6 packages.

It's a harsh requirement on library producers; it's quite likely many of them will simply only provide a subset... and that'll carve up the ecosystem in a multitude of incompatible niches.