On Mon, 9 Mar 2020, Paul Smith wrote: > 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.
Yes. The natural way to do this sort of thing is: 1. Build a cross compiler (GCC and binutils) that's configured using --with-sysroot to make use of the old-system sysroot. (You can ensure it's configured as a cross compiler by making host and target slightly different after passing through config.sub, e.g. x86_64-pc-linux-gnu versus x86-64-none-linux-gnu. If it's configured as a native compiler rather than a cross compiler, I'm not sure if it will always make use of the sysroot without ever searching native paths.) The --with-build-sysroot option is mainly or only relevant if the compiler you build in this stage is being relocated (if the sysroot location it will search at runtime is not the same as the sysroot location when it is being built). 2. Use the compiler you built in the previous step whenever you want to build binaries (of GCC or anything else) that will run on older systems. If those binaries use C++, make sure to link them with -static-libstdc++ -static-libgcc, or else link them with a suitable RPATH and ship the required libgcc_s and libstdc++ shared libraries and associated library sources with them. (Linking with RPATHs involving $ORIGIN, if you want the binaries to be relocatable, is unfortunately a pain when passing through multiple layers of shell and make interpretation, each of which needs a layer of quoting in the original linker flags passed to configure.) -- Joseph S. Myers jos...@codesourcery.com