From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61163 invoked by alias); 15 Oct 2015 14:03:36 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 61106 invoked by uid 48); 15 Oct 2015 14:03:28 -0000 From: "vogt at linux dot vnet.ibm.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug go/67976] New: Cgo + Gccgo not working like Cgo + Golang? Date: Thu, 15 Oct 2015 14:03:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: go X-Bugzilla-Version: 6.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vogt at linux dot vnet.ibm.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ian at airs dot com X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-10/txt/msg01186.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67976 Bug ID: 67976 Summary: Cgo + Gccgo not working like Cgo + Golang? Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: go Assignee: ian at airs dot com Reporter: vogt at linux dot vnet.ibm.com CC: cmang at google dot com Target Milestone: --- The authors of the Ethereum project seem to assume that cgo can handle the code below in a sensible way, but when using the -gccgo option that is not the case. -- snip -- package foo /* int foo_cgo(unsigned); */ import "C" import "unsafe" //export foo func foo(x C.unsigned) C.int { return 0 } func () bar() { _ = unsafe.Pointer(C.foo_cgo) } -- snip -- Running this through $ mkdir _obj $ cgo -objdir _obj -gccgo foo.go Results in this code in _cgo_main.c: extern char foo_cgo[]; void *_cgohack_foo_cgo = foo_cgo; #include "_cgo_export.h" And this line in _cgo_export.h: int foo_cgo(unsigned); Redeclaring foo_cgo results in an error message when trying to compile _cgo_main.c. Maybe _cgo_export.h should simply be emitted to _cgo_main.c *before* all the declarations?