This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgo patch committed: Change handling of empty structs/arrays for libffi


The recent libffi upgrade caused one of the 32-bit x86 libgo tests to
break.  The problem case is a function that returns an empty struct--a
struct with no fields.  The libffi library does not recognize the
existence of empty structs, presumably since they can't happen in C.
To work around this, the Go interface to the libffi library changes an
empty struct to void.  This normally works fine, but with the new
libffi upgrade it fails for a function that returns an empty struct.
On x86 a function that returns a struct is expected to pop the hidden
pointer when it returns.  So when we convert an empty struct to void,
libffi is calling a function that pops the hidden pointer but does not
expect that to happen.

In the older version of libffi, this didn't matter, because the libffi
code for 32-bit x86 used a frame pointer, so the fact that the stack
pointer was wonky when the function returned was ignored as the stack
pointer was immediately replaced by the saved frame pointer.  In the
newer version of libffi, the 32-bit x86 code is more efficient and
does not use a frame pointer, and therefore it matters whether libffi
expects the function to pop the hidden pointer or not.

This patch changes libgo to convert an empty to a struct with a single
field of type void.  This seems to be enough to get the test cases
working again.

Of course the real fix would be to change libffi to handle empty
types, but as libffi uses size == 0 as a marker for an uninitialized
type, that would be a non-trivial change.

Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Attachment: foo.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]