1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This package obtains parameters from the target runtime version of
35 -- System, to indicate parameters relevant to the target environment.
37 -- Conceptually, these parameters could be obtained using rtsfind, but
38 -- we do not do this for four reasons:
40 -- 1. Compiling System for every compilation wastes time
42 -- 2. This compilation impedes debugging by adding extra compile steps
44 -- 3. There are recursion problems coming from compiling System itself
45 -- or any of its children.
47 -- 4. The binder also needs the parameters, and we do not want to have
48 -- to drag a lot of front end stuff into the binder.
50 -- For all these reasons, we read in the source of System, and then scan
51 -- it at the text level to extract the parameter values.
53 -- Note however, that later on, when the ali file is written, we make sure
54 -- that the System file is at least parsed, so that the checksum is properly
55 -- computed and set in the ali file. This partially negates points 1 and 2
56 -- above although just parsing is quick and does not impact debugging much.
58 -- The parameters acquired by this routine from system.ads fall into four
61 -- 1. Configuration pragmas, that must appear at the start of the file.
62 -- Any such pragmas automatically apply to any unit compiled in the
63 -- presence of this system file. Only a limited set of such pragmas
64 -- may appear as documented in the corresponding section below,
66 -- 2. Target parameters. These are boolean constants that are defined
67 -- in the private part of the package giving fixed information
68 -- about the target architecture, and the capabilities of the
69 -- code generator and run-time library.
71 -- 3. Identification information. This is an optional string constant
72 -- that gives the name of the run-time library configuration. This
73 -- line may be ommitted for a version of system.ads to be used with
74 -- the full Ada 95 run time.
76 -- 4. Other characterisitics of package System. At the current time the
77 -- only item in this category is whether type Address is private.
79 with Rident; use Rident;
80 with Namet; use Namet;
81 with Types; use Types;
85 ---------------------------
86 -- Configuration Pragmas --
87 ---------------------------
89 -- The following switches get set if the corresponding configuration
90 -- pragma is scanned from the source of system.ads. No other pragmas
91 -- are permitted to appear at the start of the system.ads source file.
93 -- If a pragma Discard_Names appears, then Opt.Global_Discard_Names is
94 -- set to True to indicate that all units must be compiled in this mode.
96 -- If a pragma Locking_Policy appears, then Opt.Locking_Policy is set
97 -- to the first character of the policy name, and Opt.Locking_Policy_Sloc
98 -- is set to System_Location.
100 -- If a pragma Normalize_Scalars appears, then Opt.Normalize_Scalars
101 -- is set True, as well as Opt.Init_Or_Norm_Scalars.
103 -- If a pragma Queuing_Policy appears, then Opt.Queuing_Policy is set
104 -- to the first character of the policy name, and Opt.Queuing_Policy_Sloc
105 -- is set to System_Location.
107 -- If a pragma Task_Dispatching_Policy appears, then the flag
108 -- Opt.Task_Dispatching_Policy is set to the first character of the
109 -- policy name, and Opt.Task_Dispatching_Policy_Sloc is set to
112 -- If a pragma Polling (On) appears, then the flag Opt.Polling_Required
115 -- If a pragma Detect_Blocking appears, then the flag Opt.Detect_Blocking
118 -- if a pragma Suppress_Exception_Locations appears, then the flag
119 -- Opt.Exception_Locations_Suppressed is set to True.
121 -- If a pragma Profile with a valid profile argument appears, then
122 -- the appropriate restrictions and policy flags are set.
124 -- The only other pragma allowed is a pragma Restrictions that specifies
125 -- a restriction that will be imposed on all units in the partition. Note
126 -- that in this context, only one restriction can be specified in a single
127 -- pragma, and the pragma must appear on its own on a single source line.
129 -- If package System contains exactly the line "type Address is private;"
130 -- then the flag Opt.Address_Is_Private is set True, otherwise this flag
133 Restrictions_On_Target : Restrictions_Info := No_Restrictions;
134 -- Records restrictions specified by system.ads. Only the Set and Value
135 -- members are modified. The Violated and Count fields are never modified.
136 -- Note that entries can be set either by a pragma Restrictions or by
143 -- This parameter should be regarded as read only by all clients of
144 -- of package. The only way they get modified is by calling the
145 -- Get_Target_Parameters routine which reads the values from a provided
146 -- text buffer containing the source of the system package.
148 -- The corresponding string constant is placed immediately at the start
149 -- of the private part of system.ads if is present, e.g. in the form:
151 -- Run_Time_Name : constant String := "Zero Footprint Run Time";
153 -- the corresponding messages will look something like
155 -- xxx not supported (Zero Footprint Run Time)
157 Run_Time_Name_On_Target : Name_Id := No_Name;
158 -- Set to appropriate names table entry Id value if a Run_Time_Name
159 -- string constant is defined in system.ads. This name is used only
160 -- for the configurable run-time case, and is used to parametrize
161 -- messages that complain about non-supported run-time features.
162 -- The name should contain only letters A-Z, digits 1-9, spaces,
165 --------------------------
166 -- Executable Extension --
167 --------------------------
169 Executable_Extension_On_Target : Name_Id := No_Name;
170 -- Executable extension on the target. This name is useful for setting
171 -- the executable extension in a dynamic way, e.g. depending on the
172 -- run time used, rather than using a configure-time macro as done by
173 -- Get_Target_Executable_Suffix. If not set (No_Name), instead use
174 -- System.OS_Lib.Get_Target_Executable_Suffix.
176 -----------------------
177 -- Target Parameters --
178 -----------------------
180 -- The following parameters correspond to the variables defined in the
181 -- private part of System (without the terminating _On_Target). Note
182 -- that it is required that all parameters defined here be specified
183 -- in the target specific version of system.ads (there are no defaults).
185 -- All these parameters should be regarded as read only by all clients
186 -- of the package. The only way they get modified is by calling the
187 -- Get_Target_Parameters routine which reads the values from a provided
188 -- text buffer containing the source of the system package.
190 -- The default values here are used if no value is found in system.ads.
191 -- This should normally happen if the special version of system.ads used
192 -- by the compiler itself is in use or if the value is only relevant to
193 -- a particular target (e.g. OpenVMS, AAMP). The default values are
194 -- suitable for use in normal environments. This approach allows the
195 -- possibility of new versions of the compiler (possibly with new system
196 -- parameters added) being used to compile older versions of the compiler
197 -- sources, as well as avoiding duplicating values in all system-*.ads
198 -- files for flags that are used on a few platforms only.
200 ----------------------------
201 -- Special Target Control --
202 ----------------------------
204 -- The great majority of GNAT ports are based on GCC. The switches in
205 -- This section indicate the use of some non-standard target back end
206 -- or other special targetting requirements.
208 AAMP_On_Target : Boolean := False;
209 -- Set to True if target is AAMP
211 OpenVMS_On_Target : Boolean := False;
212 -- Set to True if target is OpenVMS
214 type Virtual_Machine_Kind is (No_VM, JVM_Target, CLI_Target);
215 VM_Target : Virtual_Machine_Kind := No_VM;
216 -- Kind of virtual machine targetted
218 -------------------------------
219 -- Backend Arithmetic Checks --
220 -------------------------------
222 -- Divide and overflow checks are either done in the front end or
223 -- back end. The front end will generate checks when required unless
224 -- the corresponding parameter here is set to indicate that the back
225 -- end will generate the required checks (or that the checks are
226 -- automatically performed by the hardware in an appropriate form).
228 Backend_Divide_Checks_On_Target : Boolean := False;
229 -- Set True if the back end generates divide checks, or if the hardware
230 -- checks automatically. Set False if the front end must generate the
231 -- required tests using explicit expanded code.
233 Backend_Overflow_Checks_On_Target : Boolean := False;
234 -- Set True if the back end generates arithmetic overflow checks, or if
235 -- the hardware checks automatically. Set False if the front end must
236 -- generate the required tests using explicit expanded code.
238 -----------------------------------
239 -- Control of Exception Handling --
240 -----------------------------------
242 -- GNAT implements three methods of implementing exceptions:
244 -- Front-End Longjmp/Setjmp Exceptions
246 -- This approach uses longjmp/setjmp to handle exceptions. It
247 -- uses less storage, and can often propagate exceptions faster,
248 -- at the expense of (sometimes considerable) overhead in setting
249 -- up an exception handler. This approach is available on all
250 -- targets, and is the default where it is the only approach.
252 -- The generation of the setjmp and longjmp calls is handled by
253 -- the front end of the compiler (this includes gigi in the case
254 -- of the standard GCC back end). It does not use any back end
255 -- suport (such as the GCC3 exception handling mechanism). When
256 -- this approach is used, the compiler generates special exception
257 -- handlers for handling cleanups when an exception is raised.
259 -- Front-End Zero Cost Exceptions
261 -- This approach uses separate exception tables. These use extra
262 -- storage, and exception propagation can be quite slow, but there
263 -- is no overhead in setting up an exception handler (it is to this
264 -- latter operation that the phrase zero-cost refers). This approach
265 -- is only available on some targets, and is the default where it is
268 -- The generation of the exception tables is handled by the front
269 -- end of the compiler. It does not use any back end support (such
270 -- as the GCC3 exception handling mechanism). When this approach
271 -- is used, the compiler generates special exception handlers for
272 -- handling cleanups when an exception is raised.
274 -- Back-End Zero Cost Exceptions
276 -- With this approach, the back end handles the generation and
277 -- handling of exceptions. For example, the GCC3 exception handling
278 -- mechanisms are used in this mode. The front end simply generates
279 -- code for explicit exception handlers, and AT END cleanup handlers
280 -- are simply passed unchanged to the backend for generating cleanups
281 -- both in the exceptional and non-exceptional cases.
283 -- As the name implies, this approach generally uses a zero-cost
284 -- mechanism with tables, but the tables are generated by the back
285 -- end. However, since the back-end is entirely responsible for the
286 -- handling of exceptions, another mechanism might be used. In the
287 -- case of GCC3 for instance, it might be the case that the compiler
288 -- is configured for setjmp/longjmp handling, then everything will
289 -- work correctly. However, it is definitely preferred that the
290 -- back end provide zero cost exception handling.
292 -- Controlling the selection of methods
294 -- On most implementations, back-end zero-cost exceptions are used.
295 -- Otherwise, Front-End Longjmp/Setjmp approach is used.
296 -- Note that there is a requirement that all Ada units in a partition
297 -- be compiled with the same exception model.
299 -- Control of Available Methods and Defaults
301 -- The following switches specify whether ZCX is available, and
302 -- whether it is enabled by default.
304 ZCX_By_Default_On_Target : Boolean := False;
305 -- Indicates if zero cost exceptions are active by default. If this
306 -- variable is False, then the only possible exception method is the
307 -- front-end setjmp/longjmp approach, and this is the default. If
308 -- this variable is True, then GCC ZCX is used.
310 GCC_ZCX_Support_On_Target : Boolean := False;
311 -- Indicates that the target supports GCC Exceptions
313 ------------------------------------
314 -- Run-Time Library Configuration --
315 ------------------------------------
317 -- In configurable run-time mode, the system run-time may not support
318 -- the full Ada language. The effect of setting this switch is to let
319 -- the compiler know that it is not surprising (i.e. the system is not
320 -- misconfigured) if run-time library units or entities within units are
321 -- not present in the run-time.
323 Configurable_Run_Time_On_Target : Boolean := False;
324 -- Indicates that the system.ads file is for a configurable run-time
326 -- This has some specific effects as follows
328 -- The binder generates the gnat_argc/argv/envp variables in the
329 -- binder file instead of being imported from the run-time library.
330 -- If Command_Line_Args_On_Target is set to False, then the
331 -- generation of these variables is suppressed completely.
333 -- The binder generates the gnat_exit_status variable in the binder
334 -- file instead of being imported from the run-time library. If
335 -- Exit_Status_Supported_On_Target is set to False, then the
336 -- generation of this variable is suppressed entirely.
338 -- The routine __gnat_break_start is defined within the binder file
339 -- instead of being imported from the run-time library.
341 -- The variable __gnat_exit_status is generated within the binder file
342 -- instead of being imported from the run-time library.
344 Suppress_Standard_Library_On_Target : Boolean := False;
345 -- If this flag is True, then the standard library is not included by
346 -- default in the executable (see unit System.Standard_Library in file
347 -- s-stalib.ads for details of what this includes). This is for example
348 -- set True for the zero foot print case, where these files should not
349 -- be included by default.
351 -- This flag has some other related effects:
353 -- The generation of global variables in the bind file is suppressed,
354 -- with the exception of the priority of the environment task, which
355 -- is needed by the Ravenscar run-time.
357 -- The calls to __gnat_initialize and __gnat_finalize are omitted
359 -- All finalization and initialization (controlled types) is omitted
361 -- The routine __gnat_handler_installed is not imported
363 Preallocated_Stacks_On_Target : Boolean := False;
364 -- If this flag is True, then the expander preallocates all task stacks
365 -- at compile time. If the flag is False, then task stacks are not pre-
366 -- allocated, and task stack allocation is the responsibility of the
367 -- run-time (which typically delegates the task to the underlying
368 -- operating system environment).
370 ---------------------
371 -- Duration Format --
372 ---------------------
374 -- By default, type Duration is a 64-bit fixed-point type with a delta
375 -- and small of 10**(-9) (i.e. it is a count in nanoseconds. This flag
376 -- allows that standard format to be modified.
378 Duration_32_Bits_On_Target : Boolean := False;
379 -- If True, then Duration is represented in 32 bits and the delta and
380 -- small values are set to 20.0*(10**(-3)) (i.e. it is a count in units
381 -- of 20 milliseconds.
383 ------------------------------------
384 -- Back-End Code Generation Flags --
385 ------------------------------------
387 -- These flags indicate possible limitations in what the code generator
388 -- can handle. They will all be True for a full run-time, but one or more
389 -- of these may be false for a configurable run-time, and if a feature is
390 -- used at the source level, and the corresponding flag is false, then an
391 -- error message will be issued saying the feature is not supported.
393 Support_64_Bit_Divides_On_Target : Boolean := True;
394 -- If True, the back end supports 64-bit divide operations. If False, then
395 -- the source program may not contain 64-bit divide operations. This is
396 -- specifically useful in the zero foot-print case, where the issue is
397 -- whether there is a hardware divide instruction for 64-bits so that
398 -- no run-time support is required. It should always be set True if the
399 -- necessary run-time support is present.
401 Support_Aggregates_On_Target : Boolean := True;
402 -- In the general case, the use of aggregates may generate calls
403 -- to run-time routines in the C library, including memset, memcpy,
404 -- memmove, and bcopy. This flag is set to True if these routines
405 -- are available. If any of these routines is not available, then
406 -- this flag is False, and the use of aggregates is not permitted.
408 Support_Composite_Assign_On_Target : Boolean := True;
409 -- The assignment of composite objects other than small records and
410 -- arrays whose size is 64-bits or less and is set by an explicit
411 -- size clause may generate calls to memcpy, memmove, and bcopy.
412 -- If versions of all these routines are available, then this flag
413 -- is set to True. If any of these routines is not available, then
414 -- the flag is set False, and composite assignments are not allowed.
416 Support_Composite_Compare_On_Target : Boolean := True;
417 -- If this flag is True, then the back end supports bit-wise comparison
418 -- of composite objects for equality, either generating inline code or
419 -- calling appropriate (and available) run-time routines. If this flag
420 -- is False, then the back end does not provide this support, and the
421 -- front end uses component by component comparison for composites.
423 Support_Long_Shifts_On_Target : Boolean := True;
424 -- If True, the back end supports 64-bit shift operations. If False, then
425 -- the source program may not contain explicit 64-bit shifts. In addition,
426 -- the code generated for packed arrays will avoid the use of long shifts.
428 -------------------------------
429 -- Control of Stack Checking --
430 -------------------------------
432 -- GNAT provides two methods of implementing exceptions:
434 -- GCC Probing Mechanism
436 -- This approach uses the standard GCC mechanism for
437 -- stack checking. The method assumes that accessing
438 -- storage immediately beyond the end of the stack
439 -- will result in a trap that is converted to a storage
440 -- error by the runtime system. This mechanism has
441 -- minimal overhead, but requires complex hardware,
442 -- operating system and run-time support. Probing is
443 -- the default method where it is available. The stack
444 -- size for the environment task depends on the operating
445 -- system and cannot be set in a system-independent way.
447 -- GNAT Stack-limit Checking
449 -- This method relies on comparing the stack pointer
450 -- with per-task stack limits. If the check fails, an
451 -- exception is explicitly raised. The advantage is
452 -- that the method requires no extra system dependent
453 -- runtime support and can be used on systems without
454 -- memory protection as well, but at the cost of more
455 -- overhead for doing the check. This method is the
456 -- default on systems that lack complete support for
459 Stack_Check_Probes_On_Target : Boolean := False;
460 -- Indicates if stack check probes are used, as opposed to the standard
461 -- target independent comparison method.
463 Stack_Check_Default_On_Target : Boolean := False;
464 -- Indicates if stack checking is on by default
466 ----------------------------
467 -- Command Line Arguments --
468 ----------------------------
470 -- For most ports of GNAT, command line arguments are supported. The
471 -- following flag is set to False for targets that do not support
472 -- command line arguments (VxWorks and AAMP). Note that support of
473 -- command line arguments is not required on such targets (RM A.15(13)).
475 Command_Line_Args_On_Target : Boolean := True;
476 -- Set False if no command line arguments on target. Note that if this
477 -- is False in with Configurable_Run_Time_On_Target set to True, then
478 -- this causes suppression of generation of the argv/argc variables
479 -- used to record command line arguments.
481 -- Similarly, most ports support the use of an exit status, but AAMP
482 -- is an exception (as allowed by RM A.15(18-20))
484 Exit_Status_Supported_On_Target : Boolean := True;
485 -- Set False if returning of an exit status is not supported on target.
486 -- Note that if this False in with Configurable_Run_Time_On_Target
487 -- set to True, then this causes suppression of the gnat_exit_status
488 -- variable used to record the exit status.
490 -----------------------
491 -- Main Program Name --
492 -----------------------
494 -- When the binder generates the main program to be used to create the
495 -- executable, the main program name is main by default (to match the
496 -- usual Unix practice). If this parameter is set to True, then the
497 -- name is instead by default taken from the actual Ada main program
498 -- name (just the name of the child if the main program is a child unit).
499 -- In either case, this value can be overridden using -M name.
501 Use_Ada_Main_Program_Name_On_Target : Boolean := False;
502 -- Set True to use the Ada main program name as the main name
504 ----------------------------------------------
505 -- Boolean-Valued Floating-Point Attributes --
506 ----------------------------------------------
508 -- The constants below give the values for representation oriented
509 -- floating-point attributes that are the same for all float types
510 -- on the target. These are all boolean values.
512 -- A value is only True if the target reliably supports the corresponding
513 -- feature. Reliably here means that support is guaranteed for all
514 -- possible settings of the relevant compiler switches (like -mieee),
515 -- since we cannot control the user setting of those switches.
517 -- The attributes cannot dependent on the current setting of compiler
518 -- switches, since the values must be static and consistent throughout
519 -- the partition. We probably should add such consistency checks in future,
520 -- but for now we don't do this.
522 -- Note: the compiler itself does not use floating-point, so the
523 -- settings of the defaults here are not really relevant.
525 -- Note: in some cases, proper support of some of these floating point
526 -- features may require a specific switch (e.g. -mieee on the Alpha)
527 -- to be used to obtain full RM compliant support.
529 Denorm_On_Target : Boolean := False;
530 -- Set to False on targets that do not reliably support denormals
532 Machine_Rounds_On_Target : Boolean := True;
533 -- Set to False for targets where S'Machine_Rounds is False
535 Machine_Overflows_On_Target : Boolean := False;
536 -- Set to True for targets where S'Machine_Overflows is True
538 Signed_Zeros_On_Target : Boolean := True;
539 -- Set to False on targets that do not reliably support signed zeros
541 -------------------------------------------
542 -- Boolean-Valued Fixed-Point Attributes --
543 -------------------------------------------
545 Fractional_Fixed_Ops_On_Target : Boolean := False;
546 -- Set to True for targets that support fixed-by-fixed multiplication
547 -- and division for fixed-point types with a small value equal to
548 -- 2 ** (-(T'Object_Size - 1)) and whose values have an absolute
549 -- value less than 1.0.
555 -- Normally when using the GCC backend, Gigi and GCC perform much of the
556 -- data layout using the standard layout capabilities of GCC. If the
557 -- parameter Backend_Layout is set to False, then the front end must
558 -- perform all data layout. For further details see the package Layout.
560 Frontend_Layout_On_Target : Boolean := False;
561 -- Set True if front end does layout
567 -- These subprograms are used to initialize the target parameter values
568 -- from the system.ads file. Note that this is only done once, so if more
569 -- than one call is made to either routine, the second and subsequent
570 -- calls are ignored.
572 procedure Get_Target_Parameters
573 (System_Text : Source_Buffer_Ptr;
574 Source_First : Source_Ptr;
575 Source_Last : Source_Ptr);
576 -- Called at the start of execution to obtain target parameters from
577 -- the source of package System. The parameters provide the source
578 -- text to be scanned (in System_Text (Source_First .. Source_Last)).
580 procedure Get_Target_Parameters;
581 -- This version reads in system.ads using Osint. The idea is that the
582 -- caller uses the first version if they have to read system.ads anyway
583 -- (e.g. the compiler) and uses this simpler interface if system.ads is
584 -- not otherwise needed.