3

I have a docker image for centos 6 with devtoolset-6 installed and I want to build my code with the new ABI available in gcc>=5, in this case gcc6. Somehow I do not get what I expect to work by default. I have tried various variations but I am at loss what trivial thing I am missing.

Any suggestion what I am missing would be greatly appreciated...

On compiling the sample code below I expected to see:

$ gcc -c test.cpp –o test.o
$ nm test.o
0000000000000000 T _Z1fNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
0000000000000000 r _ZStL19piecewise_construct

Building the following Dockerfile generates a centos6 image with gcc6:

FROM        centos:6
MAINTAINER  aap.noot@gmail.com

RUN yum -y update \
    && yum clean all \
    && yum -y install make \
    && yum clean all

RUN yum -y install centos-release-scl \
    && yum -y install devtoolset-6-gcc devtoolset-6-binutils devtoolset-6-gcc-c++ \
    && yum clean all \
    && echo 'source /opt/rh/devtoolset-6/enable' >> ~/.bashrc

RUN /usr/bin/scl enable devtoolset-6 true
ENTRYPOINT ["/usr/bin/scl", "enable", "devtoolset-6", "--"]
CMD ["/usr/bin/scl", "enable", "devtoolset-6", "--", "/bin/bash"]

and running the image with

docker run -it centos6_gcc6_test

the following snippet of code does not give the expected results

g++ --version
echo '#include <string>' > test.cpp
echo 'void f(std::string s) {}' >> test.cpp
cat test.cpp
g++ -c -o test.o test.cpp
nm test.o | c++filt

I get the old ABI version, even though the gcc documentation states that the default is to generate the new ABI

[root@3b58135d30a2 /]# g++ --version
g++ (GCC) 6.2.1 20160916 (Red Hat 6.2.1-3)
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@3b58135d30a2 /]# echo '#include <string>' > test.cpp
[root@3b58135d30a2 /]# echo 'void f(std::string s) {}' >> test.cpp
[root@3b58135d30a2 /]# cat test.cpp
#include <string>
void f(std::string s) {}
[root@3b58135d30a2 /]# g++ -c -o test.o test.cpp
[root@3b58135d30a2 /]# nm test.o | c++filt
0000000000000000 T f(std::basic_string<char, std::char_traits<char>,   std::allocator<char> >)
0000000000000000 r std::piecewise_construct
[root@3b58135d30a2 /]#

Even when compiling explicitly with -D_GLIBCXX_USE_CXX11_ABI=1 it still gives the incorrect result:

[root@3b58135d30a2 /]# g++ -D_GLIBCXX_USE_CXX11_ABI=1 -c -o test.o test.cpp
[root@3b58135d30a2 /]# nm test.o | c++filt
0000000000000000 T f(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
0000000000000000 r std::piecewise_construct

So obviously I am missing something trivial.

Any help?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user1357687
  • 571
  • 1
  • 6
  • 9
  • The output you're expecting to see have not been run through `c++filt`. That happens for the output you say is incorrect. That makes it very hard to compare them directly. – Some programmer dude Jul 18 '17 at 00:01
  • 2
    Have you checked whether devtoolset-6's libstdc++ has been compiled using the default options? It's very possible that it has the new ABI disabled since the devtoolset stdlib needs to be compatible with the gcc-4.4.7 stdlib that ships on centos 6 – Praetorian Jul 18 '17 at 00:04
  • @SPD: the new ABI has cxx11 as a namespace so you would see something like std::cxx11::basic_string instead of std::basic_string. – user1357687 Jul 18 '17 at 02:02
  • @Praetorian: Yes that sounds like a good venue to check, thanks – user1357687 Jul 18 '17 at 02:03
  • @Praetorian: That was indeed the issue. I build the gcc6 compiler from scratch and get the desired result. Thanks for the hint :-) – user1357687 Jul 18 '17 at 03:17

1 Answers1

3

The problem was that the gcc6 compiler in devtoolset-6 didn't have the right stdlib as Praetorian suggested.

Compiling the gcc6 compiler from scratch solves the problem.

user1357687
  • 571
  • 1
  • 6
  • 9
  • Right, and this level of ABI compatibility is one major reason for DTS. It ensures that the binaries compiled with it can run on the original operating system (without DTS). – Florian Weimer Jul 18 '17 at 05:06
  • You can compile and test the D_GLIBCXX_USE_CXX11_ABI=1 compiler on Centos 6/7 using this ansible-role https://github.com/dockpack/compile_gcc. On Centos stream 8 / RHEL8 there's no need for this. – bbaassssiiee Nov 28 '22 at 21:54