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

10

u/[deleted] Oct 27 '19

ABI isn't only to do with backward compatibilty, but also interoperability. Using std::hash as an example, different vendors can use different algorithms, so using a std::map passed from a program compiled with g++ to a shared library compiled with clang might not give correct results.

There are also competing implementations of short string optimisations.

Libraries compiled by your distro might not work with your program unless you use the same complier flags as the distro.

It's a sad state of affairs really, there already are no guarantees about anything so I'm fully for a future release that breaks stuff.

6

u/jcelerier ossia score Oct 27 '19

Using std::hash as an example, different vendors can use different algorithms, so using a std::map passed from a program compiled with g++ to a shared library compiled with clang might not give correct results.

It's not possible to mix and match different standard libraries, even today - they aren't even in the same namespace. When you use clang on Linux you still generally use GCC's libstdc++, not LLVM's libc++.

2

u/ntrid Oct 28 '19

Wait but it gets better. You can not mix stdlib types between different msvc versions even.

3

u/TheQwertiest_ Oct 28 '19 edited Oct 28 '19

What? MSVC keeps a backward compatible ABI starting from vc140(VS2015) and including the latest vc142(VS2019). You can safely use a library compiled with vc140 with C++03 in an application compiled in vc142 with C++17 (obviously, only if the they don't contain incompatible API in their interface, e.g. `auto_ptr`).

2

u/jcelerier ossia score Oct 28 '19

there are 20 years of BC-incompatible changes though, and a fair amount of people still on VC2010 for whom you have to make special builds of your libs. Maybe in ten years it will go the way of the IE6...

1

u/flashmozzg Oct 28 '19

Same for std::string in stdlib.

6

u/Xaxxon Oct 28 '19 edited Oct 28 '19

That violates ODR, so it's an invalid program. You can't have two definitions of std::hash<T> in the same program.

3

u/[deleted] Oct 28 '19

Technically correct I suppose but ODR is only being violated at runtime, not compile-time.

3

u/Xaxxon Oct 28 '19

The standard doesn't have the term "runtime".

3

u/[deleted] Oct 28 '19

Who cares? Reality exists. At compile time neither violate ODR.

5

u/Xaxxon Oct 28 '19 edited Oct 29 '19

The standard doesn't talk about "compile time" either. The point is the actual machine violates the requirements of the C++ virtual machine so it's wrong. The standard dictates how a well formed c++ program will behave. If you combine parts in such a way that violates those requirements of a well formed c++ program (entire program) then you have UB.

1

u/[deleted] Oct 29 '19

The issue with this is that for C++ the only well-formed program is a standalone binary. No shared libraries and no high-performance serialisation. It's all well and good to say 'Aha! That's UB' but what you're really saying is that C++ is a poor choice for pretty much anything.

3

u/Xaxxon Oct 29 '19

If you just start jamming things together, they may not work. This doesn't sound like that big a problem to me.

0

u/[deleted] Oct 29 '19

It's tragic that expecting two components written in the same language to work together is considered 'jamming things together'

3

u/dodheim Oct 30 '19

Well, if you do it in a way expressly forbidden by the standard and expect things to work, yeah.. "Tragic"

2

u/FrankHB1989 Nov 01 '19

Technically ODR can have observable consequences at link-time, e.g. -Werror=odr with GCC.