1 /* Handling of compile-time options that influence the library.
2 Copyright (C) 2005, 2007, 2009, 2010, 2011, 2012
3 Free Software Foundation, Inc.
5 This file is part of the GNU Fortran runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #include "libgfortran.h"
30 /* Useful compile-time options will be stored in here. */
31 compile_options_t compile_options;
34 volatile sig_atomic_t fatal_error_in_progress = 0;
37 /* Helper function for backtrace_handler to write information about the
38 received signal to stderr before actually giving the backtrace. */
40 show_signal (int signum)
42 const char * name = NULL, * desc = NULL;
49 desc = "Terminal quit signal";
53 /* The following 4 signals are defined by C89. */
56 desc = "Illegal instruction";
61 desc = "Process abort signal";
66 desc = "Floating-point exception - erroneous arithmetic operation";
71 desc = "Segmentation fault - invalid memory reference";
77 desc = "Access to an undefined portion of a memory object";
84 desc = "Bad system call";
91 desc = "Trace/breakpoint trap";
98 desc = "CPU time limit exceeded";
105 desc = "File size limit exceeded";
111 st_printf ("\nProgram received signal %s: %s.\n", name, desc);
113 st_printf ("\nProgram received signal %d.\n", signum);
117 /* A signal handler to allow us to output a backtrace. */
119 backtrace_handler (int signum)
121 /* Since this handler is established for more than one kind of signal,
122 it might still get invoked recursively by delivery of some other kind
123 of signal. Use a static variable to keep track of that. */
124 if (fatal_error_in_progress)
126 fatal_error_in_progress = 1;
128 show_signal (signum);
131 /* Now reraise the signal. We reactivate the signal's
132 default handling, which is to terminate the process.
133 We could just call exit or abort,
134 but reraising the signal sets the return status
135 from the process correctly. */
136 signal (signum, SIG_DFL);
141 /* Helper function for set_options because we need to access the
142 global variable options which is not seen in set_options. */
144 maybe_find_addr2line (void)
146 if (options.backtrace == -1)
150 /* Set the usual compile-time options. */
151 extern void set_options (int , int []);
152 export_proto(set_options);
155 set_options (int num, int options[])
158 compile_options.warn_std = options[0];
160 compile_options.allow_std = options[1];
162 compile_options.pedantic = options[2];
163 /* options[3] is the removed -fdump-core option. It's place in the
164 options array is retained due to ABI compatibility. Remove when
165 bumping the library ABI. */
167 compile_options.backtrace = options[4];
169 compile_options.sign_zero = options[5];
171 compile_options.bounds_check = options[6];
173 compile_options.range_check = options[7];
175 /* If backtrace is required, we set signal handlers on the POSIX
176 2001 signals with core action. */
177 if (compile_options.backtrace)
180 signal (SIGQUIT, backtrace_handler);
183 /* The following 4 signals are defined by C89. */
184 signal (SIGILL, backtrace_handler);
185 signal (SIGABRT, backtrace_handler);
186 signal (SIGFPE, backtrace_handler);
187 signal (SIGSEGV, backtrace_handler);
190 signal (SIGBUS, backtrace_handler);
194 signal (SIGSYS, backtrace_handler);
198 signal (SIGTRAP, backtrace_handler);
202 signal (SIGXCPU, backtrace_handler);
206 signal (SIGXFSZ, backtrace_handler);
209 maybe_find_addr2line ();
214 /* Default values for the compile-time options. Keep in sync with
215 gcc/fortran/options.c (gfc_init_options). */
217 init_compile_options (void)
219 compile_options.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
220 compile_options.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
221 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
222 | GFC_STD_F2008_OBS | GFC_STD_GNU | GFC_STD_LEGACY;
223 compile_options.pedantic = 0;
224 compile_options.backtrace = 0;
225 compile_options.sign_zero = 1;
226 compile_options.range_check = 1;
229 /* Function called by the front-end to tell us the
230 default for unformatted data conversion. */
232 extern void set_convert (int);
233 export_proto (set_convert);
236 set_convert (int conv)
238 compile_options.convert = conv;
241 extern void set_record_marker (int);
242 export_proto (set_record_marker);
246 set_record_marker (int val)
252 compile_options.record_marker = sizeof (GFC_INTEGER_4);
256 compile_options.record_marker = sizeof (GFC_INTEGER_8);
260 runtime_error ("Invalid value for record marker");
265 extern void set_max_subrecord_length (int);
266 export_proto (set_max_subrecord_length);
268 void set_max_subrecord_length(int val)
270 if (val > GFC_MAX_SUBRECORD_LENGTH || val < 1)
272 runtime_error ("Invalid value for maximum subrecord length");
276 compile_options.max_subrecord_length = val;