public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/66458] New: Loading libgfortran.so changes the FPU exception flags
@ 2015-06-08 9:54 jan at epgmod dot phys.tue.nl
2015-06-08 10:02 ` [Bug libfortran/66458] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: jan at epgmod dot phys.tue.nl @ 2015-06-08 9:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66458
Bug ID: 66458
Summary: Loading libgfortran.so changes the FPU exception flags
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libfortran
Assignee: unassigned at gcc dot gnu.org
Reporter: jan at epgmod dot phys.tue.nl
Target Milestone: ---
It appears that the mere act of loading libgfortran.so changes the FPU
exception mask. It looks as if the library contains initialization code that I
would have expected to appear in the program's start-up code. (Indeed it
appears to do so in line 266 of libgfortran/runtime/main.c.)
The problem can be reproduced by compiling the following C program:
// fpuflags
#include <fenv.h>
#include <dlfcn.h>
int main(int argc, char* argv[])
{
volatile double d=0;
feenableexcept(FE_ALL_EXCEPT);
if (argc==2)
{
dlopen(argv[1],RTLD_NOW);
}
// I expect the expression 1/d to generate an FPU exception:
return 1/d;
}
> gcc fpuflags.c -ldl -lm
> ./a.out
Floating point exception
> ./a.out /usr/lib64/libstdc++.so.6
Floating point exception
> ./a.out /usr/lib64/gcc/x86_64-suse-linux/4.8/libgfortran.so
> #nothing happens
After merely loading libgfortan.so, no FPU exceptions are generated anymore.
Loading libstdc++.so does not result in such problem.
This is a problem in my numerical application where libgfortran.so is loaded as
a depency of a plugin library that is loaded at runtime.
At first sight, this problem may be similar to that in PR20788.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libfortran/66458] Loading libgfortran.so changes the FPU exception flags
2015-06-08 9:54 [Bug libfortran/66458] New: Loading libgfortran.so changes the FPU exception flags jan at epgmod dot phys.tue.nl
@ 2015-06-08 10:02 ` pinskia at gcc dot gnu.org
2015-06-08 10:06 ` jan at epgmod dot phys.tue.nl
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-06-08 10:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66458
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is done on purpose.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libfortran/66458] Loading libgfortran.so changes the FPU exception flags
2015-06-08 9:54 [Bug libfortran/66458] New: Loading libgfortran.so changes the FPU exception flags jan at epgmod dot phys.tue.nl
2015-06-08 10:02 ` [Bug libfortran/66458] " pinskia at gcc dot gnu.org
@ 2015-06-08 10:06 ` jan at epgmod dot phys.tue.nl
2015-06-08 15:16 ` kargl at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jan at epgmod dot phys.tue.nl @ 2015-06-08 10:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66458
Jan van Dijk <jan at epgmod dot phys.tue.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |x86_64-unknown-linux-gnu
Host| |x86_64-unknown-linux-gnu
Build| |x86_64-unknown-linux-gnu
--- Comment #2 from Jan van Dijk <jan at epgmod dot phys.tue.nl> ---
Could you elaborate on the rationale? I this behaviour is
implementation-defined, this may need to be marked a documentation issue
(assuming that I did not miss existing docs about the subject).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libfortran/66458] Loading libgfortran.so changes the FPU exception flags
2015-06-08 9:54 [Bug libfortran/66458] New: Loading libgfortran.so changes the FPU exception flags jan at epgmod dot phys.tue.nl
2015-06-08 10:02 ` [Bug libfortran/66458] " pinskia at gcc dot gnu.org
2015-06-08 10:06 ` jan at epgmod dot phys.tue.nl
@ 2015-06-08 15:16 ` kargl at gcc dot gnu.org
2015-07-05 12:13 ` fxcoudert at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: kargl at gcc dot gnu.org @ 2015-06-08 15:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66458
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
--- Comment #3 from kargl at gcc dot gnu.org ---
(In reply to Jan van Dijk from comment #0)
> It appears that the mere act of loading libgfortran.so changes the FPU
> exception mask. It looks as if the library contains initialization code that
> I would have expected to appear in the program's start-up code. (Indeed it
> appears to do so in line 266 of libgfortran/runtime/main.c.)
>
> The problem can be reproduced by compiling the following C program:
>
> // fpuflags
> #include <fenv.h>
> #include <dlfcn.h>
#pragma STDC FENV_ACCESS ON
> int main(int argc, char* argv[])
> {
> volatile double d=0;
fenv_t fpu;
> feenableexcept(FE_ALL_EXCEPT);
> if (argc==2)
> {
fegetenv(&fpu);
> dlopen(argv[1],RTLD_NOW);
fesetenv(&fpu);
> }
> // I expect the expression 1/d to generate an FPU exception:
> return 1/d;
> }
>
> > gcc fpuflags.c -ldl -lm
> > ./a.out
> Floating point exception
> > ./a.out /usr/lib64/libstdc++.so.6
> Floating point exception
> > ./a.out /usr/lib64/gcc/x86_64-suse-linux/4.8/libgfortran.so
> > #nothing happens
>
> After merely loading libgfortan.so, no FPU exceptions are generated anymore.
> Loading libstdc++.so does not result in such problem.
>
> This is a problem in my numerical application where libgfortran.so is loaded
> as a depency of a plugin library that is loaded at runtime.
You're loading a dynamic library that has a constructor that is
executed to set up the library's internal state. If you're loading
libraries and you want a specific FPU state, then you'll need to
save and reset the state.
--
steve
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libfortran/66458] Loading libgfortran.so changes the FPU exception flags
2015-06-08 9:54 [Bug libfortran/66458] New: Loading libgfortran.so changes the FPU exception flags jan at epgmod dot phys.tue.nl
` (2 preceding siblings ...)
2015-06-08 15:16 ` kargl at gcc dot gnu.org
@ 2015-07-05 12:13 ` fxcoudert at gcc dot gnu.org
2015-08-06 18:16 ` fxcoudert at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2015-07-05 12:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66458
Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2015-07-05
CC| |fxcoudert at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |fxcoudert at gcc dot gnu.org
Target Milestone|--- |6.0
Ever confirmed|0 |1
--- Comment #4 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
(In reply to kargl from comment #3)
> You're loading a dynamic library that has a constructor that is
> executed to set up the library's internal state. If you're loading
> libraries and you want a specific FPU state, then you'll need to
> save and reset the state.
Yet, if not FPE-specific option was passed, there is no good reason for us to
mess with the FPU state.
Anyway, currently something's a bit suboptimal here. For example, if a program
is compiled with -ffpe-trap, we're gonna call set_fpu() twice: once from the
constructor, then again from the main program. That doesn't seem right.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libfortran/66458] Loading libgfortran.so changes the FPU exception flags
2015-06-08 9:54 [Bug libfortran/66458] New: Loading libgfortran.so changes the FPU exception flags jan at epgmod dot phys.tue.nl
` (3 preceding siblings ...)
2015-07-05 12:13 ` fxcoudert at gcc dot gnu.org
@ 2015-08-06 18:16 ` fxcoudert at gcc dot gnu.org
2015-08-07 16:24 ` fxcoudert at gcc dot gnu.org
2015-08-08 7:22 ` fxcoudert at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2015-08-06 18:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66458
--- Comment #5 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
The comment in the front-end confirms the original intent, which is that FPU
shouldn't be messed with if the user didn't explicitly request it:
/* If -ffpe-trap option was provided, add a call to set_fpe so that
the library will raise a FPE when needed. */
The patch below makes libgfortran behave in the same way:
Index: runtime/main.c
===================================================================
--- runtime/main.c (revision 226632)
+++ runtime/main.c (working copy)
@@ -263,7 +263,11 @@ init (void)
init_variables ();
init_units ();
- set_fpu ();
+
+ /* If (and only if) the user asked for it, set up the FPU state. */
+ if (options.fpe != 0)
+ set_fpu ();
+
init_compile_options ();
#ifdef DEBUG
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libfortran/66458] Loading libgfortran.so changes the FPU exception flags
2015-06-08 9:54 [Bug libfortran/66458] New: Loading libgfortran.so changes the FPU exception flags jan at epgmod dot phys.tue.nl
` (4 preceding siblings ...)
2015-08-06 18:16 ` fxcoudert at gcc dot gnu.org
@ 2015-08-07 16:24 ` fxcoudert at gcc dot gnu.org
2015-08-08 7:22 ` fxcoudert at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2015-08-07 16:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66458
--- Comment #6 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
Author: fxcoudert
Date: Fri Aug 7 16:23:53 2015
New Revision: 226725
URL: https://gcc.gnu.org/viewcvs?rev=226725&root=gcc&view=rev
Log:
PR libfortran/66458
* runtime/main.c (init): Only call set_fpu() if requested by user.
Modified:
trunk/libgfortran/ChangeLog
trunk/libgfortran/runtime/main.c
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libfortran/66458] Loading libgfortran.so changes the FPU exception flags
2015-06-08 9:54 [Bug libfortran/66458] New: Loading libgfortran.so changes the FPU exception flags jan at epgmod dot phys.tue.nl
` (5 preceding siblings ...)
2015-08-07 16:24 ` fxcoudert at gcc dot gnu.org
@ 2015-08-08 7:22 ` fxcoudert at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2015-08-08 7:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66458
Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
Fixed on trunk.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-08-08 7:22 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-08 9:54 [Bug libfortran/66458] New: Loading libgfortran.so changes the FPU exception flags jan at epgmod dot phys.tue.nl
2015-06-08 10:02 ` [Bug libfortran/66458] " pinskia at gcc dot gnu.org
2015-06-08 10:06 ` jan at epgmod dot phys.tue.nl
2015-06-08 15:16 ` kargl at gcc dot gnu.org
2015-07-05 12:13 ` fxcoudert at gcc dot gnu.org
2015-08-06 18:16 ` fxcoudert at gcc dot gnu.org
2015-08-07 16:24 ` fxcoudert at gcc dot gnu.org
2015-08-08 7:22 ` fxcoudert at gcc dot gnu.org
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).