[Llvm-bgq-discuss] -std=c++11

Hal Finkel hfinkel at anl.gov
Wed Jan 2 13:27:24 CST 2013


----- Original Message -----
> From: "Hal Finkel" <hfinkel at anl.gov>
> To: "Michael Blocksome" <blocksom at us.ibm.com>
> Cc: llvm-bgq-discuss at lists.alcf.anl.gov
> Sent: Saturday, December 22, 2012 6:11:28 PM
> Subject: Re: [Llvm-bgq-discuss] -std=c++11
> 
> Michael, et al.,
> 
> I have C++11 support working now using LLVM's libc++ implementation
> of the C++ standard library. Using the GNU implementation of the C++
> standard library, which Clang does by default, won't work in C++11
> mode. In order to tell Clang to use libc++ you'll need
> -stdlib=libc++ in addition to -std=c++11. For example:
> 
> /home/projects/llvm/bin/bgclang++ -std=c++11 -stdlib=libc++ -o /tmp/t
> -O3 /tmp/t.cxx

It turns out that this is all a bit more complicated than I had at first thought. Because libraries pulled in by the MPI implementation (among other things) use C++, and specifically were compiled against the libstd++ headers, we need to make sure that libc++ does not duplicate non-namespace-versioned symbols from libstdc++. For containers, etc. this is not a problem (because libc++ puts most of its classes and other symbols under std::__1), but this is a problem for the basic exception-handling infrastructure (things in <new>, <exception>, <stdexcept> and <typeinfo>). For all of this to work with pre-compiled static libraries (necessary for BG/Q MPI), even libc++ needs to use the libstdc++ implementations of these interfaces. Of these <stdexcept> is the most problematic, because it needs <string> (and I'd prefer to make the libc++ <string> implementation available), and so I've moved things in <stdexcept> into the versioned namespace (as this happens to be possible).

That <exception> appears in the above list forces us to deal with the original error motivating using libc++ in the first place: the compiler error involving type_info. It turns out that this is LLVM PR13364, and can be worked-around fairly easily using a wrapper header. So that is what I've now done. Now that's fixed, and you can compile C++ programs in c++11 mode even using the provided 4.4.6 libstdc++.

To make this easier, I've modified the wrapper script to add the necessary options when called using the name bgclang++11 (this actually uses gnu++11 mode which is c++11 with some GNU extensions). So you can use:

/home/projects/llvm/bin/bgclang++11 -o /tmp/t -O3 /tmp/t.cxx

Also, I've updated our MPI wrapper scripts, so you can use /home/projects/llvm/mpi/clang/bin/mpic++11 or /home/projects/llvm/mpi/clang.legacy/bin/mpic++11 to compile MPI programs in c++11 mode (using libc++ as the STL implementation). You can use the regular C++ MPI scripts with -std=c++11 to get c++11 mode with the more-limited c++11 support in libstdc++ version 4.4.6.

For those of you with your own builds, I've attached an updated wrapper script, clang patches, the wrapper header you'll need and the libc++ build script. I've also included updated llvm patches that include a small fix to a problem with 64-bit atomic ops revealed by compiling the libc++ test suite.

Happy new year!

 -Hal

> 
> Please be aware that, in general, libc++ and libstdc++ objects are
> incompatible, and so if you'd like to use C++11 with your project,
> you should recompile and relink all C++ library dependencies using
> -std=c++11 -stdlib=libc++.
> 
> For those of you with your own builds, I've attached an updated Clang
> patch, bgclang wrapper script, and the script that I used to build
> libc++.
> 
> Happy holidays!
> 
>  -Hal
> 
> ----- Original Message -----
> > From: "Hal Finkel" <hfinkel at anl.gov>
> > To: "Michael Blocksome" <blocksom at us.ibm.com>
> > Cc: llvm-bgq-discuss at lists.alcf.anl.gov
> > Sent: Friday, December 21, 2012 3:27:33 PM
> > Subject: Re: [Llvm-bgq-discuss] -std=c++11
> > 
> > I think that the gcc libstdc++ 4.4.6 headers are too old for C++11
> > support to really work well. I am planning to investigate providing
> > an alternative, based either on libstdc++ 4.6.x or based on LLVM's
> > libc++ project.
> > 
> >  -Hal
> > 
> > ----- Original Message -----
> > > From: "Michael Blocksome" <blocksom at us.ibm.com>
> > > To: llvm-bgq-discuss at lists.alcf.anl.gov
> > > Sent: Friday, December 21, 2012 2:12:12 PM
> > > Subject: [Llvm-bgq-discuss] -std=c++11
> > > 
> > > 
> > > Has anyone had any luck compiling with '-std=c++11' ?
> > > 
> > > I get the following error with a simple testcase. This particular
> > > error goes away if I remove the '-std=c++11' option.
> > > 
> > > .../test> cat vector_test.cc
> > > 
> > > #include <vector>
> > > 
> > > int main ()
> > > {
> > > std::vector<unsigned> foo;
> > > 
> > > return 0;
> > > };
> > > 
> > > .../test> /bghome/blocksom/development/llvm/bgclang -v -std=c++11
> > > vector_test.cc -o vector_test.cnk
> > > clang version 3.3 (trunk 170436)
> > > Target: powerpc64-bgq-linux
> > > Thread model: posix
> > > "/bghome/blocksom/development/llvm/install/bin/clang" -cc1
> > > -triple
> > > powerpc64-bgq-linux -S -disable-free -main-file-name
> > > vector_test.cc
> > > -static-define -mrelocation-model static -mdisable-fp-elim
> > > -fmath-errno -ffp-contract=fast -mconstructor-aliases -target-cpu
> > > a2q -target-linker-version 2.20.51.0.2 -momit-leaf-frame-pointer
> > > -v
> > > -resource-dir
> > > /bghome/blocksom/development/llvm/install/bin/../lib/clang/3.3
> > > -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6
> > > -internal-isystem
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/powerpc64-bgq-linux
> > > -internal-isystem
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/backward
> > > -internal-isystem /usr/local/include -internal-isystem
> > > /bghome/blocksom/development/llvm/install/bin/../lib/clang/3.3/include
> > > -internal-externc-isystem /include -internal-externc-isystem
> > > /usr/include -std=c++11 -fdeprecated-macro
> > > -fno-dwarf-directory-asm
> > > -fdebug-compilation-dir
> > > /bghome/blocksom/development/boost-pami/next/test -ferror-limit
> > > 19
> > > -fmessage-length 231 -mstackrealign -fno-signed-char
> > > -fobjc-runtime=gcc -fcxx-exceptions -fexceptions
> > > -fdiagnostics-show-option -fcolor-diagnostics -isystem
> > > /bgsys/drivers/ppcfloor/gnu-linux/powerpc64-bgq-linux/sys-include
> > > -mllvm -enable-misched -mllvm -enable-aa-sched-mi -o
> > > /tmp/vector_test-mdmziM.s -x c++ vector_test.cc
> > > clang -cc1 version 3.3 based upon LLVM 3.3svn default target
> > > powerpc64-unknown-linux-gnu
> > > ignoring nonexistent directory "/include"
> > > #include "..." search starts here:
> > > #include <...> search starts here:
> > > /bgsys/drivers/ppcfloor/gnu-linux/powerpc64-bgq-linux/sys-include
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/powerpc64-bgq-linux
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/backward
> > > /usr/local/include
> > > /bghome/blocksom/development/llvm/install/bin/../lib/clang/3.3/include
> > > /usr/include
> > > End of search list.
> > > In file included from vector_test.cc:4:
> > > In file included from
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/vector:61:
> > > In file included from
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/bits/allocator.h:48:
> > > In file included from
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/powerpc64-bgq-linux/bits/c++allocator.h:34:
> > > In file included from
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/ext/new_allocator.h:33:
> > > In file included from
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/new:40:
> > > In file included from
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/exception:148:
> > > /bgsys/drivers/ppcfloor/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.6/../../../../powerpc64-bgq-linux/include/c++/4.4.6/exception_ptr.h:143:13:
> > > error: unknown type name 'type_info'
> > > const type_info*
> > > ^
> > > 1 error generated.
> > > 
> > > 
> > > ====
> > > 
> > > Thanks,
> > > 
> > > Michael Blocksome
> > > Blue Gene Messaging
> > > blocksom at us.ibm.com
> > > 
> > > _______________________________________________
> > > llvm-bgq-discuss mailing list
> > > llvm-bgq-discuss at lists.alcf.anl.gov
> > > https://lists.alcf.anl.gov/mailman/listinfo/llvm-bgq-discuss
> > > 
> > 
> > --
> > Hal Finkel
> > Postdoctoral Appointee
> > Leadership Computing Facility
> > Argonne National Laboratory
> > _______________________________________________
> > llvm-bgq-discuss mailing list
> > llvm-bgq-discuss at lists.alcf.anl.gov
> > https://lists.alcf.anl.gov/mailman/listinfo/llvm-bgq-discuss
> > 
> 
> --
> Hal Finkel
> Postdoctoral Appointee
> Leadership Computing Facility
> Argonne National Laboratory
> 
> _______________________________________________
> llvm-bgq-discuss mailing list
> llvm-bgq-discuss at lists.alcf.anl.gov
> https://lists.alcf.anl.gov/mailman/listinfo/llvm-bgq-discuss
> 

-- 
Hal Finkel
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libcxx-trunk-build.sh-r170456-20121221-3
Type: application/x-shellscript
Size: 2379 bytes
Desc: not available
URL: <http://lists.alcf.anl.gov/pipermail/llvm-bgq-discuss/attachments/20130102/11d97989/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exception_ptr.h-r170456-20121221-3
Type: text/x-csrc
Size: 999 bytes
Desc: not available
URL: <http://lists.alcf.anl.gov/pipermail/llvm-bgq-discuss/attachments/20130102/11d97989/attachment-0001.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bgclang-r170456-20121221-3
Type: application/x-shellscript
Size: 3678 bytes
Desc: not available
URL: <http://lists.alcf.anl.gov/pipermail/llvm-bgq-discuss/attachments/20130102/11d97989/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm-bgq-r170456-20121221-3.patch
Type: text/x-patch
Size: 188373 bytes
Desc: not available
URL: <http://lists.alcf.anl.gov/pipermail/llvm-bgq-discuss/attachments/20130102/11d97989/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-bgq-r170456-20121221-3.patch
Type: text/x-patch
Size: 73689 bytes
Desc: not available
URL: <http://lists.alcf.anl.gov/pipermail/llvm-bgq-discuss/attachments/20130102/11d97989/attachment-0007.bin>


More information about the llvm-bgq-discuss mailing list