Bug 51835 - ARM EABI violation when passing arguments to helper floating functions like __aeabi_d2iz
Summary: ARM EABI violation when passing arguments to helper floating functions like _...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.5.4
Assignee: Not yet assigned to anyone
URL:
Keywords: ABI, wrong-code
Depends on:
Blocks:
 
Reported: 2012-01-12 08:00 UTC by bin.cheng
Modified: 2012-02-23 02:33 UTC (History)
2 users (show)

See Also:
Host:
Target: arm-none-eabi
Build:
Known to work:
Known to fail: 4.5.3, 4.6.0, 4.6.1, 4.6.2, 4.7.0
Last reconfirmed: 2012-01-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bin.cheng 2012-01-12 08:00:57 UTC
For following program
int func(float f)
{
  double d = (double)f;
  return (int)d;
}
compile it with following command:
$ arm-none-eabi-gcc -O2 -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -S test.c -o test.S

the generated assembly code is:
-----------------------------------------------
fun:
	@ args = 0, pretend = 0, frame = 0
	@ frame_needed = 0, uses_anonymous_args = 0
	push	{r3, lr}
	fmrs	r0, s0
	bl	__aeabi_f2d
	fmdrr	d0, r0, r1
	bl	__aeabi_d2iz
	pop	{r3, pc}
	.size	fun, .-fun

The argument of __aeabi_d2iz is passed in fp register, While ARM RTABI document says that such functions should use the soft-float ABI, even when -mfloat-abi=hard is specified.

The problem at least exists on trunk and 4.6 branch.

I am working a patch and will send it for review later.
Comment 1 Richard Earnshaw 2012-01-16 09:37:33 UTC
Confirmed
Comment 2 Ramana Radhakrishnan 2012-01-19 22:40:51 UTC
This is only applicable to the 4.6 branch and trunk since support for the Cortex M4 wasn't added till 4.6. 

cheers
Ramana
Comment 3 jye2 2012-01-30 16:59:21 UTC
Author: jye2
Date: Mon Jan 30 16:59:14 2012
New Revision: 183733

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183733
Log:
2012-01-30  Bin Cheng  <bin.cheng@arm.com>

	PR target/51835
	* config/arm/arm.c (arm_libcall_uses_aapcs_base): Use correct ABI
	for __aeabi_d2iz/__aeabi_d2uiz with hard-float.

testcases:
	PR target/51835
	* gcc.target/arm/pr51835.c: New testcase.


Added:
    trunk/gcc/testsuite/gcc.target/arm/pr51835.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 jye2 2012-01-30 17:22:08 UTC
Author: jye2
Date: Mon Jan 30 17:22:04 2012
New Revision: 183734

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183734
Log:
2012-01-30  Bin Cheng  <bin.cheng@arm.com>

	PR target/51835
	* config/arm/arm.c (arm_libcall_uses_aapcs_base): Use correct ABI
	for __aeabi_d2iz/__aeabi_d2uiz with hard-float.

testcases:
	PR target/51835
	* gcc.target/arm/pr51835.c: New testcase.


Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.target/arm/pr51835.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/config/arm/arm.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 5 Mikael Pettersson 2012-02-05 14:07:49 UTC
(In reply to comment #2)
> This is only applicable to the 4.6 branch and trunk since support for the
> Cortex M4 wasn't added till 4.6. 
> 
> cheers
> Ramana

Maybe the Cortex M4 wasn't added until 4.6, but the other options are permitted by 4.5 and I can easily get 4.5 to produce wrong-looking code.  With -O2 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -march=armv7-a -marm I see the following code generation difference between 4.5 and 4.6:

@@ -22,8 +22,9 @@
        @ frame_needed = 0, uses_anonymous_args = 0
        stmfd   sp!, {r3, lr}
        bl      __aeabi_f2d
+       fmrrd   r0, r1, d0
        bl      __aeabi_d2iz
        ldmfd   sp!, {r3, pc}
        .size   func, .-func
-       .ident  "GCC: (GNU) 4.5.4 20120126 (prerelease)"
+       .ident  "GCC: (GNU) 4.6.3 20120203 (prerelease)"
        .section        .note.GNU-stack,"",%progbits

Backporting r183734 from 4.6 to 4.5 makes 4.5 generate the same code as 4.6, i.e., with the fmrrd between the two calls.
Comment 6 bin.cheng 2012-02-06 05:51:25 UTC
(In reply to comment #5)
> (In reply to comment #2)
> > This is only applicable to the 4.6 branch and trunk since support for the
> > Cortex M4 wasn't added till 4.6. 
> > 
> > cheers
> > Ramana
> 
> Maybe the Cortex M4 wasn't added until 4.6, but the other options are permitted
> by 4.5 and I can easily get 4.5 to produce wrong-looking code.  With -O2
> -mfloat-abi=hard -mfpu=fpv4-sp-d16 -march=armv7-a -marm I see the following
> code generation difference between 4.5 and 4.6:
> 
> @@ -22,8 +22,9 @@
>         @ frame_needed = 0, uses_anonymous_args = 0
>         stmfd   sp!, {r3, lr}
>         bl      __aeabi_f2d
> +       fmrrd   r0, r1, d0
>         bl      __aeabi_d2iz
>         ldmfd   sp!, {r3, pc}
>         .size   func, .-func
> -       .ident  "GCC: (GNU) 4.5.4 20120126 (prerelease)"
> +       .ident  "GCC: (GNU) 4.6.3 20120203 (prerelease)"
>         .section        .note.GNU-stack,"",%progbits
> 
> Backporting r183734 from 4.6 to 4.5 makes 4.5 generate the same code as 4.6,
> i.e., with the fmrrd between the two calls.

beside this patch, Julian Brown's patch r174803 is necessary too.

For now,
1, arguments for both __aeabi_f2d and __aeabi_d2iz are wrong in 4.5;
2, arguments for __aeabi_f2d is wrong in 4.6
To solve this, have to:
1, backport r183734 and r174803 to 4.5;
2, backport r174803 to 4.6;
Comment 7 bin cheng 2012-02-10 03:14:45 UTC
Author: amker
Date: Fri Feb 10 03:14:40 2012
New Revision: 184082

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184082
Log:
	Backport from mainline.
	2012-01-30  Bin Cheng  <bin.cheng@arm.com>

	PR target/51835
	* config/arm/arm.c (arm_libcall_uses_aapcs_base): Use correct ABI
	for __aeabi_d2iz/__aeabi_d2uiz with hard-float.

	Backport from mainline.
	2012-01-30  Bin Cheng  <bin.cheng@arm.com>

	PR target/51835
	* gcc.target/arm/pr51835.c: New testcase.


Added:
    branches/ARM/embedded-4_6-branch/gcc/testsuite/gcc.target/arm/pr51835.c
Modified:
    branches/ARM/embedded-4_6-branch/gcc/ChangeLog.arm
    branches/ARM/embedded-4_6-branch/gcc/config/arm/arm.c
    branches/ARM/embedded-4_6-branch/gcc/testsuite/ChangeLog.arm
Comment 8 bin cheng 2012-02-14 07:42:47 UTC
Author: amker
Date: Tue Feb 14 07:42:41 2012
New Revision: 184197

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184197
Log:

	Backport from mainline.
	2012-01-30  Bin Cheng  <bin.cheng@arm.com>

	PR target/51835
	* config/arm/arm.c (arm_libcall_uses_aapcs_base): Use correct ABI
	for __aeabi_d2iz/__aeabi_d2uiz with hard-float.

	2011-06-08  Julian Brown  <julian@codesourcery.com>

	* config/arm/arm.c (arm_libcall_uses_aapcs_base): Use correct ABI
	for double-precision helper functions in hard-float mode if only
	single-precision arithmetic is supported in hardware.


Added:
    branches/gcc-4_5-branch/gcc/testsuite/gcc.target/arm/pr51835.c
Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/config/arm/arm.c
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
Comment 9 Ramana Radhakrishnan 2012-02-23 02:33:30 UTC
Fixed I think now on all release branches where affected and trunk.