Bug 31937 - libffi doesn't support ppc without FPU
Summary: libffi doesn't support ppc without FPU
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libffi (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Andreas Tobler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-15 16:39 UTC by Patrick Olinet
Modified: 2007-12-01 21:02 UTC (History)
3 users (show)

See Also:
Host: powerpc-405-linux-gnu
Target: powerpc-405-linux-gnu
Build: i686-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2007-11-21 22:14:29


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Olinet 2007-05-15 16:39:32 UTC
PowerPC CPU without FPU (such as the PPC405EP) doesn't pass the libffi testsuite. Most of the tests crash with an "illegal instruction" error message, even those that don't manipulate double/float. For instance, it crashes with the "cls_uint" test.

After investigating, I think the problem comes from the ppc assembly code from the libffi/src/powerpc directory that includes FPU instructions not supported by those CPU. In particular, the ppc_closure.S file contains "stfd" FPU instructions that are supposed to save FPU registers and are always executed, even if no fpu operation is to be performed.

If you don't need fpu support (as I do), a quick and dirty hack is to comment out those "stfd" instructions from the ppc_closure.S file.

I guess the right way to fix it would be to use the soft-float system when no FPU is present. But that's something I don't know how to do...

I've tried with gcc 3.4.3 and gcc 4.1.0, but I guess all versions are affected.
Comment 1 Patrick Olinet 2007-05-16 14:23:06 UTC
Notice that this bug prevents loading and running java bytecode from a native code binary compiled with gcj. I guess it relies on libffi to call the methods of the bytecode.

This java problem is what I've encountered first before investigating and finding out that it all comes from libfii.
Comment 2 Andreas Tobler 2007-11-02 22:01:59 UTC
Working on support for.
Comment 3 Andreas Tobler 2007-11-06 22:55:19 UTC
Patch is posted here:
http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00286.html
Comment 4 Andreas Tobler 2007-11-08 19:34:01 UTC
The mentioned patch does not work properly, it only handles soft-float when no-long-double-128 is used.
Working on a better one which should support both, 'double == long double' and long double == 128.

Comment 5 Andreas Tobler 2007-11-21 22:13:40 UTC
New patch here: http://gcc.gnu.org/ml/gcc-patches/2007-11/msg01128.html
Comment 6 Andreas Tobler 2007-11-21 22:14:29 UTC
Buh, reassigng.
Comment 7 Andreas Tobler 2007-12-01 21:00:17 UTC
Subject: Bug 31937

Author: andreast
Date: Sat Dec  1 21:00:04 2007
New Revision: 130559

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130559
Log:
2007-12-01  Andreas Tobler  <a.tobler@schweiz.org>

	PR libffi/31937
	* src/powerpc/ffitarget.h: Introduce new ABI FFI_LINUX_SOFT_FLOAT.
	Add local FFI_TYPE_UINT128 to handle soft-float long-double-128.
	* src/powerpc/ffi.c: Distinguish between __NO_FPRS__ and not and
	set the NUM_FPR_ARG_REGISTERS according to.
	Add support for potential soft-float support under hard-float
	architecture.
	(ffi_prep_args_SYSV): Set NUM_FPR_ARG_REGISTERS to 0 in case of
	FFI_LINUX_SOFT_FLOAT, handle float, doubles and long-doubles according
	to the FFI_LINUX_SOFT_FLOAT ABI.
	(ffi_prep_cif_machdep): Likewise.
	(ffi_closure_helper_SYSV): Likewise.
	* src/powerpc/ppc_closure.S: Make sure not to store float/double
	on archs where __NO_FPRS__ is true.
	Add FFI_TYPE_UINT128 support.
	* src/powerpc/sysv.S: Add support for soft-float long-double-128.
	Adjust copyright notice.

Modified:
    trunk/libffi/ChangeLog
    trunk/libffi/src/powerpc/ffi.c
    trunk/libffi/src/powerpc/ffitarget.h
    trunk/libffi/src/powerpc/ppc_closure.S
    trunk/libffi/src/powerpc/sysv.S

Comment 8 Andreas Tobler 2007-12-01 21:02:33 UTC
Implemented. Hopefully it will be of some use to others :)