I was trying to compile GCC 9.2 against a custom built GLIBC 2.30. I have installed GLIBC in a non-standard location. Then I have followed these steps to compile GCC:
sfinix@multivac:~$ GLIBCDIR=/home/sfinix/programming/repos/glibc/glibc-install/
sfinix@multivac:~$ export LDFLAGS="-Wl,-q"
sfinix@multivac:~$ CFLAGS="-L "${GLIBCDIR}/lib" -I "${GLIBCDIR}/include" -Wl,--rpath="${GLIBCDIR}/lib" -Wl,--dynamic-linker="${GLIBCDIR}/lib/ld-linux-x86-64.so.2""
sfinix@multivac:~$ cd ${GCC_BUILD_DIR}
sfinix@multivac:~$ make -j 4 CFLAGS="${CFLAGS}" CXXFLAGS="${CFLAGS}"
The compilation was successful but the problem is GCC is still picking up the old library:
sfinix@multivac:~$ ldd programming/repos/gcc/gcc-install/bin/gcc-9.2
linux-vdso.so.1 (0x00007ffc3b7cb000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f177772f000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f177733e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1777acd000)
Output of readelf -d programming/repos/gcc/gcc-install/bin/gcc-9.2:
Dynamic section at offset 0x113dd8 contains 27 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
0x000000000000000c (INIT) 0x402a80
0x000000000000000d (FINI) 0x488440
0x0000000000000019 (INIT_ARRAY) 0x712de8
0x000000000000001b (INIT_ARRAYSZ) 48 (bytes)
0x000000000000001a (FINI_ARRAY) 0x712e18
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x0000000000000004 (HASH) 0x4002b0
0x000000006ffffef5 (GNU_HASH) 0x400728
0x0000000000000005 (STRTAB) 0x4015f0
0x0000000000000006 (SYMTAB) 0x400798
0x000000000000000a (STRSZ) 1373 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000015 (DEBUG) 0x0
0x0000000000000003 (PLTGOT) 0x714000
0x0000000000000002 (PLTRELSZ) 3264 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x401dc0
0x0000000000000007 (RELA) 0x401d00
0x0000000000000008 (RELASZ) 192 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0x401c80
0x000000006fffffff (VERNEEDNUM) 2
0x000000006ffffff0 (VERSYM) 0x401b4e
0x0000000000000000 (NULL) 0x0
Though this approach is working for other programs I am compiling myself for testing:
sfinix@multivac:~$ GLIBDIR=/home/sfinix/programming/repos/glibc/glibc-install/
sfinix@multivac:~$ vim test.c
sfinix@multivac:~$ CFLAGS="-L ${GLIBDIR}/lib -I ${GLIBDIR}/include -Wl,--rpath=${GLIBDIR}/lib -Wl,--dynamic-linker=${GLIBDIR}/lib/ld-linux-x86-64.so.2"
sfinix@multivac:~$ gcc -Wall -g ${CFLAGS} test.c -o run
sfinix@multivac:~$ ldd run
linux-vdso.so.1 (0x00007ffd616d5000)
libc.so.6 => /home/sfinix/programming/repos/glibc/glibc-install//lib/libc.so.6 (0x00007f5fcdc6e000)
/home/sfinix/programming/repos/glibc/glibc-install//lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f5fce22a000)
What am I missing? How can I compile GCC against a custom GLIBC? How can I pass compiler and linker flags?
readelf -d programming/repos/gcc/gcc-install/bin/gcc-9.2into the question? Note also for your working example you have glibc-install/lib (i.e. the install directory) but for the non-working case you have root/lib so maybe you didn't specify the correct directory. I know these are just examples but it shows how helpful it is to say exactly what you did rather than try and obscure details.readelf -d programming/repos/gcc/gcc-install/bin/gcc-9.2.RUNPATHentry in other binary's dynamic section. My guess was that the Makefile was not passing theCFLAGSI am providing but I wasn't sure. I have also tried to follow the Makefile but it is huge and I think auto generated. I am not very familiar with the build system of GNU tools other thanmake && make install. So I am waiting for a person to answer who has experience with this.