Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 418141 - sys-devel/clang-3.1-r2 fails to link 32-bit executables on multilib systems
Summary: sys-devel/clang-3.1-r2 fails to link 32-bit executables on multilib systems
Status: RESOLVED TEST-REQUEST
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal with 1 vote (vote)
Assignee: Gentoo Clang Team (OBSOLETE)
URL:
Whiteboard:
Keywords: Bug, REGRESSION
Depends on:
Blocks: systemwide-clang
  Show dependency tree
 
Reported: 2012-05-29 14:42 UTC by Daniel Scharrer
Modified: 2015-10-16 11:12 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Scharrer 2012-05-29 14:42:02 UTC
Using the -m32 switch for clang or clang++ on amd64 systems results in linker errors because ld cannot find -lgcc and -lgcc_s

Everything worked fine with sys-devel/clang-3.1

Reproducible: Always

Steps to Reproduce:
1. echo "int main() { return 0; }" > test.c
2. clang -m32 test.c
Actual Results:  
/usr/bin/x86_64-pc-linux-gnu-ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/libgcc.a when searching for -lgcc
/usr/bin/x86_64-pc-linux-gnu-ld: cannot find -lgcc
/usr/bin/x86_64-pc-linux-gnu-ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/libgcc_s.so when searching for -lgcc_s
/usr/bin/x86_64-pc-linux-gnu-ld: cannot find -lgcc_s
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Expected Results:  
ld is told to look in /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/32/

clang USE flags: multitarget static-analyzer -debug -kernel_FreeBSD -test

clang -v -m32 test.c output:

clang version 3.1 (branches/release_31)
Target: i386-pc-linux-gnu
Thread model: posix
 "/usr/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.22 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.1 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/dscharrer -ferror-limit 19 -fmessage-length 116 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/test-t9fo9j.o -x c test.c
clang -cc1 version 3.1 based upon LLVM 3.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/bin/../lib/clang/3.1/include
 /usr/include
End of search list.
 "/usr/bin/x86_64-pc-linux-gnu-ld" --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o a.out /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib/../lib32/crt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib/../lib32/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/crtbegin.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib/../lib32 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../../lib32 -L/lib/../lib32 -L/usr/lib/../lib32 -L/usr/lib//../../lib32 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../.. -L/lib -L/usr/lib /tmp/test-t9fo9j.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/crtend.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib/../lib32/crtn.o
/usr/bin/x86_64-pc-linux-gnu-ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/libgcc.a when searching for -lgcc
/usr/bin/x86_64-pc-linux-gnu-ld: cannot find -lgcc
/usr/bin/x86_64-pc-linux-gnu-ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/libgcc_s.so when searching for -lgcc_s
/usr/bin/x86_64-pc-linux-gnu-ld: cannot find -lgcc_s
clang: error: linker command failed with exit code 1 (use -v to see invocation)

emerge --info output:

Portage 2.2.0_alpha108 (default/linux/amd64/10.0, gcc-4.6.3, glibc-2.14.1-r3, 3.3.7-gentoo x86_64)
=================================================================
System uname: Linux-3.3.7-gentoo-x86_64-AMD_Phenom-tm-_9750_Quad-Core_Processor-with-gentoo-2.1
Timestamp of tree: Mon, 28 May 2012 12:30:01 +0000
app-shells/bash:          4.2_p28
dev-lang/python:          2.7.3-r1, 3.2.3
dev-util/cmake:           2.8.8-r2
dev-util/pkgconfig:       0.26
sys-apps/baselayout:      2.1-r1
sys-apps/openrc:          0.10.2
sys-apps/sandbox:         2.5
sys-devel/autoconf:       2.13, 2.69
sys-devel/automake:       1.9.6-r3, 1.11.5
sys-devel/binutils:       2.22-r1
sys-devel/gcc:            4.3.6-r1, 4.4.7, 4.5.3-r2, 4.6.3, 4.7.0, 4.8.0_pre9999::toolchain
sys-devel/gcc-config:     1.5-r2
sys-devel/libtool:        2.4.2
sys-devel/make:           3.82-r1
sys-kernel/linux-headers: 3.4 (virtual/os-headers)
sys-libs/glibc:           2.14.1-r3
Repositories: gentoo local-repo kde toolchain gamerlay-stable arx-libertatis
Installed sets: @kdeadmin-4.8, @kdeartwork-4.8, @kdebase-4.8, @kdegraphics-4.8, @kdeutils-4.8, @system
ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -O2 -march=amdfam10 -ggdb -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt /usr/share/maven-bin-3.0/conf"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -pipe -O2 -march=amdfam10 -ggdb -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles news parallel-fetch parse-eapi-ebuild-head preserve-libs protect-owned sandbox sfperms splitdebug strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
FFLAGS=""
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.utf8"
LC_ALL="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS=" -j5"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage /var/lib/layman/kde /var/lib/layman/toolchain /var/lib/layman/gamerlay /home/dscharrer/pro/gentoo"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="3dnow 3dnowext X X11 acl alsa amd64 bash-completion berkdb bzip2 cli consolekit cracklib crypt cups cxx dbus dri fortran gdbm gpm iconv ipv6 j2k jpeg2k kde kde4 lm_sensors mmx mmxext modules mudflap multilib ncurses nls nptl openexr opengl openmp pam pch pcre png poliicykit pppd qt qt4 readline sdl semantic-desktop session sse sse2 sse3 ssl ssse3 tcpd threads truetype udev unicode x11 xgl xorg xv zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump" CAMERAS="canon directory ptp2 template" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" PHP_TARGETS="php5-3" PYTHON_TARGETS="python3_2 python2_7" RUBY_TARGETS="ruby18 ruby19" SANE_BACKENDS="hp*" USERLAND="GNU" VIDEO_CARDS="fglrx" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LINGUAS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON
Comment 1 Jeroen Roovers (RETIRED) gentoo-dev 2012-05-29 20:55:04 UTC
1) Please attach the entire build log to this bug report.
2) Please post your `gcc-config -l' output in a comment.
3) Have a look at bug #406163 - it might be related.
Comment 2 Daniel Scharrer 2012-05-30 10:03:29 UTC
> 1) Please attach the entire build log to this bug report.
The build log of what? sys-devel/clang itself compiles fine, but the resulting clang binary cannot compile 32-bit programs.
I have already provided the complete output of `clang -v -m32 test.c` above.

2) Please post your `gcc-config -l' output in a comment.
$ gcc-config -l
 [1] i686-w64-mingw32-4.6.3 *

 [2] x86_64-pc-linux-gnu-4.3.6
 [3] x86_64-pc-linux-gnu-4.4.7
 [4] x86_64-pc-linux-gnu-4.5.3
 [5] x86_64-pc-linux-gnu-4.6.3 *
 [6] x86_64-pc-linux-gnu-4.7.0
 [7] x86_64-pc-linux-gnu-4.8.0-pre9999

3) Have a look at bug #406163 - it might be related.
It think it's a different bug, but the fix for it in 3.1-r2 (clang-3.1-gentoo-runtime-gcc-detection.patch) breaks multiarch gcc detection. More specificly it fails to set GCCMultiarchSuffix if ither a /32/crtbegin.o or /64/crtbegin.o exists in the GCCInstallPath. The old in ScanLibDirForGCCTriple (the one that just picked the latest gcc version) *did* check for the /32 subdirectory, but is no longer executed vecause of the gentoo patch.
Comment 3 Bernard Cafarelli gentoo-dev 2012-05-30 15:16:04 UTC
Thanks for the detailed report! CC-ing Richard on this one
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2012-05-30 16:38:49 UTC
I've noticed that as well. As a workaround, you can try to use '-ccc-host-triple i386-pc-linux-gnu' which works fine for me.
Comment 5 Richard Yao (RETIRED) gentoo-dev 2012-05-30 22:31:26 UTC
This is related to the issue causing bug #417913. Expect this to be fixed sometime this week.
Comment 6 Richard Yao (RETIRED) gentoo-dev 2012-06-05 02:04:25 UTC
I have committed sys-devel/clang-3.1-r3, which fixes this issue on my system.
Comment 7 Daniel Scharrer 2012-06-05 13:37:16 UTC
clang-3.1-gentoo-runtime-gcc-detection-v2.patch only "fixes" this because the revised patch doesn't come into effect at all with -m32 on a multilib system as only /etc/env.d/gcc/config-x86_64-pc-linux-gnu and no /etc/env.d/gcc/config-i386-pc-linux-gnu or similar.

As a result, the upstream gcc detection is used for -m32 which picks the 32-bit variants of the gcc libraries, but from the highest available gcc versionb - not the one selected by gcc-config.

Compare

$ echo 'int main() { return 0; }' | clang++ -m32 -v -x c++ - -o /dev/null
clang version 3.1 (branches/release_31)
Target: i386-pc-linux-gnu
Thread model: posix
 "/usr/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.22 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.1 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4 -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-linux-gnu -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/dscharrer -ferror-limit 19 -fmessage-length 116 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/--0sjeFy.o -x c++ -
clang -cc1 version 3.1 based upon LLVM 3.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4
 /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-linux-gnu
 /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/backward
 /usr/local/include
 /usr/bin/../lib/clang/3.1/include
 /usr/include
End of search list.
 "/usr/bin/x86_64-pc-linux-gnu-ld" --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o /dev/null /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/../../../../lib32/crt1.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/../../../../lib32/crti.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/32/crtbegin.o -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/32 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/../../../../lib32 -L/lib/../lib32 -L/usr/lib/../lib32 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/../../.. -L/lib -L/usr/lib /tmp/--0sjeFy.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/32/crtend.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/../../../../lib32/crtn.o

with

$ echo 'int main() { return 0; }' | clang++ -v -x c++ - -o /dev/null
clang version 3.1 (branches/release_31)
Target: x86_64-pc-linux-gnu
Thread model: posix
 "/usr/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version 2.22 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.1 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4 -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/x86_64-pc-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/dscharrer -ferror-limit 19 -fmessage-length 116 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/--p0Ethf.o -x c++ -
clang -cc1 version 3.1 based upon LLVM 3.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/x86_64-pc-linux-gnu
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/backward
 /usr/local/include
 /usr/bin/../lib/clang/3.1/include
 /usr/include
End of search list.
 "/usr/bin/x86_64-pc-linux-gnu-ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /dev/null /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib/../lib64/crt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib/../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/crtbegin.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib//../../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../.. -L/lib -L/usr/lib /tmp/--p0Ethf.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/crtend.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../..//lib/../lib64/crtn.o

At least in this case, the selected headers and libraries match so there should be no compilation errors.
Comment 8 Daniel Scharrer 2012-06-05 13:43:01 UTC
Also, shouldn't it be /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-linux-gnu/32 instead of /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-linux-gnu for -m32 ? g++ adds the /32 here for -m32

At least /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-linux-gnu/bits/c++config.h and /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-linux-gnu/32/bits/c++config.h differ!
Comment 9 Richard Yao (RETIRED) gentoo-dev 2012-06-06 04:52:13 UTC
(In reply to comment #8)
> Also, shouldn't it be
> /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-
> linux-gnu/32 instead of
> /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-
> linux-gnu for -m32 ? g++ adds the /32 here for -m32
> 
> At least
> /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-
> linux-gnu/bits/c++config.h and
> /usr/lib64/gcc/x86_64-pc-linux-gnu/4.8.0-pre9999/include/g++-v4/x86_64-pc-
> linux-gnu/32/bits/c++config.h differ!

Try doing this and let me know if it addresses that issue:

ebuild /usr/portage/sys-devel/clang/clang-3.1-r3.ebuild prepare && patch -R -p1 -d /var/tmp/portage/sys-devel/clang-3.1-r3/work < /usr/portage/sys-devel/clang/files/clang-3.1-gentoo-linux-fix-cxx-include.patch && ebuild /usr/portage/sys-devel/clang/clang-3.1-r3.ebuild merge
Comment 10 Daniel Scharrer 2012-06-06 16:36:06 UTC
In that case ebuild /usr/portage/sys-devel/clang/clang-3.1-r3.ebuild merge fails with

/var/tmp/portage/sys-devel/clang-3.1-r3/work/llvm-3.1.src/Release/bin/clang -Wall -Werror -O3 -fomit-frame-pointer -m64 -c -fno-exceptions -fPIC -funwind-tables -o /var/tmp/portage/sys-devel/clang-3.1-r3/work/llvm-3.1.src/tools/clang/runtime/compiler-rt/clang_linux/asan-x86_64/x86_64/SubDir.lib__asan/asan_posix.o /var/tmp/portage/sys-devel/clang-3.1-r3/work/llvm-3.1.src/projects/compiler-rt/lib/asan/asan_posix.cc
In file included from /var/tmp/portage/sys-devel/clang-3.1-r3/work/llvm-3.1.src/projects/compiler-rt/lib/asan/asan_new_delete.cc:19:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/new:40:10: fatal error: 'bits/c++config.h' file not found

should I post the full build log?
Comment 11 Richard Yao (RETIRED) gentoo-dev 2012-06-07 00:41:49 UTC
Clang is looking for files that are only present on 32-bit systems when -m32 is passed, which is wrong:

$ strace clang -v -m32 hello.c 2>&1 | grep config
open("/etc/env.d/gcc/config-i686-linux-gnu", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/env.d/gcc/config-i686-pc-linux-gnu", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/env.d/gcc/config-i486-linux-gnu", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/env.d/gcc/config-i386-linux-gnu", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/env.d/gcc/config-i686-redhat-linux", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/env.d/gcc/config-i586-redhat-linux", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/env.d/gcc/config-i386-redhat-linux", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/env.d/gcc/config-i586-suse-linux", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/env.d/gcc/config-i486-slackware-linux", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/env.d/gcc/config-i386-pc-linux-gnu", O_RDONLY) = -1 ENOENT (No such file or directory)

Aside from that, I cannot tell why this is failing on your system. On mine, it falls back to the non-Gentoo behavior, which works.

(In reply to comment #10)
> In that case ebuild /usr/portage/sys-devel/clang/clang-3.1-r3.ebuild merge
> fails with
> 
> /var/tmp/portage/sys-devel/clang-3.1-r3/work/llvm-3.1.src/Release/bin/clang
> -Wall -Werror -O3 -fomit-frame-pointer -m64 -c -fno-exceptions -fPIC
> -funwind-tables -o
> /var/tmp/portage/sys-devel/clang-3.1-r3/work/llvm-3.1.src/tools/clang/
> runtime/compiler-rt/clang_linux/asan-x86_64/x86_64/SubDir.lib__asan/
> asan_posix.o
> /var/tmp/portage/sys-devel/clang-3.1-r3/work/llvm-3.1.src/projects/compiler-
> rt/lib/asan/asan_posix.cc
> In file included from
> /var/tmp/portage/sys-devel/clang-3.1-r3/work/llvm-3.1.src/projects/compiler-
> rt/lib/asan/asan_new_delete.cc:19:
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/new:40:10: fatal
> error: 'bits/c++config.h' file not found
> 
> should I post the full build log?

That is bug #418141. Try sys-devel/clang-3.1-r4. It should address that.
Comment 12 Daniel Scharrer 2012-06-08 12:22:15 UTC
-r4 consistently picks the correct variants of 34/64-bit headers and libraries.

It still falls back to the vanilla gcc detection for -m32 and picks the latest gcc as opposed to the eselected one - not sure if this is worth fixing.
Comment 13 Richard Yao (RETIRED) gentoo-dev 2012-06-08 13:23:27 UTC
(In reply to comment #12)
> -r4 consistently picks the correct variants of 34/64-bit headers and
> libraries.
> 
> It still falls back to the vanilla gcc detection for -m32 and picks the
> latest gcc as opposed to the eselected one - not sure if this is worth
> fixing.

That is definitely worth fixing, but it is harder to fix than the previous issue. I will work on it as I have time.
Comment 14 Bernard Cafarelli gentoo-dev 2015-10-16 11:12:39 UTC
Cleaning old bugs, newer versions of llvm/clang work fine here with -m32.
Don't hesitate to reopen if you still have the problem!