Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 199904 - GCC 4.2 misuses atomic builtins on multilib x86 (__sync_fetch_and_add_4, etc.)
Summary: GCC 4.2 misuses atomic builtins on multilib x86 (__sync_fetch_and_add_4, etc.)
Status: RESOLVED DUPLICATE of bug 185404
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: AMD64 Linux
: High major (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-21 16:03 UTC by Dani Church
Modified: 2007-11-21 19:30 UTC (History)
0 users

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 Dani Church 2007-11-21 16:03:09 UTC
GCC 4.2 (tested: sys-devel/gcc-4.2.2) mistakenly inserts the 64-bit atomic builtins into 32-bit code that it generates, creating linker errors during 32-bit compilation when ld cannot find any references to __sync_bool_compare_and_swap_4, __sync_fetch_and_add_4, __sync_val_compare_and_swap_4, etc.  This manifests especially when building glibc (tested: sys-libs/glibc-2.7), as that uses a bunch of 32-bit code.  I thought this might have something to do with the CFLAGS being passed to the GCC build process (-march, in particular), but it seems to have that trouble no matter what CFLAGS are used to build GCC.

A workaround I am currently using is to add -march=i686 to the CFLAGS added by eselect-compiler when i686-pc-linux-gnu-gcc is called, in /etc/eselect/compiler/x86_64-pc-linux-gnu-4.2.2.conf; this generates proper code in 32-bit mode.

There seems to be some sort of black magic going on here.  I don't really understand what's causing these problems, or how that fixes it.  Something is definitely broken, but I have no idea what it is.

Reproducible: Always

Steps to Reproduce:
1. emerge =sys-devel/gcc-4.2*
2. emerge =sys-libs/glibc-4.7*
Actual Results:  
In glibc build:

i686-pc-linux-gnu-gcc   -shared -static-libgcc -Wl,-O1  -Wl,-z,defs -Wl,-dynamic-linker=/lib32/ld-linux.so.2 [...] -o /var/tmp/portage/sys-libs/glibc-2.7/work/build-x86-x86_64-pc-linux-gnu-nptl/libc.so [...] -lgcc
/var/tmp/portage/sys-libs/glibc-2.7/work/build-x86-x86_64-pc-linux-gnu-nptl/libc_pic.os: In function `__fork':
(.text+0x7b8ef): undefined reference to `__sync_bool_compare_and_swap_4'
/var/tmp/portage/sys-libs/glibc-2.7/work/build-x86-x86_64-pc-linux-gnu-nptl/libc_pic.os: In function `nscd_getpw_r':
nscd_getpw_r.c:(.text+0xdde87): undefined reference to `__sync_fetch_and_add_4'
nscd_getpw_r.c:(.text+0xddecb): undefined reference to `__sync_fetch_and_add_4'
/var/tmp/portage/sys-libs/glibc-2.7/work/build-x86-x86_64-pc-linux-gnu-nptl/libc_pic.os: In function `nscd_getgr_r':
nscd_getgr_r.c:(.text+0xde2cb): undefined reference to `__sync_fetch_and_add_4'
nscd_getgr_r.c:(.text+0xde310): undefined reference to `__sync_fetch_and_add_4'
/var/tmp/portage/sys-libs/glibc-2.7/work/build-x86-x86_64-pc-linux-gnu-nptl/libc_pic.os: In function `nscd_gethst_r':
nscd_gethst_r.c:(.text+0xde97d): undefined reference to `__sync_fetch_and_add_4'
/var/tmp/portage/sys-libs/glibc-2.7/work/build-x86-x86_64-pc-linux-gnu-nptl/libc_pic.os:nscd_gethst_r.c:(.text+0xde9c4): more undefined references to `__sync_fetch_and_add_4' follow
/var/tmp/portage/sys-libs/glibc-2.7/work/build-x86-x86_64-pc-linux-gnu-nptl/libc_pic.os: In function `__nscd_get_map_ref':
(.text+0xe09d0): undefined reference to `__sync_val_compare_and_swap_4'
/var/tmp/portage/sys-libs/glibc-2.7/work/build-x86-x86_64-pc-linux-gnu-nptl/libc_pic.os: In function `__GI___libc_freeres':
(__libc_freeres_fn+0x87e): undefined reference to `__sync_bool_compare_and_swap_4'
collect2: ld returned 1 exit status
make[1]: *** [/var/tmp/portage/sys-libs/glibc-2.7/work/build-x86-x86_64-pc-linux-gnu-nptl/libc.so] Error 1
make[1]: Leaving directory `/var/tmp/portage/sys-libs/glibc-2.7/work/glibc-2.7'
make: *** [all] Error 2


Expected Results:  
glibc compiles without error, of course.  This happens using the workaround above.

Portage 2.1.3.19 (default-linux/amd64/2007.0/desktop, gcc-4.2.2/amd64-vanilla, glibc-2.7-r0, 2.6.22-gentoo-r4 x86_64)
=================================================================
System uname: 2.6.22-gentoo-r4 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 3800+
Timestamp of tree: Tue, 20 Nov 2007 04:46:01 +0000
distcc 2.18.3 x86_64-pc-linux-gnu (protocols 1 and 2) (default port 3632) [disabled]
ccache version 2.4 [enabled]
app-admin/eselect-compiler: 2.0.0_rc2-r1
app-shells/bash:     3.2_p17-r1
dev-java/java-config: 1.3.7, 2.1.2-r1
dev-lang/python:     2.4.3-r3, 2.5.1-r3
dev-python/pycrypto: 2.0.1-r6
dev-util/ccache:     2.4-r7
sys-apps/baselayout: 1.12.10-r5
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r1
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10
sys-devel/binutils:  2.18-r1
sys-devel/libtool:   1.5.24
virtual/os-headers:  2.6.23-r2
ACCEPT_KEYWORDS="amd64 ~amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -march=athlon64 -fomit-frame-pointer -funroll-loops -ftracer"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/eselect/compiler /etc/gconf /etc/revdep-rebuild /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-O2 -pipe -march=athlon64 -fomit-frame-pointer -funroll-loops -ftracer"
DISTDIR="/usr/portage/distfiles"
FEATURES="ccache distlocks metadata-transfer parallel-fetch sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://gentoo.mirrors.pair.com/ http://mirror.mcs.anl.gov/pub/gentoo/ http://gentoo.cites.uiuc.edu/pub/gentoo/ http://gentoo.osuosl.org/"
INSTALL_MASK="/sbin/installkernel /etc/hotplug/firmware.agent"
LINGUAS="en ja"
MAKEOPTS="-j1"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --filter=H_**/files/digest-*"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local/layman/armagetron /usr/local/portage"
SYNC="rsync://rsync.us.gentoo.org/gentoo-portage"
USE="3dnow 3dnowext X a52 aac aalib acl acpi alsa amd64 amr bash-completion berkdb bitmap-fonts bzip2 cairo canna cdparanoia cdr cjk cli cracklib crypt cscope cups curl dbus dga divx divx4linux dmx dpms dri dts dv dvb dvd dvdnav dvdr dvdread emboss encode evo expat fam fame ffmpeg firefox flac font-server freewnn gdbm gif gimp gimpprint glut gmedia gnome gpm gtk gtkhtml hal iconv ieee1394 ipod isdnlog ithreads java javascript jpeg kdrive kerberos kqemu ladspa lcms ldap leim libcaca libsamplerate live mad madwifi midi mikmod mjpeg mmx mmxext mng mozbranding mozdevelop mozilla mp3 mpeg mysql nas ncurses nethack network nls nptl nptlonly nsplugin ogg opengl oss pam pcre pdf perl png pppd python qt3 qt3support qt4 quicktime readline realmedia reflection rtc samba sblive scanner sdl session skey slang smp spell spl sse sse2 ssl svg tcltk threads tiff timidity truetype truetype-fonts type1-fonts unicode usb v4l v4l2 vim-with-x vorbis wma wmp x264 xcomposite xforms xinerama xml xorg xprint xrandr xv xvid xvmc 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 mulaw multi null plug rate route share shm softvol" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en ja" USERLAND="GNU" VIDEO_CARDS="nvidia nv"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, LANG, LC_ALL, LDFLAGS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Jakub Moc (RETIRED) gentoo-dev 2007-11-21 19:30:49 UTC
> app-admin/eselect-compiler: 2.0.0_rc2-r1

Unmerge this junk and downgrade your gcc-config; it's breaking your toolchain.

*** This bug has been marked as a duplicate of bug 185404 ***