Opened 4 years ago

Last modified 4 years ago

#20350 new defect

Work with gcc's new cxx11 abi

Reported by: vbraun Owned by:
Priority: major Milestone: sage-7.2
Component: packages: standard Keywords:
Cc: fbissey, jdemeyer Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

gcc-5 introduces a new cxx11 abi, and linking C++ libraries with different abi versions will cause missing std::__cxx11 symbols like

undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::push_back(char)@GLIBCXX_3.4.21'

This is an issue whenever we build our own gcc; Right now that means gcc-4.9.3 which only supports the old abi. So linking with any system C++ library will fail, and there are various optional libraries that packages test for and link when available. Also, gcc-5 system installations may default to the old abi (e.g. Fedora), so we can't just do a version check.

Originated in this thread: https://groups.google.com/d/msg/sage-devel/2lRw3RO1ZlQ/H8fc7fCYEAAJ

Its clear that we must update our gcc to 5 if we ever want to be able to link to new-abi libraries. Then we could also match the abi by putting -D_GLIBCXX_USE_CXX11_ABI=[0|1] into the CFLAGS

The only alternative would be to never link against a system C++ library, e.g. disable the optional libqd support in libfplll (and probably more).

Change History (6)

comment:2 Changed 4 years ago by fbissey

suspected that was it. It has been known for some time that the c++11 abi between gcc version 4.8, 4.9 and 5.1+ are not compatible. Which will be a problem for anyone upgrading a previously built sage after a gcc upgrade for 4.9 to 5.x. I didn't know fedora was defaulting to the old abi or that there was a switch.

comment:3 follow-up: Changed 4 years ago by vbraun

This is not just an upgrade problem, everybody with a sufficiently new distro will fail to link Sage stuff to system C++ libraries.

To be precise, Fedora 22 shipped gcc-5 with the old abi as default, and Fedora 23 (current) uses gcc-5 with the new abi as default.

comment:4 in reply to: ↑ 3 Changed 4 years ago by leif

Replying to vbraun:

This is not just an upgrade problem, everybody with a sufficiently new distro will fail to link Sage stuff to system C++ libraries.

Linux distro that is (at least not MacOS X where we really need to build GCC).

With sufficiently new distros, GCC should be recent enough that we could disable SAGE_INSTALL_GCC, which means g++ and gfortran have to be already installed of course.

(Although we currently have trouble with GCC 6.1... >8( )

Or am I missing something?

comment:5 in reply to: ↑ description ; follow-up: Changed 4 years ago by leif

Replying to vbraun:

gcc-5 introduces a new cxx11 abi, and linking C++ libraries with different abi versions will cause missing std::__cxx11 symbols like

undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::push_back(char)@GLIBCXX_3.4.21'

GCC's newer libstdc++ comes (by default at least) with a dual ABI, so there's no problem when older programs or libraries use the newer one (e.g. if we upgrade our GCC to 5.x or later and the system GCC is < 5.x).


This is an issue whenever we build our own gcc; Right now that means gcc-4.9.3 which only supports the old abi. So linking with any system C++ library will fail, and there are various optional libraries that packages test for and link when available.

The real problem arises from incompatibilites of (C++) libraries that expose functions whose signatures contain types like std::string, because the symbol names differ depending on whether the library was compiled using the old or the new ABI (same of course when compiling code using such libraries). This leads to linker errors if a library and modules using it are compiled with different ABIs (but only if the modules actually use such functions).


Also, gcc-5 system installations may default to the old abi (e.g. Fedora), so we can't just do a version check. [...]

Well, that's easy to figure out, and we can configure Sage's GCC (>= 5.x) accordingly: ;-)

GCC_CONFIGURE_CXX_ABI="--with-default-libstdcxx-abi="$(
($CXX -x c++ -S -o - - | awk '/.globl/{print $2!~/__cxx11/?"gcc4-compatible":"c++11"}') <<EOF
#include <string>
void foo(std::string s){}
EOF
)


Its clear that we must update our gcc to 5 if we ever want to be able to link to new-abi libraries. Then we could also match the abi by putting -D_GLIBCXX_USE_CXX11_ABI=[0|1] into the CFLAGS.

CXXFLAGS (if respected by a package) that is, but see above.

Last edited 4 years ago by leif (previous) (diff)

comment:6 in reply to: ↑ 5 Changed 4 years ago by leif

Replying to leif:

Replying to vbraun:

Then we could also match the abi by putting -D_GLIBCXX_USE_CXX11_ABI=[0|1] into the CFLAGS.

CXXFLAGS (if respected by a package) that is, but see above.

In fact CPPFLAGS, since it changes the behavior of included system C++ headers.

Note: See TracTickets for help on using tickets.