From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103806 invoked by alias); 8 Jun 2015 15:16:33 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 103736 invoked by uid 48); 8 Jun 2015 15:16:24 -0000 From: "kargl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libfortran/66458] Loading libgfortran.so changes the FPU exception flags Date: Mon, 08 Jun 2015 15:16:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libfortran X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kargl at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-06/txt/msg00720.txt.bz2 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 > #include #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