public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/16198] New: fegetenv() clears exception mask on x86_64
@ 2013-11-20 22:50 fxcoudert at gcc dot gnu.org
  2013-11-20 23:38 ` [Bug math/16198] " joseph at codesourcery dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2013-11-20 22:50 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16198

            Bug ID: 16198
           Summary: fegetenv() clears exception mask on x86_64
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
          Assignee: unassigned at sourceware dot org
          Reporter: fxcoudert at gcc dot gnu.org

Take the following code:

#include <stdio.h>
#include <fenv.h>

int main (void)
{
  fenv_t e;

  printf ("%d\n", fegetexcept () & FE_INVALID ? 1 : 0);
  feenableexcept (FE_INVALID);
  printf ("%d\n", fegetexcept () & FE_INVALID ? 1 : 0);
  fegetenv (&e);
  printf ("%d\n", fegetexcept () & FE_INVALID ? 1 : 0);
  fesetenv (&e);
  printf ("%d\n", fegetexcept () & FE_INVALID ? 1 : 0);
}


I expect it to output "0 1 1 1", and it does on i386-linux. But on
x86_64-linux, it outputs "0 1 0 1", showing that the call to fegetenv() clears
the exception mask. I don't see this behavior documented, and I don't think
it's allowed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug math/16198] fegetenv() clears exception mask on x86_64
  2013-11-20 22:50 [Bug math/16198] New: fegetenv() clears exception mask on x86_64 fxcoudert at gcc dot gnu.org
@ 2013-11-20 23:38 ` joseph at codesourcery dot com
  2013-11-20 23:41 ` fxcoudert at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: joseph at codesourcery dot com @ 2013-11-20 23:38 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=16198

--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
Presumably fegetenv needs to call fldenv right after fnstenv just like it 
does on x86 (and of course there should be a testcase, which can be 
architecture-independent, added to the testsuite for this bug).

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug math/16198] fegetenv() clears exception mask on x86_64
  2013-11-20 22:50 [Bug math/16198] New: fegetenv() clears exception mask on x86_64 fxcoudert at gcc dot gnu.org
  2013-11-20 23:38 ` [Bug math/16198] " joseph at codesourcery dot com
@ 2013-11-20 23:41 ` fxcoudert at gcc dot gnu.org
  2013-11-21  0:23 ` joseph at codesourcery dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2013-11-20 23:41 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16198

--- Comment #2 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
(In reply to joseph@codesourcery.com from comment #1)
> Presumably fegetenv needs to call fldenv right after fnstenv just like it 
> does on x86 (and of course there should be a testcase, which can be 
> architecture-independent, added to the testsuite for this bug).

I have found code that uses fldcw, right after fnstenv:

  __asm__ __volatile__ ("fnstenv\t%0" : "=m" (*envp));

  /* fnstenv has the side effect of masking all exceptions, so we need
     to restore the control word after that.  */
  __asm__ __volatile__ ("fldcw\t%0" : : "m" (envp->__control_word));


(I've tried to understand why there are so many occurrences of fegetenv, either
in function or macro forms, in x86/i?86/x86_64-specific files in libc, but I
failed utterly. Thanks for having a look at this.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug math/16198] fegetenv() clears exception mask on x86_64
  2013-11-20 22:50 [Bug math/16198] New: fegetenv() clears exception mask on x86_64 fxcoudert at gcc dot gnu.org
  2013-11-20 23:38 ` [Bug math/16198] " joseph at codesourcery dot com
  2013-11-20 23:41 ` fxcoudert at gcc dot gnu.org
@ 2013-11-21  0:23 ` joseph at codesourcery dot com
  2013-11-21  7:18 ` fxcoudert at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: joseph at codesourcery dot com @ 2013-11-21  0:23 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=16198

--- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Wed, 20 Nov 2013, fxcoudert at gcc dot gnu.org wrote:

> I have found code that uses fldcw, right after fnstenv:
> 
>   __asm__ __volatile__ ("fnstenv\t%0" : "=m" (*envp));
> 
>   /* fnstenv has the side effect of masking all exceptions, so we need
>      to restore the control word after that.  */
>   __asm__ __volatile__ ("fldcw\t%0" : : "m" (envp->__control_word));

I don't see that anywhere in glibc.

> (I've tried to understand why there are so many occurrences of fegetenv, either
> in function or macro forms, in x86/i?86/x86_64-specific files in libc, but I
> failed utterly. Thanks for having a look at this.)

Various optimized versions of environment functions are for use by libm 
functions that only need to change one of the x87 and SSE environments, 
not both, or that can optimize by storing and restoring only relevant bits 
of environment in local variables without needing the full user semantics 
of the public <fenv.h> functions.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug math/16198] fegetenv() clears exception mask on x86_64
  2013-11-20 22:50 [Bug math/16198] New: fegetenv() clears exception mask on x86_64 fxcoudert at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2013-11-21  0:23 ` joseph at codesourcery dot com
@ 2013-11-21  7:18 ` fxcoudert at gcc dot gnu.org
  2014-02-06 18:34 ` [Bug math/16198] [x86_64] " jsm28 at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2013-11-21  7:18 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16198

--- Comment #4 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
> I don't see that anywhere in glibc.

Sorry if that was misleading: it's not in glibc, it's in one of my group's
codes (that implements its own fenv.h-like facilities).

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug math/16198] [x86_64] fegetenv() clears exception mask on x86_64
  2013-11-20 22:50 [Bug math/16198] New: fegetenv() clears exception mask on x86_64 fxcoudert at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2013-11-21  7:18 ` fxcoudert at gcc dot gnu.org
@ 2014-02-06 18:34 ` jsm28 at gcc dot gnu.org
  2014-03-26 19:00 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2014-02-06 18:34 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16198

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
               Host|                            |x86_64-*-*
            Summary|fegetenv() clears exception |[x86_64] fegetenv() clears
                   |mask on x86_64              |exception mask on x86_64

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug math/16198] [x86_64] fegetenv() clears exception mask on x86_64
  2013-11-20 22:50 [Bug math/16198] New: fegetenv() clears exception mask on x86_64 fxcoudert at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2014-03-26 19:00 ` cvs-commit at gcc dot gnu.org
@ 2014-03-26 19:00 ` jsm28 at gcc dot gnu.org
  2014-06-13 11:53 ` fweimer at redhat dot com
  7 siblings, 0 replies; 9+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2014-03-26 19:00 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16198

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Joseph Myers <jsm28 at gcc dot gnu.org> ---
Fixed for 2.20.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug math/16198] [x86_64] fegetenv() clears exception mask on x86_64
  2013-11-20 22:50 [Bug math/16198] New: fegetenv() clears exception mask on x86_64 fxcoudert at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-02-06 18:34 ` [Bug math/16198] [x86_64] " jsm28 at gcc dot gnu.org
@ 2014-03-26 19:00 ` cvs-commit at gcc dot gnu.org
  2014-03-26 19:00 ` jsm28 at gcc dot gnu.org
  2014-06-13 11:53 ` fweimer at redhat dot com
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2014-03-26 19:00 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16198

--- Comment #5 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  9be36fb8cb5bcdab5bbbc7a36388dc9a3d1cc397 (commit)
      from  60a2f3c166cebf56048d00cee47b9ed1969844d6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9be36fb8cb5bcdab5bbbc7a36388dc9a3d1cc397

commit 9be36fb8cb5bcdab5bbbc7a36388dc9a3d1cc397
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Wed Mar 26 18:59:08 2014 +0000

    Make x86_64 fegetenv preserve exception mask (bug 16198).

    Bug 16198 is x86_64 fegetenv wrongly masking exceptions for which
    traps are enabled, because that's a side-effect of the fnstenv
    instruction.  This patch fixes it to use fldenv immediately after
    fnstenv, like the i386 version.  Tested x86_64 and x86.

        [BZ #16198]
        * sysdeps/x86_64/fpu/fegetenv.c (fegetenv): Use fldenv after
        fnstenv.
        * math/test-fenv-preserve.c: New file.
        * math/Makefile (tests): Add test-fenv-preserve.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                     |    8 +++++
 NEWS                                          |    8 +++---
 math/Makefile                                 |    2 +-
 nptl/tst-spin1.c => math/test-fenv-preserve.c |   35 +++++++++++-------------
 sysdeps/x86_64/fpu/fegetenv.c                 |    3 ++
 5 files changed, 32 insertions(+), 24 deletions(-)
 copy nptl/tst-spin1.c => math/test-fenv-preserve.c (62%)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug math/16198] [x86_64] fegetenv() clears exception mask on x86_64
  2013-11-20 22:50 [Bug math/16198] New: fegetenv() clears exception mask on x86_64 fxcoudert at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2014-03-26 19:00 ` jsm28 at gcc dot gnu.org
@ 2014-06-13 11:53 ` fweimer at redhat dot com
  7 siblings, 0 replies; 9+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13 11:53 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16198

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

end of thread, other threads:[~2014-06-13 11:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-20 22:50 [Bug math/16198] New: fegetenv() clears exception mask on x86_64 fxcoudert at gcc dot gnu.org
2013-11-20 23:38 ` [Bug math/16198] " joseph at codesourcery dot com
2013-11-20 23:41 ` fxcoudert at gcc dot gnu.org
2013-11-21  0:23 ` joseph at codesourcery dot com
2013-11-21  7:18 ` fxcoudert at gcc dot gnu.org
2014-02-06 18:34 ` [Bug math/16198] [x86_64] " jsm28 at gcc dot gnu.org
2014-03-26 19:00 ` cvs-commit at gcc dot gnu.org
2014-03-26 19:00 ` jsm28 at gcc dot gnu.org
2014-06-13 11:53 ` fweimer at redhat dot com

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).