public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug go/64021] New: Empty struct vs libffi
@ 2014-11-22  8:51 rth at gcc dot gnu.org
  2014-11-22  8:55 ` [Bug go/64021] " rth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: rth at gcc dot gnu.org @ 2014-11-22  8:51 UTC (permalink / raw)
  To: gcc-bugs

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?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug go/64021] Empty struct vs libffi
  2014-11-22  8:51 [Bug go/64021] New: Empty struct vs libffi rth at gcc dot gnu.org
@ 2014-11-22  8:55 ` rth at gcc dot gnu.org
  2014-11-22 13:09 ` hjl.tools at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu.org @ 2014-11-22  8:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64021

--- Comment #1 from Richard Henderson <rth at gcc dot gnu.org> ---
Oh, that should read "fail after the merge of the new libffi".

Current libffi happens to have nothing interesting in the stack
slot that's incorrectly popped, and to happens not to fail.  Not
so with the ffi_call_go rewrite.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug go/64021] Empty struct vs libffi
  2014-11-22  8:51 [Bug go/64021] New: Empty struct vs libffi rth at gcc dot gnu.org
  2014-11-22  8:55 ` [Bug go/64021] " rth at gcc dot gnu.org
@ 2014-11-22 13:09 ` hjl.tools at gmail dot com
  2014-11-22 21:56 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: hjl.tools at gmail dot com @ 2014-11-22 13:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64021

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
FWIW, gcc and g++ pass empty struct differently on x86.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug go/64021] Empty struct vs libffi
  2014-11-22  8:51 [Bug go/64021] New: Empty struct vs libffi rth at gcc dot gnu.org
  2014-11-22  8:55 ` [Bug go/64021] " rth at gcc dot gnu.org
  2014-11-22 13:09 ` hjl.tools at gmail dot com
@ 2014-11-22 21:56 ` pinskia at gcc dot gnu.org
  2014-11-24  7:48 ` rth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-11-22 21:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64021

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-11-22
     Ever confirmed|0                           |1

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug go/64021] Empty struct vs libffi
  2014-11-22  8:51 [Bug go/64021] New: Empty struct vs libffi rth at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2014-11-22 21:56 ` pinskia at gcc dot gnu.org
@ 2014-11-24  7:48 ` rth at gcc dot gnu.org
  2014-11-24  9:16 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu.org @ 2014-11-24  7:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64021

Richard Henderson <rth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1

--- Comment #4 from Richard Henderson <rth at gcc dot gnu.org> ---
If we decide to follow C++, this is an abi change,
and thus should happen before gcc 5.  Thus P1.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug go/64021] Empty struct vs libffi
  2014-11-22  8:51 [Bug go/64021] New: Empty struct vs libffi rth at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2014-11-24  7:48 ` rth at gcc dot gnu.org
@ 2014-11-24  9:16 ` jakub at gcc dot gnu.org
  2014-11-24  9:58 ` rth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-11-24  9:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64021

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Isn't that just because in C++ empty structs are forced by the FE into having
length of one byte?  I mean, if you:
struct S {};
int a = sizeof (struct S);
struct S b;
then in C it is int a = 0; and b is a common with zero size, while in C++ it is
int a = 1; and b has size 1.  So it is natural that those two (which are very
much different thing) are passed differently, I don't see anything to change on
that.  So, for go, the question is if it follows GNU C or C++ for empty
structs.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug go/64021] Empty struct vs libffi
  2014-11-22  8:51 [Bug go/64021] New: Empty struct vs libffi rth at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-11-24  9:16 ` jakub at gcc dot gnu.org
@ 2014-11-24  9:58 ` rth at gcc dot gnu.org
  2014-11-24 15:40 ` ian at airs dot com
  2014-11-24 15:45 ` rth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu.org @ 2014-11-24  9:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64021

--- Comment #6 from Richard Henderson <rth at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #5)
> Isn't that just because in C++ empty structs are forced by the FE into
> having length of one byte?

Yes, of course.

> I mean, if you:
> struct S {};
> int a = sizeof (struct S);
> struct S b;
> then in C it is int a = 0; and b is a common with zero size...

The zero-sized data thing is a rather useless GCC extension, IMO.
If you use -pedantic you will of course error out.

> So, for go, the question is if it follows GNU C or C++ for
> empty structs.

Since Go doesn't really have pointers in the usual sense, it's
difficult to ask the question "&a[1] != &a[2]".  Which *must* be
false for C++ and will be true for the GCC extension.

This does need a Go expert to figure out if there's another case
which can be determined from the language level.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug go/64021] Empty struct vs libffi
  2014-11-22  8:51 [Bug go/64021] New: Empty struct vs libffi rth at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2014-11-24  9:58 ` rth at gcc dot gnu.org
@ 2014-11-24 15:40 ` ian at airs dot com
  2014-11-24 15:45 ` rth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: ian at airs dot com @ 2014-11-24 15:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64021

--- Comment #7 from Ian Lance Taylor <ian at airs dot com> ---
The Go language says that "Pointers to distinct zero-size variables may or may
not be equal" (http://golang.org/ref/spec#Comparison_operators).  So in the
language sense it would be OK to always convert zero-sized structs to contain a
single byte.  Go programmers routinely write things like make(chan struct{},
1000) and expect the channel to not take any space--the channel will keep a
count of elements but the element storage won't take any space; however, I
think that would continue to work as expected, since the libgo code looks at
the size in the Go type descriptor, which would continue to be zero.

I think the cleanest approach would be to modify libffi.  But as far as I can
always representing zero-sized structs as 1 byte in GIMPLE would work.  It
would mean we could remove Gcc_backend::non_zero_size_type.

I note that a zero-sized array is converted to an empty struct in go-ffi.c.  I
wonder how libffi handles that today.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug go/64021] Empty struct vs libffi
  2014-11-22  8:51 [Bug go/64021] New: Empty struct vs libffi rth at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2014-11-24 15:40 ` ian at airs dot com
@ 2014-11-24 15:45 ` rth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu.org @ 2014-11-24 15:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64021

--- Comment #8 from Richard Henderson <rth at gcc dot gnu.org> ---
(In reply to Ian Lance Taylor from comment #7)
> I note that a zero-sized array is converted to an empty struct in go-ffi.c. 
> I wonder how libffi handles that today.

It doesn't.  There will be an assertion error.

I'll look at changing libffi to handle empty structures then.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-11-24 15:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-22  8:51 [Bug go/64021] New: Empty struct vs libffi rth at gcc dot gnu.org
2014-11-22  8:55 ` [Bug go/64021] " rth at gcc dot gnu.org
2014-11-22 13:09 ` hjl.tools at gmail dot com
2014-11-22 21:56 ` pinskia at gcc dot gnu.org
2014-11-24  7:48 ` rth at gcc dot gnu.org
2014-11-24  9:16 ` jakub at gcc dot gnu.org
2014-11-24  9:58 ` rth at gcc dot gnu.org
2014-11-24 15:40 ` ian at airs dot com
2014-11-24 15:45 ` rth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).