Bug 10094 - use of FPU_SETCW or FPU_GETCW causes illegal instruction on armel
Summary: use of FPU_SETCW or FPU_GETCW causes illegal instruction on armel
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: ports (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Roland McGrath
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-23 21:44 UTC by Aurelien Jarno
Modified: 2014-07-01 20:37 UTC (History)
1 user (show)

See Also:
Host: armv5tejl-unknown-linux-gnueabi
Target: armv5tejl-unknown-linux-gnueabi
Build: armv5tejl-unknown-linux-gnueabi
Last reconfirmed:
fweimer: security-


Attachments
Patch (480 bytes, patch)
2009-04-24 09:43 UTC, Aurelien Jarno
Details | Diff
v2 of the patch (499 bytes, patch)
2009-04-25 08:19 UTC, Aurelien Jarno
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Aurelien Jarno 2009-04-23 21:44:59 UTC
/usr/include/fpu_control.h on ARM EABI defines FPU_[SG]ETCW as VFP
coprocessor instructions, whereas armel is soft-float.

#define _FPU_GETCW(cw) \
  __asm__ __volatile__ ("mrc p10, 7, %0, cr1, cr0, 0" : "=r" (cw))
/* This is fmxr fpscr, %0.  */
#define _FPU_SETCW(cw) \
  __asm__ __volatile__ ("mcr p10, 7, %0, cr1, cr0, 0" : : "r" (cw))

This causes an illegal instruction trap on hardware that does not have a VFP 
unit.
Comment 1 jsm-csl@polyomino.org.uk 2009-04-23 22:23:56 UTC
Subject: Re:  New: use of FPU_SETCW or FPU_GETCW causes
 illegal instruction on armel

On Thu, 23 Apr 2009, aurelien at aurel32 dot net wrote:

> /usr/include/fpu_control.h on ARM EABI defines FPU_[SG]ETCW as VFP
> coprocessor instructions, whereas armel is soft-float.
> 
> #define _FPU_GETCW(cw) \
>   __asm__ __volatile__ ("mrc p10, 7, %0, cr1, cr0, 0" : "=r" (cw))
> /* This is fmxr fpscr, %0.  */
> #define _FPU_SETCW(cw) \
>   __asm__ __volatile__ ("mcr p10, 7, %0, cr1, cr0, 0" : : "r" (cw))
> 
> This causes an illegal instruction trap on hardware that does not have a VFP 
> unit.

I'm not convinced this is a bug; these macros are inherently nonportable 
and should only be used by code that knows it is being built for a 
particular FPU and knows about how to use it.  Normal code should use 
<fenv.h> instead.  That said, making the contents compile-time conditional 
like the MIPS version would be reasonable; I don't think it can sensibly 
be made run-time conditional.

Comment 2 Aurelien Jarno 2009-04-24 09:43:36 UTC
Created attachment 3907 [details]
Patch
Comment 3 Aurelien Jarno 2009-04-24 09:44:18 UTC
> That said, making the contents compile-time conditional 
> like the MIPS version would be reasonable; I don't think it can sensibly 
> be made run-time conditional.

I agree. The patch I just attached, inspired by the mips version should to 
the trick.
Comment 4 jsm-csl@polyomino.org.uk 2009-04-24 11:21:15 UTC
Subject: Re:  use of FPU_SETCW or FPU_GETCW causes illegal
 instruction on armel

On Fri, 24 Apr 2009, aurelien at aurel32 dot net wrote:

> ------- Additional Comments From aurelien at aurel32 dot net  2009-04-24 09:44 -------
> > That said, making the contents compile-time conditional 
> > like the MIPS version would be reasonable; I don't think it can sensibly 
> > be made run-time conditional.
> 
> I agree. The patch I just attached, inspired by the mips version should to 
> the trick.

I think you need to condition on _LIBC not being defined as well, or 
you'll break the runtime VFP detection in the fenv.h functions (which use 
fpu_control.h).  I'd be surprised if glibc even built for soft-float with 
that patch applied, since fesetenv.c uses _FPU_IEEE which the patch would 
make undefined in the soft-float case.

Comment 5 Aurelien Jarno 2009-04-24 19:13:23 UTC
I admit I hadn't made a build test, it takes long on ARM. I have just
started one, I'll come with the final patch when it is built.
Comment 6 Aurelien Jarno 2009-04-25 08:19:28 UTC
Created attachment 3908 [details]
v2 of the patch
Comment 7 Aurelien Jarno 2009-04-25 08:20:44 UTC
I have just added a new version of the patch, with the change you suggested. 
This version has been compile tested.
Comment 8 Joseph Myers 2009-04-25 15:25:10 UTC
Thanks, I have committed this patch.  Note that the path in your
ChangeLog entry was wrong.