This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libfortran/66458] Loading libgfortran.so changes the FPU exception flags


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]