5 ms·
The Case of GCC-5.1 and the Two C++ ABIs
- bluejekyll 11y agoDid the ABI break for all libraries of C++11 or is it just gcc produced ones?
- Sanddancer 11y agoJust gcc produced ones. GCC wanted to add a feature so that developers can add and change functions without changing the library version number. Which, to be quite honest, is a silly feature, as it leads to problems like the one we're seeing right here.
- rleigh 11y agoGCC libstdc++ has been backward compatible with no ABI breaks for around a decade. GNU libc for what, two decades. You don't break such fundamental ABIs on a whim. If the libstdc++ ABI had changed, it would have broken every single bit of C++ code built with GCC4 over the last decade. Including code with transitive dependencies on the old ABI. Rather than declaring this as a "silly feature", I think we might be better off thanking the developers concerned for solving a very hard problem and going the extra mile to ensure backward compatibility. They could have been lazy and said "ABI break! Flag day today: every user of GCC much rebuild the entire world and, by the way, none of your old software will run any longer", but they didn't. So clang hasn't got the new ABI quite right to match GCC, that's a minor niggle. It can be fixed. You can't fix breaking the whole world. As an example, consider that the Mesa OpenGL C library internally uses libstdc++. If this was built using an incompatible new ABI, it would break every C++ program linked against the old ABI. And vice-versa. That game or expensive visualisation software you bought, that's not going to work any more. Stable ABIs matter.
- nly 11y agoWell said. I was using Gentoo around the GCC 3.3 -> 3.4 migration (that's when the ABI last broke seriously). That wasn't fun.
- Sanddancer 11y agoThis is a flag day, though. Even the Fedora developers have said as much [1]. Had they changed the version number to add this feature, it would have caused less pain for developers and distributors, because they wouldn't have to worry about what ABI to link to and who to make angry. They could have been in a position to bundle both, and tools that require delving into the deeper workings of the library, like compilers, would be better able to get the info they need. Had the GCC team done this correctly, they'd have bumped the version number, so people who depend on their software can choose to ship both versions if they want to. Instead, c++ software linked against libstdc++ is going to have a period of confusion, because both versions exist in the same library. [1] http://fedoramagazine.org/gcc-5-in-fedora-whats-an-abi-and-what-happens-when-we-change-it/ http://fedoramagazine.org/gcc-5-in-fedora-whats-an-abi-and-w...
- rleigh 11y agoThe dual ABI is only implemented in libstdc++, so if you want to use the new ABI in a library then all your dependent libraries will then need to use the new ABI so you are all using the same std::string etc.. From this point of view it's perfectly sensible for a Linux distribution to decide to rebuild everything using the new ABI. You're right that a soname increment would have been one way to do this. But you would still have the problem of transitive dependencies on the old ABI since you can't load two libstdc++ libraries at the same time. In a few months time we'll all forget this was an issue since it will for all intents and purposes (for the end user and developer) be a completely transparent upgrade.
- twoodfin 11y agoI don't think there was anything specific about C++11 that would have forced every implementation to change their ABI. IIRC, one of the most significant was a change that made copy-on-write an invalid (or at least much more difficult) implementation for std::string, and gcc's std::string was CoW. http://developerblog.redhat.com/2015/02/05/gcc5-and-the-c11-abi/ http://developerblog.redhat.com/2015/02/05/gcc5-and-the-c11-...
- rleigh 11y agoWell, this is a false question. The ABI didn't break; GCC5 deliberately supports both the old pre-C++11 and new C++11 ABIs in the same library. There are various arguments for and against this approach, but the bottom line is that binary compatibility was explicitly not broken. The issue here is solely that clang++ doesn't yet implement some of the requirements of the new ABI and so isn't fully compatible with it. This is a very different point.
- pbiggar 11y agoI really love the Go has gone with static binaries. There are so few use cases where we really need to be distributing libraries separately from apps and link them dynamically later. It's 2015, static binaries only takes a tiny bit of memory (relative to how much is available and what we use for other things), and both disk space and bandwidth for downloading binaries is pretty abundant. Why are we still worrying about ABIs!! [edit: clarified it isn't about the type of linking, it's about separate distribution of libs from apps that use the libs).
- millstone 11y agoImagine writing, say, Firefox, without dynamic linking. You would have to provide a separate version of Firefox for every version of the OS, and when the next version of the OS is released, your current Firefox would stop working! It's not about saving memory or disk space (although those are still very significant, especially on mobile). It's about allowing a program's components to evolve separately.
- pbiggar 11y agoI don't understand why you would need a separate version of Firefox for every version of the OS?
- millstone 11y agoConsider Copy/Paste. This is a system feature, and all apps must agree on where the clipboard is and how to access it. If the system implementation of the clipboard changes (say, in the next OS), then apps that statically linked against the old implementation will not be able to Copy/Paste with those in the new implementation. You also have the reverse problem: apps compiled against the new implementation will break when run on the prior OS. Dynamic linking is one way to ensure that all apps automatically get the correct clipboard implementation for the system they are running on. Of course this applies to all system features, not just copy/paste.
- 11y ago
- haberman 11y agoWould love to see some more background on this. Is it the C++11 ABI itself that changed, or just the ABI of libstdc++ when compiled as C++11?
- DSMan195276 11y agoMy understanding is that supporting C++11 requires changes to libstdc++ (Specifically, how std::string and std::list are implemented) which will make the new implementation incompatible with code compiled for older versions of libstdc++.
- rleigh 11y agoYou are correct that C++11 required changes to certain implementation details of libstdc++. However, you are incorrect about this making the new implementation incompatible with old code compiled against older libstdc++ versions; this is explicitly and intentially supported via a dual ABI--the "new" libstdc++ will provide both the old and new variants simultaneously.
- DSMan195276 11y agoSorry, I wasn't trying to imply the new libstdc++ wouldn't work with old code, just explaining to the poster why the new ABI is required in the first place. The changes to libstdc++ which are incompatible are what is causing the dual ABI to be required - And of course, the dual ABI is what allows old programs to continue to use the old ABI with a newer libstdc++ library without problems.
- DannyBee 11y agoInterestingly, this was a suggestion made many many years ago and started as an experiment. Like 10 years ago, i believe ;) libc++ is also versioned using namespaces, but no abi_tag