OSDN Git Service

PR 48931 Use async-signal-safe execve instead of execvp
[pf3gnuchains/gcc-fork.git] / libgfortran / runtime / compile_options.c
1 /* Handling of compile-time options that influence the library.
2    Copyright (C) 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
3
4 This file is part of the GNU Fortran runtime library (libgfortran).
5
6 Libgfortran is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 Libgfortran is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 <http://www.gnu.org/licenses/>.  */
24
25 #include "libgfortran.h"
26
27 #ifdef HAVE_SIGNAL_H
28 #include <signal.h>
29 #endif
30
31
32 /* Useful compile-time options will be stored in here.  */
33 compile_options_t compile_options;
34
35
36 volatile sig_atomic_t fatal_error_in_progress = 0;
37
38 /* A signal handler to allow us to output a backtrace.  */
39 void
40 backtrace_handler (int signum)
41 {
42   /* Since this handler is established for more than one kind of signal, 
43      it might still get invoked recursively by delivery of some other kind
44      of signal.  Use a static variable to keep track of that. */
45   if (fatal_error_in_progress)
46     raise (signum);
47   fatal_error_in_progress = 1;
48
49   show_backtrace();
50
51   /* Now reraise the signal.  We reactivate the signal's
52      default handling, which is to terminate the process.
53      We could just call exit or abort,
54      but reraising the signal sets the return status
55      from the process correctly. */
56   signal (signum, SIG_DFL);
57   raise (signum);
58 }
59
60
61 /* Helper function for set_options because we need to access the
62    global variable options which is not seen in set_options.  */
63 static void
64 maybe_find_addr2line (void)
65 {
66   if (options.backtrace == -1)
67     find_addr2line ();
68 }
69
70 /* Set the usual compile-time options.  */
71 extern void set_options (int , int []);
72 export_proto(set_options);
73
74 void
75 set_options (int num, int options[])
76 {
77   if (num >= 1)
78     compile_options.warn_std = options[0];
79   if (num >= 2)
80     compile_options.allow_std = options[1];
81   if (num >= 3)
82     compile_options.pedantic = options[2];
83   /* options[3] is the removed -fdump-core option. It's place in the
84      options array is retained due to ABI compatibility. Remove when
85      bumping the library ABI.  */
86   if (num >= 5)
87     compile_options.backtrace = options[4];
88   if (num >= 6)
89     compile_options.sign_zero = options[5];
90   if (num >= 7)
91     compile_options.bounds_check = options[6];
92   if (num >= 8)
93     compile_options.range_check = options[7];
94
95   /* If backtrace is required, we set signal handlers on the POSIX
96      2001 signals with core action.  */
97 #if defined(HAVE_SIGNAL) && (defined(SIGQUIT) || defined(SIGILL) \
98                              || defined(SIGABRT) || defined(SIGFPE) \
99                              || defined(SIGSEGV) || defined(SIGBUS) \
100                              || defined(SIGSYS) || defined(SIGTRAP) \
101                              || defined(SIGXCPU) || defined(SIGXFSZ))
102   if (compile_options.backtrace)
103     {
104 #if defined(SIGQUIT)
105       signal (SIGQUIT, backtrace_handler);
106 #endif
107
108 #if defined(SIGILL)
109       signal (SIGILL, backtrace_handler);
110 #endif
111
112 #if defined(SIGABRT)
113       signal (SIGABRT, backtrace_handler);
114 #endif
115
116 #if defined(SIGFPE)
117       signal (SIGFPE, backtrace_handler);
118 #endif
119
120 #if defined(SIGSEGV)
121       signal (SIGSEGV, backtrace_handler);
122 #endif
123
124 #if defined(SIGBUS)
125       signal (SIGBUS, backtrace_handler);
126 #endif
127
128 #if defined(SIGSYS)
129       signal (SIGSYS, backtrace_handler);
130 #endif
131
132 #if defined(SIGTRAP)
133       signal (SIGTRAP, backtrace_handler);
134 #endif
135
136 #if defined(SIGXCPU)
137       signal (SIGXCPU, backtrace_handler);
138 #endif
139
140 #if defined(SIGXFSZ)
141       signal (SIGXFSZ, backtrace_handler);
142 #endif
143
144       maybe_find_addr2line ();
145     }
146 #endif
147
148 }
149
150
151 /* Default values for the compile-time options.  Keep in sync with
152    gcc/fortran/options.c (gfc_init_options).  */
153 void
154 init_compile_options (void)
155 {
156   compile_options.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
157   compile_options.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
158     | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
159     | GFC_STD_F2008_OBS | GFC_STD_GNU | GFC_STD_LEGACY;
160   compile_options.pedantic = 0;
161   compile_options.backtrace = 0;
162   compile_options.sign_zero = 1;
163   compile_options.range_check = 1;
164 }
165
166 /* Function called by the front-end to tell us the
167    default for unformatted data conversion.  */
168
169 extern void set_convert (int);
170 export_proto (set_convert);
171
172 void
173 set_convert (int conv)
174 {
175   compile_options.convert = conv;
176 }
177
178 extern void set_record_marker (int);
179 export_proto (set_record_marker);
180
181
182 void
183 set_record_marker (int val)
184 {
185
186   switch(val)
187     {
188     case 4:
189       compile_options.record_marker = sizeof (GFC_INTEGER_4);
190       break;
191
192     case 8:
193       compile_options.record_marker = sizeof (GFC_INTEGER_8);
194       break;
195
196     default:
197       runtime_error ("Invalid value for record marker");
198       break;
199     }
200 }
201
202 extern void set_max_subrecord_length (int);
203 export_proto (set_max_subrecord_length);
204
205 void set_max_subrecord_length(int val)
206 {
207   if (val > GFC_MAX_SUBRECORD_LENGTH || val < 1)
208     {
209       runtime_error ("Invalid value for maximum subrecord length");
210       return;
211     }
212
213   compile_options.max_subrecord_length = val;
214 }