Setting 1: Glibc without dedicated GCC
This setting can work quickly, as it does not recompile the entire GCC toolkit, only glibc.
, C, crt1.o, crti.o crtn.o glibc. : https://sourceware.org/glibc/wiki/Testing/Builds?action=recall&rev=21#Compile_against_glibc_in_an_installed_location. , glibc, , - .
. 2 .
glibc :
export glibc_install="$(pwd)/glibc/build/install"
git clone git://sourceware.org/git/glibc.git
cd glibc
git checkout glibc-2.28
mkdir build
cd build
../configure --prefix "$glibc_install"
make -j 'nproc'
make install -j 'nproc'
1:
test_glibc.c
#define _GNU_SOURCE
#include <assert.h>
#include <gnu/libc-version.h>
#include <stdatomic.h>
#include <stdio.h>
#include <threads.h>
atomic_int acnt;
int cnt;
int f(void* thr_data) {
for(int n = 0; n < 1000; ++n) {
++cnt;
++acnt;
}
return 0;
}
int main(int argc, char **argv) {
printf("gnu_get_libc_version() = %s\n", gnu_get_libc_version());
thrd_t thr[10];
for(int n = 0; n < 10; ++n)
thrd_create(&thr[n], f, NULL);
for(int n = 0; n < 10; ++n)
thrd_join(thr[n], NULL);
printf("The atomic counter is %u\n", acnt);
printf("The non-atomic counter is %u\n", cnt);
}
test_glibc.sh:
#!/usr/bin/env bash
set -eux
gcc \
-L "${glibc_install}/lib" \
-I "${glibc_install}/include" \
-Wl,--rpath="${glibc_install}/lib" \
-Wl,--dynamic-linker="${glibc_install}/lib/ld-linux-x86-64.so.2" \
-std=c11 \
-o test_glibc.out \
-v \
test_glibc.c \
-pthread \
;
ldd ./test_glibc.out
./test_glibc.out
:
gnu_get_libc_version() = 2.28
The atomic counter is 10000
The non-atomic counter is 8674
https://sourceware.org/glibc/wiki/Testing/Builds?action=recall&rev=21#Compile_against_glibc_in_an_installed_location, --sysroot:
cannot find /home/ciro/glibc/build/install/lib/libc.so.6 inside /home/ciro/glibc/build/install
.
ldd , ldd , , :
+ ldd test_glibc.out
linux-vdso.so.1 (0x00007ffe4bfd3000)
libpthread.so.0 => /home/ciro/glibc/build/install/lib/libpthread.so.0 (0x00007fc12ed92000)
libc.so.6 => /home/ciro/glibc/build/install/lib/libc.so.6 (0x00007fc12e9dc000)
/home/ciro/glibc/build/install/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007fc12f1b3000)
gcc , , , , , , , :
COLLECT_GCC_OPTIONS=/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crt1.o
1: glibc
glibc:
diff --git a/nptl/thrd_create.c b/nptl/thrd_create.c
index 113ba0d93e..b00f088abb 100644
--- a/nptl/thrd_create.c
+++ b/nptl/thrd_create.c
@@ -16,11 +16,14 @@
License along with the GNU C Library; if not, see
<http:
+#include <stdio.h>
+
#include "thrd_priv.h"
int
thrd_create (thrd_t *thr, thrd_start_t func, void *arg)
{
+ puts("hacked");
_Static_assert (sizeof (thr) == sizeof (pthread_t),
"sizeof (thr) != sizeof (pthread_t)");
glibc, :
cd glibc/build
make -j 'nproc'
make -j 'nproc' install
./test_glibc.sh
hacked , .
, glibc, .
Ubuntu 18.04.
2: crosstool-NG
1, , : , , C, crt1.o, crti.o crtn.o,
GCC, glibc, .
, . - .
crosstool-NG - , , GCC, glibc binutils.
, GCC , .
, crosstool-NG -Wl -Wl, , GCC. , , , .
crosstool-NG, :
git clone https://github.com/crosstool-ng/crosstool-ng
cd crosstool-ng
git checkout a6580b8e8b55345a5a342b5bd96e42c83e640ac5
export CT_PREFIX="$(pwd)/.build/install"
export PATH="/usr/lib/ccache:${PATH}"
./bootstrap
./configure --enable-local
make -j 'nproc'
./ct-ng x86_64-unknown-linux-gnu
./ct-ng menuconfig
env -u LD_LIBRARY_PATH time ./ct-ng build CT_JOBS='nproc'
.
, , - . :
uname -a
:
4.15.0-34-generic
menuconfig :
:
4.14.71
. , .
2:
.config ./ct-ng x86_64-unknown-linux-gnu :
CT_GLIBC_V_2_27=y
, menuconfig :
C-libraryVersion of glibc
.config .
, glibc, , glibc git, :
Paths and misc optionsTry features marked as EXPERIMENTAL: true
C-librarySource of glibcCustom location:Custom locationCustom source location: , glibc
glibc :
git clone git://sourceware.org/git/glibc.git
cd glibc
git checkout glibc-2.28
2:
, :
#!/usr/bin/env bash
set -eux
install_dir="${CT_PREFIX}/x86_64-unknown-linux-gnu"
PATH="${PATH}:${install_dir}/bin" \
x86_64-unknown-linux-gnu-gcc \
-Wl,--dynamic-linker="${install_dir}/x86_64-unknown-linux-gnu/sysroot/lib/ld-linux-x86-64.so.2" \
-Wl,--rpath="${install_dir}/x86_64-unknown-linux-gnu/sysroot/lib" \
-v \
-o test_glibc.out \
test_glibc.c \
-pthread \
;
ldd test_glibc.out
./test_glibc.out
, 1, , :
COLLECT_GCC_OPTIONS=/home/ciro/crosstool-ng/.build/install/x86_64-unknown-linux-gnu/bin/../x86_64-unknown-linux-gnu/sysroot/usr/lib/../lib64/crt1.o
2: glibc
Crosstool-NG, .
;
env -u LD_LIBRARY_PATH time ./ct-ng build CT_JOBS='nproc'
glibc , , .
:
./ct-ng list-steps
:
Available build steps, in order:
- companion_tools_for_build
- companion_libs_for_build
- binutils_for_build
- companion_tools_for_host
- companion_libs_for_host
- binutils_for_host
- cc_core_pass_1
- kernel_headers
- libc_start_files
- cc_core_pass_2
- libc
- cc_for_build
- cc_for_host
- libc_post_cc
- companion_libs_for_target
- binutils_for_target
- debug
- test_suite
- finish
Use "<step>" as action to execute only that step.
Use "+<step>" as action to execute up to that step.
Use "<step>+" as action to execute from that step onward.
, glibc, GCC, libc_start_files cc_core_pass_2, , , cc_core_pass_1.
, " " .config :
:
env -u LD_LIBRARY_PATH time ./ct-ng libc+ -j'nproc'
, , + , : https://github.com/crosstool-ng/crosstool-ng/issues/1033#issuecomment-424877536
, , . .. libc, , libc (, , , libstdc++).
, , , , crosstool-NG.
, libc, , Custom source location, .
: stdlibc++
, C++: GCC libstdc++ C++?