I am working on some research and would like to edit some of the source code in the libstdc++ library for experimentation. I am, specifically, interested in experimenting with the parallel sorting algorithms. Is there a place I can find documentation to easily edit and build the source code?
I have tried, unsuccessfully, to build various versions of the libstdc++ library. It seems like most new versions require building the entire gcc package, which is a much more lengthy process, especially if I am going to be editing and experimenting with a few files in libstdc++.
I have also been unable to find the source files that contain the parallel sorting algorithms. I can only seem to find the header files that define the functions, and not the source code itself. Any advice or links to documentation would be greatly appreciated.
Minimal step-by-step example
Compile GCC from source. Condensed commands:
Wait from 30-minutes to two hours. Now let's use this test program
a.cpp
:First compile and run it to ensure that the initial compilation worked:
Now let's hack up the
priority_queue
constructor.First, you can find the actual constructor easily with GDB as explained at: When should I use make_heap vs. Priority Queue?
So we hack it up with this patch:
Then rebuild and re-install just libstdc++ to save a lot of time:
and now the next build and run:
outputs:
Tested on Ubuntu 16.04.
glibc
As a bonus, if you are also interested in C: Multiple glibc libraries on a single host
Yes, you have to build the whole of GCC, but once you've done that you only need to rebuild the libstdc++ part.
Building GCC is described at http://gcc.gnu.org/wiki/InstallingGCC
The libstdc++ sources are in the
libstdc++-v3
directory. The parallel algorithms are inlibstdc++-v3/include/parallel
, they are templates so all the code is in headers. The small amount of non-header code is inlibstdc++-v3/src/c++98/parallel-settings.cc
To rebuild libstdc++ from the top-level build dir go into the
$TARGET/libstdc++-v3
directory (where$TARGET
is something likex86_64-unknown-linux-gnu
) and runmake
.