Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: cannot use stdout anymore with GCC4.8 #5118

Closed
remyoudompheng opened this issue Mar 24, 2013 · 11 comments

Comments

@remyoudompheng
Copy link
Contributor

commented Mar 24, 2013

What steps will reproduce the problem?
1. Run ./all.bash

What is the expected output? What do you see instead?

Expected: all runs successful.

Instead:
# ../doc/progs
# command-line-arguments
could not determine kind of name for C.stdout

It turns out that "stdout;" is no longer a "statement with no
effect" in GCC >= 4.8.0.

$ cat truc.c
#include <stdio.h>

void f(void) {
stdout;
}
$ /opt/gccgo/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/opt/gccgo/bin/gcc
COLLECT_LTO_WRAPPER=/opt/gccgo/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gccgo/configure --cache-file=/storage/src/gccgo-svn/src/config.cache
--enable-languages=go --prefix=/opt/gccgo --disable-bootstrap --with-ld=/usr/bin/ld.gold
: (reconfigured) ../gccgo/configure --cache-file=/storage/src/gccgo-svn/src/config.cache
--enable-languages=go --prefix=/opt/gccgo --disable-bootstrap --with-ld=/usr/bin/ld.gold
: (reconfigured) ../gccgo/configure --cache-file=/storage/src/gccgo-svn/src/config.cache
--enable-languages=go --prefix=/opt/gccgo --disable-bootstrap --with-ld=/usr/bin/ld.gold
: (reconfigured) ../gccgo/configure --cache-file=/storage/src/gccgo-svn/src/config.cache
--enable-languages=go --prefix=/opt/gccgo --disable-bootstrap --with-ld=/usr/bin/ld.gold
: (reconfigured) ../gccgo/configure --cache-file=/storage/src/gccgo-svn/src/config.cache
--enable-languages=go --prefix=/opt/gccgo --disable-bootstrap --with-ld=/usr/bin/ld.gold
: (reconfigured) ../gccgo/configure --cache-file=/storage/src/gccgo-svn/src/config.cache
--enable-languages=go --prefix=/opt/gccgo --disable-bootstrap --with-ld=/usr/bin/ld.gold
: (reconfigured) ../gccgo/configure --cache-file=/storage/src/gccgo-svn/src/config.cache
--enable-languages=go --prefix=/opt/gccgo --disable-bootstrap --with-ld=/usr/bin/ld.gold
: (reconfigured) ../gccgo/configure --cache-file=/storage/src/gccgo-svn/src/config.cache
--enable-languages=go --prefix=/opt/gccgo --disable-bootstrap --with-ld=/usr/bin/ld.gold
: (reconfigured) ../gccgo/configure --cache-file=/storage/src/gccgo-svn/src/config.cache
--enable-languages=go --prefix=/opt/gccgo --disable-bootstrap --with-ld=/usr/bin/ld.gold
Thread model: posix
gcc version 4.9.0 20130324 (experimental) (GCC) 
$ /opt/gccgo/bin/gcc -Wall -Werror -c truc.c
$
@remyoudompheng

This comment has been minimized.

Copy link
Contributor Author

commented Mar 30, 2013

Comment 1:

GCC 4.8 is released and will be adopted by Linux distributions: Archlinux already ships
it.
The GCC bug started with the following commit (SVN revision 186977):
http://gcc.gnu.org/viewcvs/gcc?view=revision&revision=186977
Author: dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Mon Apr 30 11:43:43 2012 +0000
    Switch -ftrack-macro-expansion=2 on by default.
    
    This switches the compiler to -ftrack-macro-expansion=2 by default.
    
    Tested and bootstrapped on x86_64-unknown-linux-gnu against trunk.
    
    libcpp/
    
        * init.c (cpp_create_reader): Switch -ftrack-macro-expansion=2 on
        by default.  Add comments.
    
    gcc/docs/
    
        * cppopts.texi: Adjust for enabling -ftrack-macro-expansion=2 by
        default.
I don't think GCC 4.8.1 will ship early enough. A possible fix is to patch cgo to use
-ftrack-macro-expansion=0, how will it behave with older GCCs? clang happily ignores it.
diff -r 5260abd6df41 src/cmd/cgo/gcc.go
--- a/src/cmd/cgo/gcc.go    Sat Mar 30 19:05:00 2013 +0800
+++ b/src/cmd/cgo/gcc.go    Sat Mar 30 18:12:48 2013 +0100
@@ -787,6 +787,10 @@
            "-Wno-unused-function",
            "-Qunused-arguments",
        )
+   } else {
+       c = append(c,
+           "-ftrack-macro-expansion=0", // GCC 4.8 misses statements with no effect (issue
5118).
+       )
    }
 
    c = append(c, p.GccOptions...)
@minux

This comment has been minimized.

Copy link
Member

commented Mar 30, 2013

Comment 2:

have you filed bug reports to gcc?
gcc on gentoo (version 4.6.3) still rejects the -ftrack-macro-expansion=0 option,
so we need another workaround, i'm afraid (that option is introduced in gcc 4.7
and i think there will be plenty of pre 4.7 gcc installations out there, so just in
case we can't find better workarounds, i'm inclined to leave this for Go 1.1.1).
because gcc 4.8.0 is release before Go 1.1, i will label this issue as Go 1.1Maybe.

Labels changed: added priority-soon, go1.1maybe, removed priority-triage.

@remyoudompheng

This comment has been minimized.

Copy link
Contributor Author

commented Mar 31, 2013

Comment 3:

I don't know how to report:
 * I cannot attach preprocessed files to the report, because they compile fine
 * I cannot attach a copy of my stdio.h to the report, because including it from the local directory makes it work correctly.
 * Even replacing the include by #include "/usr/include/stdio.h" makes the warning work as expected.
@minux

This comment has been minimized.

Copy link
Member

commented Mar 31, 2013

Comment 4:

This is caused by bad interaction with -Wsystem-headers, so perhaps it's not a bug in
the eyes of a gcc
developer. @iant.
$ cat stdio.c
#include <test.h>
void f(void) {
        stdout;
}
$ cat test.h 
int *stdout;
#define stdout stdout
$ gcc -Wall -Werror -c stdio.c  -I .
In file included from stdio.c:1:0:
stdio.c: In function ‘f’:
./test.h:2:16: error: statement with no effect [-Werror=unused-value]
 #define stdout stdout
                ^
stdio.c:4:2: note: in expansion of macro ‘stdout’
  stdout;
  ^
cc1: all warnings being treated as errors
$ gcc -Wall -Werror -c stdio.c  -isystem .
$ 
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.8.0/configure --enable-languages=c,c++,go,lto
Thread model: posix
gcc version 4.8.0 (GCC)
@minux

This comment has been minimized.

Copy link
Member

commented Apr 2, 2013

Comment 5:

Issue #5153 has been merged into this issue.

@gopherbot

This comment has been minimized.

Copy link

commented Apr 4, 2013

Comment 6 by jon.forums:

I don't see this build error on Win7 (32-bit) or Win8 (64-bit) using one of the
mingw-w64 based 4.8.0 toolchains from
  http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.0/
Only 4.8.0-based builds on my Arch 32 and 64-bit boxes currently fail.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 8, 2013

Comment 7:

Labels changed: added go1.1, removed go1.1maybe.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 8, 2013

Comment 8:

Filed http://gcc.gnu.org/PR57201 .
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 8, 2013

Comment 9:

I think we can work around this problem by passing -Wsystem-headers when we look for
errors.  That will cause additional errors, but it doesn't matter because we discard all
errors that are not for the imaginary "cgo-test" file.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 8, 2013

Comment 10:

This issue was closed by revision 8a28085.

Status changed to Fixed.

@adg

This comment has been minimized.

Copy link
Contributor

commented May 8, 2013

Comment 11:

This issue was closed by revision 8b13b2ec6b18.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015

@rsc rsc removed the go1.1 label Apr 14, 2015

adg added a commit that referenced this issue May 11, 2015
[release-branch.go1.1] cmd/cgo: pass -Wsystem-headers when looking fo…
…r errors

««« CL 9120045 / e4f62df3e6c9
cmd/cgo: pass -Wsystem-headers when looking for errors

This works around a bug in GCC 4.8.0.

Fixes #5118.

R=golang-dev, r, minux.ma
CC=golang-dev
https://golang.org/cl/9120045
»»»

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9259047

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants
You can’t perform that action at this time.