Changing the toolchain architecture (in gentoo)

cross-compilationgccgentootoolchain

This is somewhat gentoo-specific, so I'll explain it in that context, then try to abstract it to a generic linux machine.

I accidently set my CHOST to "i686-pc-linux-gnu" in the beginning, not paying attention, when my machine is a Athlon64. I would like to change it to "x86_64-pc-linux-gnu". There is a guide for this. It doesn't work.

The first step is "Recompile binutils, then recompile gcc"

Here's the problem illustrated:

  1. Compile binutils using gcc – this succeeds producing new as, ar, and the like files
  2. This breaks gcc. gcc is now trying to use the new /usr/bin/as – but it can't work with them
  3. Since gcc can't compile anything, I can't compile gcc. I have to revert as, ar, etc; then revert the CHOST change, and recompile binutils.

So I tried the following:

  1. back up as, ar, etc
  2. Compile binutils, rendering gcc inoperabe
  3. link ar, as, etc to the old versions I backed up
  4. try to compile gcc

The gcc compile fails with:

/usr/x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/usr/x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
/usr/x86_64-pc-linux-gnu/bin/ld: cannot find -lc
collect2: ld returned 1 exit status

This is a glibc error (completing the chain).

So it seems:

  1. for gcc to compile it has a dependency on the new version glibc
  2. for gcc to run, binutils must be the older version

The steps I haven't tried, because it's so complicated I wanted to get opinions first, are:

  1. compile binutils under new architecture,
  2. relink as, ar, etc to old executables
  3. compile new glibc with old-gcc and old-binutils
  4. compile new-gcc with old-gcc and old-binutils but new-glibc
  5. relink as, ars, etc to new-binutils
  6. recompile everything like a boss

Is there any chance of #4 above working? Do I have any hope of accomplishing this without a complete reinstall?

Best Answer

As far as I know it is not possible. Please remember that toolchain does not exist in vaccum and is interlinked.

What might work is to build cross-compiler of new infrastructure but I really doubt it - the "atomicity" on update of glibc will break everything.

I would advice backup & reinstall of system.

Related Question