Hi, this simple bug led me to rethink normal and error termination and thus the patch changes some other related stuff as well. So the original problem was that when -fdump-core was enabled, STOP with a numeric stop code made the program terminate with an incorrect return code, since the core dump generation is done by the program killing itself. The real problem is that previously, we were mixing up normal termination with a non-zero exit status (e.g. file not found) with aborting the program (e.g. some serious error detected). The attached patch reworks this so that normal termination (with a zero or non-zero exit code) is done with exit(), and no backtrace or core dump is generated in any circumstance. For serious errors, a backtrace and core dump are generated. Since OS'es contain widely used ways to control core dump generation (e.g. ulimit -c), and we no longer "frivolously" try to generate a core dump just because we're exiting with non-zero status, there is IMHO no longer any need for a gfortran-specific option; if we hit a serious error, we call abort() and a core dump is always generated if the user environment is so configured (and the system supports core dumps). Also, since backtraces and core dumps are now only generated for serious errors (not e.g. file not found). -fbacktrace is enabled by default. Regtested on x86_64-unknown-linux-gnu, Ok for trunk? frontend ChangeLog: 2011-05-07 Janne Blomqvist PR libfortran/48915 * gfortran.h (gfc_option_t): Remove flag_dump_core. * gfortran.texi (GFORTRAN_ERROR_DUMPCORE): Remove section. (GFORTRAN_ERROR_BACKTRACE): Document that it's enabled by default. * intrinsic.texi (ABORT): Remove explanation of -fdump-core. * invoke.texi: Remove -fdump-core, document that -fbacktrace is enabled by default. * lang.opt: Remove -fdump-core. * options.c (gfc_init_options): Make backtrace default to enabled, remove dump_core. (gfc_handle_option): Remove OPT_fdump-core. * trans-decl.c: Pass a 0 to preserve ABI. library ChangeLog: 2011-05-07 Janne Blomqvist PR libfortran/48915 * intrinsics/abort.c (abort): Call sys_abort(). * io/unix.c (st_vprintf): Call sys_abort(). * libgfortran.h (options_t): Remove dump_core member. (handler): Rename to backtrace_handler. (compile_options_t): Remove dump_core member. (sys_exit): Remove. (sys_abort): New function. * runtime/backtrace.c (show_backtrace): Print a message if backtrace is not available on target. * runtime/compile_options.c (backtrace_handler): New implementation based on example in Glibc manual. (set_options): Remove dump_core handling, make signal handler handle more signals. (init_compile_options): Remove dump_core. * runtime/environ.c (variable_table[]): Remove GFORTRAN_ERROR_DUMPCORE element. (show_variables): Update name, call exit(). * runtime/error.c (sys_exit): Remove. (sys_abort): New function. (recursion_check): Call sys_abort(). (os_error): Call exit(). (runtime_error): Likewise. (runtime_error_at): Likewise. (internal_error): Likewise. (generate_error): Likewise. (notify_std): Likewise. * runtime/stop.c (stop_numeric): Call exit(). (stop_numeric_f08): Likewise. (stop_string): Likewise. (error_stop_string): Call sys_abort(). (error_stop_numeric): Print backtrace, exit with provided code. -- Janne Blomqvist