How to edit and rebuild the source source of the GCC libstdc ++ C ++ library?

I am working on some research and would like to edit some of the source code in the libstdc ++ library for experimentation. I'm particularly interested in experimenting with parallel sorting algorithms. Is there a place where I can find documentation to easily edit and build source code?

I tried unsuccessfully to create different versions of the libstdc ++ library. It seems that most of the new versions require the creation of the whole gcc package, which is a much longer process, especially if I am going to edit and experiment with several files in libstdc ++.

I also could not find the source files containing parallel sorting algorithms. I can only find the header files that define the functions, not the source code itself. Any recommendations or links to documentation would be greatly appreciated.

+5
source share
2 answers

Yes, you need to build all of GCC, but once you have done this, you only need to restore the libstdC ++ part.

The GCC building is described at http://gcc.gnu.org/wiki/InstallingGCC

The sources of libstdc ++ are in the directory libstdc++-v3. Parallel algorithms are in libstdc++-v3/include/parallel, they are templates, so all the code is in the headers. A small amount of code without a header is inlibstdc++-v3/src/c++98/parallel-settings.cc

libstd++ , $TARGET/libstdc++-v3 ( $TARGET - x86_64-unknown-linux-gnu) make.

+4

GCC . :

sudo apt-get build-dep gcc
git clone git://gcc.gnu.org/git/gcc.git
cd gcc
git checkout gcc-6_4_0-release
./contrib/download_prerequisites
mkdir build
cd build
../configure --enable-languages=c,c++ --prefix="$(pwd)/install"
make -j'nproc'

30 . a.cpp:

#include <cassert>
#include <queue>

int main() {
    std::priority_queue<int> q;
    q.emplace(2);
    q.emplace(1);
    q.emplace(3);
    assert(q.top() == 3);
    q.pop();
    assert(q.top() == 2);
    q.pop();
    assert(q.top() == 1);
    q.pop();
}

, , :

gcc/build/install/bin/g++ -g -std=c++11 -O0 -o a.out ./a.cpp
./a.out

priority_queue.

-, GDB, : make_heap Priority Queue?

, :

diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h
index 5d255e7300b..deec7bc4d99 100644
--- a/libstdc++-v3/include/bits/stl_queue.h
+++ b/libstdc++-v3/include/bits/stl_queue.h
@@ -61,6 +61,7 @@
 #if __cplusplus >= 201103L
 # include <bits/uses_allocator.h>
 #endif
+#include <iostream>

 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -444,7 +445,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       priority_queue(const _Compare& __x = _Compare(),
             _Sequence&& __s = _Sequence())
       : c(std::move(__s)), comp(__x)
-      { std::make_heap(c.begin(), c.end(), comp); }
+      {
+        std::cout << "hacked" << std::endl;
+        std::make_heap(c.begin(), c.end(), comp);
+      }

       template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
    explicit

libstdc++, :

cd gcc/build/x86_64-pc-linux-gnu/libstdc++-v3
make -j'nproc'
make install

:

gcc/build/install/bin/g++ -g -std=c++11 -O0 -o a.out ./a.cpp
./a.out

:

hacked

Ubuntu 16.04.

Glibc

, C: glibc

0

All Articles