I have a somewhat complex makefile that I've been using for many years
to build GCC: it builds tools needed (make, bison, flex, m4, binutils),
downloads the source prerequisites and links them, etc.

I'd like some advice, hopefully an easy answer, that allows me to
simplify that system, which currently does a psuedo-cross-compile,
involving rebuilding GCC a few times.  Also I'd like to build GCC
profiled, which doesn't seem to work with my makefile system.

The tricky bit is that although both the host and target are always
x86_64/i686 GNU/Linux systems, I need the generated compiler to run on
much older systems than the one I build it on.

I have a sysroot I've created (downloading RPMs from older systems and
unpacking them) which is sufficient to build GCC (and binutils etc.)  I
need the GCC binaries I create to be compiled using this sysroot so
that they can run on older systems.

It seems that options like --with-sysroot and --with-build-sysroot are
more about how the compiler builds other things and less about how the
compiler itself is built.

Should it be sufficient to invoke configure with --sysroot options for
the compiler used to build GCC, like this?

   $ cd /obj

   $ ../gcc-9.2.0/configure CFLAGS=--sysroot=/sysroot \
                            CXXFLAGS=--sysroot=/sysroot \
                            LDFLAGS=--sysroot=/sysroot \
                            --disable-multilib --enable-gold \
                            --with-build-config=bootstrap-lto

When I try this I get a failure trying to create libstdc++.  I describe
it below, but I wonder if I'm just chasing down the wrong path
altogether here?

The failure:

/bin/bash ../libtool --tag CXX   --mode=link /obj/./gcc/xgcc -shared-
libgcc -B/obj/./gcc -nostdinc++ -L/obj/x86_64-pc-linux-gnu/libstdc++-
v3/src -L/obj/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/obj/x86_64-
pc-linux-gnu/libstdc++-v3/libsupc++/.libs -B/dist/x86_64-pc-linux-
gnu/bin/ -B/dist/x86_64-pc-linux-gnu/lib/ -isystem /dist/x86_64-pc-
linux-gnu/include -isystem /dist/x86_64-pc-linux-gnu/sys-include   -
fno-checking  -Wl,-O1 -Wl,-z,relro -Wl,--gc-sections  -std=gnu++98
-fPIC -DPIC -fno-implicit-templates  -Wall -Wextra -Wwrite-strings
-Wcast-qual -Wabi=2  -fdiagnostics-show-location=once   -ffunction-
sections -fdata-sections  -frandom-seed=libstdc++.la  -o libstdc++.la
-version-info 6:27:0 -Wl,--version-script=libstdc++-symbols.ver -lm
-rpath /dist/lib/../lib64 compatibility.lo compatibility-debug_list.lo
compatibility-debug_list-2.lo  compatibility-c++0x.lo compatibility-
atomic-c++0x.lo compatibility-thread-c++0x.lo compatibility-chrono.lo
compatibility-condvar.lo  ../libsupc++/libsupc++convenience.la
../src/c++98/libc++98convenience.la ../src/c++11/libc++11convenience.la
../src/c++17/libc++17convenience.la

Interestingly although my sysroot doesn't appear on this command, the
output generated by libtool does show it:

libtool: link:  /obj/./gcc/xgcc -shared-libgcc -B/obj/./gcc -nostdinc++
-L/obj/x86_64-pc-linux-gnu/libstdc++-v3/src -L/obj/x86_64-pc-linux-
gnu/libstdc++-v3/src/.libs -L/obj/x86_64-pc-linux-gnu/libstdc++-
v3/libsupc++/.libs -B/dist/x86_64-pc-linux-gnu/bin/ -B/dist/x86_64-pc-
linux-gnu/lib/ -isystem /dist/x86_64-pc-linux-gnu/include -isystem
/dist/x86_64-pc-linux-gnu/sys-include   -fno-checking  -fPIC -DPIC
-D_GLIBCXX_SHARED -shared -nostdlib
/sysroot/tools/usr/lib/../lib64/crti.o
/obj/./gcc/crtbeginS.o  .libs/compatibility.o .libs/compatibility-
debug_list.o .libs/compatibility-debug_list-2.o .libs/compatibility-
c++0x.o .libs/compatibility-atomic-c++0x.o .libs/compatibility-thread-
c++0x.o .libs/compatibility-chrono.o .libs/compatibility-condvar.o  -
Wl,--whole-archive ../libsupc++/.libs/libsupc++convenience.a
../src/c++98/.libs/libc++98convenience.a
../src/c++11/.libs/libc++11convenience.a
../src/c++17/.libs/libc++17convenience.a -Wl,--no-whole-archive  -
L/obj/x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -L/obj/x86_64-
pc-linux-gnu/libstdc++-v3/src -L/obj/x86_64-pc-linux-gnu/libstdc++-
v3/src/.libs -lm -L/obj/./gcc -L/sysroot/tools/lib/../lib64
-L/sysroot/tools/usr/lib/../lib64 -L/sysroot/tools/lib
-L/sysroot/tools/usr/lib -lc -lgcc_s /obj/./gcc/crtendS.o
/sysroot/tools/usr/lib/../lib64/crtn.o  -Wl,-O1 -Wl,-z -Wl,relro -Wl,
--gc-sections -Wl,--version-script=libstdc++-symbols.ver   -Wl,-soname
-Wl,libstdc++.so.6 -o .libs/libstdc++.so.6.0.27

you can see the -L/sysroot/tools/... here.

However this command fails:

/tools/bin/ld: cannot find /lib64/libc.so.6
/tools/bin/ld: cannot find /usr/lib64/libc_nonshared.a
collect2: error: ld returned 1 exit status
make[6]: *** [Makefile:697: libstdc++.la] Error 1
make[5]: *** [Makefile:730: all-recursive] Error 1
make[4]: *** [Makefile:562: all-recursive] Error 1
make[3]: *** [Makefile:487: all] Error 2
make[2]: *** [Makefile:19557: all-stage1-target-libstdc++-v3] Error 2
make[1]: *** [Makefile:27618: stage1-bubble] Error 2
make: *** [Makefile:28760: profiledbootstrap-lean] Error 2

Well, I mean I don't want to use /lib64/libc.so.6 since that would be
my native libc, which lives in /lib/x86_64-linux-gnu anyway.

However in my sysroot I do have that file:

$ find /sysroot/tools/ -name libc.so.6
/sysroot/tools/lib64/libc.so.6
/sysroot/tools/lib/i686/nosegneg/libc.so.6
/sysroot/tools/lib/libc.so.6

Cheers!

Reply via email to