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.