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

Bug 365015

Summary: [4.6/4.7/4.8/4.9] indirect function call with a yet undetermined callee for stdio.h functions (-O1) (was:games-emulation/zsnes fails with gcc-4.6)
Product: Gentoo Linux Reporter: Diego Elio Pettenò (RETIRED) <flameeyes>
Component: [OLD] GamesAssignee: Gentoo Toolchain Maintainers <toolchain>
Status: RESOLVED FIXED    
Severity: normal CC: alex, esigra, O01eg, pacho, xarthisius
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 346809    
Attachments: Build log

Description Diego Elio Pettenò (RETIRED) gentoo-dev 2011-04-27 00:01:15 UTC
Created attachment 271281 [details]
Build log

Portage 2.1.9.46 (default/linux/x86/10.0, gcc-4.6.0-asneeded, libc-0-r0, 2.6.38.3 i686)
=================================================================
System uname: Linux-2.6.38.3-i686-Quad-Core_AMD_Opteron-tm-_Processor_2350-with-gentoo-2.0.2
Timestamp of tree: Tue, 26 Apr 2011 23:00:01 +0000
distcc 3.1 i686-pc-linux-gnu [disabled]
ccache version 3.1.4 [disabled]
app-shells/bash:     4.2_p8
dev-java/java-config: 2.1.11-r3
dev-lang/python:     2.4.6, 2.7.1-r1, 3.1.3-r1
dev-util/ccache:     3.1.4
dev-util/cmake:      2.8.4
sys-apps/baselayout: 2.0.2
sys-apps/openrc:     0.8.2
sys-apps/sandbox:    2.5
sys-devel/autoconf:  2.13, 2.68
sys-devel/automake:  1.9.6-r3, 1.10.3, 1.11.1-r1
sys-devel/binutils:  2.21
sys-devel/gcc:       4.6.0
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   2.4-r1
sys-devel/make:      3.82
sys-kernel/linux-headers: 2.6.38
virtual/os-headers:  0
ACCEPT_KEYWORDS="x86 ~x86"
ACCEPT_LICENSE="*"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-O2 -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib/tomoyo/conf /usr/share/bufrtables /usr/share/config /usr/share/gnupg/qualified.txt /usr/share/maven-bin-3.0/conf /usr/share/qpsmtpd/plugins /var/lib/hsqldb /var/phxd /var/qmail/alias /var/qmail/control /var/yp/Makefile"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.3/ext-active/ /etc/php/cgi-php5.3/ext-active/ /etc/php/cli-php5.3/ext-active/ /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"
DISTDIR="/var/cache/portage/distfiles"
FEATURES="assume-digests binpkg-logs distlocks fixlafiles fixpackages news parallel-fetch protect-owned sandbox sfperms split-log strict test test-fail-continue unknown-features-warn unmerge-orphans userfetch userpriv usersandbox"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://gentoo.wheel.sk/"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu"
MAKEOPTS="-j14"
PKGDIR="/var/spool/portage/packages"
PORTAGE_COMPRESS=""
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/var/cache/portage/tree"
PORTDIR_OVERLAY=""
SYNC="rsync://yamato.home.flameeyes.eu/gentoo-portage"
USE="acl berkdb bzip2 cli cracklib crypt cups cxx dri fortran gdbm gpm iconv ipv6 java5 java6 modules mudflap mysql ncurses nls nostatic nptl nptlonly openmp pam pcre pcsc-lite perl postgres pppd python qt3support readline ruby session ssl sysfs tcpd unicode vhosts x86 xorg zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 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 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 auth_digest cgi" CAMERAS="ptp2" 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" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18 jruby ruby19 ree18" USERLAND="GNU" VIDEO_CARDS="intel radeon nouveau vmware" 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, LC_ALL, LINGUAS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Tupone Alfredo gentoo-dev 2011-04-28 13:21:39 UTC
cannot reproduce here
Comment 2 Tupone Alfredo gentoo-dev 2011-04-28 13:56:39 UTC
Ok. I did reproduce it.
It does not seems to me a parallel make.
It is a problem with the FORTIFY_SOURCE and the  new compiler.

Compiling one of the source file generated by parsegen (in zsnes) the compiler raises a lot of warning and does not generate any code.
This is one of that warning

/usr/include/bits/stdio2.h:96:1: sorry, unimplemented: inlining failed in call to 'fprintf': indirect function call with a yet undetermined callee
cfg.c:1140:7: sorry, unimplemented: called from here

you can do manually by running the following command:

gcc -I. -D__UNIXSDL__  -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DNO_PNG  -D__RELEASE__ -O1 -o cfg.o -c cfg.c

Normally there is no problem with that ebuild as the FORTIFY SOURCE is disabled there, but I guess you have a gcc that does not respect the -U_FORTIFY_SOURCE

Don't know what I could do with this bug. Assign to gcc maintainers?
Comment 3 Tupone Alfredo gentoo-dev 2011-04-29 06:21:52 UTC
I reduced the code to:

cfg.c: 


#include <stdio.h>
static void w_i(void *fp, int (*outf)(void *, const char *, ...))
{
  outf(fp, ";%s\n", " - EOF -");
}

void write_cfg()
{
  FILE *fp = 0;
  w_i(fp, (int (*)(void *, const char *, ...))fprintf);
}

------------------

gcc -O1 -o cfg.o -c cfg.c
cfg.c: In function 'write_cfg':
/usr/include/bits/stdio2.h:96:1: sorry, unimplemented: inlining failed in call to 'fprintf': indirect function call with a yet undetermined callee
cfg.c:4:7: sorry, unimplemented: called from here

It does compile if I switch to gcc-4.5 or I put -U_FORTIFY_SOURCE
Comment 4 Ryan Hill (RETIRED) gentoo-dev 2011-05-13 16:08:15 UTC
-U_FORTIFY was broken in the first 4.6 patchset but it has been fixed for p1.1 and later, so you can close this bug unless you want to fix the underlying issue.
Comment 5 Tupone Alfredo gentoo-dev 2011-05-16 06:22:14 UTC
(In reply to comment #4)
> -U_FORTIFY was broken in the first 4.6 patchset but it has been fixed for p1.1
> and later, so you can close this bug unless you want to fix the underlying
> issue.

I build again gcc and tested with the same cfg.c program.

It is still failing with the same error.

I guess that the problem is with inlining and not with FORTIFY. FORTIFY is just using inline for its job.
Comment 6 Ryan Hill (RETIRED) gentoo-dev 2011-06-23 04:13:47 UTC
You said it works with -U_FORTIFY_SOURCE, which the ebuild already uses.  So it's up to you if you want to leave the workaround in or fix the bug in your package.  It's not a toolchain issue.
Comment 7 SpanKY gentoo-dev 2011-06-25 04:33:20 UTC
i think the example in comment #3 shows that is a toolchain issue ...
Comment 8 Dennis Schridde 2011-08-10 15:29:00 UTC
Any news on this?
Comment 9 Rafał Mużyło 2011-09-11 15:05:07 UTC
@comment 8:
well, as Ryan decided to hijack my gcc bug (PR39333) for bug 360513,
I've decided to reacquire it for this bug and attached a trimmed down test case from comment 3.

Now, I think, it's up to gcc upstream.
Comment 10 Ryan Hill (RETIRED) gentoo-dev 2011-09-12 00:50:15 UTC
You'll have to explain to me what this bug has to do with that PR, seeing as they seem to be about completely different things.
Comment 11 Rafał Mużyło 2011-09-13 11:41:26 UTC
@comment 10:
well, it's hard to tell if this bug is the *same* problem as the PR, but honestly, the same thing can be said about the PR and bug 360513.

Now, what do this bug and the PR have in common ?
That's easy - something goes wrong in regard of inlining.
Comment 12 Ryan Hill (RETIRED) gentoo-dev 2011-09-14 01:02:01 UTC
That's a pretty general definition.  There are 800 other bugs in upstream's bugzilla that it would also fit.

I drew a link between bug #306513 and PR39333 when the exact same experiments that you attempted led to the same results with my testcase.  This is not the same bug.
Comment 13 Rafał Mużyło 2011-09-14 11:43:11 UTC
OK, let's just agree we both still aren't sure what exactly is going wrong there, but...

a) the original problem there *seemed* fixed with gcc 4.4.0
b) in the original problem, inlining caused "wrong code", just as (it seems) in bug 360513, while here it fails to accept proper code while inlining is forced
(though)
c) -fipa-cp might just be a coincidence, then again, maybe not

The bottom line is that without a reduced testcase, bug 360513 won't be getting anywhere anyway, while now, there's a highly reduced testcase for this bug.
Comment 14 Ryan Hill (RETIRED) gentoo-dev 2011-09-15 00:44:26 UTC
(In reply to comment #13)
> OK, let's just agree we both still aren't sure what exactly is going wrong
> there, but...
> 
> a) the original problem there *seemed* fixed with gcc 4.4.0
> b) in the original problem, inlining caused "wrong code", just as (it seems) in
> bug 360513, while here it fails to accept proper code while inlining is forced
> (though)
> c) -fipa-cp might just be a coincidence, then again, maybe not
> 
> The bottom line is that without a reduced testcase, bug 360513 won't be getting
> anywhere anyway, while now, there's a highly reduced testcase for this bug.

I'm not so sure it is valid code, but I don't know.  ZSNES has a couple other issues that make it impossible to build with fortification enabled anyways.

I would suggest opening a new PR for this.  At least then someone will actually look at it.
Comment 15 Rafał Mużyło 2011-09-15 05:24:09 UTC
Well, as for zsnes and _FORTIFY_SOURCE, I don't recall a full list, only instance I do recall, is a minor case of abuse, where instead of array[MAX_SIZE+ind], they should have used array+(sizeof(*array)*(MAX_SIZE+ind)) (or something similar).

As for the other thing, in the reduced testcase, I've attached there, nothing seems to be *obviously* wrong with the code, yet it fails.
Comment 16 Rafał Mużyło 2011-09-24 15:41:34 UTC
I eventually decided to follow your advice and filed a new separate bug.

In the process, I've stumbled on an interesting result - this failure can be reproduced in gcc 4.5.3 - see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50506.
Comment 17 Oschtan 2012-03-31 10:40:51 UTC
Hmm. Strange. Compile without problems.
Comment 18 Pacho Ramos gentoo-dev 2012-09-23 14:31:18 UTC
What is the status of this with gcc-4.6.3?
Comment 19 Jan Vesely 2012-09-26 09:27:18 UTC
(In reply to comment #18)
> What is the status of this with gcc-4.6.3?

dunno if it counts, but for me using:
 gcc (Gentoo 4.6.3 p1.6, pie-0.5.2) 4.6.3 on amd64

 - problem mentioned in comment 3 still exists, but it compiles fine when using -O{0,2,3,s}
 - games-emulation/zsnes compiles fine
Comment 20 Jan Vesely 2012-09-26 09:39:03 UTC
PS: comment3 compiles fine on gcc-4.7.1
Comment 21 Rafał Mużyło 2012-11-05 11:11:48 UTC
(In reply to comment #20)
> PS: comment3 compiles fine on gcc-4.7.1

Odd, cause reduced testcase still fails for me with 4.7.2 (from 12 Oct 2012) with -O1 and glibc 2.15-r3.
Comment 22 Sean Santos 2012-12-16 05:46:28 UTC
It appears that this bug is one of the last three blocking gcc-4.6 stabilization. It's unclear from the comments if anyone understands and/or is seriously working on this since March, but the zsnes seems to be fine.

If there is no ebuild that's actually broken right now, may I suggest that this be removed from the list of blockers for 4.6?
Comment 23 Rafał Mużyło 2013-01-08 00:19:47 UTC
I've noted something interesting.
In gcc-4.7.2-patches-1.3.tar.bz2 tarball, there's 93_all_pr33763_4.7.3_extern-inline.patch.

It doesn't help with this problem, but the reduced testcase in PR33763 is very much alike to the reduced testcase for this issue and commenting out '__attribute__ ((always_inline))' in the reduced testcase for this problem makes the code accepted.

Anyone has idea about this ?
Comment 24 Ryan Hill (RETIRED) gentoo-dev 2014-04-05 02:56:17 UTC
Your testcase passes with 4.9 after this commit:  
http://gcc.gnu.org/git/?p=gcc.git;a=commit;h=f0d26d578d94a3fafc81d191d2168ab3517b3f0e

This is the fix for bug #496216 and I hope to get it in 4.8 as well.
Comment 25 Rafał Mużyło 2014-04-06 18:43:44 UTC
(In reply to Ryan Hill from comment #24)
> Your testcase passes with 4.9 after this commit:  
> http://gcc.gnu.org/git/?p=gcc.git;a=commit;
> h=f0d26d578d94a3fafc81d191d2168ab3517b3f0e
> 
> This is the fix for bug #496216 and I hope to get it in 4.8 as well.

Well, I'm honestly surprised.
Thank you for still having interest in this bug, despite its corner-case nature.
Comment 26 SpanKY gentoo-dev 2015-10-22 14:17:59 UTC
(In reply to Ryan Hill from comment #24)

that commit is in gcc-4.9.3 which is stable now