Recover GCC on Gentoo

Published on Author Artem Butusov1 Comment

Why?

Gentoo could became completely unusable if for some reason build chain is broken.

If you see “Segmentation fault” from “gcc” then probably replacing whole GCC by the version provided in Stage 3 could be a good fix.

You could also use this method to install binary version of other packages, like binutils, libtool, glibc etc…

Download and extract GCC

mkdir ~/gentoo
cd ~/gentoo
wget http://distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64-hardened/stage3-amd64-hardened-*.tar.bz2
tar xvpf stage3-*.tar.bz2
chroot ~/gentoo /bin/bash
quickpkg sys-devel/gcc
exit

Install binary GCC

mkdir -p /usr/portage/packages/sys-devel
cp -v ~/gentoo/usr/portage/packages/sys-devel/gcc-*.tbz2 /usr/portage/packages/sys-devel
emerge gcc -1 --usepkgonly

Cleanup

cd ~
rm /usr/portage/packages/sys-devel/gcc-*.tbz2
rm -rf ~/gentoo

Switch to new GCC

gcc-config -l
 [1] x86_64-pc-linux-gnu-4.9.4 *
 [2] x86_64-pc-linux-gnu-4.9.4-hardenednopie
 [3] x86_64-pc-linux-gnu-4.9.4-hardenednopiessp
 [4] x86_64-pc-linux-gnu-4.9.4-hardenednossp
 [5] x86_64-pc-linux-gnu-4.9.4-vanilla
 [6] x86_64-pc-linux-gnu-5.4.0
 [7] x86_64-pc-linux-gnu-5.4.0-hardenednopie
 [8] x86_64-pc-linux-gnu-5.4.0-hardenednopiessp
 [9] x86_64-pc-linux-gnu-5.4.0-hardenednossp
 [10] x86_64-pc-linux-gnu-5.4.0-vanilla

gcc-config x86_64-pc-linux-gnu-5.4.0
source /etc/profile

Rebuild other toolchain packages

General recommendation after gcc update is to rebuild also:

emerge -1 sys-devel/libtool
emerge -1 sys-devel/binutils
emerge -1 sys-libs/glibc

One Response to Recover GCC on Gentoo

  1. Yay! This post saved me from stupidly unmerging gcc while trying to rebuild it :&
    By the way, PKGDIR now defaults to /var/cache/binpkgs

    Thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.