I just ran into this problem myself on all of my Solaris Prefixes.
Problem: after upgrading GNU binutils to 2.22, compiling starts to fail
On x86-based Solaris, any compilation fails with an ld error like this:
ld: target elf32-i386 not found
sparc-based systems fail when linking against libraries that GNU linker
scripts exist for (e.g. libpcre, or libz) with a similar error.
Cause: starting from GNU ld 2.21 a targets for Solaris were introduced,
*_sol2, that strictly match the Solaris 2 ABI. In GNU ld 2.22 these
targets are the only ones that work. GCC 4.5 knows about this, and
targets the *_sol2 targets at configure time.
If you upgrade GNU binutils to 2.22, your system hence breaks when your
GCC wasn't compiled when GNU binutils 2.21 was around on your system.
On sparc-based systems, the problem can be remedied quite easily,
fortunately, by just fixing the GNU ld-scripts to reference the right
target, like so for a 32-bits environment:
sed -i -e 's/^OUTPUT_FORMAT ( elf32-sparc )$/OUTPUT_FORMAT ( elf32-sparc-sol2 )/' $EPREFIX/usr/lib/lib*.so
or likewise for a 64-bits environment:
sed -i -e 's/^OUTPUT_FORMAT ( elf64-sparc )$/OUTPUT_FORMAT ( elf64-sparc-sol2 )/' $EPREFIX/usr/lib/lib*.so
Because of a different setup in the GCC spec-file for x86-based systems,
the fix there is much more complicated. If possible, recompile gcc
before upgrading binutils. GCC now has a patch that makes it behave
on x86 like sparc, such that the damage is reduced.
Like on sparc, we need to fix the GNU ld-scripts, for 32-bits
sed -i -e 's/^OUTPUT_FORMAT ( elf32-i386 )$/OUTPUT_FORMAT ( elf32-i386-sol2 )/' $EPREFIX/usr/lib/lib*.so
or for a 64-bits environment:
sed -i -e 's/^OUTPUT_FORMAT ( elf64-x86-64 )$/OUTPUT_FORMAT ( elf64-x86-64-sol2 )/' $EPREFIX/usr/lib/lib*.so
With the broken interaction of the compiler with the linker, we have to
hack around it by using a GCC spec-file that won't omit a (wrong) target
when calling the linker.
gcc -dumpspecs | sed 's/!m64:/m32/' > /var/tmp/specs
env CC="gcc -specs=/var/tmp/specs" emerge -1 gcc
After this you should have a working compiler again.
Gentoo on a different level