Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 545176

Summary: app-shells/tcsh-6.18.01-r2: calloc helper optimized into recursive calloc call with gcc-5.1
Product: Gentoo Linux Reporter: David Kredba <kredba>
Component: [OLD] GCC PortingAssignee: Fabian Groffen <grobian>
Status: RESOLVED FIXED    
Severity: normal CC: rhill
Priority: Normal Keywords: PATCH
Version: unspecified   
Hardware: All   
OS: Linux   
URL: https://gcc.gnu.org/ml/gcc-help/2015-03/msg00112.html
See Also: http://bugs.debian.org/778142
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 536984    
Attachments: Build.log
Config.log
tcsh-6.18.01-gcc5.patch

Description David Kredba 2015-03-31 18:56:53 UTC
Markus Trippelsdorf helped me on gcc-help list and found the root cause and that -fno-builtin fixes it:

-citation begins-
markus@x4 tmp % cat tc.alloc.i
typedef long unsigned int size_t;
extern void *memset(void *__s, int __c, size_t __n);
extern void *malloc(size_t __size);

void *calloc(size_t i, size_t j) {
  char *cp;
  i *= j;
  cp = malloc(i);
  memset(cp, 0, i);
  return ((void *)cp);
}

markus@x4 tmp % gcc -O2 -S tc.alloc.i

markus@x4 tmp % cat tc.alloc.s
        .file   "tc.alloc.i"
        .section        .text.unlikely,"ax",@progbits
.LCOLDB0:
        .text
.LHOTB0:
        .p2align 4,,15
        .globl  calloc
        .type   calloc, @function
calloc:
.LFB0:
        .cfi_startproc
        imulq   %rsi, %rdi
        movl    $1, %esi
        jmp     calloc
        .cfi_endproc
.LFE0:
        .size   calloc, .-calloc
        .section        .text.unlikely
.LCOLDE0:
        .text
.LHOTE0:
        .ident  "GCC: (GNU) 5.0.0 20150330 (experimental)"
        .section        .note.GNU-stack,"",@progbits

So it gets compiled into an endless loop.
-fno-builtin fixes the issue.
-citation ends-

Reproducible: Always




emerge --info
Portage 2.2.18 (python 2.7.9-final-0, default/linux/amd64/13.0/desktop, gcc-5.0.0, glibc-2.20-r2, 3.19.3-gentoo x86_64)
=================================================================
System uname: Linux-3.19.3-gentoo-x86_64-Intel-R-_Core-TM-2_Quad_CPU_Q9550_@_2.83GHz-with-gentoo-2.2
KiB Mem:     8169704 total,   1934516 free
KiB Swap:    8396796 total,   8371820 free
Timestamp of repository gentoo: Tue, 31 Mar 2015 18:00:01 +0000
sh bash 4.3_p33-r2
ld GNU ld (Gentoo 2.25 p1.0) 2.25
app-shells/bash:          4.3_p33-r2::gentoo
dev-java/java-config:     2.2.0::gentoo
dev-lang/perl:            5.20.2::gentoo
dev-lang/python:          2.7.9-r2::gentoo, 3.4.3::gentoo
dev-util/cmake:           3.1.0::gentoo
dev-util/pkgconfig:       0.28-r2::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.13.11::gentoo
sys-apps/sandbox:         2.6-r1::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69-r1::gentoo
sys-devel/automake:       1.11.6-r1::gentoo, 1.13.4::gentoo, 1.14.1::gentoo, 1.15::gentoo
sys-devel/binutils:       2.25::gentoo, 2.26.51::x-portage
sys-devel/gcc:            4.8.4::gentoo, 4.9.2::gentoo, 4.10.0_pre20150328::x-portage, 5.0.0::x-portage
sys-devel/gcc-config:     1.8::gentoo
sys-devel/libtool:        2.4.6-r1::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 3.19::gentoo (virtual/os-headers)
sys-libs/glibc:           2.20-r2::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

x-portage
    location: /usr/local/portage
    masters: gentoo
    priority: 0

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-flto=4 -fuse-linker-plugin -O2 -g -pipe -march=core2 -mtune=core2"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/config /usr/share/gnupg/qualified.txt /var/bind /var/lib/hsqldb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /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="-flto=4 -fuse-linker-plugin -O2 -g -pipe -march=core2 -mtune=core2"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--quiet-build=n"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms splitdebug strict unknown-features-warn unmerge-logs unmerge-orphans userfetch usersandbox usersync xattr"
FFLAGS="-flto=4 -fuse-linker-plugin -O2 -g -pipe -march=core2 -mtune=core2"
GENTOO_MIRRORS="ftp://gentoo.mirror.web4u.cz/"
LANG="cs_CZ.utf8"
LC_ALL="cs_CZ.UTF-8"
LDFLAGS="-Wl,-flto -fuse-linker-plugin -Wl,--as-needed -Wl,-O2 -Wl,--sort-common -Wl,--hash-style=gnu -O2 -g -pipe -march=core2 -mtune=core2"
MAKEOPTS="-j4"
PKGDIR="/usr/portage/packages"
PORTAGE_COMPRESS="echo"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
USE="X a52 aac aalib acl acpi alsa amd64 berkdb blas bluetooth branding bzip2 cairo caps cdda cddb cdparanoia cdr cli consolekit cracklib crypt cups cvs cxx dbus declarative djvu dri dts dv dvb dvd dvdr emboss encode exif fam ffmpeg fftw firefox flac fontconfig fortran ftp gd gdbm geoip gif glamor gmp gnuplot gpm gps graphviz gsl gsm gstreamer gtk hdf5 iconv icu idn ieee1394 imagemagick imlib ipv6 ithreads javascript jbig jpeg jpeg2k ladspa lame lapack lcms ldap libass libnotify libsamplerate lzma lzo mad matroska mms mmx mmxext mng modplug modules mp3 mp4 mpeg mplayer msn mtp multilib musepack musicbrainz ncurses netcdf nls nptl ocaml ocamlopt odbc ogg opencl openexr opengl openmp pam pango pch pcre pdf perl pic plotutils png policykit postscript ppds pulseaudio python qt3support qt4 quicktime rdesktop readline samba scanner sdl semantic-desktop session slang smp sndfile sox speex spell sse sse2 ssl ssse3 startup-notification svg szip tcpd theora threads tidy tiff truetype udev udisks unicode upower usb v4l vcd vdpau vnc vorbis wavpack wmf wxwidgets x264 xattr xcb xft xine xinerama xml xosd xpm xscreensaver xv xvid xvmc zlib" ABI_X86="64 32" 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" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd 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 author" CAMERAS="ptp2 adc65 agfa_cl20 aox ax203 barbie canon casio_qv clicksmart310 digigr8 digita dimagev dimera3500 directory enigma13 fuji gsmart300 hp215 iclick jamcam jd11 jl2005a jl2005c kodak_dc120 kodak_dc210 kodak_dc240 kodak_dc3200 kodak_ez200 konica konica_qm150 largan lg_gsm mars mustek panasonic_coolshot panasonic_dc1000 panasonic_dc1580 panasonic_l859 pccam300 pccam600 pentax polaroid_pdc320 polaroid_pdc640 polaroid_pdc700 ricoh ricoh_g3 samsung sierra sipix_blink2 sipix_web2 smal sonix sony_dscf1 sony_dscf55 soundvision spca50x sq905 st2205 stv0674 stv0680 sx330z topfield toshiba_pdrm11 tp6801" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2 sse3 sse4_1 ssse3" CURL_SSL="gnutls" ELIBC="glibc" FFTOOLS="aviocat cws2fws ffescape ffeval fourcc2pixfmt graph2dot ismindex pktdumper qt-faststart trasher ffhash" GPSD_PROTOCOLS="aivdm ashtech earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 navcom nmea ntrip oceanserver oncore rtcm104v2 rtcm104v3 sirf superstar2 tnt tripmate tsip ubx fury geostar nmea2000" GRUB_PLATFORMS="pc" INPUT_DEVICES="evdev keyboard mouse joystick" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer scripting-beanshell scripting-javascript nlpsolver" LINGUAS="cs en" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_4" QEMU_SOFTMMU_TARGETS="x86_64 arm i386" QEMU_USER_TARGETS="arm i386 x86_64" RUBY_TARGETS="ruby19 ruby20 ruby21 ruby22" USERLAND="GNU" VIDEO_CARDS="nouveau radeon" 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"
USE_PYTHON="2.7 3.4"
Unset:  CPPFLAGS, CTARGET, INSTALL_MASK, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 SpanKY gentoo-dev 2015-04-04 20:14:54 UTC
-fno-builtin isn't the right answer.  tcsh shouldn't be defining calloc at all.
Comment 2 Fabian Groffen gentoo-dev 2015-04-05 06:50:10 UTC
Linux should have SYSMALLOC defined, so you would end up using scalloc (wrapper to system calloc) instead.  Is __GLIBC__ defined in your case?
Comment 3 David Kredba 2015-04-05 18:44:23 UTC
(In reply to Fabian Groffen from comment #2)
> Linux should have SYSMALLOC defined, so you would end up using scalloc
> (wrapper to system calloc) instead.  Is __GLIBC__ defined in your case?

I not found any "glibc" nor "GLIBC" in ./config.log and Makefile.

Environment file states ELIBC=glibc

I will attach build.log up to compile phase, including it + config.log.
Comment 4 David Kredba 2015-04-05 18:46:52 UTC
Created attachment 400626 [details]
Build.log
Comment 5 David Kredba 2015-04-05 18:47:21 UTC
Created attachment 400628 [details]
Config.log
Comment 6 Kacper Kowalik (Xarthisius) (RETIRED) gentoo-dev 2015-04-05 19:37:39 UTC
(In reply to Fabian Groffen from comment #2)
> Linux should have SYSMALLOC defined, so you would end up using scalloc
> (wrapper to system calloc) instead.  Is __GLIBC__ defined in your case?

gcc doesn't define __GLIBC__ on linux. you need to include <features.h> for that.
Comment 7 Ryan Hill (RETIRED) gentoo-dev 2015-07-07 03:35:24 UTC
Created attachment 406286 [details, diff]
tcsh-6.18.01-gcc5.patch

Upstream discussion: 
http://mx.gw.com/pipermail/tcsh-bugs/2015-May/000930.html

Upstream commit:
https://github.com/tcsh-org/tcsh/commit/624d3aebb6e6afadb4f35e894d11b5ebe290cd87

That commit doesn't fix the problem though; k needs to be made volatile for it to work.
Comment 8 Fabian Groffen gentoo-dev 2015-07-07 06:30:27 UTC
feel free to apply/commit/push
Comment 9 Ryan Hill (RETIRED) gentoo-dev 2015-07-19 10:13:52 UTC
Fixed in tcsh-6.18.01-r3.