From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31120 invoked by alias); 22 Nov 2014 08:51:00 -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 31083 invoked by uid 48); 22 Nov 2014 08:50:56 -0000 From: "rth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug go/64021] New: Empty struct vs libffi Date: Sat, 22 Nov 2014 08:51: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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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 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: 2014-11/txt/msg02511.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64021 Bug ID: 64021 Summary: Empty struct vs libffi Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: go Assignee: ian at airs dot com Reporter: rth at gcc dot gnu.org CC: cmang at google dot com In go_struct_to_ffi, an empty struct is maped to ffi_type_void. On i386, some ABIs return a struct pop 4 bytes of stack. If one calls a function returning a structure without preparing for this, the stack will be corrupted. On sparc32, functions returning a structure return to a different address. If one calls a function returning a structure without preparing for this, the instruction after the call will be skipped. In both cases, this causes reflect/all_test.go returnEmpty to fail. I wonder what's better: follow C++ and map empty structures to a single byte (i.e. no more zero-sized structures), or enhance libffi to be able to deal with empty structures so that we don't have to lie to libffi about the type being manipulated?