Update copyright dates.
[gcc.git] / gcc / ada / gnat_ugn.texi
index 22d6f1469ec85924ebe636b2d7a2d9249492e11b..360177b042bd4f26a00b8618b71ad61f410a531d 100644 (file)
 
 @copying
 @quotation
-GNAT User's Guide for Native Platforms , Sep 25, 2017
+GNAT User's Guide for Native Platforms , Dec 11, 2020
 
 AdaCore
 
-Copyright @copyright{} 2008-2017, Free Software Foundation
+Copyright @copyright{} 2008-2021, Free Software Foundation
 @end quotation
 
 @end copying
@@ -85,15 +85,14 @@ About This Guide
 * What This Guide Contains:: 
 * What You Should Know before Reading This Guide:: 
 * Related Information:: 
-* A Note to Readers of Previous Versions of the Manual:: 
 * Conventions:: 
 
 Getting Started with GNAT
 
+* System Requirements:: 
 * Running GNAT:: 
 * Running a Simple Ada Program:: 
 * Running a Program with Multiple Units:: 
-* Using the gnatmake Utility:: 
 
 The GNAT Compilation Model
 
@@ -313,8 +312,6 @@ GNAT Utility Programs
 
 * The File Cleanup Utility gnatclean:: 
 * The GNAT Library Browser gnatls:: 
-* The Cross-Referencing Tools gnatxref and gnatfind:: 
-* The Ada to HTML Converter gnathtml:: 
 
 The File Cleanup Utility gnatclean
 
@@ -327,29 +324,10 @@ The GNAT Library Browser gnatls
 * Switches for gnatls:: 
 * Example of gnatls Usage:: 
 
-The Cross-Referencing Tools gnatxref and gnatfind
-
-* gnatxref Switches:: 
-* gnatfind Switches:: 
-* Configuration Files for gnatxref and gnatfind:: 
-* Regular Expressions in gnatfind and gnatxref:: 
-* Examples of gnatxref Usage:: 
-* Examples of gnatfind Usage:: 
-
-Examples of gnatxref Usage
-
-* General Usage:: 
-* Using gnatxref with vi:: 
-
-The Ada to HTML Converter gnathtml
-
-* Invoking gnathtml:: 
-* Installing gnathtml:: 
-
 GNAT and Program Execution
 
 * Running and Debugging Ada Programs:: 
-* Code Coverage and Profiling:: 
+* Profiling:: 
 * Improving Performance:: 
 * Overflow Check Handling in GNAT:: 
 * Performing Dimensionality Analysis in GNAT:: 
@@ -379,16 +357,10 @@ Stack Traceback
 * Non-Symbolic Traceback:: 
 * Symbolic Traceback:: 
 
-Code Coverage and Profiling
+Profiling
 
-* Code Coverage of Ada Programs with gcov:: 
 * Profiling an Ada Program with gprof:: 
 
-Code Coverage of Ada Programs with gcov
-
-* Quick startup guide:: 
-* GNAT specifics:: 
-
 Profiling an Ada Program with gprof
 
 * Compilation for profiling:: 
@@ -409,7 +381,7 @@ Performance Considerations
 * Optimization Levels:: 
 * Debugging Optimized Code:: 
 * Inlining of Subprograms:: 
-* Floating_Point_Operations:: 
+* Floating Point Operations:: 
 * Vectorization of loops:: 
 * Other Optimization Switches:: 
 * Optimization and Strict Aliasing:: 
@@ -446,6 +418,7 @@ Platform-Specific Information
 
 * Run-Time Libraries:: 
 * Specifying a Run-Time Library:: 
+* GNU/Linux Topics:: 
 * Microsoft Windows Topics:: 
 * Mac OS Topics:: 
 
@@ -457,6 +430,10 @@ Specifying a Run-Time Library
 
 * Choosing the Scheduling Policy:: 
 
+GNU/Linux Topics
+
+* Required Packages on GNU/Linux:: 
+
 Microsoft Windows Topics
 
 * Using GNAT on Windows:: 
@@ -464,6 +441,7 @@ Microsoft Windows Topics
 * CONSOLE and WINDOWS subsystems:: 
 * Temporary Files:: 
 * Disabling Command Line Argument Expansion:: 
+* Windows Socket Timeouts:: 
 * Mixed-Language Programming on Windows:: 
 * Windows Specific Add-Ons:: 
 
@@ -529,19 +507,18 @@ Mac OS Topics
 Elaboration Order Handling in GNAT
 
 * Elaboration Code:: 
+* Elaboration Order:: 
 * Checking the Elaboration Order:: 
-* Controlling the Elaboration Order:: 
-* Controlling Elaboration in GNAT - Internal Calls:: 
-* Controlling Elaboration in GNAT - External Calls:: 
-* Default Behavior in GNAT - Ensuring Safety:: 
-* Treatment of Pragma Elaborate:: 
-* Elaboration Issues for Library Tasks:: 
+* Controlling the Elaboration Order in Ada:: 
+* Controlling the Elaboration Order in GNAT:: 
 * Mixing Elaboration Models:: 
-* What to Do If the Default Elaboration Behavior Fails:: 
-* Elaboration for Indirect Calls:: 
+* ABE Diagnostics:: 
+* SPARK Diagnostics:: 
+* Elaboration Circularities:: 
+* Resolving Elaboration Circularities:: 
+* Elaboration-related Compiler Switches:: 
 * Summary of Procedures for Elaboration Control:: 
-* Other Elaboration Order Considerations:: 
-* Determining the Chosen Elaboration Order:: 
+* Inspecting the Chosen Elaboration Order:: 
 
 Inline Assembler
 
@@ -572,19 +549,18 @@ toolset for the full Ada programming language.
 It documents the features of the compiler and tools, and explains
 how to use them to build Ada applications.
 
-GNAT implements Ada 95, Ada 2005 and Ada 2012, and it may also be
+GNAT implements Ada 95, Ada 2005, Ada 2012, and Ada 202x, and it may also be
 invoked in Ada 83 compatibility mode.
 By default, GNAT assumes Ada 2012, but you can override with a
 compiler switch (@ref{6,,Compiling Different Versions of Ada})
 to explicitly specify the language version.
 Throughout this manual, references to 'Ada' without a year suffix
-apply to all Ada 95/2005/2012 versions of the language.
+apply to all Ada versions of the language, starting with Ada 95.
 
 @menu
 * What This Guide Contains:: 
 * What You Should Know before Reading This Guide:: 
 * Related Information:: 
-* A Note to Readers of Previous Versions of the Manual:: 
 * Conventions:: 
 
 @end menu
@@ -657,12 +633,10 @@ in an Ada program.
 This guide assumes a basic familiarity with the Ada 95 language, as
 described in the International Standard ANSI/ISO/IEC-8652:1995, January
 1995.
-It does not require knowledge of the features introduced by Ada 2005
-or Ada 2012.
 Reference manuals for Ada 95, Ada 2005, and Ada 2012 are included in
 the GNAT documentation package.
 
-@node Related Information,A Note to Readers of Previous Versions of the Manual,What You Should Know before Reading This Guide,About This Guide
+@node Related Information,Conventions,What You Should Know before Reading This Guide,About This Guide
 @anchor{gnat_ugn/about_this_guide related-information}@anchor{12}
 @section Related Information
 
@@ -683,12 +657,12 @@ material for the several revisions of the Ada language standard.
 implementation of Ada.
 
 @item 
-@cite{Using the GNAT Programming Studio}, which describes the GPS
+@cite{Using GNAT Studio}, which describes the GNAT Studio
 Integrated Development Environment.
 
 @item 
-@cite{GNAT Programming Studio Tutorial}, which introduces the
-main GPS features through examples.
+@cite{GNAT Studio Tutorial}, which introduces the
+main GNAT Studio features through examples.
 
 @item 
 @cite{Debugging with GDB},
@@ -700,145 +674,8 @@ for full information on the extensible editor and programming
 environment Emacs.
 @end itemize
 
-@node A Note to Readers of Previous Versions of the Manual,Conventions,Related Information,About This Guide
-@anchor{gnat_ugn/about_this_guide a-note-to-readers-of-previous-versions-of-the-manual}@anchor{13}
-@section A Note to Readers of Previous Versions of the Manual
-
-
-In early 2015 the GNAT manuals were transitioned to the
-reStructuredText (rst) / Sphinx documentation generator technology.
-During that process the @cite{GNAT User's Guide} was reorganized
-so that related topics would be described together in the same chapter
-or appendix.  Here's a summary of the major changes realized in
-the new document structure.
-
-
-@itemize *
-
-@item 
-@ref{9,,The GNAT Compilation Model} has been extended so that it now covers
-the following material:
-
-
-@itemize -
-
-@item 
-The @code{gnatname}, @code{gnatkr}, and @code{gnatchop} tools
-
-@item 
-@ref{14,,Configuration Pragmas}
-
-@item 
-@ref{15,,GNAT and Libraries}
-
-@item 
-@ref{16,,Conditional Compilation} including @ref{17,,Preprocessing with gnatprep}
-and @ref{18,,Integrated Preprocessing}
-
-@item 
-@ref{19,,Generating Ada Bindings for C and C++ headers}
-
-@item 
-@ref{1a,,Using GNAT Files with External Tools}
-@end itemize
-
-@item 
-@ref{a,,Building Executable Programs with GNAT} is a new chapter consolidating
-the following content:
-
-
-@itemize -
-
-@item 
-@ref{1b,,Building with gnatmake}
-
-@item 
-@ref{1c,,Compiling with gcc}
-
-@item 
-@ref{1d,,Binding with gnatbind}
-
-@item 
-@ref{1e,,Linking with gnatlink}
-
-@item 
-@ref{1f,,Using the GNU make Utility}
-@end itemize
-
-@item 
-@ref{b,,GNAT Utility Programs} is a new chapter consolidating the information about several
-GNAT tools:
-
-
-
-@itemize -
-
-@item 
-@ref{20,,The File Cleanup Utility gnatclean}
-
-@item 
-@ref{21,,The GNAT Library Browser gnatls}
-
-@item 
-@ref{22,,The Cross-Referencing Tools gnatxref and gnatfind}
-
-@item 
-@ref{23,,The Ada to HTML Converter gnathtml}
-@end itemize
-
-@item 
-@ref{c,,GNAT and Program Execution} is a new chapter consolidating the following:
-
-
-@itemize -
-
-@item 
-@ref{24,,Running and Debugging Ada Programs}
-
-@item 
-@ref{25,,Code Coverage and Profiling}
-
-@item 
-@ref{26,,Improving Performance}
-
-@item 
-@ref{27,,Overflow Check Handling in GNAT}
-
-@item 
-@ref{28,,Performing Dimensionality Analysis in GNAT}
-
-@item 
-@ref{29,,Stack Related Facilities}
-
-@item 
-@ref{2a,,Memory Management Issues}
-@end itemize
-
-@item 
-@ref{d,,Platform-Specific Information} is a new appendix consolidating the following:
-
-
-@itemize -
-
-@item 
-@ref{2b,,Run-Time Libraries}
-
-@item 
-@ref{2c,,Microsoft Windows Topics}
-
-@item 
-@ref{2d,,Mac OS Topics}
-@end itemize
-
-@item 
-The @emph{Compatibility and Porting Guide} appendix has been moved to the
-@cite{GNAT Reference Manual}. It now includes a section
-@emph{Writing Portable Fixed-Point Declarations} which was previously
-a separate chapter in the @cite{GNAT User's Guide}.
-@end itemize
-
-@node Conventions,,A Note to Readers of Previous Versions of the Manual,About This Guide
-@anchor{gnat_ugn/about_this_guide conventions}@anchor{2e}
+@node Conventions,,Related Information,About This Guide
+@anchor{gnat_ugn/about_this_guide conventions}@anchor{13}
 @section Conventions
 
 
@@ -891,30 +728,59 @@ the '\' character should be used instead.
 @end itemize
 
 @node Getting Started with GNAT,The GNAT Compilation Model,About This Guide,Top
-@anchor{gnat_ugn/getting_started_with_gnat getting-started-with-gnat}@anchor{8}@anchor{gnat_ugn/getting_started_with_gnat doc}@anchor{2f}@anchor{gnat_ugn/getting_started_with_gnat id1}@anchor{30}
+@anchor{gnat_ugn/getting_started_with_gnat getting-started-with-gnat}@anchor{8}@anchor{gnat_ugn/getting_started_with_gnat doc}@anchor{14}@anchor{gnat_ugn/getting_started_with_gnat id1}@anchor{15}
 @chapter Getting Started with GNAT
 
 
 This chapter describes how to use GNAT's command line interface to build
 executable Ada programs.
 On most platforms a visually oriented Integrated Development Environment
-is also available, the GNAT Programming Studio (GPS).
-GPS offers a graphical "look and feel", support for development in
+is also available: GNAT Studio.
+GNAT Studio offers a graphical "look and feel", support for development in
 other programming languages, comprehensive browsing features, and
 many other capabilities.
-For information on GPS please refer to
-@cite{Using the GNAT Programming Studio}.
+For information on GNAT Studio please refer to the
+@cite{GNAT Studio documentation}.
 
 @menu
+* System Requirements:: 
 * Running GNAT:: 
 * Running a Simple Ada Program:: 
 * Running a Program with Multiple Units:: 
-* Using the gnatmake Utility:: 
 
 @end menu
 
-@node Running GNAT,Running a Simple Ada Program,,Getting Started with GNAT
-@anchor{gnat_ugn/getting_started_with_gnat running-gnat}@anchor{31}@anchor{gnat_ugn/getting_started_with_gnat id2}@anchor{32}
+@node System Requirements,Running GNAT,,Getting Started with GNAT
+@anchor{gnat_ugn/getting_started_with_gnat id2}@anchor{16}@anchor{gnat_ugn/getting_started_with_gnat system-requirements}@anchor{17}
+@section System Requirements
+
+
+Even though any machine can run the GNAT toolset and GNAT Studio IDE, in order
+to get the best experience, we recommend using a machine with as many cores
+as possible since all individual compilations can run in parallel.
+A comfortable setup for a compiler server is a machine with 24 physical cores
+or more, with at least 48 GB of memory (2 GB per core).
+
+For a desktop machine, a minimum of 4 cores is recommended (8 preferred),
+with at least 2GB per core (so 8 to 16GB).
+
+In addition, for running and navigating sources in GNAT Studio smoothly, we
+recommend at least 1.5 GB plus 3 GB of RAM per 1 million source line of code.
+In other words, we recommend at least 3 GB for for 500K lines of code and
+7.5 GB for 2 million lines of code.
+
+Note that using local and fast drives will also make a difference in terms of
+build and link time. Network drives such as NFS, SMB, or worse, configuration
+management filesystems (such as ClearCase dynamic views) should be avoided as
+much as possible and will produce very degraded performance (typically 2 to 3
+times slower than on local fast drives). If such slow drives cannot be avoided
+for accessing the source code, then you should at least configure your project
+file so that the result of the compilation is stored on a drive local to the
+machine performing the run. This can be achieved by setting the @code{Object_Dir}
+project file attribute.
+
+@node Running GNAT,Running a Simple Ada Program,System Requirements,Getting Started with GNAT
+@anchor{gnat_ugn/getting_started_with_gnat running-gnat}@anchor{18}@anchor{gnat_ugn/getting_started_with_gnat id3}@anchor{19}
 @section Running GNAT
 
 
@@ -939,7 +805,7 @@ utility program that, given the name of the main program, automatically
 performs the necessary compilation, binding and linking steps.
 
 @node Running a Simple Ada Program,Running a Program with Multiple Units,Running GNAT,Getting Started with GNAT
-@anchor{gnat_ugn/getting_started_with_gnat running-a-simple-ada-program}@anchor{33}@anchor{gnat_ugn/getting_started_with_gnat id3}@anchor{34}
+@anchor{gnat_ugn/getting_started_with_gnat running-a-simple-ada-program}@anchor{1a}@anchor{gnat_ugn/getting_started_with_gnat id4}@anchor{1b}
 @section Running a Simple Ada Program
 
 
@@ -968,12 +834,12 @@ extension is @code{ads} for a
 spec and @code{adb} for a body.
 You can override this default file naming convention by use of the
 special pragma @code{Source_File_Name} (for further information please
-see @ref{35,,Using Other File Names}).
+see @ref{1c,,Using Other File Names}).
 Alternatively, if you want to rename your files according to this default
 convention, which is probably more convenient if you will be using GNAT
 for all your compilations, then the @code{gnatchop} utility
 can be used to generate correctly-named source files
-(see @ref{36,,Renaming Files with gnatchop}).
+(see @ref{1d,,Renaming Files with gnatchop}).
 
 You can compile the program using the following command (@code{$} is used
 as the command prompt in the examples in this document):
@@ -999,24 +865,12 @@ file corresponding to your Ada program. It also generates
 an 'Ada Library Information' file @code{hello.ali},
 which contains additional information used to check
 that an Ada program is consistent.
-To build an executable file,
-use @code{gnatbind} to bind the program
-and @code{gnatlink} to link it. The
-argument to both @code{gnatbind} and @code{gnatlink} is the name of the
-@code{ALI} file, but the default extension of @code{.ali} can
-be omitted. This means that in the most common case, the argument
-is simply the name of the main program:
-
-@example
-$ gnatbind hello
-$ gnatlink hello
-@end example
 
-A simpler method of carrying out these steps is to use @code{gnatmake},
-a master program that invokes all the required
-compilation, binding and linking tools in the correct order. In particular,
-@code{gnatmake} automatically recompiles any sources that have been
-modified since they were last compiled, or sources that depend
+To build an executable file, use either @code{gnatmake} or gprbuild with
+the name of the main file: these tools are builders that will take care of
+all the necessary build steps in the correct order.
+In particular, these builders automatically recompile any sources that have
+been modified since they were last compiled, or sources that depend
 on such modified sources, so that 'version skew' is avoided.
 
 @geindex Version skew (avoided by `@w{`}gnatmake`@w{`})
@@ -1043,8 +897,8 @@ Hello WORLD!
 
 appear in response to this command.
 
-@node Running a Program with Multiple Units,Using the gnatmake Utility,Running a Simple Ada Program,Getting Started with GNAT
-@anchor{gnat_ugn/getting_started_with_gnat id4}@anchor{37}@anchor{gnat_ugn/getting_started_with_gnat running-a-program-with-multiple-units}@anchor{38}
+@node Running a Program with Multiple Units,,Running a Simple Ada Program,Getting Started with GNAT
+@anchor{gnat_ugn/getting_started_with_gnat id5}@anchor{1e}@anchor{gnat_ugn/getting_started_with_gnat running-a-program-with-multiple-units}@anchor{1f}
 @section Running a Program with Multiple Units
 
 
@@ -1097,17 +951,6 @@ body of package @code{Greetings}
 body of main program
 @end table
 
-To build an executable version of
-this program, we could use four separate steps to compile, bind, and link
-the program, as follows:
-
-@example
-$ gcc -c gmain.adb
-$ gcc -c greetings.adb
-$ gnatbind gmain
-$ gnatlink gmain
-@end example
-
 Note that there is no required order of compilation when using GNAT.
 In particular it is perfectly fine to compile the main program first.
 Also, it is not necessary to compile package specs in the case where
@@ -1119,74 +962,17 @@ generation, then use the @code{-gnatc} switch:
 $ gcc -c greetings.ads -gnatc
 @end example
 
-Although the compilation can be done in separate steps as in the
-above example, in practice it is almost always more convenient
-to use the @code{gnatmake} tool. All you need to know in this case
-is the name of the main program's source file. The effect of the above four
-commands can be achieved with a single one:
+Although the compilation can be done in separate steps, in practice it is
+almost always more convenient to use the @code{gnatmake} or @code{gprbuild} tools:
 
 @example
 $ gnatmake gmain.adb
 @end example
 
-In the next section we discuss the advantages of using @code{gnatmake} in
-more detail.
-
-@node Using the gnatmake Utility,,Running a Program with Multiple Units,Getting Started with GNAT
-@anchor{gnat_ugn/getting_started_with_gnat using-the-gnatmake-utility}@anchor{39}@anchor{gnat_ugn/getting_started_with_gnat id5}@anchor{3a}
-@section Using the @code{gnatmake} Utility
-
-
-If you work on a program by compiling single components at a time using
-@code{gcc}, you typically keep track of the units you modify. In order to
-build a consistent system, you compile not only these units, but also any
-units that depend on the units you have modified.
-For example, in the preceding case,
-if you edit @code{gmain.adb}, you only need to recompile that file. But if
-you edit @code{greetings.ads}, you must recompile both
-@code{greetings.adb} and @code{gmain.adb}, because both files contain
-units that depend on @code{greetings.ads}.
-
-@code{gnatbind} will warn you if you forget one of these compilation
-steps, so that it is impossible to generate an inconsistent program as a
-result of forgetting to do a compilation. Nevertheless it is tedious and
-error-prone to keep track of dependencies among units.
-One approach to handle the dependency-bookkeeping is to use a
-makefile. However, makefiles present maintenance problems of their own:
-if the dependencies change as you change the program, you must make
-sure that the makefile is kept up-to-date manually, which is also an
-error-prone process.
-
-The @code{gnatmake} utility takes care of these details automatically.
-Invoke it using either one of the following forms:
-
-@example
-$ gnatmake gmain.adb
-$ gnatmake gmain
-@end example
-
-The argument is the name of the file containing the main program;
-you may omit the extension. @code{gnatmake}
-examines the environment, automatically recompiles any files that need
-recompiling, and binds and links the resulting set of object files,
-generating the executable file, @code{gmain}.
-In a large program, it
-can be extremely helpful to use @code{gnatmake}, because working out by hand
-what needs to be recompiled can be difficult.
-
-Note that @code{gnatmake} takes into account all the Ada rules that
-establish dependencies among units. These include dependencies that result
-from inlining subprogram bodies, and from
-generic instantiation. Unlike some other
-Ada make tools, @code{gnatmake} does not rely on the dependencies that were
-found by the compiler on a previous compilation, which may possibly
-be wrong when sources change. @code{gnatmake} determines the exact set of
-dependencies from scratch each time it is run.
-
 @c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit
 
 @node The GNAT Compilation Model,Building Executable Programs with GNAT,Getting Started with GNAT,Top
-@anchor{gnat_ugn/the_gnat_compilation_model doc}@anchor{3b}@anchor{gnat_ugn/the_gnat_compilation_model the-gnat-compilation-model}@anchor{9}@anchor{gnat_ugn/the_gnat_compilation_model id1}@anchor{3c}
+@anchor{gnat_ugn/the_gnat_compilation_model doc}@anchor{20}@anchor{gnat_ugn/the_gnat_compilation_model the-gnat-compilation-model}@anchor{9}@anchor{gnat_ugn/the_gnat_compilation_model id1}@anchor{21}
 @chapter The GNAT Compilation Model
 
 
@@ -1210,44 +996,44 @@ Topics related to source file makeup and naming
 @itemize *
 
 @item 
-@ref{3d,,Source Representation}
+@ref{22,,Source Representation}
 
 @item 
-@ref{3e,,Foreign Language Representation}
+@ref{23,,Foreign Language Representation}
 
 @item 
-@ref{3f,,File Naming Topics and Utilities}
+@ref{24,,File Naming Topics and Utilities}
 @end itemize
 
 @item 
-@ref{14,,Configuration Pragmas}
+@ref{25,,Configuration Pragmas}
 
 @item 
-@ref{40,,Generating Object Files}
+@ref{26,,Generating Object Files}
 
 @item 
-@ref{41,,Source Dependencies}
+@ref{27,,Source Dependencies}
 
 @item 
-@ref{42,,The Ada Library Information Files}
+@ref{28,,The Ada Library Information Files}
 
 @item 
-@ref{43,,Binding an Ada Program}
+@ref{29,,Binding an Ada Program}
 
 @item 
-@ref{15,,GNAT and Libraries}
+@ref{2a,,GNAT and Libraries}
 
 @item 
-@ref{16,,Conditional Compilation}
+@ref{2b,,Conditional Compilation}
 
 @item 
-@ref{44,,Mixed Language Programming}
+@ref{2c,,Mixed Language Programming}
 
 @item 
-@ref{45,,GNAT and Other Compilation Models}
+@ref{2d,,GNAT and Other Compilation Models}
 
 @item 
-@ref{1a,,Using GNAT Files with External Tools}
+@ref{2e,,Using GNAT Files with External Tools}
 @end itemize
 
 @menu
@@ -1268,7 +1054,7 @@ Topics related to source file makeup and naming
 @end menu
 
 @node Source Representation,Foreign Language Representation,,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model source-representation}@anchor{3d}@anchor{gnat_ugn/the_gnat_compilation_model id2}@anchor{46}
+@anchor{gnat_ugn/the_gnat_compilation_model source-representation}@anchor{22}@anchor{gnat_ugn/the_gnat_compilation_model id2}@anchor{2f}
 @section Source Representation
 
 
@@ -1283,7 +1069,7 @@ Topics related to source file makeup and naming
 Ada source programs are represented in standard text files, using
 Latin-1 coding. Latin-1 is an 8-bit code that includes the familiar
 7-bit ASCII set, plus additional characters used for
-representing foreign languages (see @ref{3e,,Foreign Language Representation}
+representing foreign languages (see @ref{23,,Foreign Language Representation}
 for support of non-USA character sets). The format effector characters
 are represented using their standard ASCII encodings, as follows:
 
@@ -1394,13 +1180,13 @@ compilation units) is represented using a sequence of files. Similarly,
 you will place each subunit or child unit in a separate file.
 
 @node Foreign Language Representation,File Naming Topics and Utilities,Source Representation,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model foreign-language-representation}@anchor{3e}@anchor{gnat_ugn/the_gnat_compilation_model id3}@anchor{47}
+@anchor{gnat_ugn/the_gnat_compilation_model foreign-language-representation}@anchor{23}@anchor{gnat_ugn/the_gnat_compilation_model id3}@anchor{30}
 @section Foreign Language Representation
 
 
 GNAT supports the standard character sets defined in Ada as well as
 several other non-standard character sets for use in localized versions
-of the compiler (@ref{48,,Character Set Control}).
+of the compiler (@ref{31,,Character Set Control}).
 
 @menu
 * Latin-1:: 
@@ -1411,7 +1197,7 @@ of the compiler (@ref{48,,Character Set Control}).
 @end menu
 
 @node Latin-1,Other 8-Bit Codes,,Foreign Language Representation
-@anchor{gnat_ugn/the_gnat_compilation_model id4}@anchor{49}@anchor{gnat_ugn/the_gnat_compilation_model latin-1}@anchor{4a}
+@anchor{gnat_ugn/the_gnat_compilation_model id4}@anchor{32}@anchor{gnat_ugn/the_gnat_compilation_model latin-1}@anchor{33}
 @subsection Latin-1
 
 
@@ -1434,7 +1220,7 @@ string literals. In addition, the extended characters that represent
 letters can be used in identifiers.
 
 @node Other 8-Bit Codes,Wide_Character Encodings,Latin-1,Foreign Language Representation
-@anchor{gnat_ugn/the_gnat_compilation_model other-8-bit-codes}@anchor{4b}@anchor{gnat_ugn/the_gnat_compilation_model id5}@anchor{4c}
+@anchor{gnat_ugn/the_gnat_compilation_model other-8-bit-codes}@anchor{34}@anchor{gnat_ugn/the_gnat_compilation_model id5}@anchor{35}
 @subsection Other 8-Bit Codes
 
 
@@ -1551,7 +1337,7 @@ the GNAT compiler sources. You will need to obtain a full source release
 of GNAT to obtain this file.
 
 @node Wide_Character Encodings,Wide_Wide_Character Encodings,Other 8-Bit Codes,Foreign Language Representation
-@anchor{gnat_ugn/the_gnat_compilation_model id6}@anchor{4d}@anchor{gnat_ugn/the_gnat_compilation_model wide-character-encodings}@anchor{4e}
+@anchor{gnat_ugn/the_gnat_compilation_model id6}@anchor{36}@anchor{gnat_ugn/the_gnat_compilation_model wide-character-encodings}@anchor{37}
 @subsection Wide_Character Encodings
 
 
@@ -1662,7 +1448,7 @@ use of the upper half of the Latin-1 set.
 @end cartouche
 
 @node Wide_Wide_Character Encodings,,Wide_Character Encodings,Foreign Language Representation
-@anchor{gnat_ugn/the_gnat_compilation_model id7}@anchor{4f}@anchor{gnat_ugn/the_gnat_compilation_model wide-wide-character-encodings}@anchor{50}
+@anchor{gnat_ugn/the_gnat_compilation_model id7}@anchor{38}@anchor{gnat_ugn/the_gnat_compilation_model wide-wide-character-encodings}@anchor{39}
 @subsection Wide_Wide_Character Encodings
 
 
@@ -1714,7 +1500,7 @@ ACATS (Ada Conformity Assessment Test Suite) test suite distributions.
 @end table
 
 @node File Naming Topics and Utilities,Configuration Pragmas,Foreign Language Representation,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model id8}@anchor{51}@anchor{gnat_ugn/the_gnat_compilation_model file-naming-topics-and-utilities}@anchor{3f}
+@anchor{gnat_ugn/the_gnat_compilation_model id8}@anchor{3a}@anchor{gnat_ugn/the_gnat_compilation_model file-naming-topics-and-utilities}@anchor{24}
 @section File Naming Topics and Utilities
 
 
@@ -1733,7 +1519,7 @@ source files correspond to the Ada compilation units that they contain.
 @end menu
 
 @node File Naming Rules,Using Other File Names,,File Naming Topics and Utilities
-@anchor{gnat_ugn/the_gnat_compilation_model file-naming-rules}@anchor{52}@anchor{gnat_ugn/the_gnat_compilation_model id9}@anchor{53}
+@anchor{gnat_ugn/the_gnat_compilation_model file-naming-rules}@anchor{3b}@anchor{gnat_ugn/the_gnat_compilation_model id9}@anchor{3c}
 @subsection File Naming Rules
 
 
@@ -1842,7 +1628,7 @@ unit names are long (for example, if child units or subunits are
 heavily nested). An option is available to shorten such long file names
 (called file name 'krunching'). This may be particularly useful when
 programs being developed with GNAT are to be used on operating systems
-with limited file name lengths. @ref{54,,Using gnatkr}.
+with limited file name lengths. @ref{3d,,Using gnatkr}.
 
 Of course, no file shortening algorithm can guarantee uniqueness over
 all possible unit names; if file name krunching is used, it is your
@@ -1851,7 +1637,7 @@ can specify the exact file names that you want used, as described
 in the next section. Finally, if your Ada programs are migrating from a
 compiler with a different naming convention, you can use the gnatchop
 utility to produce source files that follow the GNAT naming conventions.
-(For details see @ref{36,,Renaming Files with gnatchop}.)
+(For details see @ref{1d,,Renaming Files with gnatchop}.)
 
 Note: in the case of Windows or Mac OS operating systems, case is not
 significant. So for example on Windows if the canonical name is
@@ -1861,7 +1647,7 @@ if you want to use other than canonically cased file names on a Unix system,
 you need to follow the procedures described in the next section.
 
 @node Using Other File Names,Alternative File Naming Schemes,File Naming Rules,File Naming Topics and Utilities
-@anchor{gnat_ugn/the_gnat_compilation_model id10}@anchor{55}@anchor{gnat_ugn/the_gnat_compilation_model using-other-file-names}@anchor{35}
+@anchor{gnat_ugn/the_gnat_compilation_model id10}@anchor{3e}@anchor{gnat_ugn/the_gnat_compilation_model using-other-file-names}@anchor{1c}
 @subsection Using Other File Names
 
 
@@ -1899,7 +1685,7 @@ normally it will be placed in the @code{gnat.adc}
 file used to hold configuration
 pragmas that apply to a complete compilation environment.
 For more details on how the @code{gnat.adc} file is created and used
-see @ref{56,,Handling of Configuration Pragmas}.
+see @ref{3f,,Handling of Configuration Pragmas}.
 
 @geindex gnat.adc
 
@@ -1921,7 +1707,7 @@ then it must be included in the @code{gnatmake} command, it may not
 be omitted.
 
 @node Alternative File Naming Schemes,Handling Arbitrary File Naming Conventions with gnatname,Using Other File Names,File Naming Topics and Utilities
-@anchor{gnat_ugn/the_gnat_compilation_model id11}@anchor{57}@anchor{gnat_ugn/the_gnat_compilation_model alternative-file-naming-schemes}@anchor{58}
+@anchor{gnat_ugn/the_gnat_compilation_model id11}@anchor{40}@anchor{gnat_ugn/the_gnat_compilation_model alternative-file-naming-schemes}@anchor{41}
 @subsection Alternative File Naming Schemes
 
 
@@ -2065,7 +1851,7 @@ pragma Source_File_Name
 @geindex gnatname
 
 @node Handling Arbitrary File Naming Conventions with gnatname,File Name Krunching with gnatkr,Alternative File Naming Schemes,File Naming Topics and Utilities
-@anchor{gnat_ugn/the_gnat_compilation_model handling-arbitrary-file-naming-conventions-with-gnatname}@anchor{59}@anchor{gnat_ugn/the_gnat_compilation_model id12}@anchor{5a}
+@anchor{gnat_ugn/the_gnat_compilation_model handling-arbitrary-file-naming-conventions-with-gnatname}@anchor{42}@anchor{gnat_ugn/the_gnat_compilation_model id12}@anchor{43}
 @subsection Handling Arbitrary File Naming Conventions with @code{gnatname}
 
 
@@ -2080,7 +1866,7 @@ pragma Source_File_Name
 @end menu
 
 @node Arbitrary File Naming Conventions,Running gnatname,,Handling Arbitrary File Naming Conventions with gnatname
-@anchor{gnat_ugn/the_gnat_compilation_model arbitrary-file-naming-conventions}@anchor{5b}@anchor{gnat_ugn/the_gnat_compilation_model id13}@anchor{5c}
+@anchor{gnat_ugn/the_gnat_compilation_model arbitrary-file-naming-conventions}@anchor{44}@anchor{gnat_ugn/the_gnat_compilation_model id13}@anchor{45}
 @subsubsection Arbitrary File Naming Conventions
 
 
@@ -2091,11 +1877,11 @@ does not need additional information.
 
 When the source file names do not follow the standard GNAT default file naming
 conventions, the GNAT compiler must be given additional information through
-a configuration pragmas file (@ref{14,,Configuration Pragmas})
+a configuration pragmas file (@ref{25,,Configuration Pragmas})
 or a project file.
 When the non-standard file naming conventions are well-defined,
 a small number of pragmas @code{Source_File_Name} specifying a naming pattern
-(@ref{58,,Alternative File Naming Schemes}) may be sufficient. However,
+(@ref{41,,Alternative File Naming Schemes}) may be sufficient. However,
 if the file naming conventions are irregular or arbitrary, a number
 of pragma @code{Source_File_Name} for individual compilation units
 must be defined.
@@ -2105,7 +1891,7 @@ GNAT provides a tool @code{gnatname} to generate the required pragmas for a
 set of files.
 
 @node Running gnatname,Switches for gnatname,Arbitrary File Naming Conventions,Handling Arbitrary File Naming Conventions with gnatname
-@anchor{gnat_ugn/the_gnat_compilation_model running-gnatname}@anchor{5d}@anchor{gnat_ugn/the_gnat_compilation_model id14}@anchor{5e}
+@anchor{gnat_ugn/the_gnat_compilation_model running-gnatname}@anchor{46}@anchor{gnat_ugn/the_gnat_compilation_model id14}@anchor{47}
 @subsubsection Running @code{gnatname}
 
 
@@ -2156,7 +1942,7 @@ with pragmas @code{Source_File_Name} for each file that contains a valid Ada
 unit.
 
 @node Switches for gnatname,Examples of gnatname Usage,Running gnatname,Handling Arbitrary File Naming Conventions with gnatname
-@anchor{gnat_ugn/the_gnat_compilation_model id15}@anchor{5f}@anchor{gnat_ugn/the_gnat_compilation_model switches-for-gnatname}@anchor{60}
+@anchor{gnat_ugn/the_gnat_compilation_model id15}@anchor{48}@anchor{gnat_ugn/the_gnat_compilation_model switches-for-gnatname}@anchor{49}
 @subsubsection Switches for @code{gnatname}
 
 
@@ -2339,7 +2125,7 @@ except those whose names end with @code{_nt.ada}.
 @end table
 
 @node Examples of gnatname Usage,,Switches for gnatname,Handling Arbitrary File Naming Conventions with gnatname
-@anchor{gnat_ugn/the_gnat_compilation_model examples-of-gnatname-usage}@anchor{61}@anchor{gnat_ugn/the_gnat_compilation_model id16}@anchor{62}
+@anchor{gnat_ugn/the_gnat_compilation_model examples-of-gnatname-usage}@anchor{4a}@anchor{gnat_ugn/the_gnat_compilation_model id16}@anchor{4b}
 @subsubsection Examples of @code{gnatname} Usage
 
 
@@ -2365,7 +2151,7 @@ even in conjunction with one or several switches
 are used in this example.
 
 @node File Name Krunching with gnatkr,Renaming Files with gnatchop,Handling Arbitrary File Naming Conventions with gnatname,File Naming Topics and Utilities
-@anchor{gnat_ugn/the_gnat_compilation_model file-name-krunching-with-gnatkr}@anchor{63}@anchor{gnat_ugn/the_gnat_compilation_model id17}@anchor{64}
+@anchor{gnat_ugn/the_gnat_compilation_model file-name-krunching-with-gnatkr}@anchor{4c}@anchor{gnat_ugn/the_gnat_compilation_model id17}@anchor{4d}
 @subsection File Name Krunching with @code{gnatkr}
 
 
@@ -2386,7 +2172,7 @@ applying this shortening.
 @end menu
 
 @node About gnatkr,Using gnatkr,,File Name Krunching with gnatkr
-@anchor{gnat_ugn/the_gnat_compilation_model id18}@anchor{65}@anchor{gnat_ugn/the_gnat_compilation_model about-gnatkr}@anchor{66}
+@anchor{gnat_ugn/the_gnat_compilation_model id18}@anchor{4e}@anchor{gnat_ugn/the_gnat_compilation_model about-gnatkr}@anchor{4f}
 @subsubsection About @code{gnatkr}
 
 
@@ -2424,7 +2210,7 @@ The @code{gnatkr} utility can be used to determine the krunched name for
 a given file, when krunched to a specified maximum length.
 
 @node Using gnatkr,Krunching Method,About gnatkr,File Name Krunching with gnatkr
-@anchor{gnat_ugn/the_gnat_compilation_model id19}@anchor{67}@anchor{gnat_ugn/the_gnat_compilation_model using-gnatkr}@anchor{54}
+@anchor{gnat_ugn/the_gnat_compilation_model id19}@anchor{50}@anchor{gnat_ugn/the_gnat_compilation_model using-gnatkr}@anchor{3d}
 @subsubsection Using @code{gnatkr}
 
 
@@ -2461,7 +2247,7 @@ The output is the krunched name. The output has an extension only if the
 original argument was a file name with an extension.
 
 @node Krunching Method,Examples of gnatkr Usage,Using gnatkr,File Name Krunching with gnatkr
-@anchor{gnat_ugn/the_gnat_compilation_model id20}@anchor{68}@anchor{gnat_ugn/the_gnat_compilation_model krunching-method}@anchor{69}
+@anchor{gnat_ugn/the_gnat_compilation_model id20}@anchor{51}@anchor{gnat_ugn/the_gnat_compilation_model krunching-method}@anchor{52}
 @subsubsection Krunching Method
 
 
@@ -2591,7 +2377,7 @@ program @code{gnatkr} is supplied for conveniently determining the
 krunched name of a file.
 
 @node Examples of gnatkr Usage,,Krunching Method,File Name Krunching with gnatkr
-@anchor{gnat_ugn/the_gnat_compilation_model id21}@anchor{6a}@anchor{gnat_ugn/the_gnat_compilation_model examples-of-gnatkr-usage}@anchor{6b}
+@anchor{gnat_ugn/the_gnat_compilation_model id21}@anchor{53}@anchor{gnat_ugn/the_gnat_compilation_model examples-of-gnatkr-usage}@anchor{54}
 @subsubsection Examples of @code{gnatkr} Usage
 
 
@@ -2605,7 +2391,7 @@ $ gnatkr very_long_unit_name.ads/count=0 --> very_long_unit_name.ads
 @end example
 
 @node Renaming Files with gnatchop,,File Name Krunching with gnatkr,File Naming Topics and Utilities
-@anchor{gnat_ugn/the_gnat_compilation_model id22}@anchor{6c}@anchor{gnat_ugn/the_gnat_compilation_model renaming-files-with-gnatchop}@anchor{36}
+@anchor{gnat_ugn/the_gnat_compilation_model id22}@anchor{55}@anchor{gnat_ugn/the_gnat_compilation_model renaming-files-with-gnatchop}@anchor{1d}
 @subsection Renaming Files with @code{gnatchop}
 
 
@@ -2625,7 +2411,7 @@ files to meet the standard GNAT default file naming conventions.
 @end menu
 
 @node Handling Files with Multiple Units,Operating gnatchop in Compilation Mode,,Renaming Files with gnatchop
-@anchor{gnat_ugn/the_gnat_compilation_model id23}@anchor{6d}@anchor{gnat_ugn/the_gnat_compilation_model handling-files-with-multiple-units}@anchor{6e}
+@anchor{gnat_ugn/the_gnat_compilation_model id23}@anchor{56}@anchor{gnat_ugn/the_gnat_compilation_model handling-files-with-multiple-units}@anchor{57}
 @subsubsection Handling Files with Multiple Units
 
 
@@ -2633,23 +2419,18 @@ The basic compilation model of GNAT requires that a file submitted to the
 compiler have only one unit and there be a strict correspondence
 between the file name and the unit name.
 
-The @code{gnatchop} utility allows both of these rules to be relaxed,
-allowing GNAT to process files which contain multiple compilation units
-and files with arbitrary file names. @code{gnatchop}
-reads the specified file and generates one or more output files,
-containing one unit per file. The unit and the file name correspond,
-as required by GNAT.
+If you want to keep your files with multiple units,
+perhaps to maintain compatibility with some other Ada compilation system,
+you can use @code{gnatname} to generate or update your project files.
+Generated or modified project files can be processed by GNAT.
 
-If you want to permanently restructure a set of 'foreign' files so that
-they match the GNAT rules, and do the remaining development using the
-GNAT structure, you can simply use @code{gnatchop} once, generate the
-new set of files and work with them from that point on.
+See @ref{42,,Handling Arbitrary File Naming Conventions with gnatname}
+for more details on how to use @cite{gnatname}.
 
-Alternatively, if you want to keep your files in the 'foreign' format,
-perhaps to maintain compatibility with some other Ada compilation
-system, you can set up a procedure where you use @code{gnatchop} each
-time you compile, regarding the source files that it writes as temporary
-files that you throw away.
+Alternatively, if you want to permanently restructure a set of 'foreign'
+files so that they match the GNAT rules, and do the remaining development
+using the GNAT structure, you can simply use @code{gnatchop} once, generate the
+new set of files and work with them from that point on.
 
 Note that if your file containing multiple units starts with a byte order
 mark (BOM) specifying UTF-8 encoding, then the files generated by gnatchop
@@ -2657,7 +2438,7 @@ will each start with a copy of this BOM, meaning that they can be compiled
 automatically in UTF-8 mode without needing to specify an explicit encoding.
 
 @node Operating gnatchop in Compilation Mode,Command Line for gnatchop,Handling Files with Multiple Units,Renaming Files with gnatchop
-@anchor{gnat_ugn/the_gnat_compilation_model operating-gnatchop-in-compilation-mode}@anchor{6f}@anchor{gnat_ugn/the_gnat_compilation_model id24}@anchor{70}
+@anchor{gnat_ugn/the_gnat_compilation_model operating-gnatchop-in-compilation-mode}@anchor{58}@anchor{gnat_ugn/the_gnat_compilation_model id24}@anchor{59}
 @subsubsection Operating gnatchop in Compilation Mode
 
 
@@ -2690,7 +2471,7 @@ should apply to all subsequent compilations in the same compilation
 environment. Using GNAT, the current directory, possibly containing a
 @code{gnat.adc} file is the representation
 of a compilation environment. For more information on the
-@code{gnat.adc} file, see @ref{56,,Handling of Configuration Pragmas}.
+@code{gnat.adc} file, see @ref{3f,,Handling of Configuration Pragmas}.
 
 Second, in compilation mode, if @code{gnatchop}
 is given a file that starts with
@@ -2717,7 +2498,7 @@ switch provides the required behavior, and is for example the mode
 in which GNAT processes the ACVC tests.
 
 @node Command Line for gnatchop,Switches for gnatchop,Operating gnatchop in Compilation Mode,Renaming Files with gnatchop
-@anchor{gnat_ugn/the_gnat_compilation_model id25}@anchor{71}@anchor{gnat_ugn/the_gnat_compilation_model command-line-for-gnatchop}@anchor{72}
+@anchor{gnat_ugn/the_gnat_compilation_model id25}@anchor{5a}@anchor{gnat_ugn/the_gnat_compilation_model command-line-for-gnatchop}@anchor{5b}
 @subsubsection Command Line for @code{gnatchop}
 
 
@@ -2791,7 +2572,7 @@ no source files written
 @end example
 
 @node Switches for gnatchop,Examples of gnatchop Usage,Command Line for gnatchop,Renaming Files with gnatchop
-@anchor{gnat_ugn/the_gnat_compilation_model switches-for-gnatchop}@anchor{73}@anchor{gnat_ugn/the_gnat_compilation_model id26}@anchor{74}
+@anchor{gnat_ugn/the_gnat_compilation_model switches-for-gnatchop}@anchor{5c}@anchor{gnat_ugn/the_gnat_compilation_model id26}@anchor{5d}
 @subsubsection Switches for @code{gnatchop}
 
 
@@ -2957,7 +2738,7 @@ no attempt is made to add the prefix to the GNAT parser executable.
 @end table
 
 @node Examples of gnatchop Usage,,Switches for gnatchop,Renaming Files with gnatchop
-@anchor{gnat_ugn/the_gnat_compilation_model id27}@anchor{75}@anchor{gnat_ugn/the_gnat_compilation_model examples-of-gnatchop-usage}@anchor{76}
+@anchor{gnat_ugn/the_gnat_compilation_model id27}@anchor{5e}@anchor{gnat_ugn/the_gnat_compilation_model examples-of-gnatchop-usage}@anchor{5f}
 @subsubsection Examples of @code{gnatchop} Usage
 
 
@@ -2998,7 +2779,7 @@ be the one that is output, and earlier duplicate occurrences for a given
 unit will be skipped.
 
 @node Configuration Pragmas,Generating Object Files,File Naming Topics and Utilities,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model id28}@anchor{77}@anchor{gnat_ugn/the_gnat_compilation_model configuration-pragmas}@anchor{14}
+@anchor{gnat_ugn/the_gnat_compilation_model id28}@anchor{60}@anchor{gnat_ugn/the_gnat_compilation_model configuration-pragmas}@anchor{25}
 @section Configuration Pragmas
 
 
@@ -3069,7 +2850,6 @@ Overflow_Mode
 Overriding_Renamings
 Partition_Elaboration_Policy
 Persistent_BSS
-Polling
 Prefix_Exception_Messages
 Priority_Specific_Dispatching
 Profile
@@ -3109,7 +2889,7 @@ Wide_Character_Encoding
 @end menu
 
 @node Handling of Configuration Pragmas,The Configuration Pragmas Files,,Configuration Pragmas
-@anchor{gnat_ugn/the_gnat_compilation_model id29}@anchor{78}@anchor{gnat_ugn/the_gnat_compilation_model handling-of-configuration-pragmas}@anchor{56}
+@anchor{gnat_ugn/the_gnat_compilation_model id29}@anchor{61}@anchor{gnat_ugn/the_gnat_compilation_model handling-of-configuration-pragmas}@anchor{3f}
 @subsection Handling of Configuration Pragmas
 
 
@@ -3120,7 +2900,7 @@ all compilations performed in a given compilation environment.
 GNAT also provides the @code{gnatchop} utility to provide an automatic
 way to handle configuration pragmas following the semantics for
 compilations (that is, files with multiple units), described in the RM.
-See @ref{6f,,Operating gnatchop in Compilation Mode} for details.
+See @ref{58,,Operating gnatchop in Compilation Mode} for details.
 However, for most purposes, it will be more convenient to edit the
 @code{gnat.adc} file that contains configuration pragmas directly,
 as described in the following section.
@@ -3150,7 +2930,7 @@ relevant units). It can appear on a subunit only if it has previously
 appeared in the body of spec.
 
 @node The Configuration Pragmas Files,,Handling of Configuration Pragmas,Configuration Pragmas
-@anchor{gnat_ugn/the_gnat_compilation_model the-configuration-pragmas-files}@anchor{79}@anchor{gnat_ugn/the_gnat_compilation_model id30}@anchor{7a}
+@anchor{gnat_ugn/the_gnat_compilation_model the-configuration-pragmas-files}@anchor{62}@anchor{gnat_ugn/the_gnat_compilation_model id30}@anchor{63}
 @subsection The Configuration Pragmas Files
 
 
@@ -3190,14 +2970,18 @@ temporary files that are immediately deleted; it doesn't make sense to
 depend on a file that no longer exists. Such tools include
 @code{gprbuild}, @code{gnatmake}, and @code{gnatcheck}.
 
+By default, configuration pragma files are stored by their absolute paths in
+ALI files. You can use the @code{-gnateb} switch in order to store them by
+their basename instead.
+
 If you are using project file, a separate mechanism is provided using
 project attributes.
 
-@c --Comment:
+@c --Comment
 @c See :ref:`Specifying_Configuration_Pragmas` for more details.
 
 @node Generating Object Files,Source Dependencies,Configuration Pragmas,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model generating-object-files}@anchor{40}@anchor{gnat_ugn/the_gnat_compilation_model id31}@anchor{7b}
+@anchor{gnat_ugn/the_gnat_compilation_model generating-object-files}@anchor{26}@anchor{gnat_ugn/the_gnat_compilation_model id31}@anchor{64}
 @section Generating Object Files
 
 
@@ -3268,7 +3052,7 @@ part of the process of building a program. To compile a file in this
 checking mode, use the @code{-gnatc} switch.
 
 @node Source Dependencies,The Ada Library Information Files,Generating Object Files,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model id32}@anchor{7c}@anchor{gnat_ugn/the_gnat_compilation_model source-dependencies}@anchor{41}
+@anchor{gnat_ugn/the_gnat_compilation_model id32}@anchor{65}@anchor{gnat_ugn/the_gnat_compilation_model source-dependencies}@anchor{27}
 @section Source Dependencies
 
 
@@ -3363,7 +3147,7 @@ recompilations is done automatically when one uses @code{gnatmake}.
 @end itemize
 
 @node The Ada Library Information Files,Binding an Ada Program,Source Dependencies,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model id33}@anchor{7d}@anchor{gnat_ugn/the_gnat_compilation_model the-ada-library-information-files}@anchor{42}
+@anchor{gnat_ugn/the_gnat_compilation_model id33}@anchor{66}@anchor{gnat_ugn/the_gnat_compilation_model the-ada-library-information-files}@anchor{28}
 @section The Ada Library Information Files
 
 
@@ -3431,7 +3215,7 @@ see the source of the body of unit @code{Lib.Writ}, contained in file
 @code{lib-writ.adb} in the GNAT compiler sources.
 
 @node Binding an Ada Program,GNAT and Libraries,The Ada Library Information Files,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model id34}@anchor{7e}@anchor{gnat_ugn/the_gnat_compilation_model binding-an-ada-program}@anchor{43}
+@anchor{gnat_ugn/the_gnat_compilation_model id34}@anchor{67}@anchor{gnat_ugn/the_gnat_compilation_model binding-an-ada-program}@anchor{29}
 @section Binding an Ada Program
 
 
@@ -3467,7 +3251,7 @@ using the object from the main program from the bind step as well as the
 object files for the Ada units of the program.
 
 @node GNAT and Libraries,Conditional Compilation,Binding an Ada Program,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model gnat-and-libraries}@anchor{15}@anchor{gnat_ugn/the_gnat_compilation_model id35}@anchor{7f}
+@anchor{gnat_ugn/the_gnat_compilation_model gnat-and-libraries}@anchor{2a}@anchor{gnat_ugn/the_gnat_compilation_model id35}@anchor{68}
 @section GNAT and Libraries
 
 
@@ -3487,7 +3271,7 @@ Project Manager facility (see the @emph{GNAT_Project_Manager} chapter of the
 @end menu
 
 @node Introduction to Libraries in GNAT,General Ada Libraries,,GNAT and Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model introduction-to-libraries-in-gnat}@anchor{80}@anchor{gnat_ugn/the_gnat_compilation_model id36}@anchor{81}
+@anchor{gnat_ugn/the_gnat_compilation_model introduction-to-libraries-in-gnat}@anchor{69}@anchor{gnat_ugn/the_gnat_compilation_model id36}@anchor{6a}
 @subsection Introduction to Libraries in GNAT
 
 
@@ -3514,7 +3298,7 @@ In the GNAT environment, a library has three types of components:
 Source files,
 
 @item 
-@code{ALI} files (see @ref{42,,The Ada Library Information Files}), and
+@code{ALI} files (see @ref{28,,The Ada Library Information Files}), and
 
 @item 
 Object files, an archive or a shared library.
@@ -3526,7 +3310,7 @@ an external user to make use of the library. That is to say, the specs
 reflecting the library services along with all the units needed to compile
 those specs, which can include generic bodies or any body implementing an
 inlined routine. In the case of @emph{stand-alone libraries} those exposed
-units are called @emph{interface units} (@ref{82,,Stand-alone Ada Libraries}).
+units are called @emph{interface units} (@ref{6b,,Stand-alone Ada Libraries}).
 
 All compilation units comprising an application, including those in a library,
 need to be elaborated in an order partially defined by Ada's semantics. GNAT
@@ -3537,7 +3321,7 @@ library elaboration routine is produced independently of the application(s)
 using the library.
 
 @node General Ada Libraries,Stand-alone Ada Libraries,Introduction to Libraries in GNAT,GNAT and Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model general-ada-libraries}@anchor{83}@anchor{gnat_ugn/the_gnat_compilation_model id37}@anchor{84}
+@anchor{gnat_ugn/the_gnat_compilation_model general-ada-libraries}@anchor{6c}@anchor{gnat_ugn/the_gnat_compilation_model id37}@anchor{6d}
 @subsection General Ada Libraries
 
 
@@ -3549,7 +3333,7 @@ using the library.
 @end menu
 
 @node Building a library,Installing a library,,General Ada Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model building-a-library}@anchor{85}@anchor{gnat_ugn/the_gnat_compilation_model id38}@anchor{86}
+@anchor{gnat_ugn/the_gnat_compilation_model building-a-library}@anchor{6e}@anchor{gnat_ugn/the_gnat_compilation_model id38}@anchor{6f}
 @subsubsection Building a library
 
 
@@ -3631,7 +3415,7 @@ for this task. In special cases where this is not desired, the necessary
 steps are discussed below.
 
 There are various possibilities for compiling the units that make up the
-library: for example with a Makefile (@ref{1f,,Using the GNU make Utility}) or
+library: for example with a Makefile (@ref{70,,Using the GNU make Utility}) or
 with a conventional script. For simple libraries, it is also possible to create
 a dummy main program which depends upon all the packages that comprise the
 interface of the library. This dummy main program can then be given to
@@ -3682,7 +3466,7 @@ or @code{lib@emph{xxx}.so} (or @code{lib@emph{xxx}.dll} on Windows) in order to
 be accessed by the directive @code{-l@emph{xxx}} at link time.
 
 @node Installing a library,Using a library,Building a library,General Ada Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model installing-a-library}@anchor{87}@anchor{gnat_ugn/the_gnat_compilation_model id39}@anchor{88}
+@anchor{gnat_ugn/the_gnat_compilation_model installing-a-library}@anchor{71}@anchor{gnat_ugn/the_gnat_compilation_model id39}@anchor{72}
 @subsubsection Installing a library
 
 
@@ -3697,7 +3481,7 @@ process (see the @emph{Installing a Library with Project Files} section of the
 When project files are not an option, it is also possible, but not recommended,
 to install the library so that the sources needed to use the library are on the
 Ada source path and the ALI files & libraries be on the Ada Object path (see
-@ref{89,,Search Paths and the Run-Time Library (RTL)}. Alternatively, the system
+@ref{73,,Search Paths and the Run-Time Library (RTL)}. Alternatively, the system
 administrator can place general-purpose libraries in the default compiler
 paths, by specifying the libraries' location in the configuration files
 @code{ada_source_path} and @code{ada_object_path}. These configuration files
@@ -3739,7 +3523,7 @@ library must be installed before the GNAT library if it redefines
 any part of it.
 
 @node Using a library,,Installing a library,General Ada Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model using-a-library}@anchor{8a}@anchor{gnat_ugn/the_gnat_compilation_model id40}@anchor{8b}
+@anchor{gnat_ugn/the_gnat_compilation_model using-a-library}@anchor{74}@anchor{gnat_ugn/the_gnat_compilation_model id40}@anchor{75}
 @subsubsection Using a library
 
 
@@ -3778,8 +3562,8 @@ left to the tools having visibility over project dependence information.
 
 In order to use an Ada library manually, you need to make sure that this
 library is on both your source and object path
-(see @ref{89,,Search Paths and the Run-Time Library (RTL)}
-and @ref{8c,,Search Paths for gnatbind}). Furthermore, when the objects are grouped
+(see @ref{73,,Search Paths and the Run-Time Library (RTL)}
+and @ref{76,,Search Paths for gnatbind}). Furthermore, when the objects are grouped
 in an archive or a shared library, you need to specify the desired
 library at link time.
 
@@ -3833,7 +3617,7 @@ in the directory @code{share/examples/gnat/plugins} within the GNAT
 install area.
 
 @node Stand-alone Ada Libraries,Rebuilding the GNAT Run-Time Library,General Ada Libraries,GNAT and Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model stand-alone-ada-libraries}@anchor{82}@anchor{gnat_ugn/the_gnat_compilation_model id41}@anchor{8d}
+@anchor{gnat_ugn/the_gnat_compilation_model stand-alone-ada-libraries}@anchor{6b}@anchor{gnat_ugn/the_gnat_compilation_model id41}@anchor{77}
 @subsection Stand-alone Ada Libraries
 
 
@@ -3848,7 +3632,7 @@ install area.
 @end menu
 
 @node Introduction to Stand-alone Libraries,Building a Stand-alone Library,,Stand-alone Ada Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model introduction-to-stand-alone-libraries}@anchor{8e}@anchor{gnat_ugn/the_gnat_compilation_model id42}@anchor{8f}
+@anchor{gnat_ugn/the_gnat_compilation_model introduction-to-stand-alone-libraries}@anchor{78}@anchor{gnat_ugn/the_gnat_compilation_model id42}@anchor{79}
 @subsubsection Introduction to Stand-alone Libraries
 
 
@@ -3883,7 +3667,7 @@ Stand-alone libraries are also well suited to be used in an executable whose
 main routine is not written in Ada.
 
 @node Building a Stand-alone Library,Creating a Stand-alone Library to be used in a non-Ada context,Introduction to Stand-alone Libraries,Stand-alone Ada Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model id43}@anchor{90}@anchor{gnat_ugn/the_gnat_compilation_model building-a-stand-alone-library}@anchor{91}
+@anchor{gnat_ugn/the_gnat_compilation_model id43}@anchor{7a}@anchor{gnat_ugn/the_gnat_compilation_model building-a-stand-alone-library}@anchor{7b}
 @subsubsection Building a Stand-alone Library
 
 
@@ -4002,10 +3786,10 @@ read-only.
 @end itemize
 
 Using SALs is not different from using other libraries
-(see @ref{8a,,Using a library}).
+(see @ref{74,,Using a library}).
 
 @node Creating a Stand-alone Library to be used in a non-Ada context,Restrictions in Stand-alone Libraries,Building a Stand-alone Library,Stand-alone Ada Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model creating-a-stand-alone-library-to-be-used-in-a-non-ada-context}@anchor{92}@anchor{gnat_ugn/the_gnat_compilation_model id44}@anchor{93}
+@anchor{gnat_ugn/the_gnat_compilation_model creating-a-stand-alone-library-to-be-used-in-a-non-ada-context}@anchor{7c}@anchor{gnat_ugn/the_gnat_compilation_model id44}@anchor{7d}
 @subsubsection Creating a Stand-alone Library to be used in a non-Ada context
 
 
@@ -4090,7 +3874,7 @@ must be ensured at the application level using a specific operating
 system services like a mutex or a critical-section.
 
 @node Restrictions in Stand-alone Libraries,,Creating a Stand-alone Library to be used in a non-Ada context,Stand-alone Ada Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model id45}@anchor{94}@anchor{gnat_ugn/the_gnat_compilation_model restrictions-in-stand-alone-libraries}@anchor{95}
+@anchor{gnat_ugn/the_gnat_compilation_model id45}@anchor{7e}@anchor{gnat_ugn/the_gnat_compilation_model restrictions-in-stand-alone-libraries}@anchor{7f}
 @subsubsection Restrictions in Stand-alone Libraries
 
 
@@ -4136,7 +3920,7 @@ In practice these attributes are rarely used, so this is unlikely
 to be a consideration.
 
 @node Rebuilding the GNAT Run-Time Library,,Stand-alone Ada Libraries,GNAT and Libraries
-@anchor{gnat_ugn/the_gnat_compilation_model id46}@anchor{96}@anchor{gnat_ugn/the_gnat_compilation_model rebuilding-the-gnat-run-time-library}@anchor{97}
+@anchor{gnat_ugn/the_gnat_compilation_model id46}@anchor{80}@anchor{gnat_ugn/the_gnat_compilation_model rebuilding-the-gnat-run-time-library}@anchor{81}
 @subsection Rebuilding the GNAT Run-Time Library
 
 
@@ -4150,10 +3934,9 @@ to be a consideration.
 @geindex Run-Time Library
 @geindex rebuilding
 
-It may be useful to recompile the GNAT library in various contexts, the
-most important one being the use of partition-wide configuration pragmas
-such as @code{Normalize_Scalars}. A special Makefile called
-@code{Makefile.adalib} is provided to that effect and can be found in
+It may be useful to recompile the GNAT library in various debugging or
+experimentation contexts. A project file called
+@code{libada.gpr} is provided to that effect and can be found in
 the directory containing the GNAT library. The location of this
 directory depends on the way the GNAT environment has been installed and can
 be determined by means of the command:
@@ -4162,15 +3945,18 @@ be determined by means of the command:
 $ gnatls -v
 @end example
 
-The last entry in the object search path usually contains the
-gnat library. This Makefile contains its own documentation and in
-particular the set of instructions needed to rebuild a new library and
-to use it.
+The last entry in the source search path usually contains the
+gnat library (the @code{adainclude} directory). This project file contains its
+own documentation and in particular the set of instructions needed to rebuild a
+new library and to use it.
+
+Note that rebuilding the GNAT Run-Time is only recommended for temporary
+experiments or debugging, and is not supported.
 
 @geindex Conditional compilation
 
 @node Conditional Compilation,Mixed Language Programming,GNAT and Libraries,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model id47}@anchor{98}@anchor{gnat_ugn/the_gnat_compilation_model conditional-compilation}@anchor{16}
+@anchor{gnat_ugn/the_gnat_compilation_model id47}@anchor{82}@anchor{gnat_ugn/the_gnat_compilation_model conditional-compilation}@anchor{2b}
 @section Conditional Compilation
 
 
@@ -4187,7 +3973,7 @@ gnatprep preprocessor utility.
 @end menu
 
 @node Modeling Conditional Compilation in Ada,Preprocessing with gnatprep,,Conditional Compilation
-@anchor{gnat_ugn/the_gnat_compilation_model modeling-conditional-compilation-in-ada}@anchor{99}@anchor{gnat_ugn/the_gnat_compilation_model id48}@anchor{9a}
+@anchor{gnat_ugn/the_gnat_compilation_model modeling-conditional-compilation-in-ada}@anchor{83}@anchor{gnat_ugn/the_gnat_compilation_model id48}@anchor{84}
 @subsection Modeling Conditional Compilation in Ada
 
 
@@ -4238,7 +4024,7 @@ be achieved using Ada in general, and GNAT in particular.
 @end menu
 
 @node Use of Boolean Constants,Debugging - A Special Case,,Modeling Conditional Compilation in Ada
-@anchor{gnat_ugn/the_gnat_compilation_model id49}@anchor{9b}@anchor{gnat_ugn/the_gnat_compilation_model use-of-boolean-constants}@anchor{9c}
+@anchor{gnat_ugn/the_gnat_compilation_model id49}@anchor{85}@anchor{gnat_ugn/the_gnat_compilation_model use-of-boolean-constants}@anchor{86}
 @subsubsection Use of Boolean Constants
 
 
@@ -4282,7 +4068,7 @@ Then any other unit requiring conditional compilation can do a @emph{with}
 of @code{Config} to make the constants visible.
 
 @node Debugging - A Special Case,Conditionalizing Declarations,Use of Boolean Constants,Modeling Conditional Compilation in Ada
-@anchor{gnat_ugn/the_gnat_compilation_model debugging-a-special-case}@anchor{9d}@anchor{gnat_ugn/the_gnat_compilation_model id50}@anchor{9e}
+@anchor{gnat_ugn/the_gnat_compilation_model debugging-a-special-case}@anchor{87}@anchor{gnat_ugn/the_gnat_compilation_model id50}@anchor{88}
 @subsubsection Debugging - A Special Case
 
 
@@ -4395,7 +4181,7 @@ end if;
 @end example
 
 @node Conditionalizing Declarations,Use of Alternative Implementations,Debugging - A Special Case,Modeling Conditional Compilation in Ada
-@anchor{gnat_ugn/the_gnat_compilation_model conditionalizing-declarations}@anchor{9f}@anchor{gnat_ugn/the_gnat_compilation_model id51}@anchor{a0}
+@anchor{gnat_ugn/the_gnat_compilation_model conditionalizing-declarations}@anchor{89}@anchor{gnat_ugn/the_gnat_compilation_model id51}@anchor{8a}
 @subsubsection Conditionalizing Declarations
 
 
@@ -4460,7 +4246,7 @@ constant was introduced as @code{System.Default_Bit_Order}, so you do not
 need to define this one yourself).
 
 @node Use of Alternative Implementations,Preprocessing,Conditionalizing Declarations,Modeling Conditional Compilation in Ada
-@anchor{gnat_ugn/the_gnat_compilation_model use-of-alternative-implementations}@anchor{a1}@anchor{gnat_ugn/the_gnat_compilation_model id52}@anchor{a2}
+@anchor{gnat_ugn/the_gnat_compilation_model use-of-alternative-implementations}@anchor{8b}@anchor{gnat_ugn/the_gnat_compilation_model id52}@anchor{8c}
 @subsubsection Use of Alternative Implementations
 
 
@@ -4594,7 +4380,7 @@ The same idea can also be implemented using tagged types and dispatching
 calls.
 
 @node Preprocessing,,Use of Alternative Implementations,Modeling Conditional Compilation in Ada
-@anchor{gnat_ugn/the_gnat_compilation_model preprocessing}@anchor{a3}@anchor{gnat_ugn/the_gnat_compilation_model id53}@anchor{a4}
+@anchor{gnat_ugn/the_gnat_compilation_model preprocessing}@anchor{8d}@anchor{gnat_ugn/the_gnat_compilation_model id53}@anchor{8e}
 @subsubsection Preprocessing
 
 
@@ -4617,7 +4403,7 @@ The preprocessor may be used in two separate modes. It can be used quite
 separately from the compiler, to generate a separate output source file
 that is then fed to the compiler as a separate step. This is the
 @code{gnatprep} utility, whose use is fully described in
-@ref{17,,Preprocessing with gnatprep}.
+@ref{8f,,Preprocessing with gnatprep}.
 
 The preprocessing language allows such constructs as
 
@@ -4637,10 +4423,10 @@ often more convenient. In this approach the preprocessing is integrated into
 the compilation process. The compiler is given the preprocessor input which
 includes @code{#if} lines etc, and then the compiler carries out the
 preprocessing internally and processes the resulting output.
-For more details on this approach, see @ref{18,,Integrated Preprocessing}.
+For more details on this approach, see @ref{90,,Integrated Preprocessing}.
 
 @node Preprocessing with gnatprep,Integrated Preprocessing,Modeling Conditional Compilation in Ada,Conditional Compilation
-@anchor{gnat_ugn/the_gnat_compilation_model id54}@anchor{a5}@anchor{gnat_ugn/the_gnat_compilation_model preprocessing-with-gnatprep}@anchor{17}
+@anchor{gnat_ugn/the_gnat_compilation_model id54}@anchor{91}@anchor{gnat_ugn/the_gnat_compilation_model preprocessing-with-gnatprep}@anchor{8f}
 @subsection Preprocessing with @code{gnatprep}
 
 
@@ -4653,7 +4439,7 @@ preprocessing.
 Although designed for use with GNAT, @code{gnatprep} does not depend on any
 special GNAT features.
 For further discussion of conditional compilation in general, see
-@ref{16,,Conditional Compilation}.
+@ref{2b,,Conditional Compilation}.
 
 @menu
 * Preprocessing Symbols:: 
@@ -4665,7 +4451,7 @@ For further discussion of conditional compilation in general, see
 @end menu
 
 @node Preprocessing Symbols,Using gnatprep,,Preprocessing with gnatprep
-@anchor{gnat_ugn/the_gnat_compilation_model id55}@anchor{a6}@anchor{gnat_ugn/the_gnat_compilation_model preprocessing-symbols}@anchor{a7}
+@anchor{gnat_ugn/the_gnat_compilation_model id55}@anchor{92}@anchor{gnat_ugn/the_gnat_compilation_model preprocessing-symbols}@anchor{93}
 @subsubsection Preprocessing Symbols
 
 
@@ -4675,7 +4461,7 @@ normal Ada (case-insensitive) rules for its syntax, with the restriction that
 all characters need to be in the ASCII set (no accented letters).
 
 @node Using gnatprep,Switches for gnatprep,Preprocessing Symbols,Preprocessing with gnatprep
-@anchor{gnat_ugn/the_gnat_compilation_model using-gnatprep}@anchor{a8}@anchor{gnat_ugn/the_gnat_compilation_model id56}@anchor{a9}
+@anchor{gnat_ugn/the_gnat_compilation_model using-gnatprep}@anchor{94}@anchor{gnat_ugn/the_gnat_compilation_model id56}@anchor{95}
 @subsubsection Using @code{gnatprep}
 
 
@@ -4733,7 +4519,7 @@ optional, and can be replaced by the use of the @code{-D} switch.
 @end itemize
 
 @node Switches for gnatprep,Form of Definitions File,Using gnatprep,Preprocessing with gnatprep
-@anchor{gnat_ugn/the_gnat_compilation_model switches-for-gnatprep}@anchor{aa}@anchor{gnat_ugn/the_gnat_compilation_model id57}@anchor{ab}
+@anchor{gnat_ugn/the_gnat_compilation_model switches-for-gnatprep}@anchor{96}@anchor{gnat_ugn/the_gnat_compilation_model id57}@anchor{97}
 @subsubsection Switches for @code{gnatprep}
 
 
@@ -4884,7 +4670,7 @@ deleted lines are completely removed from the output, unless -r is
 specified, in which case -b is assumed.
 
 @node Form of Definitions File,Form of Input Text for gnatprep,Switches for gnatprep,Preprocessing with gnatprep
-@anchor{gnat_ugn/the_gnat_compilation_model form-of-definitions-file}@anchor{ac}@anchor{gnat_ugn/the_gnat_compilation_model id58}@anchor{ad}
+@anchor{gnat_ugn/the_gnat_compilation_model form-of-definitions-file}@anchor{98}@anchor{gnat_ugn/the_gnat_compilation_model id58}@anchor{99}
 @subsubsection Form of Definitions File
 
 
@@ -4914,7 +4700,7 @@ the usual @code{--},
 and comments may be added to the definitions lines.
 
 @node Form of Input Text for gnatprep,,Form of Definitions File,Preprocessing with gnatprep
-@anchor{gnat_ugn/the_gnat_compilation_model id59}@anchor{ae}@anchor{gnat_ugn/the_gnat_compilation_model form-of-input-text-for-gnatprep}@anchor{af}
+@anchor{gnat_ugn/the_gnat_compilation_model id59}@anchor{9a}@anchor{gnat_ugn/the_gnat_compilation_model form-of-input-text-for-gnatprep}@anchor{9b}
 @subsubsection Form of Input Text for @code{gnatprep}
 
 
@@ -5046,7 +4832,7 @@ Header : String := $XYZ;
 and then the substitution will occur as desired.
 
 @node Integrated Preprocessing,,Preprocessing with gnatprep,Conditional Compilation
-@anchor{gnat_ugn/the_gnat_compilation_model id60}@anchor{b0}@anchor{gnat_ugn/the_gnat_compilation_model integrated-preprocessing}@anchor{18}
+@anchor{gnat_ugn/the_gnat_compilation_model id60}@anchor{9c}@anchor{gnat_ugn/the_gnat_compilation_model integrated-preprocessing}@anchor{90}
 @subsection Integrated Preprocessing
 
 
@@ -5107,7 +4893,7 @@ because @code{gnatmake} cannot compute the checksum of the source after
 preprocessing.
 
 The actual preprocessing function is described in detail in
-@ref{17,,Preprocessing with gnatprep}. This section explains the switches
+@ref{8f,,Preprocessing with gnatprep}. This section explains the switches
 that relate to integrated preprocessing.
 
 @geindex -gnatep (gcc)
@@ -5206,7 +4992,7 @@ lines starting with the character '*'.
 
 After the file name or '*', an optional literal string specifies the name of
 the definition file to be used for preprocessing
-(@ref{ac,,Form of Definitions File}). The definition files are found by the
+(@ref{98,,Form of Definitions File}). The definition files are found by the
 compiler in one of the source directories. In some cases, when compiling
 a source in a directory other than the current directory, if the definition
 file is in the current directory, it may be necessary to add the current
@@ -5298,7 +5084,7 @@ the output file will be @code{foo.adb.prep}.
 @end table
 
 @node Mixed Language Programming,GNAT and Other Compilation Models,Conditional Compilation,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model mixed-language-programming}@anchor{44}@anchor{gnat_ugn/the_gnat_compilation_model id61}@anchor{b1}
+@anchor{gnat_ugn/the_gnat_compilation_model mixed-language-programming}@anchor{2c}@anchor{gnat_ugn/the_gnat_compilation_model id61}@anchor{9d}
 @section Mixed Language Programming
 
 
@@ -5317,7 +5103,7 @@ with a focus on combining Ada with C or C++.
 @end menu
 
 @node Interfacing to C,Calling Conventions,,Mixed Language Programming
-@anchor{gnat_ugn/the_gnat_compilation_model interfacing-to-c}@anchor{b2}@anchor{gnat_ugn/the_gnat_compilation_model id62}@anchor{b3}
+@anchor{gnat_ugn/the_gnat_compilation_model interfacing-to-c}@anchor{9e}@anchor{gnat_ugn/the_gnat_compilation_model id62}@anchor{9f}
 @subsection Interfacing to C
 
 
@@ -5428,7 +5214,7 @@ $ gnatmake my_main.adb -largs file1.o file2.o
 If the main program is in a language other than Ada, then you may have
 more than one entry point into the Ada subsystem. You must use a special
 binder option to generate callable routines that initialize and
-finalize the Ada units (@ref{b4,,Binding with Non-Ada Main Programs}).
+finalize the Ada units (@ref{a0,,Binding with Non-Ada Main Programs}).
 Calls to the initialization and finalization routines must be inserted
 in the main program, or some other appropriate point in the code. The
 call to initialize the Ada units must occur before the first Ada
@@ -5544,7 +5330,7 @@ GNAT linker not to include the standard startup objects by passing the
 @code{-nostartfiles} switch to @code{gnatlink}.
 
 @node Calling Conventions,Building Mixed Ada and C++ Programs,Interfacing to C,Mixed Language Programming
-@anchor{gnat_ugn/the_gnat_compilation_model calling-conventions}@anchor{b5}@anchor{gnat_ugn/the_gnat_compilation_model id63}@anchor{b6}
+@anchor{gnat_ugn/the_gnat_compilation_model calling-conventions}@anchor{a1}@anchor{gnat_ugn/the_gnat_compilation_model id63}@anchor{a2}
 @subsection Calling Conventions
 
 
@@ -5868,7 +5654,7 @@ identifier (for example in an @code{Import} pragma) with the same
 meaning as Fortran.
 
 @node Building Mixed Ada and C++ Programs,Generating Ada Bindings for C and C++ headers,Calling Conventions,Mixed Language Programming
-@anchor{gnat_ugn/the_gnat_compilation_model id64}@anchor{b7}@anchor{gnat_ugn/the_gnat_compilation_model building-mixed-ada-and-c-programs}@anchor{b8}
+@anchor{gnat_ugn/the_gnat_compilation_model id64}@anchor{a3}@anchor{gnat_ugn/the_gnat_compilation_model building-mixed-ada-and-c-programs}@anchor{a4}
 @subsection Building Mixed Ada and C++ Programs
 
 
@@ -5886,7 +5672,7 @@ challenge.  This section gives a few hints that should make this task easier.
 @end menu
 
 @node Interfacing to C++,Linking a Mixed C++ & Ada Program,,Building Mixed Ada and C++ Programs
-@anchor{gnat_ugn/the_gnat_compilation_model id65}@anchor{b9}@anchor{gnat_ugn/the_gnat_compilation_model id66}@anchor{ba}
+@anchor{gnat_ugn/the_gnat_compilation_model id65}@anchor{a5}@anchor{gnat_ugn/the_gnat_compilation_model id66}@anchor{a6}
 @subsubsection Interfacing to C++
 
 
@@ -5898,7 +5684,7 @@ Interfacing can be done at 3 levels: simple data, subprograms, and
 classes. In the first two cases, GNAT offers a specific @code{Convention C_Plus_Plus}
 (or @code{CPP}) that behaves exactly like @code{Convention C}.
 Usually, C++ mangles the names of subprograms. To generate proper mangled
-names automatically, see @ref{19,,Generating Ada Bindings for C and C++ headers}).
+names automatically, see @ref{a7,,Generating Ada Bindings for C and C++ headers}).
 This problem can also be addressed manually in two ways:
 
 
@@ -5917,7 +5703,7 @@ Interfacing at the class level can be achieved by using the GNAT specific
 pragmas such as @code{CPP_Constructor}.  See the @cite{GNAT_Reference_Manual} for additional information.
 
 @node Linking a Mixed C++ & Ada Program,A Simple Example,Interfacing to C++,Building Mixed Ada and C++ Programs
-@anchor{gnat_ugn/the_gnat_compilation_model linking-a-mixed-c-ada-program}@anchor{bb}@anchor{gnat_ugn/the_gnat_compilation_model linking-a-mixed-c-and-ada-program}@anchor{bc}
+@anchor{gnat_ugn/the_gnat_compilation_model linking-a-mixed-c-ada-program}@anchor{a8}@anchor{gnat_ugn/the_gnat_compilation_model linking-a-mixed-c-and-ada-program}@anchor{a9}
 @subsubsection Linking a Mixed C++ & Ada Program
 
 
@@ -6032,7 +5818,7 @@ which has a large knowledge base and knows how to link Ada and C++ code
 together automatically in most cases.
 
 @node A Simple Example,Interfacing with C++ constructors,Linking a Mixed C++ & Ada Program,Building Mixed Ada and C++ Programs
-@anchor{gnat_ugn/the_gnat_compilation_model id67}@anchor{bd}@anchor{gnat_ugn/the_gnat_compilation_model a-simple-example}@anchor{be}
+@anchor{gnat_ugn/the_gnat_compilation_model id67}@anchor{aa}@anchor{gnat_ugn/the_gnat_compilation_model a-simple-example}@anchor{ab}
 @subsubsection A Simple Example
 
 
@@ -6040,7 +5826,7 @@ The following example, provided as part of the GNAT examples, shows how
 to achieve procedural interfacing between Ada and C++ in both
 directions. The C++ class A has two methods. The first method is exported
 to Ada by the means of an extern C wrapper function. The second method
-calls an Ada subprogram. On the Ada side, The C++ calls are modelled by
+calls an Ada subprogram. On the Ada side, the C++ calls are modelled by
 a limited record with a layout comparable to the C++ class. The Ada
 subprogram, in turn, calls the C++ method. So, starting from the C++
 main program, the process passes back and forth between the two
@@ -6161,7 +5947,7 @@ end Simple_Cpp_Interface;
 @end example
 
 @node Interfacing with C++ constructors,Interfacing with C++ at the Class Level,A Simple Example,Building Mixed Ada and C++ Programs
-@anchor{gnat_ugn/the_gnat_compilation_model id68}@anchor{bf}@anchor{gnat_ugn/the_gnat_compilation_model interfacing-with-c-constructors}@anchor{c0}
+@anchor{gnat_ugn/the_gnat_compilation_model id68}@anchor{ac}@anchor{gnat_ugn/the_gnat_compilation_model interfacing-with-c-constructors}@anchor{ad}
 @subsubsection Interfacing with C++ constructors
 
 
@@ -6188,8 +5974,8 @@ public:
 
 For this purpose we can write the following package spec (further
 information on how to build this spec is available in
-@ref{c1,,Interfacing with C++ at the Class Level} and
-@ref{19,,Generating Ada Bindings for C and C++ headers}).
+@ref{ae,,Interfacing with C++ at the Class Level} and
+@ref{a7,,Generating Ada Bindings for C and C++ headers}).
 
 @example
 with Interfaces.C; use Interfaces.C;
@@ -6358,7 +6144,7 @@ by means of a limited aggregate. Any further action associated with
 the constructor can be placed inside the construct.
 
 @node Interfacing with C++ at the Class Level,,Interfacing with C++ constructors,Building Mixed Ada and C++ Programs
-@anchor{gnat_ugn/the_gnat_compilation_model interfacing-with-c-at-the-class-level}@anchor{c1}@anchor{gnat_ugn/the_gnat_compilation_model id69}@anchor{c2}
+@anchor{gnat_ugn/the_gnat_compilation_model interfacing-with-c-at-the-class-level}@anchor{ae}@anchor{gnat_ugn/the_gnat_compilation_model id69}@anchor{af}
 @subsubsection Interfacing with C++ at the Class Level
 
 
@@ -6454,7 +6240,7 @@ package Animals is
 
   type Dog is new Animal and Carnivore and Domestic with record
     Tooth_Count : Natural;
-    Owner       : String (1 .. 30);
+    Owner       : Chars_Ptr;
   end record;
   pragma Import (C_Plus_Plus, Dog);
 
@@ -6604,7 +6390,7 @@ int main ()
 @end example
 
 @node Generating Ada Bindings for C and C++ headers,Generating C Headers for Ada Specifications,Building Mixed Ada and C++ Programs,Mixed Language Programming
-@anchor{gnat_ugn/the_gnat_compilation_model id70}@anchor{c3}@anchor{gnat_ugn/the_gnat_compilation_model generating-ada-bindings-for-c-and-c-headers}@anchor{19}
+@anchor{gnat_ugn/the_gnat_compilation_model id70}@anchor{b0}@anchor{gnat_ugn/the_gnat_compilation_model generating-ada-bindings-for-c-and-c-headers}@anchor{a7}
 @subsection Generating Ada Bindings for C and C++ headers
 
 
@@ -6643,8 +6429,9 @@ identifiers with identical name (except casing) will generate compilation
 errors (e.g. @code{shm_get} vs @code{SHM_GET}).
 @end itemize
 
-The code generated is using the Ada 2005 syntax, which makes it
-easier to interface with other languages than previous versions of Ada.
+The code is generated using Ada 2012 syntax, which makes it easier to interface
+with other languages. In most cases you can still use the generated binding
+even if your code is compiled using earlier versions of Ada (e.g. @code{-gnat95}).
 
 @menu
 * Running the Binding Generator:: 
@@ -6654,7 +6441,7 @@ easier to interface with other languages than previous versions of Ada.
 @end menu
 
 @node Running the Binding Generator,Generating Bindings for C++ Headers,,Generating Ada Bindings for C and C++ headers
-@anchor{gnat_ugn/the_gnat_compilation_model id71}@anchor{c4}@anchor{gnat_ugn/the_gnat_compilation_model running-the-binding-generator}@anchor{c5}
+@anchor{gnat_ugn/the_gnat_compilation_model id71}@anchor{b1}@anchor{gnat_ugn/the_gnat_compilation_model running-the-binding-generator}@anchor{b2}
 @subsubsection Running the Binding Generator
 
 
@@ -6665,7 +6452,7 @@ header files needed by these files transitively. For example:
 
 @example
 $ g++ -c -fdump-ada-spec -C /usr/include/time.h
-$ gcc -c -gnat05 *.ads
+$ gcc -c *.ads
 @end example
 
 will generate, under GNU/Linux, the following files: @code{time_h.ads},
@@ -6748,7 +6535,7 @@ $ g++ -c -fdump-ada-spec readline1.h
 @end example
 
 @node Generating Bindings for C++ Headers,Switches,Running the Binding Generator,Generating Ada Bindings for C and C++ headers
-@anchor{gnat_ugn/the_gnat_compilation_model id72}@anchor{c6}@anchor{gnat_ugn/the_gnat_compilation_model generating-bindings-for-c-headers}@anchor{c7}
+@anchor{gnat_ugn/the_gnat_compilation_model id72}@anchor{b3}@anchor{gnat_ugn/the_gnat_compilation_model generating-bindings-for-c-headers}@anchor{b4}
 @subsubsection Generating Bindings for C++ Headers
 
 
@@ -6849,7 +6636,7 @@ use Class_Dog;
 @end example
 
 @node Switches,,Generating Bindings for C++ Headers,Generating Ada Bindings for C and C++ headers
-@anchor{gnat_ugn/the_gnat_compilation_model switches}@anchor{c8}@anchor{gnat_ugn/the_gnat_compilation_model switches-for-ada-binding-generation}@anchor{c9}
+@anchor{gnat_ugn/the_gnat_compilation_model switches}@anchor{b5}@anchor{gnat_ugn/the_gnat_compilation_model switches-for-ada-binding-generation}@anchor{b6}
 @subsubsection Switches
 
 
@@ -6897,7 +6684,7 @@ Extract comments from headers and generate Ada comments in the Ada spec files.
 @end table
 
 @node Generating C Headers for Ada Specifications,,Generating Ada Bindings for C and C++ headers,Mixed Language Programming
-@anchor{gnat_ugn/the_gnat_compilation_model generating-c-headers-for-ada-specifications}@anchor{ca}@anchor{gnat_ugn/the_gnat_compilation_model id73}@anchor{cb}
+@anchor{gnat_ugn/the_gnat_compilation_model generating-c-headers-for-ada-specifications}@anchor{b7}@anchor{gnat_ugn/the_gnat_compilation_model id73}@anchor{b8}
 @subsection Generating C Headers for Ada Specifications
 
 
@@ -6940,7 +6727,7 @@ Subprogram declarations
 @end menu
 
 @node Running the C Header Generator,,,Generating C Headers for Ada Specifications
-@anchor{gnat_ugn/the_gnat_compilation_model running-the-c-header-generator}@anchor{cc}
+@anchor{gnat_ugn/the_gnat_compilation_model running-the-c-header-generator}@anchor{b9}
 @subsubsection Running the C Header Generator
 
 
@@ -7008,7 +6795,7 @@ You can then @code{include} @code{pack1.h} from a C source file and use the type
 call subprograms, reference objects, and constants.
 
 @node GNAT and Other Compilation Models,Using GNAT Files with External Tools,Mixed Language Programming,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model id74}@anchor{cd}@anchor{gnat_ugn/the_gnat_compilation_model gnat-and-other-compilation-models}@anchor{45}
+@anchor{gnat_ugn/the_gnat_compilation_model id74}@anchor{ba}@anchor{gnat_ugn/the_gnat_compilation_model gnat-and-other-compilation-models}@anchor{2d}
 @section GNAT and Other Compilation Models
 
 
@@ -7024,7 +6811,7 @@ used for Ada 83.
 @end menu
 
 @node Comparison between GNAT and C/C++ Compilation Models,Comparison between GNAT and Conventional Ada Library Models,,GNAT and Other Compilation Models
-@anchor{gnat_ugn/the_gnat_compilation_model comparison-between-gnat-and-c-c-compilation-models}@anchor{ce}@anchor{gnat_ugn/the_gnat_compilation_model id75}@anchor{cf}
+@anchor{gnat_ugn/the_gnat_compilation_model comparison-between-gnat-and-c-c-compilation-models}@anchor{bb}@anchor{gnat_ugn/the_gnat_compilation_model id75}@anchor{bc}
 @subsection Comparison between GNAT and C/C++ Compilation Models
 
 
@@ -7058,7 +6845,7 @@ elaboration, a C++ compiler would simply construct a program that
 malfunctioned at run time.
 
 @node Comparison between GNAT and Conventional Ada Library Models,,Comparison between GNAT and C/C++ Compilation Models,GNAT and Other Compilation Models
-@anchor{gnat_ugn/the_gnat_compilation_model comparison-between-gnat-and-conventional-ada-library-models}@anchor{d0}@anchor{gnat_ugn/the_gnat_compilation_model id76}@anchor{d1}
+@anchor{gnat_ugn/the_gnat_compilation_model comparison-between-gnat-and-conventional-ada-library-models}@anchor{bd}@anchor{gnat_ugn/the_gnat_compilation_model id76}@anchor{be}
 @subsection Comparison between GNAT and Conventional Ada Library Models
 
 
@@ -7126,7 +6913,7 @@ of rules saying what source files must be present when a file is
 compiled.
 
 @node Using GNAT Files with External Tools,,GNAT and Other Compilation Models,The GNAT Compilation Model
-@anchor{gnat_ugn/the_gnat_compilation_model using-gnat-files-with-external-tools}@anchor{1a}@anchor{gnat_ugn/the_gnat_compilation_model id77}@anchor{d2}
+@anchor{gnat_ugn/the_gnat_compilation_model using-gnat-files-with-external-tools}@anchor{2e}@anchor{gnat_ugn/the_gnat_compilation_model id77}@anchor{bf}
 @section Using GNAT Files with External Tools
 
 
@@ -7140,7 +6927,7 @@ used with tools designed for other languages.
 @end menu
 
 @node Using Other Utility Programs with GNAT,The External Symbol Naming Scheme of GNAT,,Using GNAT Files with External Tools
-@anchor{gnat_ugn/the_gnat_compilation_model using-other-utility-programs-with-gnat}@anchor{d3}@anchor{gnat_ugn/the_gnat_compilation_model id78}@anchor{d4}
+@anchor{gnat_ugn/the_gnat_compilation_model using-other-utility-programs-with-gnat}@anchor{c0}@anchor{gnat_ugn/the_gnat_compilation_model id78}@anchor{c1}
 @subsection Using Other Utility Programs with GNAT
 
 
@@ -7155,7 +6942,7 @@ gprof (a profiling program), gdb (the FSF debugger), and utilities such
 as Purify.
 
 @node The External Symbol Naming Scheme of GNAT,,Using Other Utility Programs with GNAT,Using GNAT Files with External Tools
-@anchor{gnat_ugn/the_gnat_compilation_model the-external-symbol-naming-scheme-of-gnat}@anchor{d5}@anchor{gnat_ugn/the_gnat_compilation_model id79}@anchor{d6}
+@anchor{gnat_ugn/the_gnat_compilation_model the-external-symbol-naming-scheme-of-gnat}@anchor{c2}@anchor{gnat_ugn/the_gnat_compilation_model id79}@anchor{c3}
 @subsection The External Symbol Naming Scheme of GNAT
 
 
@@ -7214,23 +7001,23 @@ the external name of this procedure will be @code{_ada_hello}.
 @c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit
 
 @node Building Executable Programs with GNAT,GNAT Utility Programs,The GNAT Compilation Model,Top
-@anchor{gnat_ugn/building_executable_programs_with_gnat building-executable-programs-with-gnat}@anchor{a}@anchor{gnat_ugn/building_executable_programs_with_gnat doc}@anchor{d7}@anchor{gnat_ugn/building_executable_programs_with_gnat id1}@anchor{d8}
+@anchor{gnat_ugn/building_executable_programs_with_gnat building-executable-programs-with-gnat}@anchor{a}@anchor{gnat_ugn/building_executable_programs_with_gnat doc}@anchor{c4}@anchor{gnat_ugn/building_executable_programs_with_gnat id1}@anchor{c5}
 @chapter Building Executable Programs with GNAT
 
 
 This chapter describes first the gnatmake tool
-(@ref{1b,,Building with gnatmake}),
+(@ref{c6,,Building with gnatmake}),
 which automatically determines the set of sources
 needed by an Ada compilation unit and executes the necessary
 (re)compilations, binding and linking.
 It also explains how to use each tool individually: the
-compiler (gcc, see @ref{1c,,Compiling with gcc}),
-binder (gnatbind, see @ref{1d,,Binding with gnatbind}),
-and linker (gnatlink, see @ref{1e,,Linking with gnatlink})
+compiler (gcc, see @ref{c7,,Compiling with gcc}),
+binder (gnatbind, see @ref{c8,,Binding with gnatbind}),
+and linker (gnatlink, see @ref{c9,,Linking with gnatlink})
 to build executable programs.
 Finally, this chapter provides examples of
 how to make use of the general GNU make mechanism
-in a GNAT context (see @ref{1f,,Using the GNU make Utility}).
+in a GNAT context (see @ref{70,,Using the GNU make Utility}).
 
 
 @menu
@@ -7245,7 +7032,7 @@ in a GNAT context (see @ref{1f,,Using the GNU make Utility}).
 @end menu
 
 @node Building with gnatmake,Compiling with gcc,,Building Executable Programs with GNAT
-@anchor{gnat_ugn/building_executable_programs_with_gnat the-gnat-make-program-gnatmake}@anchor{1b}@anchor{gnat_ugn/building_executable_programs_with_gnat building-with-gnatmake}@anchor{d9}
+@anchor{gnat_ugn/building_executable_programs_with_gnat the-gnat-make-program-gnatmake}@anchor{c6}@anchor{gnat_ugn/building_executable_programs_with_gnat building-with-gnatmake}@anchor{ca}
 @section Building with @code{gnatmake}
 
 
@@ -7309,7 +7096,7 @@ to @code{gnatmake}.
 @end menu
 
 @node Running gnatmake,Switches for gnatmake,,Building with gnatmake
-@anchor{gnat_ugn/building_executable_programs_with_gnat running-gnatmake}@anchor{da}@anchor{gnat_ugn/building_executable_programs_with_gnat id2}@anchor{db}
+@anchor{gnat_ugn/building_executable_programs_with_gnat running-gnatmake}@anchor{cb}@anchor{gnat_ugn/building_executable_programs_with_gnat id2}@anchor{cc}
 @subsection Running @code{gnatmake}
 
 
@@ -7337,14 +7124,14 @@ be searched for in the specified directory only. Otherwise, the input
 source file will first be searched in the directory where
 @code{gnatmake} was invoked and if it is not found, it will be search on
 the source path of the compiler as described in
-@ref{89,,Search Paths and the Run-Time Library (RTL)}.
+@ref{73,,Search Paths and the Run-Time Library (RTL)}.
 
 All @code{gnatmake} output (except when you specify @code{-M}) is sent to
 @code{stderr}. The output produced by the
 @code{-M} switch is sent to @code{stdout}.
 
 @node Switches for gnatmake,Mode Switches for gnatmake,Running gnatmake,Building with gnatmake
-@anchor{gnat_ugn/building_executable_programs_with_gnat switches-for-gnatmake}@anchor{dc}@anchor{gnat_ugn/building_executable_programs_with_gnat id3}@anchor{dd}
+@anchor{gnat_ugn/building_executable_programs_with_gnat switches-for-gnatmake}@anchor{cd}@anchor{gnat_ugn/building_executable_programs_with_gnat id3}@anchor{ce}
 @subsection Switches for @code{gnatmake}
 
 
@@ -7718,7 +7505,7 @@ then instead object files and ALI files that already exist are overwritten
 in place. This means that once a large project is organized into separate
 directories in the desired manner, then @code{gnatmake} will automatically
 maintain and update this organization. If no ALI files are found on the
-Ada object path (see @ref{89,,Search Paths and the Run-Time Library (RTL)}),
+Ada object path (see @ref{73,,Search Paths and the Run-Time Library (RTL)}),
 the new object and ALI files are created in the
 directory containing the source being compiled. If another organization
 is desired, where objects and sources are kept in different directories,
@@ -7925,7 +7712,7 @@ Unique. Recompile at most the main files. It implies -c. Combined with
 -u with a project file and no main has a special meaning.
 @end table
 
-@c --Comment:
+@c --Comment
 @c (See :ref:`Project_Files_and_Main_Subprograms`.)
 
 @geindex -U (gnatmake)
@@ -7984,7 +7771,7 @@ Verbosity level High. Equivalent to -v.
 @item @code{-vP@emph{x}}
 
 Indicate the verbosity of the parsing of GNAT project files.
-See @ref{de,,Switches Related to Project Files}.
+See @ref{cf,,Switches Related to Project Files}.
 @end table
 
 @geindex -x (gnatmake)
@@ -8008,7 +7795,7 @@ command line need to be sources of a project file.
 Indicate that external variable @code{name} has the value @code{value}.
 The Project Manager will use this value for occurrences of
 @code{external(name)} when parsing the project file.
-@ref{de,,Switches Related to Project Files}.
+@ref{cf,,Switches Related to Project Files}.
 @end table
 
 @geindex -z (gnatmake)
@@ -8042,7 +7829,7 @@ is passed to @code{gcc} (e.g., @code{-O}, @code{-gnato,} etc.)
 
 When looking for source files also look in directory @code{dir}.
 The order in which source files search is undertaken is
-described in @ref{89,,Search Paths and the Run-Time Library (RTL)}.
+described in @ref{73,,Search Paths and the Run-Time Library (RTL)}.
 @end table
 
 @geindex -aL (gnatmake)
@@ -8074,7 +7861,7 @@ ALI files.
 
 When searching for library and object files, look in directory
 @code{dir}. The order in which library files are searched is described in
-@ref{8c,,Search Paths for gnatbind}.
+@ref{76,,Search Paths for gnatbind}.
 @end table
 
 @geindex Search paths
@@ -8155,9 +7942,9 @@ Do not look for library files in the system default directory.
 
 @item @code{--RTS=@emph{rts-path}}
 
-Specifies the default location of the runtime library. GNAT looks for the
-runtime
-in the following directories, and stops as soon as a valid runtime is found
+Specifies the default location of the run-time library. GNAT looks for the
+run-time
+in the following directories, and stops as soon as a valid run-time is found
 (@code{adainclude} or @code{ada_source_path}, and @code{adalib} or
 @code{ada_object_path} present):
 
@@ -8179,7 +7966,7 @@ The selected path is handled like a normal RTS path.
 @end table
 
 @node Mode Switches for gnatmake,Notes on the Command Line,Switches for gnatmake,Building with gnatmake
-@anchor{gnat_ugn/building_executable_programs_with_gnat id4}@anchor{df}@anchor{gnat_ugn/building_executable_programs_with_gnat mode-switches-for-gnatmake}@anchor{e0}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id4}@anchor{d0}@anchor{gnat_ugn/building_executable_programs_with_gnat mode-switches-for-gnatmake}@anchor{d1}
 @subsection Mode Switches for @code{gnatmake}
 
 
@@ -8239,7 +8026,7 @@ or @code{-largs}.
 @end table
 
 @node Notes on the Command Line,How gnatmake Works,Mode Switches for gnatmake,Building with gnatmake
-@anchor{gnat_ugn/building_executable_programs_with_gnat id5}@anchor{e1}@anchor{gnat_ugn/building_executable_programs_with_gnat notes-on-the-command-line}@anchor{e2}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id5}@anchor{d2}@anchor{gnat_ugn/building_executable_programs_with_gnat notes-on-the-command-line}@anchor{d3}
 @subsection Notes on the Command Line
 
 
@@ -8309,7 +8096,7 @@ that the debugging information may be out of date.
 @end itemize
 
 @node How gnatmake Works,Examples of gnatmake Usage,Notes on the Command Line,Building with gnatmake
-@anchor{gnat_ugn/building_executable_programs_with_gnat id6}@anchor{e3}@anchor{gnat_ugn/building_executable_programs_with_gnat how-gnatmake-works}@anchor{e4}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id6}@anchor{d4}@anchor{gnat_ugn/building_executable_programs_with_gnat how-gnatmake-works}@anchor{d5}
 @subsection How @code{gnatmake} Works
 
 
@@ -8349,14 +8136,14 @@ When invoking @code{gnatmake} with several @code{file_names}, if a unit is
 imported by several of the executables, it will be recompiled at most once.
 
 Note: when using non-standard naming conventions
-(@ref{35,,Using Other File Names}), changing through a configuration pragmas
+(@ref{1c,,Using Other File Names}), changing through a configuration pragmas
 file the version of a source and invoking @code{gnatmake} to recompile may
 have no effect, if the previous version of the source is still accessible
 by @code{gnatmake}. It may be necessary to use the switch
 -f.
 
 @node Examples of gnatmake Usage,,How gnatmake Works,Building with gnatmake
-@anchor{gnat_ugn/building_executable_programs_with_gnat examples-of-gnatmake-usage}@anchor{e5}@anchor{gnat_ugn/building_executable_programs_with_gnat id7}@anchor{e6}
+@anchor{gnat_ugn/building_executable_programs_with_gnat examples-of-gnatmake-usage}@anchor{d6}@anchor{gnat_ugn/building_executable_programs_with_gnat id7}@anchor{d7}
 @subsection Examples of @code{gnatmake} Usage
 
 
@@ -8388,7 +8175,7 @@ displaying commands it is executing.
 @end table
 
 @node Compiling with gcc,Compiler Switches,Building with gnatmake,Building Executable Programs with GNAT
-@anchor{gnat_ugn/building_executable_programs_with_gnat compiling-with-gcc}@anchor{1c}@anchor{gnat_ugn/building_executable_programs_with_gnat id8}@anchor{e7}
+@anchor{gnat_ugn/building_executable_programs_with_gnat compiling-with-gcc}@anchor{c7}@anchor{gnat_ugn/building_executable_programs_with_gnat id8}@anchor{d8}
 @section Compiling with @code{gcc}
 
 
@@ -8405,7 +8192,7 @@ that can be used to control the behavior of the compiler.
 @end menu
 
 @node Compiling Programs,Search Paths and the Run-Time Library RTL,,Compiling with gcc
-@anchor{gnat_ugn/building_executable_programs_with_gnat compiling-programs}@anchor{e8}@anchor{gnat_ugn/building_executable_programs_with_gnat id9}@anchor{e9}
+@anchor{gnat_ugn/building_executable_programs_with_gnat compiling-programs}@anchor{d9}@anchor{gnat_ugn/building_executable_programs_with_gnat id9}@anchor{da}
 @subsection Compiling Programs
 
 
@@ -8518,11 +8305,11 @@ calls @code{gnat1} (the Ada compiler) twice to compile @code{x.adb} and
 The compiler generates two object files @code{x.o} and @code{y.o}
 and the two ALI files @code{x.ali} and @code{y.ali}.
 
-Any switches apply to all the files listed, see @ref{ea,,Compiler Switches} for a
+Any switches apply to all the files listed, see @ref{db,,Compiler Switches} for a
 list of available @code{gcc} switches.
 
 @node Search Paths and the Run-Time Library RTL,Order of Compilation Issues,Compiling Programs,Compiling with gcc
-@anchor{gnat_ugn/building_executable_programs_with_gnat id10}@anchor{eb}@anchor{gnat_ugn/building_executable_programs_with_gnat search-paths-and-the-run-time-library-rtl}@anchor{89}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id10}@anchor{dc}@anchor{gnat_ugn/building_executable_programs_with_gnat search-paths-and-the-run-time-library-rtl}@anchor{73}
 @subsection Search Paths and the Run-Time Library (RTL)
 
 
@@ -8579,7 +8366,7 @@ names separated by colons (semicolons when working with the NT version).
 The content of the @code{ada_source_path} file which is part of the GNAT
 installation tree and is used to store standard libraries such as the
 GNAT Run Time Library (RTL) source files.
-@ref{87,,Installing a library}
+@ref{71,,Installing a library}
 @end itemize
 
 Specifying the switch @code{-I-}
@@ -8621,7 +8408,7 @@ in compiling sources from multiple directories. This can make
 development environments much more flexible.
 
 @node Order of Compilation Issues,Examples,Search Paths and the Run-Time Library RTL,Compiling with gcc
-@anchor{gnat_ugn/building_executable_programs_with_gnat id11}@anchor{ec}@anchor{gnat_ugn/building_executable_programs_with_gnat order-of-compilation-issues}@anchor{ed}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id11}@anchor{dd}@anchor{gnat_ugn/building_executable_programs_with_gnat order-of-compilation-issues}@anchor{de}
 @subsection Order of Compilation Issues
 
 
@@ -8649,7 +8436,7 @@ source files on which it depends.
 
 @item 
 There is no library as such, apart from the ALI files
-(@ref{42,,The Ada Library Information Files}, for information on the format
+(@ref{28,,The Ada Library Information Files}, for information on the format
 of these files). For now we find it convenient to create separate ALI files,
 but eventually the information therein may be incorporated into the object
 file directly.
@@ -8662,7 +8449,7 @@ described above), or you will receive a fatal error message.
 @end itemize
 
 @node Examples,,Order of Compilation Issues,Compiling with gcc
-@anchor{gnat_ugn/building_executable_programs_with_gnat id12}@anchor{ee}@anchor{gnat_ugn/building_executable_programs_with_gnat examples}@anchor{ef}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id12}@anchor{df}@anchor{gnat_ugn/building_executable_programs_with_gnat examples}@anchor{e0}
 @subsection Examples
 
 
@@ -8690,7 +8477,7 @@ Compile the subunit in file @code{abc-def.adb} in semantic-checking-only
 mode.
 
 @node Compiler Switches,Linker Switches,Compiling with gcc,Building Executable Programs with GNAT
-@anchor{gnat_ugn/building_executable_programs_with_gnat compiler-switches}@anchor{f0}@anchor{gnat_ugn/building_executable_programs_with_gnat switches-for-gcc}@anchor{ea}
+@anchor{gnat_ugn/building_executable_programs_with_gnat compiler-switches}@anchor{e1}@anchor{gnat_ugn/building_executable_programs_with_gnat switches-for-gcc}@anchor{db}
 @section Compiler Switches
 
 
@@ -8729,7 +8516,7 @@ compilation units.
 @end menu
 
 @node Alphabetical List of All Switches,Output and Error Message Control,,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat id13}@anchor{f1}@anchor{gnat_ugn/building_executable_programs_with_gnat alphabetical-list-of-all-switches}@anchor{f2}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id13}@anchor{e2}@anchor{gnat_ugn/building_executable_programs_with_gnat alphabetical-list-of-all-switches}@anchor{e3}
 @subsection Alphabetical List of All Switches
 
 
@@ -8807,17 +8594,15 @@ in the compiler sources for details in files @code{scos.ads} and
 @code{scos.adb}.
 @end table
 
-@geindex -fdump-xref (gcc)
+@geindex -fgnat-encodings (gcc)
 
 
 @table @asis
 
-@item @code{-fdump-xref}
+@item @code{-fgnat-encodings=[all|gdb|minimal]}
 
-Generates cross reference information in GLI files for C and C++ sources.
-The GLI files have the same syntax as the ALI files for Ada, and can be used
-for source navigation in IDEs and on the command line using e.g. gnatxref
-and the @code{--ext=gli} switch.
+This switch controls the balance between GNAT encodings and standard DWARF
+emitted in the debug information.
 @end table
 
 @geindex -flto (gcc)
@@ -8828,14 +8613,15 @@ and the @code{--ext=gli} switch.
 @item @code{-flto[=@emph{n}]}
 
 Enables Link Time Optimization. This switch must be used in conjunction
-with the traditional @code{-Ox} switches and instructs the compiler to
-defer most optimizations until the link stage. The advantage of this
+with the @code{-Ox} switches (but not with the @code{-gnatn} switch
+since it is a full replacement for the latter) and instructs the compiler
+to defer most optimizations until the link stage. The advantage of this
 approach is that the compiler can do a whole-program analysis and choose
 the best interprocedural optimization strategy based on a complete view
 of the program, instead of a fragmentary view with the usual approach.
 This can also speed up the compilation of big programs and reduce the
 size of the executable, compared with a traditional per-unit compilation
-with inlining across modules enabled by the @code{-gnatn} switch.
+with inlining across units enabled by the @code{-gnatn} switch.
 The drawback of this approach is that it may require more memory and that
 the debugging information generated by -g with it might be hardly usable.
 The switch, as well as the accompanying @code{-Ox} switches, must be
@@ -8915,7 +8701,7 @@ and thus producing inferior code.
 
 Causes the compiler to avoid assumptions regarding non-aliasing
 of objects of different types. See
-@ref{f3,,Optimization and Strict Aliasing} for details.
+@ref{e4,,Optimization and Strict Aliasing} for details.
 @end table
 
 @geindex -fno-strict-overflow (gcc)
@@ -8941,7 +8727,7 @@ for very peculiar cases of low-level programming.
 @item @code{-fstack-check}
 
 Activates stack checking.
-See @ref{f4,,Stack Overflow Checking} for details.
+See @ref{e5,,Stack Overflow Checking} for details.
 @end table
 
 @geindex -fstack-usage (gcc)
@@ -8952,7 +8738,7 @@ See @ref{f4,,Stack Overflow Checking} for details.
 @item @code{-fstack-usage}
 
 Makes the compiler output stack usage information for the program, on a
-per-subprogram basis. See @ref{f5,,Static Stack Usage Analysis} for details.
+per-subprogram basis. See @ref{e6,,Static Stack Usage Analysis} for details.
 @end table
 
 @geindex -g (gcc)
@@ -9082,7 +8868,7 @@ Generate brief messages to @code{stderr} even if verbose mode set.
 @item @code{-gnatB}
 
 Assume no invalid (bad) values except for 'Valid attribute use
-(@ref{f6,,Validity Checking}).
+(@ref{e7,,Validity Checking}).
 @end table
 
 @geindex -gnatc (gcc)
@@ -9180,12 +8966,25 @@ Detect_Aliasing (Obj, Self (Obj));
 @end example
 
 In the example above, the first call to @code{Detect_Aliasing} fails with a
-@code{Program_Error} at runtime because the actuals for @code{Val_1} and
+@code{Program_Error} at run time because the actuals for @code{Val_1} and
 @code{Val_2} denote the same object. The second call executes without raising
 an exception because @code{Self(Obj)} produces an anonymous object which does
 not share the memory location of @code{Obj}.
 @end table
 
+@geindex -gnateb (gcc)
+
+
+@table @asis
+
+@item @code{-gnateb}
+
+Store configuration files by their basename in ALI files. This switch is
+used for instance by gprbuild for distributed builds in order to prevent
+issues where machine-specific absolute paths could end up being stored in
+ALI files.
+@end table
+
 @geindex -gnatec (gcc)
 
 
@@ -9195,7 +8994,7 @@ not share the memory location of @code{Obj}.
 
 Specify a configuration pragma file
 (the equal sign is optional)
-(@ref{79,,The Configuration Pragmas Files}).
+(@ref{62,,The Configuration Pragmas Files}).
 @end table
 
 @geindex -gnateC (gcc)
@@ -9228,7 +9027,7 @@ Disable atomic synchronization
 @item @code{-gnateDsymbol[=@emph{value}]}
 
 Defines a symbol, associated with @code{value}, for preprocessing.
-(@ref{18,,Integrated Preprocessing}).
+(@ref{90,,Integrated Preprocessing}).
 @end table
 
 @geindex -gnateE (gcc)
@@ -9277,7 +9076,7 @@ for unconstrained predefined types. See description of pragma
 
 The @code{-gnatc} switch must always be specified before this switch, e.g.
 @code{-gnatceg}. Generate a C header from the Ada input file. See
-@ref{ca,,Generating C Headers for Ada Specifications} for more
+@ref{b7,,Generating C Headers for Ada Specifications} for more
 information.
 @end quotation
 
@@ -9351,7 +9150,7 @@ This switch turns off the info messages about implicit elaboration pragmas.
 
 Specify a mapping file
 (the equal sign is optional)
-(@ref{f7,,Units to Sources Mapping Files}).
+(@ref{e8,,Units to Sources Mapping Files}).
 @end table
 
 @geindex -gnatep (gcc)
@@ -9363,7 +9162,7 @@ Specify a mapping file
 
 Specify a preprocessing data file
 (the equal sign is optional)
-(@ref{18,,Integrated Preprocessing}).
+(@ref{90,,Integrated Preprocessing}).
 @end table
 
 @geindex -gnateP (gcc)
@@ -9439,7 +9238,7 @@ Long_Size                  : Pos; -- Standard.Long_Integer'Size
 Maximum_Alignment          : Pos; -- Maximum permitted alignment
 Max_Unaligned_Field        : Pos; -- Maximum size for unaligned bit field
 Pointer_Size               : Pos; -- System.Address'Size
-Short_Enums                : Nat; -- Short foreign convention enums?
+Short_Enums                : Nat; -- Foreign enums use short size?
 Short_Size                 : Pos; -- Standard.Short_Integer'Size
 Strict_Alignment           : Nat; -- Strict alignment?
 System_Allocator_Alignment : Nat; -- Alignment for malloc calls
@@ -9447,6 +9246,34 @@ Wchar_T_Size               : Pos; -- Interfaces.C.wchar_t'Size
 Words_BE                   : Nat; -- Words stored big-endian?
 @end example
 
+@code{Bits_Per_Unit} is the number of bits in a storage unit, the equivalent of
+GCC macro @code{BITS_PER_UNIT} documented as follows: @cite{Define this macro to be the number of bits in an addressable storage unit (byte); normally 8.}
+
+@code{Bits_Per_Word} is the number of bits in a machine word, the equivalent of
+GCC macro @code{BITS_PER_WORD} documented as follows: @cite{Number of bits in a word; normally 32.}
+
+@code{Double_Float_Alignment}, if not zero, is the maximum alignment that the
+compiler can choose by default for a 64-bit floating-point type or object.
+
+@code{Double_Scalar_Alignment}, if not zero, is the maximum alignment that the
+compiler can choose by default for a 64-bit or larger scalar type or object.
+
+@code{Maximum_Alignment} is the maximum alignment that the compiler can choose
+by default for a type or object, which is also the maximum alignment that can
+be specified in GNAT. It is computed for GCC backends as @code{BIGGEST_ALIGNMENT
+/ BITS_PER_UNIT} where GCC macro @code{BIGGEST_ALIGNMENT} is documented as
+follows: @cite{Biggest alignment that any data type can require on this machine@comma{} in bits.}
+
+@code{Max_Unaligned_Field} is the maximum size for unaligned bit field, which is
+64 for the majority of GCC targets (but can be different on some targets like
+AAMP).
+
+@code{Strict_Alignment} is the equivalent of GCC macro @code{STRICT_ALIGNMENT}
+documented as follows: @cite{Define this macro to be the value 1 if instructions will fail to work if given data not on the nominal alignment. If instructions will merely go slower in that case@comma{} define this macro as 0.}
+
+@code{System_Allocator_Alignment} is the guaranteed alignment of data returned
+by calls to @code{malloc}.
+
 The format of the input file is as follows. First come the values of
 the variables defined above, with one line per value:
 
@@ -9533,7 +9360,7 @@ support this switch.
 @item @code{-gnateV}
 
 Check that all actual parameters of a subprogram call are valid according to
-the rules of validity checking (@ref{f6,,Validity Checking}).
+the rules of validity checking (@ref{e7,,Validity Checking}).
 @end table
 
 @geindex -gnateY (gcc)
@@ -9556,7 +9383,8 @@ checking options to be controlled from the command line.
 
 @item @code{-gnatE}
 
-Full dynamic elaboration checks.
+Dynamic elaboration checking mode enabled. For further details see
+@ref{f,,Elaboration Order Handling in GNAT}.
 @end table
 
 @geindex -gnatf (gcc)
@@ -9587,14 +9415,12 @@ Externals names are folded to all uppercase.
 
 @item @code{-gnatg}
 
-Internal GNAT implementation mode. This should not be used for
-applications programs, it is intended only for use by the compiler
-and its run-time library. For documentation, see the GNAT sources.
-Note that @code{-gnatg} implies
-@code{-gnatw.ge} and
-@code{-gnatyg}
-so that all standard warnings and all standard style options are turned on.
-All warnings and style messages are treated as errors.
+Internal GNAT implementation mode. This should not be used for applications
+programs, it is intended only for use by the compiler and its run-time
+library. For documentation, see the GNAT sources. Note that @code{-gnatg}
+implies @code{-gnatw.ge} and @code{-gnatyg} so that all standard
+warnings and all standard style options are turned on. All warnings and style
+messages are treated as errors.
 @end table
 
 @geindex -gnatG[nn] (gcc)
@@ -9617,6 +9443,18 @@ List generated expanded code in source form.
 Output usage information. The output is written to @code{stdout}.
 @end table
 
+@geindex -gnatH (gcc)
+
+
+@table @asis
+
+@item @code{-gnatH}
+
+Legacy elaboration-checking mode enabled. When this switch is in effect,
+the pre-18.x access-before-elaboration model becomes the de facto model.
+For further details see @ref{f,,Elaboration Order Handling in GNAT}.
+@end table
+
 @geindex -gnati (gcc)
 
 
@@ -9626,7 +9464,7 @@ Output usage information. The output is written to @code{stdout}.
 
 Identifier character set (@code{c} = 1/2/3/4/8/9/p/f/n/w).
 For details of the possible selections for @code{c},
-see @ref{48,,Character Set Control}.
+see @ref{31,,Character Set Control}.
 @end table
 
 @geindex -gnatI (gcc)
@@ -9648,10 +9486,6 @@ Object_Size, Scalar_Storage_Order, Size, Small, Stream_Size,
 and Value_Size. Pragma Default_Scalar_Storage_Order is also ignored.
 Note that this option should be used only for compiling -- the
 code is likely to malfunction at run time.
-
-Note that when @code{-gnatct} is used to generate trees for input
-into ASIS tools, these representation clauses are removed
-from the tree and ignored. This means that the tool will not see them.
 @end table
 
 @geindex -gnatjnn (gcc)
@@ -9664,6 +9498,57 @@ from the tree and ignored. This means that the tool will not see them.
 Reformat error messages to fit on @code{nn} character lines
 @end table
 
+@geindex -gnatJ (gcc)
+
+
+@table @asis
+
+@item @code{-gnatJ}
+
+Permissive elaboration-checking mode enabled. When this switch is in effect,
+the post-18.x access-before-elaboration model ignores potential issues with:
+
+
+@itemize -
+
+@item 
+Accept statements
+
+@item 
+Activations of tasks defined in instances
+
+@item 
+Assertion pragmas
+
+@item 
+Calls from within an instance to its enclosing context
+
+@item 
+Calls through generic formal parameters
+
+@item 
+Calls to subprograms defined in instances
+
+@item 
+Entry calls
+
+@item 
+Indirect calls using 'Access
+
+@item 
+Requeue statements
+
+@item 
+Select statements
+
+@item 
+Synchronous task suspension
+@end itemize
+
+and does not emit compile-time diagnostics or run-time checks. For further
+details see @ref{f,,Elaboration Order Handling in GNAT}.
+@end table
+
 @geindex -gnatk (gcc)
 
 
@@ -9720,10 +9605,10 @@ means that no limit applies.
 
 @item @code{-gnatn[12]}
 
-Activate inlining across modules for subprograms for which pragma @code{Inline}
+Activate inlining across units for subprograms for which pragma @code{Inline}
 is specified. This inlining is performed by the GCC back-end. An optional
-digit sets the inlining level: 1 for moderate inlining across modules
-or 2 for full inlining across modules. If no inlining level is specified,
+digit sets the inlining level: 1 for moderate inlining across units
+or 2 for full inlining across units. If no inlining level is specified,
 the compiler will pick it based on the optimization level.
 @end table
 
@@ -9828,7 +9713,7 @@ overflow checking is enabled.
 Note that division by zero is a separate check that is not
 controlled by this switch (divide-by-zero checking is on by default).
 
-See also @ref{f8,,Specifying the Desired Mode}.
+See also @ref{e9,,Specifying the Desired Mode}.
 @end table
 
 @geindex -gnatp (gcc)
@@ -9838,7 +9723,7 @@ See also @ref{f8,,Specifying the Desired Mode}.
 
 @item @code{-gnatp}
 
-Suppress all checks. See @ref{f9,,Run-Time Checks} for details. This switch
+Suppress all checks. See @ref{ea,,Run-Time Checks} for details. This switch
 has no effect if cancelled by a subsequent @code{-gnat-p} switch.
 @end table
 
@@ -9852,19 +9737,6 @@ has no effect if cancelled by a subsequent @code{-gnat-p} switch.
 Cancel effect of previous @code{-gnatp} switch.
 @end table
 
-@geindex -gnatP (gcc)
-
-
-@table @asis
-
-@item @code{-gnatP}
-
-Enable polling. This is required on some systems (notably Windows NT) to
-obtain asynchronous abort and asynchronous transfer of control capability.
-See @code{Pragma_Polling} in the @cite{GNAT_Reference_Manual} for full
-details.
-@end table
-
 @geindex -gnatq (gcc)
 
 
@@ -9902,7 +9774,7 @@ Treat pragma Restrictions as Restriction_Warnings.
 
 @table @asis
 
-@item @code{-gnatR[0/1/2/3][e][m][s]}
+@item @code{-gnatR[0|1|2|3|4][e][j][m][s]}
 
 Output representation information for declared types, objects and
 subprograms. Note that this switch is not allowed if a previous
@@ -9930,16 +9802,6 @@ Syntax check only.
 Print package Standard.
 @end table
 
-@geindex -gnatt (gcc)
-
-
-@table @asis
-
-@item @code{-gnatt}
-
-Generate tree output file.
-@end table
-
 @geindex -gnatT (gcc)
 
 
@@ -9987,7 +9849,7 @@ Verbose mode. Full error output with source lines to @code{stdout}.
 
 @item @code{-gnatV}
 
-Control level of validity checking (@ref{f6,,Validity Checking}).
+Control level of validity checking (@ref{e7,,Validity Checking}).
 @end table
 
 @geindex -gnatw (gcc)
@@ -10000,7 +9862,7 @@ Control level of validity checking (@ref{f6,,Validity Checking}).
 Warning mode where
 @code{xxx} is a string of option letters that denotes
 the exact warnings that
-are enabled or disabled (@ref{fa,,Warning Message Control}).
+are enabled or disabled (@ref{eb,,Warning Message Control}).
 @end table
 
 @geindex -gnatW (gcc)
@@ -10041,7 +9903,7 @@ Enable GNAT implementation extensions and latest Ada version.
 
 @item @code{-gnaty}
 
-Enable built-in style checks (@ref{fb,,Style Checking}).
+Enable built-in style checks (@ref{ec,,Style Checking}).
 @end table
 
 @geindex -gnatz (gcc)
@@ -10066,7 +9928,7 @@ Distribution stub generation and compilation
 
 Direct GNAT to search the @code{dir} directory for source files needed by
 the current compilation
-(see @ref{89,,Search Paths and the Run-Time Library (RTL)}).
+(see @ref{73,,Search Paths and the Run-Time Library (RTL)}).
 @end table
 
 @geindex -I- (gcc)
@@ -10080,7 +9942,7 @@ the current compilation
 
 Except for the source file named in the command line, do not look for source
 files in the directory containing the source file named in the command line
-(see @ref{89,,Search Paths and the Run-Time Library (RTL)}).
+(see @ref{73,,Search Paths and the Run-Time Library (RTL)}).
 @end table
 
 @geindex -o (gcc)
@@ -10184,7 +10046,7 @@ Optimize space usage
 @end multitable
 
 
-See also @ref{fc,,Optimization Levels}.
+See also @ref{ed,,Optimization Levels}.
 @end table
 
 @geindex -pass-exit-codes (gcc)
@@ -10205,8 +10067,8 @@ exit status.
 
 @item @code{--RTS=@emph{rts-path}}
 
-Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (@ref{dc,,Switches for gnatmake}).
+Specifies the default location of the run-time library. Same meaning as the
+equivalent @code{gnatmake} flag (@ref{cd,,Switches for gnatmake}).
 @end table
 
 @geindex -S (gcc)
@@ -10332,7 +10194,7 @@ as warning mode modifiers (see description of @code{-gnatw}).
 @item 
 Once a 'V' appears in the string (that is a use of the @code{-gnatV}
 switch), then all further characters in the switch are interpreted
-as validity checking options (@ref{f6,,Validity Checking}).
+as validity checking options (@ref{e7,,Validity Checking}).
 
 @item 
 Option 'em', 'ec', 'ep', 'l=' and 'R' must be the last options in
@@ -10340,7 +10202,7 @@ a combined list of options.
 @end itemize
 
 @node Output and Error Message Control,Warning Message Control,Alphabetical List of All Switches,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat id14}@anchor{fd}@anchor{gnat_ugn/building_executable_programs_with_gnat output-and-error-message-control}@anchor{fe}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id14}@anchor{ee}@anchor{gnat_ugn/building_executable_programs_with_gnat output-and-error-message-control}@anchor{ef}
 @subsection Output and Error Message Control
 
 
@@ -10357,7 +10219,7 @@ e.adb:4:20: ";" should be "is"
 
 The first integer after the file name is the line number in the file,
 and the second integer is the column number within the line.
-@code{GPS} can parse the error messages
+@code{GNAT Studio} can parse the error messages
 and point to the referenced character.
 The following switches provide control over the error message
 format:
@@ -10626,14 +10488,6 @@ environments) that are driven from the @code{ALI} file. This switch
 implies @code{-gnatq}, since the semantic phase must be run to get a
 meaningful ALI file.
 
-In addition, if @code{-gnatt} is also specified, then the tree file is
-generated even if there are illegalities. It may be useful in this case
-to also specify @code{-gnatq} to ensure that full semantic processing
-occurs. The resulting tree file can be processed by ASIS, for the purpose
-of providing partial information about illegal units, but if the error
-causes the tree to be badly malformed, then ASIS may crash during the
-analysis.
-
 When @code{-gnatQ} is used and the generated @code{ALI} file is marked as
 being in error, @code{gnatmake} will attempt to recompile the source when it
 finds such an @code{ALI} file, including with switch @code{-gnatc}.
@@ -10643,7 +10497,7 @@ since ALI files are never generated if @code{-gnats} is set.
 @end table
 
 @node Warning Message Control,Debugging and Assertion Control,Output and Error Message Control,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat warning-message-control}@anchor{fa}@anchor{gnat_ugn/building_executable_programs_with_gnat id15}@anchor{ff}
+@anchor{gnat_ugn/building_executable_programs_with_gnat warning-message-control}@anchor{eb}@anchor{gnat_ugn/building_executable_programs_with_gnat id15}@anchor{f0}
 @subsection Warning Message Control
 
 
@@ -10836,7 +10690,7 @@ of the pragma in the @cite{GNAT_Reference_manual}).
 
 @emph{Activate most optional warnings.}
 
-This switch activates most optional warning messages.  See the remaining list
+This switch activates most optional warning messages. See the remaining list
 in this section for details on optional warning messages that can be
 individually controlled.  The warnings that are not turned on by this
 switch are:
@@ -10880,6 +10734,9 @@ switch are:
 @item 
 @code{-gnatw.q} (questionable layout of record types)
 
+@item 
+@code{-gnatw_r} (out-of-order record representation clauses)
+
 @item 
 @code{-gnatw.s} (overridden size clause)
 
@@ -10953,6 +10810,37 @@ This switch suppresses warnings for assertions where the compiler can tell at
 compile time that the assertion will fail.
 @end table
 
+@geindex -gnatw_a
+
+
+@table @asis
+
+@item @code{-gnatw_a}
+
+@emph{Activate warnings on anonymous allocators.}
+
+@geindex Anonymous allocators
+
+This switch activates warnings for allocators of anonymous access types,
+which can involve run-time accessibility checks and lead to unexpected
+accessibility violations. For more details on the rules involved, see
+RM 3.10.2 (14).
+@end table
+
+@geindex -gnatw_A
+
+
+@table @asis
+
+@item @code{-gnatw_A}
+
+@emph{Supress warnings on anonymous allocators.}
+
+@geindex Anonymous allocators
+
+This switch suppresses warnings for anonymous access type allocators.
+@end table
+
 @geindex -gnatwb (gcc)
 
 
@@ -11088,7 +10976,7 @@ majority, but not all, of the components. A warning is given for each
 component for which no component clause is present.
 @end table
 
-@geindex -gnatwC (gcc)
+@geindex -gnatw.C (gcc)
 
 
 @table @asis
@@ -11101,6 +10989,39 @@ This switch suppresses warnings for record components that are
 missing a component clause in the situation described above.
 @end table
 
+@geindex -gnatw_c (gcc)
+
+
+@table @asis
+
+@item @code{-gnatw_c}
+
+@emph{Activate warnings on unknown condition in Compile_Time_Warning.}
+
+@geindex Compile_Time_Warning
+
+@geindex Compile_Time_Error
+
+This switch activates warnings on a pragma Compile_Time_Warning
+or Compile_Time_Error whose condition has a value that is not
+known at compile time.
+The default is that such warnings are generated.
+@end table
+
+@geindex -gnatw_C (gcc)
+
+
+@table @asis
+
+@item @code{-gnatw_C}
+
+@emph{Suppress warnings on unknown condition in Compile_Time_Warning.}
+
+This switch supresses warnings on a pragma Compile_Time_Warning
+or Compile_Time_Error whose condition has a value that is not
+known at compile time.
+@end table
+
 @geindex -gnatwd (gcc)
 
 
@@ -11586,7 +11507,7 @@ not included in this check.
 
 @emph{Suppress warnings on redefinition of names in standard.}
 
-This switch activates warnings for declarations that declare a name that
+This switch disables warnings for declarations that declare a name that
 is defined in package Standard.
 @end table
 
@@ -12072,7 +11993,7 @@ opposed to renaming the function itself).  The default is that these
 warnings are given.
 @end table
 
-@geindex -gnatwT (gcc)
+@geindex -gnatw.R (gcc)
 
 
 @table @asis
@@ -12084,6 +12005,31 @@ warnings are given.
 This switch suppresses warnings for object renaming function.
 @end table
 
+@geindex -gnatw_r (gcc)
+
+
+@table @asis
+
+@item @code{-gnatw_r}
+
+@emph{Activate warnings for out-of-order record representation clauses.}
+
+This switch activates warnings for record representation clauses,
+if the order of component declarations, component clauses,
+and bit-level layout do not all agree.
+The default is that these warnings are not given.
+@end table
+
+@geindex -gnatw_R (gcc)
+
+
+@table @asis
+
+@item @code{-gnatw_R}
+
+@emph{Suppress warnings for out-of-order record representation clauses.}
+@end table
+
 @geindex -gnatws (gcc)
 
 
@@ -12295,10 +12241,17 @@ that no warnings are given for comparisons or subranges for any type.
 
 This switch activates warnings for access to variables which
 may not be properly initialized. The default is that
-such warnings are generated.
-@end table
+such warnings are generated. This switch will also be emitted when
+initializing an array or record object via the following aggregate:
 
-@geindex -gnatwV (gcc)
+@example
+Array_Or_Record : XXX := (others => <>);
+@end example
+
+unless the relevant type fully initializes all components.
+@end table
+
+@geindex -gnatwV (gcc)
 
 
 @table @asis
@@ -12309,17 +12262,6 @@ such warnings are generated.
 
 This switch suppresses warnings for access to variables which
 may not be properly initialized.
-For variables of a composite type, the warning can also be suppressed in
-Ada 2005 by using a default initialization with a box. For example, if
-Table is an array of records whose components are only partially uninitialized,
-then the following code:
-
-@example
-Tab : Table := (others => <>);
-@end example
-
-will suppress warnings on subsequent statements that access components
-of variable Tab.
 @end table
 
 @geindex -gnatw.v (gcc)
@@ -12472,8 +12414,8 @@ should not complain at you.
 This switch activates warnings for exception usage when pragma Restrictions
 (No_Exception_Propagation) is in effect. Warnings are given for implicit or
 explicit exception raises which are not covered by a local handler, and for
-exception handlers which do not cover a local raise. The default is that these
-warnings are not given.
+exception handlers which do not cover a local raise. The default is that
+these warnings are given for units that contain exception handlers.
 
 @item @code{-gnatw.X}
 
@@ -12597,8 +12539,8 @@ sizes or conventions.
 
 @emph{Activate warnings for size not a multiple of alignment.}
 
-This switch activates warnings for cases of record types with
-specified @code{Size} and @code{Alignment} attributes where the
+This switch activates warnings for cases of array and record types
+with specified @code{Size} and @code{Alignment} attributes where the
 size is not a multiple of the alignment, resulting in an object
 size that is greater than the specified size. The default
 is that such warnings are generated.
@@ -12615,12 +12557,11 @@ is that such warnings are generated.
 
 @emph{Suppress warnings for size not a multiple of alignment.}
 
-This switch suppresses warnings for cases of record types with
-specified @code{Size} and @code{Alignment} attributes where the
+This switch suppresses warnings for cases of array and record types
+with specified @code{Size} and @code{Alignment} attributes where the
 size is not a multiple of the alignment, resulting in an object
-size that is greater than the specified size.
-The warning can also be
-suppressed by giving an explicit @code{Object_Size} value.
+size that is greater than the specified size. The warning can also
+be suppressed by giving an explicit @code{Object_Size} value.
 @end table
 
 @geindex -Wunused (gcc)
@@ -12657,7 +12598,7 @@ used in conjunction with an optimization level greater than zero.
 @item @code{-Wstack-usage=@emph{len}}
 
 Warn if the stack usage of a subprogram might be larger than @code{len} bytes.
-See @ref{f5,,Static Stack Usage Analysis} for details.
+See @ref{e6,,Static Stack Usage Analysis} for details.
 @end table
 
 @geindex -Wall (gcc)
@@ -12732,9 +12673,15 @@ When no switch @code{-gnatw} is used, this is equivalent to:
 @item 
 @code{-gnatwD}
 
+@item 
+@code{-gnatw.D}
+
 @item 
 @code{-gnatwF}
 
+@item 
+@code{-gnatw.F}
+
 @item 
 @code{-gnatwg}
 
@@ -12742,17 +12689,23 @@ When no switch @code{-gnatw} is used, this is equivalent to:
 @code{-gnatwH}
 
 @item 
-@code{-gnatwi}
+@code{-gnatw.H}
 
 @item 
-@code{-gnatw.I}
+@code{-gnatwi}
 
 @item 
 @code{-gnatwJ}
 
+@item 
+@code{-gnatw.J}
+
 @item 
 @code{-gnatwK}
 
+@item 
+@code{-gnatw.K}
+
 @item 
 @code{-gnatwL}
 
@@ -12768,6 +12721,9 @@ When no switch @code{-gnatw} is used, this is equivalent to:
 @item 
 @code{-gnatwn}
 
+@item 
+@code{-gnatw.N}
+
 @item 
 @code{-gnatwo}
 
@@ -12799,14 +12755,20 @@ When no switch @code{-gnatw} is used, this is equivalent to:
 @code{-gnatwT}
 
 @item 
-@code{-gnatw.T}
+@code{-gnatw.t}
 
 @item 
 @code{-gnatwU}
 
+@item 
+@code{-gnatw.U}
+
 @item 
 @code{-gnatwv}
 
+@item 
+@code{-gnatw.v}
+
 @item 
 @code{-gnatww}
 
@@ -12822,13 +12784,19 @@ When no switch @code{-gnatw} is used, this is equivalent to:
 @item 
 @code{-gnatwy}
 
+@item 
+@code{-gnatw.Y}
+
 @item 
 @code{-gnatwz}
+
+@item 
+@code{-gnatw.z}
 @end itemize
 @end quotation
 
 @node Debugging and Assertion Control,Validity Checking,Warning Message Control,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat debugging-and-assertion-control}@anchor{100}@anchor{gnat_ugn/building_executable_programs_with_gnat id16}@anchor{101}
+@anchor{gnat_ugn/building_executable_programs_with_gnat debugging-and-assertion-control}@anchor{f1}@anchor{gnat_ugn/building_executable_programs_with_gnat id16}@anchor{f2}
 @subsection Debugging and Assertion Control
 
 
@@ -12917,7 +12885,7 @@ is @code{False}, the exception @code{Assert_Failure} is raised.
 @end table
 
 @node Validity Checking,Style Checking,Debugging and Assertion Control,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat validity-checking}@anchor{f6}@anchor{gnat_ugn/building_executable_programs_with_gnat id17}@anchor{102}
+@anchor{gnat_ugn/building_executable_programs_with_gnat validity-checking}@anchor{e7}@anchor{gnat_ugn/building_executable_programs_with_gnat id17}@anchor{f3}
 @subsection Validity Checking
 
 
@@ -12979,7 +12947,7 @@ to the default checks required by Ada as described above.
 
 All validity checks are turned on.
 That is, @code{-gnatVa} is
-equivalent to @code{gnatVcdfimorst}.
+equivalent to @code{gnatVcdfimoprst}.
 @end table
 
 @geindex -gnatVc (gcc)
@@ -13206,7 +13174,7 @@ the validity checking mode at the program source level, and also allows for
 temporary disabling of validity checks.
 
 @node Style Checking,Run-Time Checks,Validity Checking,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat id18}@anchor{103}@anchor{gnat_ugn/building_executable_programs_with_gnat style-checking}@anchor{fb}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id18}@anchor{f4}@anchor{gnat_ugn/building_executable_programs_with_gnat style-checking}@anchor{ec}
 @subsection Style Checking
 
 
@@ -13403,6 +13371,20 @@ character (in particular the DOS line terminator sequence CR/LF is not
 allowed).
 @end table
 
+@geindex -gnatyD (gcc)
+
+
+@table @asis
+
+@item @code{-gnatyD}
+
+@emph{Check declared identifiers in mixed case.}
+
+Declared identifiers must be in mixed case, as in
+This_Is_An_Identifier. Use -gnatyr in addition to ensure
+that references match declarations.
+@end table
+
 @geindex -gnatye (gcc)
 
 
@@ -13440,7 +13422,7 @@ in the source text.
 
 The set of style check switches is set to match that used by the GNAT sources.
 This may be useful when developing code that is eventually intended to be
-incorporated into GNAT. Currently this is equivalent to @code{-gnatwydISux})
+incorporated into GNAT. Currently this is equivalent to @code{-gnatyydISux})
 but additional style switches may be added to this set in the future without
 advance notice.
 @end table
@@ -13499,7 +13481,8 @@ but not @code{in} on its own.
 
 All keywords must be in lower case (with the exception of keywords
 such as @code{digits} used as attribute names to which this check
-does not apply).
+does not apply). A single error is reported for each line breaking
+this rule even if multiple casing issues exist on a same line.
 @end table
 
 @geindex -gnatyl (gcc)
@@ -13889,7 +13872,7 @@ if any.
 
 @c end of switch description (leave this comment to ease automatic parsing for
 
-@c GPS
+@c GNAT Studio
 
 In the above rules, appearing in column one is always permitted, that is,
 counts as meeting either a requirement for a required preceding space,
@@ -13914,7 +13897,7 @@ built-in standard style check options are enabled.
 The switch @code{-gnatyN} clears any previously set style checks.
 
 @node Run-Time Checks,Using gcc for Syntax Checking,Style Checking,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat run-time-checks}@anchor{f9}@anchor{gnat_ugn/building_executable_programs_with_gnat id19}@anchor{104}
+@anchor{gnat_ugn/building_executable_programs_with_gnat run-time-checks}@anchor{ea}@anchor{gnat_ugn/building_executable_programs_with_gnat id19}@anchor{f5}
 @subsection Run-Time Checks
 
 
@@ -13964,7 +13947,7 @@ if checks are suppressed. In particular, if the compiler can prove
 that a certain check will necessarily fail, it will generate code to
 do an unconditional 'raise', even if checks are suppressed. The
 compiler warns in this case. Another case in which checks may not be
-eliminated is when they are embedded in certain run time routines such
+eliminated is when they are embedded in certain run-time routines such
 as math library routines.
 
 Of course, run-time checks are omitted whenever the compiler can prove
@@ -14108,7 +14091,7 @@ on subprogram calls and generic instantiations.
 Note that @code{-gnatE} is not necessary for safety, because in the
 default mode, GNAT ensures statically that the checks would not fail.
 For full details of the effect and use of this switch,
-@ref{1c,,Compiling with gcc}.
+@ref{c7,,Compiling with gcc}.
 @end table
 
 @geindex -fstack-check (gcc)
@@ -14124,7 +14107,7 @@ For full details of the effect and use of this switch,
 @item @code{-fstack-check}
 
 Activates stack overflow checking. For full details of the effect and use of
-this switch see @ref{f4,,Stack Overflow Checking}.
+this switch see @ref{e5,,Stack Overflow Checking}.
 @end table
 
 @geindex Unsuppress
@@ -14135,7 +14118,7 @@ checks) or @code{Unsuppress} (to add back suppressed checks) pragmas in
 the program source.
 
 @node Using gcc for Syntax Checking,Using gcc for Semantic Checking,Run-Time Checks,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat id20}@anchor{105}@anchor{gnat_ugn/building_executable_programs_with_gnat using-gcc-for-syntax-checking}@anchor{106}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id20}@anchor{f6}@anchor{gnat_ugn/building_executable_programs_with_gnat using-gcc-for-syntax-checking}@anchor{f7}
 @subsection Using @code{gcc} for Syntax Checking
 
 
@@ -14157,7 +14140,7 @@ $ gcc -c -gnats x.adb
 
 compiles file @code{x.adb} in syntax-check-only mode. You can check a
 series of files in a single command
-, and can use wild cards to specify such a group of files.
+, and can use wildcards to specify such a group of files.
 Note that you must specify the @code{-c} (compile
 only) flag in addition to the @code{-gnats} flag.
 
@@ -14188,11 +14171,11 @@ Normally, GNAT allows only a single unit in a source file. However, this
 restriction does not apply in syntax-check-only mode, and it is possible
 to check a file containing multiple compilation units concatenated
 together. This is primarily used by the @code{gnatchop} utility
-(@ref{36,,Renaming Files with gnatchop}).
+(@ref{1d,,Renaming Files with gnatchop}).
 @end table
 
 @node Using gcc for Semantic Checking,Compiling Different Versions of Ada,Using gcc for Syntax Checking,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat id21}@anchor{107}@anchor{gnat_ugn/building_executable_programs_with_gnat using-gcc-for-semantic-checking}@anchor{108}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id21}@anchor{f8}@anchor{gnat_ugn/building_executable_programs_with_gnat using-gcc-for-semantic-checking}@anchor{f9}
 @subsection Using @code{gcc} for Semantic Checking
 
 
@@ -14217,13 +14200,13 @@ semantic restrictions on file structuring to operate in this mode:
 
 @item 
 The needed source files must be accessible
-(see @ref{89,,Search Paths and the Run-Time Library (RTL)}).
+(see @ref{73,,Search Paths and the Run-Time Library (RTL)}).
 
 @item 
 Each file must contain only one compilation unit.
 
 @item 
-The file name and unit name must match (@ref{52,,File Naming Rules}).
+The file name and unit name must match (@ref{3b,,File Naming Rules}).
 @end itemize
 
 The output consists of error messages as appropriate. No object file is
@@ -14239,7 +14222,7 @@ and specifications where a separate body is present).
 @end table
 
 @node Compiling Different Versions of Ada,Character Set Control,Using gcc for Semantic Checking,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat compiling-different-versions-of-ada}@anchor{6}@anchor{gnat_ugn/building_executable_programs_with_gnat id22}@anchor{109}
+@anchor{gnat_ugn/building_executable_programs_with_gnat compiling-different-versions-of-ada}@anchor{6}@anchor{gnat_ugn/building_executable_programs_with_gnat id22}@anchor{fa}
 @subsection Compiling Different Versions of Ada
 
 
@@ -14373,7 +14356,7 @@ extensions, see the GNAT reference manual.
 @end table
 
 @node Character Set Control,File Naming Control,Compiling Different Versions of Ada,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat id23}@anchor{10a}@anchor{gnat_ugn/building_executable_programs_with_gnat character-set-control}@anchor{48}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id23}@anchor{fb}@anchor{gnat_ugn/building_executable_programs_with_gnat character-set-control}@anchor{31}
 @subsection Character Set Control
 
 
@@ -14484,7 +14467,7 @@ allowed in identifiers
 @end multitable
 
 
-See @ref{3e,,Foreign Language Representation} for full details on the
+See @ref{23,,Foreign Language Representation} for full details on the
 implementation of these character sets.
 @end table
 
@@ -14552,7 +14535,7 @@ Brackets encoding only (default value)
 
 
 For full details on these encoding
-methods see @ref{4e,,Wide_Character Encodings}.
+methods see @ref{37,,Wide_Character Encodings}.
 Note that brackets coding is always accepted, even if one of the other
 options is specified, so for example @code{-gnatW8} specifies that both
 brackets and UTF-8 encodings will be recognized. The units that are
@@ -14600,7 +14583,7 @@ comments are ended by an appropriate (CR, or CR/LF, or LF) line terminator.
 This is a common mode for many programs with foreign language comments.
 
 @node File Naming Control,Subprogram Inlining Control,Character Set Control,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat file-naming-control}@anchor{10b}@anchor{gnat_ugn/building_executable_programs_with_gnat id24}@anchor{10c}
+@anchor{gnat_ugn/building_executable_programs_with_gnat file-naming-control}@anchor{fc}@anchor{gnat_ugn/building_executable_programs_with_gnat id24}@anchor{fd}
 @subsection File Naming Control
 
 
@@ -14616,11 +14599,11 @@ Activates file name 'krunching'. @code{n}, a decimal integer in the range
 including the @code{.ads} or @code{.adb} extension). The default is not
 to enable file name krunching.
 
-For the source file naming rules, @ref{52,,File Naming Rules}.
+For the source file naming rules, @ref{3b,,File Naming Rules}.
 @end table
 
 @node Subprogram Inlining Control,Auxiliary Output Control,File Naming Control,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat subprogram-inlining-control}@anchor{10d}@anchor{gnat_ugn/building_executable_programs_with_gnat id25}@anchor{10e}
+@anchor{gnat_ugn/building_executable_programs_with_gnat subprogram-inlining-control}@anchor{fe}@anchor{gnat_ugn/building_executable_programs_with_gnat id25}@anchor{ff}
 @subsection Subprogram Inlining Control
 
 
@@ -14634,17 +14617,17 @@ For the source file naming rules, @ref{52,,File Naming Rules}.
 The @code{n} here is intended to suggest the first syllable of the word 'inline'.
 GNAT recognizes and processes @code{Inline} pragmas. However, for inlining to
 actually occur, optimization must be enabled and, by default, inlining of
-subprograms across modules is not performed. If you want to additionally
-enable inlining of subprograms specified by pragma @code{Inline} across modules,
+subprograms across units is not performed. If you want to additionally
+enable inlining of subprograms specified by pragma @code{Inline} across units,
 you must also specify this switch.
 
-In the absence of this switch, GNAT does not attempt inlining across modules
+In the absence of this switch, GNAT does not attempt inlining across units
 and does not access the bodies of subprograms for which @code{pragma Inline} is
 specified if they are not in the current unit.
 
 You can optionally specify the inlining level: 1 for moderate inlining across
-modules, which is a good compromise between compilation times and performances
-at run time, or 2 for full inlining across modules, which may bring about
+units, which is a good compromise between compilation times and performances
+at run time, or 2 for full inlining across units, which may bring about
 longer compilation times. If no inlining level is specified, the compiler will
 pick it based on the optimization level: 1 for @code{-O1}, @code{-O2} or
 @code{-Os} and 2 for @code{-O3}.
@@ -14653,7 +14636,7 @@ If you specify this switch the compiler will access these bodies,
 creating an extra source dependency for the resulting object file, and
 where possible, the call will be inlined.
 For further details on when inlining is possible
-see @ref{10f,,Inlining of Subprograms}.
+see @ref{100,,Inlining of Subprograms}.
 @end table
 
 @geindex -gnatN (gcc)
@@ -14674,32 +14657,10 @@ inlining, but that is no longer the case.
 @end table
 
 @node Auxiliary Output Control,Debugging Control,Subprogram Inlining Control,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat auxiliary-output-control}@anchor{110}@anchor{gnat_ugn/building_executable_programs_with_gnat id26}@anchor{111}
+@anchor{gnat_ugn/building_executable_programs_with_gnat auxiliary-output-control}@anchor{101}@anchor{gnat_ugn/building_executable_programs_with_gnat id26}@anchor{102}
 @subsection Auxiliary Output Control
 
 
-@geindex -gnatt (gcc)
-
-@geindex Writing internal trees
-
-@geindex Internal trees
-@geindex writing to file
-
-
-@table @asis
-
-@item @code{-gnatt}
-
-Causes GNAT to write the internal tree for a unit to a file (with the
-extension @code{.adt}.
-This not normally required, but is used by separate analysis tools.
-Typically
-these tools do the necessary compilations automatically, so you should
-not have to specify this switch in normal operation.
-Note that the combination of switches @code{-gnatct}
-generates a tree in the form required by ASIS applications.
-@end table
-
 @geindex -gnatu (gcc)
 
 
@@ -14766,7 +14727,7 @@ An object file has been generated for every source file.
 @end table
 
 @node Debugging Control,Exception Handling Control,Auxiliary Output Control,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat debugging-control}@anchor{112}@anchor{gnat_ugn/building_executable_programs_with_gnat id27}@anchor{113}
+@anchor{gnat_ugn/building_executable_programs_with_gnat debugging-control}@anchor{103}@anchor{gnat_ugn/building_executable_programs_with_gnat id27}@anchor{104}
 @subsection Debugging Control
 
 
@@ -14990,7 +14951,7 @@ restriction warnings rather than restrictions.
 
 @table @asis
 
-@item @code{-gnatR[0|1|2|3][e][m][s]}
+@item @code{-gnatR[0|1|2|3|4][e][j][m][s]}
 
 This switch controls output from the compiler of a listing showing
 representation information for declared types, objects and subprograms.
@@ -14998,6 +14959,7 @@ For @code{-gnatR0}, no information is output (equivalent to omitting
 the @code{-gnatR} switch). For @code{-gnatR1} (which is the default,
 so @code{-gnatR} with no parameter has the same effect), size and
 alignment information is listed for declared array and record types.
+
 For @code{-gnatR2}, size and alignment information is listed for all
 declared types and objects. The @code{Linker_Section} is also listed for any
 entity for which the @code{Linker_Section} is set explicitly or implicitly (the
@@ -15010,17 +14972,28 @@ a mostly obvious format with #n being used to represent the value of the
 n'th discriminant. See source files @code{repinfo.ads/adb} in the
 GNAT sources for full details on the format of @code{-gnatR3} output.
 
+For @code{-gnatR4}, information for relevant compiler-generated types
+is also listed, i.e. when they are structurally part of other declared
+types and objects.
+
 If the switch is followed by an @code{e} (e.g. @code{-gnatR2e}), then
 extended representation information for record sub-components of records
-are included.
+is included.
 
 If the switch is followed by an @code{m} (e.g. @code{-gnatRm}), then
 subprogram conventions and parameter passing mechanisms for all the
 subprograms are included.
 
+If the switch is followed by a @code{j} (e.g., @code{-gnatRj}), then
+the output is in the JSON data interchange format specified by the
+ECMA-404 standard. The semantic description of this JSON output is
+available in the specification of the Repinfo unit present in the
+compiler sources.
+
 If the switch is followed by an @code{s} (e.g., @code{-gnatR3s}), then
-the output is to a file with the name @code{file.rep} where file is
-the name of the corresponding source file.
+the output is to a file with the name @code{file.rep} where @code{file} is
+the name of the corresponding source file, except if @code{j} is also
+specified, in which case the file name is @code{file.json}.
 
 Note that it is possible for record components to have zero size. In
 this case, the component clause uses an obvious extension of permitted
@@ -15060,12 +15033,54 @@ suppresses this information. This saves some space and may slightly
 speed up compilation, but means that these tools cannot be used.
 @end table
 
+@geindex -fgnat-encodings (gcc)
+
+
+@table @asis
+
+@item @code{-fgnat-encodings=[all|gdb|minimal]}
+
+This switch controls the balance between GNAT encodings and standard DWARF
+emitted in the debug information.
+
+Historically, old debug formats like stabs were not powerful enough to
+express some Ada types (for instance, variant records or fixed-point types).
+To work around this, GNAT introduced proprietary encodings that embed the
+missing information ("GNAT encodings").
+
+Recent versions of the DWARF debug information format are now able to
+correctly describe most of these Ada constructs ("standard DWARF"). As
+third-party tools started to use this format, GNAT has been enhanced to
+generate it. However, most tools (including GDB) are still relying on GNAT
+encodings.
+
+To support all tools, GNAT needs to be versatile about the balance between
+generation of GNAT encodings and standard DWARF. This is what
+@code{-fgnat-encodings} is about.
+
+
+@itemize *
+
+@item 
+@code{=all}: Emit all GNAT encodings, and then emit as much standard DWARF as
+possible so it does not conflict with GNAT encodings.
+
+@item 
+@code{=gdb}: Emit as much standard DWARF as possible as long as the current
+GDB handles it. Emit GNAT encodings for the rest.
+
+@item 
+@code{=minimal}: Emit as much standard DWARF as possible and emit GNAT
+encodings for the rest.
+@end itemize
+@end table
+
 @node Exception Handling Control,Units to Sources Mapping Files,Debugging Control,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat id28}@anchor{114}@anchor{gnat_ugn/building_executable_programs_with_gnat exception-handling-control}@anchor{115}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id28}@anchor{105}@anchor{gnat_ugn/building_executable_programs_with_gnat exception-handling-control}@anchor{106}
 @subsection Exception Handling Control
 
 
-GNAT uses two methods for handling exceptions at run-time. The
+GNAT uses two methods for handling exceptions at run time. The
 @code{setjmp/longjmp} method saves the context when entering
 a frame with an exception handler. Then when an exception is
 raised, the context can be restored immediately, without the
@@ -15129,11 +15144,11 @@ is available for the target in use, otherwise it will generate an error.
 
 The same option @code{--RTS} must be used both for @code{gcc}
 and @code{gnatbind}. Passing this option to @code{gnatmake}
-(@ref{dc,,Switches for gnatmake}) will ensure the required consistency
+(@ref{cd,,Switches for gnatmake}) will ensure the required consistency
 through the compilation and binding steps.
 
 @node Units to Sources Mapping Files,Code Generation Control,Exception Handling Control,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat id29}@anchor{116}@anchor{gnat_ugn/building_executable_programs_with_gnat units-to-sources-mapping-files}@anchor{f7}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id29}@anchor{107}@anchor{gnat_ugn/building_executable_programs_with_gnat units-to-sources-mapping-files}@anchor{e8}
 @subsection Units to Sources Mapping Files
 
 
@@ -15185,7 +15200,7 @@ mapping file and communicates it to the compiler using this switch.
 @end table
 
 @node Code Generation Control,,Units to Sources Mapping Files,Compiler Switches
-@anchor{gnat_ugn/building_executable_programs_with_gnat code-generation-control}@anchor{117}@anchor{gnat_ugn/building_executable_programs_with_gnat id30}@anchor{118}
+@anchor{gnat_ugn/building_executable_programs_with_gnat code-generation-control}@anchor{108}@anchor{gnat_ugn/building_executable_programs_with_gnat id30}@anchor{109}
 @subsection Code Generation Control
 
 
@@ -15214,7 +15229,7 @@ there is no point in using @code{-m} switches to improve performance
 unless you actually see a performance improvement.
 
 @node Linker Switches,Binding with gnatbind,Compiler Switches,Building Executable Programs with GNAT
-@anchor{gnat_ugn/building_executable_programs_with_gnat linker-switches}@anchor{119}@anchor{gnat_ugn/building_executable_programs_with_gnat id31}@anchor{11a}
+@anchor{gnat_ugn/building_executable_programs_with_gnat linker-switches}@anchor{10a}@anchor{gnat_ugn/building_executable_programs_with_gnat id31}@anchor{10b}
 @section Linker Switches
 
 
@@ -15234,7 +15249,7 @@ platforms.
 @end table
 
 @node Binding with gnatbind,Linking with gnatlink,Linker Switches,Building Executable Programs with GNAT
-@anchor{gnat_ugn/building_executable_programs_with_gnat binding-with-gnatbind}@anchor{1d}@anchor{gnat_ugn/building_executable_programs_with_gnat id32}@anchor{11b}
+@anchor{gnat_ugn/building_executable_programs_with_gnat binding-with-gnatbind}@anchor{c8}@anchor{gnat_ugn/building_executable_programs_with_gnat id32}@anchor{10c}
 @section Binding with @code{gnatbind}
 
 
@@ -15285,7 +15300,7 @@ to be read by the @code{gnatlink} utility used to link the Ada application.
 @end menu
 
 @node Running gnatbind,Switches for gnatbind,,Binding with gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat running-gnatbind}@anchor{11c}@anchor{gnat_ugn/building_executable_programs_with_gnat id33}@anchor{11d}
+@anchor{gnat_ugn/building_executable_programs_with_gnat running-gnatbind}@anchor{10d}@anchor{gnat_ugn/building_executable_programs_with_gnat id33}@anchor{10e}
 @subsection Running @code{gnatbind}
 
 
@@ -15370,7 +15385,7 @@ Ada code provided the @code{-g} switch is used for
 @code{gnatbind} and @code{gnatlink}.
 
 @node Switches for gnatbind,Command-Line Access,Running gnatbind,Binding with gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat id34}@anchor{11e}@anchor{gnat_ugn/building_executable_programs_with_gnat switches-for-gnatbind}@anchor{11f}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id34}@anchor{10f}@anchor{gnat_ugn/building_executable_programs_with_gnat switches-for-gnatbind}@anchor{110}
 @subsection Switches for @code{gnatbind}
 
 
@@ -15489,27 +15504,25 @@ When they do not already have such a pragma.
 
 @item @code{-D@emph{nn}[k|m]}
 
-This switch can be used to change the default secondary stack size value
-to a specified size @code{nn}, which is expressed in bytes by default, or
-in kilobytes when suffixed with @code{k} or in megabytes when suffixed
-with @code{m}.
+Set the default secondary stack size to @code{nn}. The suffix indicates whether
+the size is in bytes (no suffix), kilobytes (@code{k} suffix) or megabytes
+(@code{m} suffix).
 
-The secondary stack is used to deal with functions that return a variable
-sized result, for example a function returning an unconstrained
-String. There are two ways in which this secondary stack is allocated.
+The secondary stack holds objects of unconstrained types that are returned by
+functions, for example unconstrained Strings. The size of the secondary stack
+can be dynamic or fixed depending on the target.
 
-For most targets, the secondary stack grows on demand and is allocated
-as a chain of blocks in the heap. The -D option is not very
-relevant. It only give some control over the size of the allocated
-blocks (whose size is the minimum of the default secondary stack size value,
-and the actual size needed for the current allocation request).
+For most targets, the secondary stack grows on demand and is implemented as
+a chain of blocks in the heap. In this case, the default secondary stack size
+determines the initial size of the secondary stack for each task and the
+smallest amount the secondary stack can grow by.
 
-For certain targets, notably VxWorks 653 and bare board targets,
-the secondary stack is allocated by carving off a chunk of the primary task
-stack. By default this is a fixed percentage of the primary task stack as
-defined by System.Parameter.Sec_Stack_Percentage. This can be overridden per
-task using the Secondary_Stack_Size pragma/aspect. The -D option is used to
-define the size of the environment task's secondary stack.
+For Ravenscar, ZFP, and Cert run-times the size of the secondary stack is
+fixed. This switch can be used to change the default size of these stacks.
+The default secondary stack size can be overridden on a per-task basis if
+individual tasks have different secondary stack requirements. This is
+achieved through the Secondary_Stack_Size aspect that takes the size of the
+secondary stack in bytes.
 @end table
 
 @geindex -e (gnatbind)
@@ -15567,7 +15580,8 @@ Currently the same as @code{-Ea}.
 
 @item @code{-f@emph{elab-order}}
 
-Force elaboration order.
+Force elaboration order. For further details see @ref{111,,Elaboration Control}
+and @ref{f,,Elaboration Order Handling in GNAT}.
 @end table
 
 @geindex -F (gnatbind)
@@ -15594,22 +15608,41 @@ flag checks are generated.
 @item @code{-h}
 
 Output usage (help) information.
+@end table
+
+@geindex -H (gnatbind)
+
+
+@table @asis
+
+@item @code{-H}
+
+Legacy elaboration order model enabled. For further details see
+@ref{f,,Elaboration Order Handling in GNAT}.
+@end table
 
 @geindex -H32 (gnatbind)
 
+
+@table @asis
+
 @item @code{-H32}
 
 Use 32-bit allocations for @code{__gnat_malloc} (and thus for access types).
-For further details see @ref{120,,Dynamic Allocation Control}.
+For further details see @ref{112,,Dynamic Allocation Control}.
+@end table
 
 @geindex -H64 (gnatbind)
 
 @geindex __gnat_malloc
 
+
+@table @asis
+
 @item @code{-H64}
 
 Use 64-bit allocations for @code{__gnat_malloc} (and thus for access types).
-For further details see @ref{120,,Dynamic Allocation Control}.
+For further details see @ref{112,,Dynamic Allocation Control}.
 
 @geindex -I (gnatbind)
 
@@ -15636,11 +15669,11 @@ Output chosen elaboration order.
 @item @code{-L@emph{xxx}}
 
 Bind the units for library building. In this case the @code{adainit} and
-@code{adafinal} procedures (@ref{b4,,Binding with Non-Ada Main Programs})
+@code{adafinal} procedures (@ref{a0,,Binding with Non-Ada Main Programs})
 are renamed to @code{@emph{xxx}init} and
 @code{@emph{xxx}final}.
 Implies -n.
-(@ref{15,,GNAT and Libraries}, for more details.)
+(@ref{2a,,GNAT and Libraries}, for more details.)
 
 @geindex -M (gnatbind)
 
@@ -15662,6 +15695,28 @@ limit, then a message is output and the bind is abandoned.
 A value of zero means that no limit is enforced. The equal
 sign is optional.
 
+@geindex -minimal (gnatbind)
+
+@item @code{-minimal}
+
+Generate a binder file suitable for space-constrained applications. When
+active, binder-generated objects not required for program operation are no
+longer generated. @strong{Warning:} this option comes with the following
+limitations:
+
+
+@itemize *
+
+@item 
+Starting the program's execution in the debugger will cause it to
+stop at the start of the @code{main} function instead of the main subprogram.
+This can be worked around by manually inserting a breakpoint on that
+subprogram and resuming the program's execution until reaching that breakpoint.
+
+@item 
+Programs using GNAT.Compiler_Version will not link.
+@end itemize
+
 @geindex -n (gnatbind)
 
 @item @code{-n}
@@ -15684,8 +15739,8 @@ Do not look for library files in the system default directory.
 
 @item @code{--RTS=@emph{rts-path}}
 
-Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (@ref{dc,,Switches for gnatmake}).
+Specifies the default location of the run-time library. Same meaning as the
+equivalent @code{gnatmake} flag (@ref{cd,,Switches for gnatmake}).
 
 @geindex -o (gnatbind)
 
@@ -15801,13 +15856,13 @@ then the default is @code{in} (invalid values).
 
 @item @code{-static}
 
-Link against a static GNAT run time.
+Link against a static GNAT run-time.
 
 @geindex -shared (gnatbind)
 
 @item @code{-shared}
 
-Link against a shared GNAT run time when available.
+Link against a shared GNAT run-time when available.
 
 @geindex -t (gnatbind)
 
@@ -15826,7 +15881,7 @@ does support some general notion of round-robin scheduling, then any
 nonzero value will activate round-robin scheduling.
 
 A value of zero is treated specially. It turns off time
-slicing, and in addition, indicates to the tasking run time that the
+slicing, and in addition, indicates to the tasking run-time that the
 semantics should match as closely as possible the Annex D
 requirements of the Ada RM, and in particular sets the default
 scheduling policy to @code{FIFO_Within_Priorities}.
@@ -15839,7 +15894,7 @@ Enable dynamic stack usage, with @code{n} results stored and displayed
 at program termination. A result is generated when a task
 terminates. Results that can't be stored are displayed on the fly, at
 task termination. This option is currently not supported on Itanium
-platforms. (See @ref{121,,Dynamic Stack Usage Analysis} for details.)
+platforms. (See @ref{113,,Dynamic Stack Usage Analysis} for details.)
 
 @geindex -v (gnatbind)
 
@@ -15874,6 +15929,17 @@ Override default wide character encoding for standard Text_IO files.
 
 Exclude source files (check object consistency only).
 
+@geindex -xdr (gnatbind)
+
+@item @code{-xdr}
+
+Use the target-independent XDR protocol for stream oriented attributes
+instead of the default implementation which is based on direct binary
+representations and is therefore target-and endianness-dependent.
+However it does not support 128-bit integer types and the exception
+@code{Ada.IO_Exceptions.Device_Error} is raised if any attempt is made
+at streaming 128-bit integer types with it.
+
 @geindex -Xnnn (gnatbind)
 
 @item @code{-X@emph{nnn}}
@@ -15908,7 +15974,7 @@ no arguments.
 @end menu
 
 @node Consistency-Checking Modes,Binder Error Message Control,,Switches for gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat consistency-checking-modes}@anchor{122}@anchor{gnat_ugn/building_executable_programs_with_gnat id35}@anchor{123}
+@anchor{gnat_ugn/building_executable_programs_with_gnat consistency-checking-modes}@anchor{114}@anchor{gnat_ugn/building_executable_programs_with_gnat id35}@anchor{115}
 @subsubsection Consistency-Checking Modes
 
 
@@ -15962,7 +16028,7 @@ case the checking against sources has already been performed by
 @end table
 
 @node Binder Error Message Control,Elaboration Control,Consistency-Checking Modes,Switches for gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat id36}@anchor{124}@anchor{gnat_ugn/building_executable_programs_with_gnat binder-error-message-control}@anchor{125}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id36}@anchor{116}@anchor{gnat_ugn/building_executable_programs_with_gnat binder-error-message-control}@anchor{117}
 @subsubsection Binder Error Message Control
 
 
@@ -16072,12 +16138,12 @@ with extreme care.
 @end table
 
 @node Elaboration Control,Output Control,Binder Error Message Control,Switches for gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat id37}@anchor{126}@anchor{gnat_ugn/building_executable_programs_with_gnat elaboration-control}@anchor{127}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id37}@anchor{118}@anchor{gnat_ugn/building_executable_programs_with_gnat elaboration-control}@anchor{111}
 @subsubsection Elaboration Control
 
 
 The following switches provide additional control over the elaboration
-order. For full details see @ref{f,,Elaboration Order Handling in GNAT}.
+order. For further details see @ref{f,,Elaboration Order Handling in GNAT}.
 
 @geindex -f (gnatbind)
 
@@ -16122,34 +16188,42 @@ above forced elaboration order file.
 Blank lines and Ada-style comments are ignored. Unit names that do not exist
 in the program are ignored. Units in the GNAT predefined library are also
 ignored.
+@end table
 
 @geindex -p (gnatbind)
 
+
+@table @asis
+
 @item @code{-p}
 
-Normally the binder attempts to choose an elaboration order that is
-likely to minimize the likelihood of an elaboration order error resulting
-in raising a @code{Program_Error} exception. This switch reverses the
-action of the binder, and requests that it deliberately choose an order
-that is likely to maximize the likelihood of an elaboration error.
-This is useful in ensuring portability and avoiding dependence on
-accidental fortuitous elaboration ordering.
+Pessimistic elaboration order
 
-Normally it only makes sense to use the @code{-p}
-switch if dynamic
+This switch is only applicable to the pre-20.x legacy elaboration models.
+The post-20.x elaboration model uses a more informed approach of ordering
+the units.
+
+Normally the binder attempts to choose an elaboration order that is likely to
+minimize the likelihood of an elaboration order error resulting in raising a
+@code{Program_Error} exception. This switch reverses the action of the binder,
+and requests that it deliberately choose an order that is likely to maximize
+the likelihood of an elaboration error. This is useful in ensuring
+portability and avoiding dependence on accidental fortuitous elaboration
+ordering.
+
+Normally it only makes sense to use the @code{-p} switch if dynamic
 elaboration checking is used (@code{-gnatE} switch used for compilation).
 This is because in the default static elaboration mode, all necessary
 @code{Elaborate} and @code{Elaborate_All} pragmas are implicitly inserted.
-These implicit pragmas are still respected by the binder in
-@code{-p} mode, so a
-safe elaboration order is assured.
+These implicit pragmas are still respected by the binder in @code{-p}
+mode, so a safe elaboration order is assured.
 
-Note that @code{-p} is not intended for
-production use; it is more for debugging/experimental use.
+Note that @code{-p} is not intended for production use; it is more for
+debugging/experimental use.
 @end table
 
 @node Output Control,Dynamic Allocation Control,Elaboration Control,Switches for gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat output-control}@anchor{128}@anchor{gnat_ugn/building_executable_programs_with_gnat id38}@anchor{129}
+@anchor{gnat_ugn/building_executable_programs_with_gnat output-control}@anchor{119}@anchor{gnat_ugn/building_executable_programs_with_gnat id38}@anchor{11a}
 @subsubsection Output Control
 
 
@@ -16230,7 +16304,7 @@ be used to improve code generation in some cases.
 @end table
 
 @node Dynamic Allocation Control,Binding with Non-Ada Main Programs,Output Control,Switches for gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat dynamic-allocation-control}@anchor{120}@anchor{gnat_ugn/building_executable_programs_with_gnat id39}@anchor{12a}
+@anchor{gnat_ugn/building_executable_programs_with_gnat dynamic-allocation-control}@anchor{112}@anchor{gnat_ugn/building_executable_programs_with_gnat id39}@anchor{11b}
 @subsubsection Dynamic Allocation Control
 
 
@@ -16256,7 +16330,7 @@ unless explicitly overridden by a @code{'Size} clause on the access type.
 These switches are only effective on VMS platforms.
 
 @node Binding with Non-Ada Main Programs,Binding Programs with No Main Subprogram,Dynamic Allocation Control,Switches for gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat binding-with-non-ada-main-programs}@anchor{b4}@anchor{gnat_ugn/building_executable_programs_with_gnat id40}@anchor{12b}
+@anchor{gnat_ugn/building_executable_programs_with_gnat binding-with-non-ada-main-programs}@anchor{a0}@anchor{gnat_ugn/building_executable_programs_with_gnat id40}@anchor{11c}
 @subsubsection Binding with Non-Ada Main Programs
 
 
@@ -16265,7 +16339,7 @@ program is in Ada, and that the task of the binder is to generate a
 corresponding function @code{main} that invokes this Ada main
 program. GNAT also supports the building of executable programs where
 the main program is not in Ada, but some of the called routines are
-written in Ada and compiled using GNAT (@ref{44,,Mixed Language Programming}).
+written in Ada and compiled using GNAT (@ref{2c,,Mixed Language Programming}).
 The following switch is used in this situation:
 
 @quotation
@@ -16344,7 +16418,7 @@ The output is an Ada unit in source form that can be compiled with GNAT.
 This compilation occurs automatically as part of the @code{gnatlink}
 processing.
 
-Currently the GNAT run time requires a FPU using 80 bits mode
+Currently the GNAT run-time requires a FPU using 80 bits mode
 precision. Under targets where this is not the default it is required to
 call GNAT.Float_Control.Reset before using floating point numbers (this
 include float computation, float input and output) in the Ada code. A
@@ -16352,7 +16426,7 @@ side effect is that this could be the wrong mode for the foreign code
 where floating point computation could be broken after this call.
 
 @node Binding Programs with No Main Subprogram,,Binding with Non-Ada Main Programs,Switches for gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat binding-programs-with-no-main-subprogram}@anchor{12c}@anchor{gnat_ugn/building_executable_programs_with_gnat id41}@anchor{12d}
+@anchor{gnat_ugn/building_executable_programs_with_gnat binding-programs-with-no-main-subprogram}@anchor{11d}@anchor{gnat_ugn/building_executable_programs_with_gnat id41}@anchor{11e}
 @subsubsection Binding Programs with No Main Subprogram
 
 
@@ -16383,7 +16457,7 @@ the binder switch
 @end table
 
 @node Command-Line Access,Search Paths for gnatbind,Switches for gnatbind,Binding with gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat id42}@anchor{12e}@anchor{gnat_ugn/building_executable_programs_with_gnat command-line-access}@anchor{12f}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id42}@anchor{11f}@anchor{gnat_ugn/building_executable_programs_with_gnat command-line-access}@anchor{120}
 @subsection Command-Line Access
 
 
@@ -16413,7 +16487,7 @@ required, your main program must set @code{gnat_argc} and
 it.
 
 @node Search Paths for gnatbind,Examples of gnatbind Usage,Command-Line Access,Binding with gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat search-paths-for-gnatbind}@anchor{8c}@anchor{gnat_ugn/building_executable_programs_with_gnat id43}@anchor{130}
+@anchor{gnat_ugn/building_executable_programs_with_gnat search-paths-for-gnatbind}@anchor{76}@anchor{gnat_ugn/building_executable_programs_with_gnat id43}@anchor{121}
 @subsection Search Paths for @code{gnatbind}
 
 
@@ -16421,7 +16495,7 @@ The binder takes the name of an ALI file as its argument and needs to
 locate source files as well as other ALI files to verify object consistency.
 
 For source files, it follows exactly the same search rules as @code{gcc}
-(see @ref{89,,Search Paths and the Run-Time Library (RTL)}). For ALI files the
+(see @ref{73,,Search Paths and the Run-Time Library (RTL)}). For ALI files the
 directories searched are:
 
 
@@ -16469,8 +16543,8 @@ of GNAT).
 @item 
 The content of the @code{ada_object_path} file which is part of the GNAT
 installation tree and is used to store standard libraries such as the
-GNAT Run Time Library (RTL) unless the switch @code{-nostdlib} is
-specified. See @ref{87,,Installing a library}
+GNAT Run-Time Library (RTL) unless the switch @code{-nostdlib} is
+specified. See @ref{71,,Installing a library}
 @end itemize
 
 @geindex -I (gnatbind)
@@ -16517,7 +16591,7 @@ in compiling sources from multiple directories. This can make
 development environments much more flexible.
 
 @node Examples of gnatbind Usage,,Search Paths for gnatbind,Binding with gnatbind
-@anchor{gnat_ugn/building_executable_programs_with_gnat id44}@anchor{131}@anchor{gnat_ugn/building_executable_programs_with_gnat examples-of-gnatbind-usage}@anchor{132}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id44}@anchor{122}@anchor{gnat_ugn/building_executable_programs_with_gnat examples-of-gnatbind-usage}@anchor{123}
 @subsection Examples of @code{gnatbind} Usage
 
 
@@ -16546,7 +16620,7 @@ since gnatlink will not be able to find the generated file.
 @end quotation
 
 @node Linking with gnatlink,Using the GNU make Utility,Binding with gnatbind,Building Executable Programs with GNAT
-@anchor{gnat_ugn/building_executable_programs_with_gnat id45}@anchor{133}@anchor{gnat_ugn/building_executable_programs_with_gnat linking-with-gnatlink}@anchor{1e}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id45}@anchor{124}@anchor{gnat_ugn/building_executable_programs_with_gnat linking-with-gnatlink}@anchor{c9}
 @section Linking with @code{gnatlink}
 
 
@@ -16567,7 +16641,7 @@ generated by the @code{gnatbind} to determine this list.
 @end menu
 
 @node Running gnatlink,Switches for gnatlink,,Linking with gnatlink
-@anchor{gnat_ugn/building_executable_programs_with_gnat id46}@anchor{134}@anchor{gnat_ugn/building_executable_programs_with_gnat running-gnatlink}@anchor{135}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id46}@anchor{125}@anchor{gnat_ugn/building_executable_programs_with_gnat running-gnatlink}@anchor{126}
 @subsection Running @code{gnatlink}
 
 
@@ -16626,8 +16700,8 @@ $ gnatlink my_prog -Wl,-Map,MAPFILE
 
 Using @code{linker options} it is possible to set the program stack and
 heap size.
-See @ref{136,,Setting Stack Size from gnatlink} and
-@ref{137,,Setting Heap Size from gnatlink}.
+See @ref{127,,Setting Stack Size from gnatlink} and
+@ref{128,,Setting Heap Size from gnatlink}.
 
 @code{gnatlink} determines the list of objects required by the Ada
 program and prepends them to the list of objects passed to the linker.
@@ -16636,7 +16710,7 @@ program and prepends them to the list of objects passed to the linker.
 presented to the linker.
 
 @node Switches for gnatlink,,Running gnatlink,Linking with gnatlink
-@anchor{gnat_ugn/building_executable_programs_with_gnat id47}@anchor{138}@anchor{gnat_ugn/building_executable_programs_with_gnat switches-for-gnatlink}@anchor{139}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id47}@anchor{129}@anchor{gnat_ugn/building_executable_programs_with_gnat switches-for-gnatlink}@anchor{12a}
 @subsection Switches for @code{gnatlink}
 
 
@@ -16747,18 +16821,6 @@ name as the main unit. For example, @code{gnatlink try.ali} creates
 an executable called @code{try}.
 @end table
 
-@geindex -b (gnatlink)
-
-
-@table @asis
-
-@item @code{-b @emph{target}}
-
-Compile your program to run on @code{target}, which is the name of a
-system configuration. You must have a GNAT cross-compiler built if
-@code{target} is not the same as your host system.
-@end table
-
 @geindex -B (gnatlink)
 
 
@@ -16843,7 +16905,7 @@ switch.
 @end table
 
 @node Using the GNU make Utility,,Linking with gnatlink,Building Executable Programs with GNAT
-@anchor{gnat_ugn/building_executable_programs_with_gnat using-the-gnu-make-utility}@anchor{1f}@anchor{gnat_ugn/building_executable_programs_with_gnat id48}@anchor{13a}
+@anchor{gnat_ugn/building_executable_programs_with_gnat using-the-gnu-make-utility}@anchor{70}@anchor{gnat_ugn/building_executable_programs_with_gnat id48}@anchor{12b}
 @section Using the GNU @code{make} Utility
 
 
@@ -16852,7 +16914,7 @@ switch.
 
 This chapter offers some examples of makefiles that solve specific
 problems. It does not explain how to write a makefile, nor does it try to replace the
-@code{gnatmake} utility (@ref{1b,,Building with gnatmake}).
+@code{gnatmake} utility (@ref{c6,,Building with gnatmake}).
 
 All the examples in this section are specific to the GNU version of
 make. Although @code{make} is a standard utility, and the basic language
@@ -16868,7 +16930,7 @@ is the same, these examples use some advanced features found only in
 @end menu
 
 @node Using gnatmake in a Makefile,Automatically Creating a List of Directories,,Using the GNU make Utility
-@anchor{gnat_ugn/building_executable_programs_with_gnat using-gnatmake-in-a-makefile}@anchor{13b}@anchor{gnat_ugn/building_executable_programs_with_gnat id49}@anchor{13c}
+@anchor{gnat_ugn/building_executable_programs_with_gnat using-gnatmake-in-a-makefile}@anchor{12c}@anchor{gnat_ugn/building_executable_programs_with_gnat id49}@anchor{12d}
 @subsection Using gnatmake in a Makefile
 
 
@@ -16887,7 +16949,7 @@ the appropriate directories.
 
 Note that you should also read the example on how to automatically
 create the list of directories
-(@ref{13d,,Automatically Creating a List of Directories})
+(@ref{12e,,Automatically Creating a List of Directories})
 which might help you in case your project has a lot of subdirectories.
 
 @example
@@ -16967,7 +17029,7 @@ clean::
 @end example
 
 @node Automatically Creating a List of Directories,Generating the Command Line Switches,Using gnatmake in a Makefile,Using the GNU make Utility
-@anchor{gnat_ugn/building_executable_programs_with_gnat id50}@anchor{13e}@anchor{gnat_ugn/building_executable_programs_with_gnat automatically-creating-a-list-of-directories}@anchor{13d}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id50}@anchor{12f}@anchor{gnat_ugn/building_executable_programs_with_gnat automatically-creating-a-list-of-directories}@anchor{12e}
 @subsection Automatically Creating a List of Directories
 
 
@@ -17040,12 +17102,12 @@ DIRS := $@{shell find $@{ROOT_DIRECTORY@} -type d -print@}
 @end example
 
 @node Generating the Command Line Switches,Overcoming Command Line Length Limits,Automatically Creating a List of Directories,Using the GNU make Utility
-@anchor{gnat_ugn/building_executable_programs_with_gnat id51}@anchor{13f}@anchor{gnat_ugn/building_executable_programs_with_gnat generating-the-command-line-switches}@anchor{140}
+@anchor{gnat_ugn/building_executable_programs_with_gnat id51}@anchor{130}@anchor{gnat_ugn/building_executable_programs_with_gnat generating-the-command-line-switches}@anchor{131}
 @subsection Generating the Command Line Switches
 
 
 Once you have created the list of directories as explained in the
-previous section (@ref{13d,,Automatically Creating a List of Directories}),
+previous section (@ref{12e,,Automatically Creating a List of Directories}),
 you can easily generate the command line arguments to pass to gnatmake.
 
 For the sake of completeness, this example assumes that the source path
@@ -17066,7 +17128,7 @@ all:
 @end example
 
 @node Overcoming Command Line Length Limits,,Generating the Command Line Switches,Using the GNU make Utility
-@anchor{gnat_ugn/building_executable_programs_with_gnat overcoming-command-line-length-limits}@anchor{141}@anchor{gnat_ugn/building_executable_programs_with_gnat id52}@anchor{142}
+@anchor{gnat_ugn/building_executable_programs_with_gnat overcoming-command-line-length-limits}@anchor{132}@anchor{gnat_ugn/building_executable_programs_with_gnat id52}@anchor{133}
 @subsection Overcoming Command Line Length Limits
 
 
@@ -17081,7 +17143,7 @@ even none on most systems).
 
 It assumes that you have created a list of directories in your Makefile,
 using one of the methods presented in
-@ref{13d,,Automatically Creating a List of Directories}.
+@ref{12e,,Automatically Creating a List of Directories}.
 For the sake of completeness, we assume that the object
 path (where the ALI files are found) is different from the sources patch.
 
@@ -17124,7 +17186,7 @@ all:
 @end example
 
 @node GNAT Utility Programs,GNAT and Program Execution,Building Executable Programs with GNAT,Top
-@anchor{gnat_ugn/gnat_utility_programs doc}@anchor{143}@anchor{gnat_ugn/gnat_utility_programs gnat-utility-programs}@anchor{b}@anchor{gnat_ugn/gnat_utility_programs id1}@anchor{144}
+@anchor{gnat_ugn/gnat_utility_programs doc}@anchor{134}@anchor{gnat_ugn/gnat_utility_programs gnat-utility-programs}@anchor{b}@anchor{gnat_ugn/gnat_utility_programs id1}@anchor{135}
 @chapter GNAT Utility Programs
 
 
@@ -17135,16 +17197,10 @@ This chapter describes a number of utility programs:
 @itemize *
 
 @item 
-@ref{20,,The File Cleanup Utility gnatclean}
-
-@item 
-@ref{21,,The GNAT Library Browser gnatls}
+@ref{136,,The File Cleanup Utility gnatclean}
 
 @item 
-@ref{22,,The Cross-Referencing Tools gnatxref and gnatfind}
-
-@item 
-@ref{23,,The Ada to HTML Converter gnathtml}
+@ref{137,,The GNAT Library Browser gnatls}
 @end itemize
 
 Other GNAT utilities are described elsewhere in this manual:
@@ -17153,28 +17209,26 @@ Other GNAT utilities are described elsewhere in this manual:
 @itemize *
 
 @item 
-@ref{59,,Handling Arbitrary File Naming Conventions with gnatname}
+@ref{42,,Handling Arbitrary File Naming Conventions with gnatname}
 
 @item 
-@ref{63,,File Name Krunching with gnatkr}
+@ref{4c,,File Name Krunching with gnatkr}
 
 @item 
-@ref{36,,Renaming Files with gnatchop}
+@ref{1d,,Renaming Files with gnatchop}
 
 @item 
-@ref{17,,Preprocessing with gnatprep}
+@ref{8f,,Preprocessing with gnatprep}
 @end itemize
 
 @menu
 * The File Cleanup Utility gnatclean:: 
 * The GNAT Library Browser gnatls:: 
-* The Cross-Referencing Tools gnatxref and gnatfind:: 
-* The Ada to HTML Converter gnathtml:: 
 
 @end menu
 
 @node The File Cleanup Utility gnatclean,The GNAT Library Browser gnatls,,GNAT Utility Programs
-@anchor{gnat_ugn/gnat_utility_programs id2}@anchor{145}@anchor{gnat_ugn/gnat_utility_programs the-file-cleanup-utility-gnatclean}@anchor{20}
+@anchor{gnat_ugn/gnat_utility_programs id2}@anchor{138}@anchor{gnat_ugn/gnat_utility_programs the-file-cleanup-utility-gnatclean}@anchor{136}
 @section The File Cleanup Utility @code{gnatclean}
 
 
@@ -17194,7 +17248,7 @@ generated files and executable files.
 @end menu
 
 @node Running gnatclean,Switches for gnatclean,,The File Cleanup Utility gnatclean
-@anchor{gnat_ugn/gnat_utility_programs running-gnatclean}@anchor{146}@anchor{gnat_ugn/gnat_utility_programs id3}@anchor{147}
+@anchor{gnat_ugn/gnat_utility_programs running-gnatclean}@anchor{139}@anchor{gnat_ugn/gnat_utility_programs id3}@anchor{13a}
 @subsection Running @code{gnatclean}
 
 
@@ -17218,7 +17272,7 @@ the linker. In informative-only mode, specified by switch
 normal mode is listed, but no file is actually deleted.
 
 @node Switches for gnatclean,,Running gnatclean,The File Cleanup Utility gnatclean
-@anchor{gnat_ugn/gnat_utility_programs id4}@anchor{148}@anchor{gnat_ugn/gnat_utility_programs switches-for-gnatclean}@anchor{149}
+@anchor{gnat_ugn/gnat_utility_programs id4}@anchor{13b}@anchor{gnat_ugn/gnat_utility_programs switches-for-gnatclean}@anchor{13c}
 @subsection Switches for @code{gnatclean}
 
 
@@ -17231,7 +17285,7 @@ normal mode is listed, but no file is actually deleted.
 
 @item @code{--version}
 
-Display Copyright and version, then exit disregarding all other options.
+Display copyright and version, then exit disregarding all other options.
 @end table
 
 @geindex --help (gnatclean)
@@ -17369,7 +17423,7 @@ Verbose mode.
 @item @code{-vP@emph{x}}
 
 Indicates the verbosity of the parsing of GNAT project files.
-@ref{de,,Switches Related to Project Files}.
+@ref{cf,,Switches Related to Project Files}.
 @end table
 
 @geindex -X (gnatclean)
@@ -17382,7 +17436,7 @@ Indicates the verbosity of the parsing of GNAT project files.
 Indicates that external variable @code{name} has the value @code{value}.
 The Project Manager will use this value for occurrences of
 @code{external(name)} when parsing the project file.
-See @ref{de,,Switches Related to Project Files}.
+See @ref{cf,,Switches Related to Project Files}.
 @end table
 
 @geindex -aO (gnatclean)
@@ -17419,8 +17473,8 @@ Do not look for ALI or object files in the directory
 where @code{gnatclean} was invoked.
 @end table
 
-@node The GNAT Library Browser gnatls,The Cross-Referencing Tools gnatxref and gnatfind,The File Cleanup Utility gnatclean,GNAT Utility Programs
-@anchor{gnat_ugn/gnat_utility_programs the-gnat-library-browser-gnatls}@anchor{21}@anchor{gnat_ugn/gnat_utility_programs id5}@anchor{14a}
+@node The GNAT Library Browser gnatls,,The File Cleanup Utility gnatclean,GNAT Utility Programs
+@anchor{gnat_ugn/gnat_utility_programs the-gnat-library-browser-gnatls}@anchor{137}@anchor{gnat_ugn/gnat_utility_programs id5}@anchor{13d}
 @section The GNAT Library Browser @code{gnatls}
 
 
@@ -17441,7 +17495,7 @@ as well as various characteristics.
 @end menu
 
 @node Running gnatls,Switches for gnatls,,The GNAT Library Browser gnatls
-@anchor{gnat_ugn/gnat_utility_programs id6}@anchor{14b}@anchor{gnat_ugn/gnat_utility_programs running-gnatls}@anchor{14c}
+@anchor{gnat_ugn/gnat_utility_programs id6}@anchor{13e}@anchor{gnat_ugn/gnat_utility_programs running-gnatls}@anchor{13f}
 @subsection Running @code{gnatls}
 
 
@@ -17455,7 +17509,7 @@ $ gnatls switches object_or_ali_file
 @end quotation
 
 The main argument is the list of object or @code{ali} files
-(see @ref{42,,The Ada Library Information Files})
+(see @ref{28,,The Ada Library Information Files})
 for which information is requested.
 
 In normal mode, without additional option, @code{gnatls} produces a
@@ -17521,7 +17575,7 @@ version of the same source that has been modified.
 @end table
 
 @node Switches for gnatls,Example of gnatls Usage,Running gnatls,The GNAT Library Browser gnatls
-@anchor{gnat_ugn/gnat_utility_programs id7}@anchor{14d}@anchor{gnat_ugn/gnat_utility_programs switches-for-gnatls}@anchor{14e}
+@anchor{gnat_ugn/gnat_utility_programs id7}@anchor{140}@anchor{gnat_ugn/gnat_utility_programs switches-for-gnatls}@anchor{141}
 @subsection Switches for @code{gnatls}
 
 
@@ -17534,7 +17588,7 @@ version of the same source that has been modified.
 
 @item @code{--version}
 
-Display Copyright and version, then exit disregarding all other options.
+Display copyright and version, then exit disregarding all other options.
 @end table
 
 @geindex --help (gnatls)
@@ -17636,7 +17690,7 @@ Several such switches may be specified simultaneously.
 @item @code{-aO@emph{dir}}, @code{-aI@emph{dir}}, @code{-I@emph{dir}}, @code{-I-}, @code{-nostdinc}
 
 Source path manipulation. Same meaning as the equivalent @code{gnatmake}
-flags (@ref{dc,,Switches for gnatmake}).
+flags (@ref{cd,,Switches for gnatmake}).
 @end table
 
 @geindex -aP (gnatls)
@@ -17654,10 +17708,10 @@ Add @code{dir} at the beginning of the project search dir.
 
 @table @asis
 
-@item @code{--RTS=@emph{rts-path}`}
+@item @code{--RTS=@emph{rts-path}}
 
 Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (@ref{dc,,Switches for gnatmake}).
+equivalent @code{gnatmake} flag (@ref{cd,,Switches for gnatmake}).
 @end table
 
 @geindex -v (gnatls)
@@ -17703,7 +17757,7 @@ by the user.
 @end table
 
 @node Example of gnatls Usage,,Switches for gnatls,The GNAT Library Browser gnatls
-@anchor{gnat_ugn/gnat_utility_programs id8}@anchor{14f}@anchor{gnat_ugn/gnat_utility_programs example-of-gnatls-usage}@anchor{150}
+@anchor{gnat_ugn/gnat_utility_programs id8}@anchor{142}@anchor{gnat_ugn/gnat_utility_programs example-of-gnatls-usage}@anchor{143}
 @subsection Example of @code{gnatls} Usage
 
 
@@ -17782,615 +17836,587 @@ instr.ads
 @end example
 @end quotation
 
-@node The Cross-Referencing Tools gnatxref and gnatfind,The Ada to HTML Converter gnathtml,The GNAT Library Browser gnatls,GNAT Utility Programs
-@anchor{gnat_ugn/gnat_utility_programs the-cross-referencing-tools-gnatxref-and-gnatfind}@anchor{22}@anchor{gnat_ugn/gnat_utility_programs id9}@anchor{151}
-@section The Cross-Referencing Tools @code{gnatxref} and @code{gnatfind}
-
-
-@geindex gnatxref
-
-@geindex gnatfind
 
-The compiler generates cross-referencing information (unless
-you set the @code{-gnatx} switch), which are saved in the @code{.ali} files.
-This information indicates where in the source each entity is declared and
-referenced. Note that entities in package Standard are not included, but
-entities in all other predefined units are included in the output.
 
-Before using any of these two tools, you need to compile successfully your
-application, so that GNAT gets a chance to generate the cross-referencing
-information.
-
-The two tools @code{gnatxref} and @code{gnatfind} take advantage of this
-information to provide the user with the capability to easily locate the
-declaration and references to an entity. These tools are quite similar,
-the difference being that @code{gnatfind} is intended for locating
-definitions and/or references to a specified entity or entities, whereas
-@code{gnatxref} is oriented to generating a full report of all
-cross-references.
 
-To use these tools, you must not compile your application using the
-@code{-gnatx} switch on the @code{gnatmake} command line
-(see @ref{1b,,Building with gnatmake}). Otherwise, cross-referencing
-information will not be generated.
 
-@menu
-* gnatxref Switches:: 
-* gnatfind Switches:: 
-* Configuration Files for gnatxref and gnatfind:: 
-* Regular Expressions in gnatfind and gnatxref:: 
-* Examples of gnatxref Usage:: 
-* Examples of gnatfind Usage:: 
 
-@end menu
 
-@node gnatxref Switches,gnatfind Switches,,The Cross-Referencing Tools gnatxref and gnatfind
-@anchor{gnat_ugn/gnat_utility_programs id10}@anchor{152}@anchor{gnat_ugn/gnat_utility_programs gnatxref-switches}@anchor{153}
-@subsection @code{gnatxref} Switches
 
+@c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit
 
-The command invocation for @code{gnatxref} is:
+@node GNAT and Program Execution,Platform-Specific Information,GNAT Utility Programs,Top
+@anchor{gnat_ugn/gnat_and_program_execution gnat-and-program-execution}@anchor{c}@anchor{gnat_ugn/gnat_and_program_execution doc}@anchor{144}@anchor{gnat_ugn/gnat_and_program_execution id1}@anchor{145}
+@chapter GNAT and Program Execution
 
-@quotation
 
-@example
-$ gnatxref [ switches ] sourcefile1 [ sourcefile2 ... ]
-@end example
-@end quotation
+This chapter covers several topics:
 
-where
 
+@itemize *
 
-@table @asis
+@item 
+@ref{146,,Running and Debugging Ada Programs}
 
-@item @code{sourcefile1} [, @code{sourcefile2} ...]
+@item 
+@ref{147,,Profiling}
 
-identify the source files for which a report is to be generated. The
-@code{with}ed units will be processed too. You must provide at least one file.
+@item 
+@ref{148,,Improving Performance}
 
-These file names are considered to be regular expressions, so for instance
-specifying @code{source*.adb} is the same as giving every file in the current
-directory whose name starts with @code{source} and whose extension is
-@code{adb}.
+@item 
+@ref{149,,Overflow Check Handling in GNAT}
 
-You shouldn't specify any directory name, just base names. @code{gnatxref}
-and @code{gnatfind} will be able to locate these files by themselves using
-the source path. If you specify directories, no result is produced.
-@end table
+@item 
+@ref{14a,,Performing Dimensionality Analysis in GNAT}
 
-The following switches are available for @code{gnatxref}:
+@item 
+@ref{14b,,Stack Related Facilities}
 
-@geindex --version (gnatxref)
+@item 
+@ref{14c,,Memory Management Issues}
+@end itemize
 
+@menu
+* Running and Debugging Ada Programs:: 
+* Profiling:: 
+* Improving Performance:: 
+* Overflow Check Handling in GNAT:: 
+* Performing Dimensionality Analysis in GNAT:: 
+* Stack Related Facilities:: 
+* Memory Management Issues:: 
 
-@table @asis
+@end menu
 
-@item @code{--version}
+@node Running and Debugging Ada Programs,Profiling,,GNAT and Program Execution
+@anchor{gnat_ugn/gnat_and_program_execution id2}@anchor{146}@anchor{gnat_ugn/gnat_and_program_execution running-and-debugging-ada-programs}@anchor{14d}
+@section Running and Debugging Ada Programs
 
-Display Copyright and version, then exit disregarding all other options.
-@end table
 
-@geindex --help (gnatxref)
+@geindex Debugging
 
+This section discusses how to debug Ada programs.
 
-@table @asis
+An incorrect Ada program may be handled in three ways by the GNAT compiler:
 
-@item @code{--help}
 
-If @code{--version} was not used, display usage, then exit disregarding
-all other options.
-@end table
+@itemize *
 
-@geindex -a (gnatxref)
+@item 
+The illegality may be a violation of the static semantics of Ada. In
+that case GNAT diagnoses the constructs in the program that are illegal.
+It is then a straightforward matter for the user to modify those parts of
+the program.
 
+@item 
+The illegality may be a violation of the dynamic semantics of Ada. In
+that case the program compiles and executes, but may generate incorrect
+results, or may terminate abnormally with some exception.
 
-@table @asis
+@item 
+When presented with a program that contains convoluted errors, GNAT
+itself may terminate abnormally without providing full diagnostics on
+the incorrect user program.
+@end itemize
 
-@item @code{-a}
+@geindex Debugger
 
-If this switch is present, @code{gnatfind} and @code{gnatxref} will parse
-the read-only files found in the library search path. Otherwise, these files
-will be ignored. This option can be used to protect Gnat sources or your own
-libraries from being parsed, thus making @code{gnatfind} and @code{gnatxref}
-much faster, and their output much smaller. Read-only here refers to access
-or permissions status in the file system for the current user.
-@end table
+@geindex gdb
 
-@geindex -aIDIR (gnatxref)
+@menu
+* The GNAT Debugger GDB:: 
+* Running GDB:: 
+* Introduction to GDB Commands:: 
+* Using Ada Expressions:: 
+* Calling User-Defined Subprograms:: 
+* Using the next Command in a Function:: 
+* Stopping When Ada Exceptions Are Raised:: 
+* Ada Tasks:: 
+* Debugging Generic Units:: 
+* Remote Debugging with gdbserver:: 
+* GNAT Abnormal Termination or Failure to Terminate:: 
+* Naming Conventions for GNAT Source Files:: 
+* Getting Internal Debugging Information:: 
+* Stack Traceback:: 
+* Pretty-Printers for the GNAT runtime:: 
 
+@end menu
 
-@table @asis
+@node The GNAT Debugger GDB,Running GDB,,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution the-gnat-debugger-gdb}@anchor{14e}@anchor{gnat_ugn/gnat_and_program_execution id3}@anchor{14f}
+@subsection The GNAT Debugger GDB
 
-@item @code{-aI@emph{DIR}}
 
-When looking for source files also look in directory DIR. The order in which
-source file search is undertaken is the same as for @code{gnatmake}.
-@end table
+@code{GDB} is a general purpose, platform-independent debugger that
+can be used to debug mixed-language programs compiled with @code{gcc},
+and in particular is capable of debugging Ada programs compiled with
+GNAT. The latest versions of @code{GDB} are Ada-aware and can handle
+complex Ada data structures.
 
-@geindex -aODIR (gnatxref)
+See @cite{Debugging with GDB},
+for full details on the usage of @code{GDB}, including a section on
+its usage on programs. This manual should be consulted for full
+details. The section that follows is a brief introduction to the
+philosophy and use of @code{GDB}.
 
+When GNAT programs are compiled, the compiler optionally writes debugging
+information into the generated object file, including information on
+line numbers, and on declared types and variables. This information is
+separate from the generated code. It makes the object files considerably
+larger, but it does not add to the size of the actual executable that
+will be loaded into memory, and has no impact on run-time performance. The
+generation of debug information is triggered by the use of the
+@code{-g} switch in the @code{gcc} or @code{gnatmake} command
+used to carry out the compilations. It is important to emphasize that
+the use of these options does not change the generated code.
 
-@table @asis
+The debugging information is written in standard system formats that
+are used by many tools, including debuggers and profilers. The format
+of the information is typically designed to describe C types and
+semantics, but GNAT implements a translation scheme which allows full
+details about Ada types and variables to be encoded into these
+standard C formats. Details of this encoding scheme may be found in
+the file exp_dbug.ads in the GNAT source distribution. However, the
+details of this encoding are, in general, of no interest to a user,
+since @code{GDB} automatically performs the necessary decoding.
 
-@item @code{aO@emph{DIR}}
+When a program is bound and linked, the debugging information is
+collected from the object files, and stored in the executable image of
+the program. Again, this process significantly increases the size of
+the generated executable file, but it does not increase the size of
+the executable program itself. Furthermore, if this program is run in
+the normal manner, it runs exactly as if the debug information were
+not present, and takes no more actual memory.
 
-When -searching for library and object files, look in directory
-DIR. The order in which library files are searched is the same as for
-@code{gnatmake}.
-@end table
-
-@geindex -nostdinc (gnatxref)
-
-
-@table @asis
+However, if the program is run under control of @code{GDB}, the
+debugger is activated.  The image of the program is loaded, at which
+point it is ready to run.  If a run command is given, then the program
+will run exactly as it would have if @code{GDB} were not present. This
+is a crucial part of the @code{GDB} design philosophy.  @code{GDB} is
+entirely non-intrusive until a breakpoint is encountered.  If no
+breakpoint is ever hit, the program will run exactly as it would if no
+debugger were present. When a breakpoint is hit, @code{GDB} accesses
+the debugging information and can respond to user commands to inspect
+variables, and more generally to report on the state of execution.
 
-@item @code{-nostdinc}
+@node Running GDB,Introduction to GDB Commands,The GNAT Debugger GDB,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution id4}@anchor{150}@anchor{gnat_ugn/gnat_and_program_execution running-gdb}@anchor{151}
+@subsection Running GDB
 
-Do not look for sources in the system default directory.
-@end table
 
-@geindex -nostdlib (gnatxref)
+This section describes how to initiate the debugger.
 
+The debugger can be launched from a @code{GNAT Studio} menu or
+directly from the command line. The description below covers the latter use.
+All the commands shown can be used in the @code{GNAT Studio} debug console window,
+but there are usually more GUI-based ways to achieve the same effect.
 
-@table @asis
+The command to run @code{GDB} is
 
-@item @code{-nostdlib}
+@quotation
 
-Do not look for library files in the system default directory.
-@end table
+@example
+$ gdb program
+@end example
+@end quotation
 
-@geindex --ext (gnatxref)
+where @code{program} is the name of the executable file. This
+activates the debugger and results in a prompt for debugger commands.
+The simplest command is simply @code{run}, which causes the program to run
+exactly as if the debugger were not present. The following section
+describes some of the additional commands that can be given to @code{GDB}.
 
+@node Introduction to GDB Commands,Using Ada Expressions,Running GDB,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution introduction-to-gdb-commands}@anchor{152}@anchor{gnat_ugn/gnat_and_program_execution id5}@anchor{153}
+@subsection Introduction to GDB Commands
 
-@table @asis
 
-@item @code{--ext=@emph{extension}}
+@code{GDB} contains a large repertoire of commands.
+See @cite{Debugging with GDB} for extensive documentation on the use
+of these commands, together with examples of their use. Furthermore,
+the command @emph{help} invoked from within GDB activates a simple help
+facility which summarizes the available commands and their options.
+In this section we summarize a few of the most commonly
+used commands to give an idea of what @code{GDB} is about. You should create
+a simple program with debugging information and experiment with the use of
+these @code{GDB} commands on the program as you read through the
+following section.
 
-Specify an alternate ali file extension. The default is @code{ali} and other
-extensions (e.g. @code{gli} for C/C++ sources when using @code{-fdump-xref})
-may be specified via this switch. Note that if this switch overrides the
-default, which means that only the new extension will be considered.
-@end table
 
-@geindex --RTS (gnatxref)
+@itemize *
 
+@item 
 
 @table @asis
 
-@item @code{--RTS=@emph{rts-path}}
+@item @code{set args @emph{arguments}}
 
-Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (@ref{dc,,Switches for gnatmake}).
+The @emph{arguments} list above is a list of arguments to be passed to
+the program on a subsequent run command, just as though the arguments
+had been entered on a normal invocation of the program. The @code{set args}
+command is not needed if the program does not require arguments.
 @end table
 
-@geindex -d (gnatxref)
-
+@item 
 
 @table @asis
 
-@item @code{-d}
+@item @code{run}
 
-If this switch is set @code{gnatxref} will output the parent type
-reference for each matching derived types.
+The @code{run} command causes execution of the program to start from
+the beginning. If the program is already running, that is to say if
+you are currently positioned at a breakpoint, then a prompt will ask
+for confirmation that you want to abandon the current execution and
+restart.
 @end table
 
-@geindex -f (gnatxref)
-
+@item 
 
 @table @asis
 
-@item @code{-f}
+@item @code{breakpoint @emph{location}}
 
-If this switch is set, the output file names will be preceded by their
-directory (if the file was found in the search path). If this switch is
-not set, the directory will not be printed.
+The breakpoint command sets a breakpoint, that is to say a point at which
+execution will halt and @code{GDB} will await further
+commands. @emph{location} is
+either a line number within a file, given in the format @code{file:linenumber},
+or it is the name of a subprogram. If you request that a breakpoint be set on
+a subprogram that is overloaded, a prompt will ask you to specify on which of
+those subprograms you want to breakpoint. You can also
+specify that all of them should be breakpointed. If the program is run
+and execution encounters the breakpoint, then the program
+stops and @code{GDB} signals that the breakpoint was encountered by
+printing the line of code before which the program is halted.
 @end table
 
-@geindex -g (gnatxref)
-
+@item 
 
 @table @asis
 
-@item @code{-g}
+@item @code{catch exception @emph{name}}
 
-If this switch is set, information is output only for library-level
-entities, ignoring local entities. The use of this switch may accelerate
-@code{gnatfind} and @code{gnatxref}.
+This command causes the program execution to stop whenever exception
+@code{name} is raised.  If @code{name} is omitted, then the execution is
+suspended when any exception is raised.
 @end table
 
-@geindex -IDIR (gnatxref)
-
+@item 
 
 @table @asis
 
-@item @code{-I@emph{DIR}}
+@item @code{print @emph{expression}}
 
-Equivalent to @code{-aODIR -aIDIR}.
+This will print the value of the given expression. Most simple
+Ada expression formats are properly handled by @code{GDB}, so the expression
+can contain function calls, variables, operators, and attribute references.
 @end table
 
-@geindex -pFILE (gnatxref)
-
+@item 
 
 @table @asis
 
-@item @code{-p@emph{FILE}}
-
-Specify a configuration file to use to list the source and object directories.
-
-If a file is specified, then the content of the source directory and object
-directory lines are added as if they had been specified respectively
-by @code{-aI} and @code{-aO}.
-
-See @ref{154,,Configuration Files for gnatxref and gnatfind} for the syntax
-of this configuration file.
-
-@item @code{-u}
-
-Output only unused symbols. This may be really useful if you give your
-main compilation unit on the command line, as @code{gnatxref} will then
-display every unused entity and 'with'ed package.
-
-@item @code{-v}
+@item @code{continue}
 
-Instead of producing the default output, @code{gnatxref} will generate a
-@code{tags} file that can be used by vi. For examples how to use this
-feature, see @ref{155,,Examples of gnatxref Usage}. The tags file is output
-to the standard output, thus you will have to redirect it to a file.
+Continues execution following a breakpoint, until the next breakpoint or the
+termination of the program.
 @end table
 
-All these switches may be in any order on the command line, and may even
-appear after the file names. They need not be separated by spaces, thus
-you can say @code{gnatxref -ag} instead of @code{gnatxref -a -g}.
-
-@node gnatfind Switches,Configuration Files for gnatxref and gnatfind,gnatxref Switches,The Cross-Referencing Tools gnatxref and gnatfind
-@anchor{gnat_ugn/gnat_utility_programs id11}@anchor{156}@anchor{gnat_ugn/gnat_utility_programs gnatfind-switches}@anchor{157}
-@subsection @code{gnatfind} Switches
-
-
-The command invocation for @code{gnatfind} is:
-
-@quotation
-
-@example
-$ gnatfind [ switches ]  pattern[:sourcefile[:line[:column]]]
-      [file1 file2 ...]
-@end example
-@end quotation
-
-with the following iterpretation of the command arguments:
-
+@item 
 
 @table @asis
 
-@item @emph{pattern}
-
-An entity will be output only if it matches the regular expression found
-in @emph{pattern}, see @ref{158,,Regular Expressions in gnatfind and gnatxref}.
-
-Omitting the pattern is equivalent to specifying @code{*}, which
-will match any entity. Note that if you do not provide a pattern, you
-have to provide both a sourcefile and a line.
-
-Entity names are given in Latin-1, with uppercase/lowercase equivalence
-for matching purposes. At the current time there is no support for
-8-bit codes other than Latin-1, or for wide characters in identifiers.
-
-@item @emph{sourcefile}
-
-@code{gnatfind} will look for references, bodies or declarations
-of symbols referenced in @code{sourcefile}, at line @code{line}
-and column @code{column}. See @ref{159,,Examples of gnatfind Usage}
-for syntax examples.
-
-@item @emph{line}
-
-A decimal integer identifying the line number containing
-the reference to the entity (or entities) to be located.
-
-@item @emph{column}
-
-A decimal integer identifying the exact location on the
-line of the first character of the identifier for the
-entity reference. Columns are numbered from 1.
-
-@item @emph{file1 file2 ...}
-
-The search will be restricted to these source files. If none are given, then
-the search will be conducted for every library file in the search path.
-These files must appear only after the pattern or sourcefile.
-
-These file names are considered to be regular expressions, so for instance
-specifying @code{source*.adb} is the same as giving every file in the current
-directory whose name starts with @code{source} and whose extension is
-@code{adb}.
-
-The location of the spec of the entity will always be displayed, even if it
-isn't in one of @code{file1}, @code{file2}, ... The
-occurrences of the entity in the separate units of the ones given on the
-command line will also be displayed.
+@item @code{step}
 
-Note that if you specify at least one file in this part, @code{gnatfind} may
-sometimes not be able to find the body of the subprograms.
+Executes a single line after a breakpoint. If the next statement
+is a subprogram call, execution continues into (the first statement of)
+the called subprogram.
 @end table
 
-At least one of 'sourcefile' or 'pattern' has to be present on
-the command line.
-
-The following switches are available:
-
-@geindex --version (gnatfind)
-
+@item 
 
 @table @asis
 
-@item @code{--version}
+@item @code{next}
 
-Display Copyright and version, then exit disregarding all other options.
+Executes a single line. If this line is a subprogram call, executes and
+returns from the call.
 @end table
 
-@geindex --help (gnatfind)
-
+@item 
 
 @table @asis
 
-@item @code{--help}
+@item @code{list}
 
-If @code{--version} was not used, display usage, then exit disregarding
-all other options.
+Lists a few lines around the current source location. In practice, it
+is usually more convenient to have a separate edit window open with the
+relevant source file displayed. Successive applications of this command
+print subsequent lines. The command can be given an argument which is a
+line number, in which case it displays a few lines around the specified one.
 @end table
 
-@geindex -a (gnatfind)
-
+@item 
 
 @table @asis
 
-@item @code{-a}
+@item @code{backtrace}
 
-If this switch is present, @code{gnatfind} and @code{gnatxref} will parse
-the read-only files found in the library search path. Otherwise, these files
-will be ignored. This option can be used to protect Gnat sources or your own
-libraries from being parsed, thus making @code{gnatfind} and @code{gnatxref}
-much faster, and their output much smaller. Read-only here refers to access
-or permission status in the file system for the current user.
+Displays a backtrace of the call chain. This command is typically
+used after a breakpoint has occurred, to examine the sequence of calls that
+leads to the current breakpoint. The display includes one line for each
+activation record (frame) corresponding to an active subprogram.
 @end table
 
-@geindex -aIDIR (gnatfind)
-
+@item 
 
 @table @asis
 
-@item @code{-aI@emph{DIR}}
+@item @code{up}
 
-When looking for source files also look in directory DIR. The order in which
-source file search is undertaken is the same as for @code{gnatmake}.
+At a breakpoint, @code{GDB} can display the values of variables local
+to the current frame. The command @code{up} can be used to
+examine the contents of other active frames, by moving the focus up
+the stack, that is to say from callee to caller, one frame at a time.
 @end table
 
-@geindex -aODIR (gnatfind)
-
+@item 
 
 @table @asis
 
-@item @code{-aO@emph{DIR}}
+@item @code{down}
 
-When searching for library and object files, look in directory
-DIR. The order in which library files are searched is the same as for
-@code{gnatmake}.
+Moves the focus of @code{GDB} down from the frame currently being
+examined to the frame of its callee (the reverse of the previous command),
 @end table
 
-@geindex -nostdinc (gnatfind)
-
+@item 
 
 @table @asis
 
-@item @code{-nostdinc}
+@item @code{frame @emph{n}}
 
-Do not look for sources in the system default directory.
+Inspect the frame with the given number. The value 0 denotes the frame
+of the current breakpoint, that is to say the top of the call stack.
 @end table
 
-@geindex -nostdlib (gnatfind)
-
+@item 
 
 @table @asis
 
-@item @code{-nostdlib}
+@item @code{kill}
 
-Do not look for library files in the system default directory.
-@end table
+Kills the child process in which the program is running under GDB.
+This may be useful for several purposes:
 
-@geindex --ext (gnatfind)
 
+@itemize *
 
-@table @asis
+@item 
+It allows you to recompile and relink your program, since on many systems
+you cannot regenerate an executable file while it is running in a process.
 
-@item @code{--ext=@emph{extension}}
+@item 
+You can run your program outside the debugger, on systems that do not
+permit executing a program outside GDB while breakpoints are set
+within GDB.
 
-Specify an alternate ali file extension. The default is @code{ali} and other
-extensions (e.g. @code{gli} for C/C++ sources when using @code{-fdump-xref})
-may be specified via this switch. Note that if this switch overrides the
-default, which means that only the new extension will be considered.
+@item 
+It allows you to debug a core dump rather than a running process.
+@end itemize
 @end table
+@end itemize
 
-@geindex --RTS (gnatfind)
-
-
-@table @asis
+The above list is a very short introduction to the commands that
+@code{GDB} provides. Important additional capabilities, including conditional
+breakpoints, the ability to execute command sequences on a breakpoint,
+the ability to debug at the machine instruction level and many other
+features are described in detail in @cite{Debugging with GDB}.
+Note that most commands can be abbreviated
+(for example, c for continue, bt for backtrace).
 
-@item @code{--RTS=@emph{rts-path}}
+@node Using Ada Expressions,Calling User-Defined Subprograms,Introduction to GDB Commands,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution id6}@anchor{154}@anchor{gnat_ugn/gnat_and_program_execution using-ada-expressions}@anchor{155}
+@subsection Using Ada Expressions
 
-Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (@ref{dc,,Switches for gnatmake}).
-@end table
 
-@geindex -d (gnatfind)
+@geindex Ada expressions (in gdb)
 
+@code{GDB} supports a fairly large subset of Ada expression syntax, with some
+extensions. The philosophy behind the design of this subset is
 
-@table @asis
+@quotation
 
-@item @code{-d}
 
-If this switch is set, then @code{gnatfind} will output the parent type
-reference for each matching derived types.
-@end table
+@itemize *
 
-@geindex -e (gnatfind)
+@item 
+That @code{GDB} should provide basic literals and access to operations for
+arithmetic, dereferencing, field selection, indexing, and subprogram calls,
+leaving more sophisticated computations to subprograms written into the
+program (which therefore may be called from @code{GDB}).
 
+@item 
+That type safety and strict adherence to Ada language restrictions
+are not particularly relevant in a debugging context.
 
-@table @asis
+@item 
+That brevity is important to the @code{GDB} user.
+@end itemize
+@end quotation
 
-@item @code{-e}
+Thus, for brevity, the debugger acts as if there were
+implicit @code{with} and @code{use} clauses in effect for all user-written
+packages, thus making it unnecessary to fully qualify most names with
+their packages, regardless of context. Where this causes ambiguity,
+@code{GDB} asks the user's intent.
 
-By default, @code{gnatfind} accept the simple regular expression set for
-@code{pattern}. If this switch is set, then the pattern will be
-considered as full Unix-style regular expression.
-@end table
+For details on the supported Ada syntax, see @cite{Debugging with GDB}.
 
-@geindex -f (gnatfind)
+@node Calling User-Defined Subprograms,Using the next Command in a Function,Using Ada Expressions,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution id7}@anchor{156}@anchor{gnat_ugn/gnat_and_program_execution calling-user-defined-subprograms}@anchor{157}
+@subsection Calling User-Defined Subprograms
 
 
-@table @asis
-
-@item @code{-f}
-
-If this switch is set, the output file names will be preceded by their
-directory (if the file was found in the search path). If this switch is
-not set, the directory will not be printed.
-@end table
-
-@geindex -g (gnatfind)
-
-
-@table @asis
-
-@item @code{-g}
-
-If this switch is set, information is output only for library-level
-entities, ignoring local entities. The use of this switch may accelerate
-@code{gnatfind} and @code{gnatxref}.
-@end table
+An important capability of @code{GDB} is the ability to call user-defined
+subprograms while debugging. This is achieved simply by entering
+a subprogram call statement in the form:
 
-@geindex -IDIR (gnatfind)
+@quotation
 
+@example
+call subprogram-name (parameters)
+@end example
+@end quotation
 
-@table @asis
+The keyword @code{call} can be omitted in the normal case where the
+@code{subprogram-name} does not coincide with any of the predefined
+@code{GDB} commands.
 
-@item @code{-I@emph{DIR}}
+The effect is to invoke the given subprogram, passing it the
+list of parameters that is supplied. The parameters can be expressions and
+can include variables from the program being debugged. The
+subprogram must be defined
+at the library level within your program, and @code{GDB} will call the
+subprogram within the environment of your program execution (which
+means that the subprogram is free to access or even modify variables
+within your program).
 
-Equivalent to @code{-aODIR -aIDIR}.
-@end table
+The most important use of this facility is in allowing the inclusion of
+debugging routines that are tailored to particular data structures
+in your program. Such debugging routines can be written to provide a suitably
+high-level description of an abstract type, rather than a low-level dump
+of its physical layout. After all, the standard
+@code{GDB print} command only knows the physical layout of your
+types, not their abstract meaning. Debugging routines can provide information
+at the desired semantic level and are thus enormously useful.
 
-@geindex -pFILE (gnatfind)
+For example, when debugging GNAT itself, it is crucial to have access to
+the contents of the tree nodes used to represent the program internally.
+But tree nodes are represented simply by an integer value (which in turn
+is an index into a table of nodes).
+Using the @code{print} command on a tree node would simply print this integer
+value, which is not very useful. But the PN routine (defined in file
+treepr.adb in the GNAT sources) takes a tree node as input, and displays
+a useful high level representation of the tree node, which includes the
+syntactic category of the node, its position in the source, the integers
+that denote descendant nodes and parent node, as well as varied
+semantic information. To study this example in more detail, you might want to
+look at the body of the PN procedure in the stated file.
 
+Another useful application of this capability is to deal with situations of
+complex data which are not handled suitably by GDB. For example, if you specify
+Convention Fortran for a multi-dimensional array, GDB does not know that
+the ordering of array elements has been switched and will not properly
+address the array elements. In such a case, instead of trying to print the
+elements directly from GDB, you can write a callable procedure that prints
+the elements in the desired format.
 
-@table @asis
+@node Using the next Command in a Function,Stopping When Ada Exceptions Are Raised,Calling User-Defined Subprograms,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution using-the-next-command-in-a-function}@anchor{158}@anchor{gnat_ugn/gnat_and_program_execution id8}@anchor{159}
+@subsection Using the @emph{next} Command in a Function
 
-@item @code{-p@emph{FILE}}
 
-Specify a configuration file to use to list the source and object directories.
+When you use the @code{next} command in a function, the current source
+location will advance to the next statement as usual. A special case
+arises in the case of a @code{return} statement.
 
-If a file is specified, then the content of the source directory and object
-directory lines are added as if they had been specified respectively
-by @code{-aI} and @code{-aO}.
+Part of the code for a return statement is the 'epilogue' of the function.
+This is the code that returns to the caller. There is only one copy of
+this epilogue code, and it is typically associated with the last return
+statement in the function if there is more than one return. In some
+implementations, this epilogue is associated with the first statement
+of the function.
 
-See @ref{154,,Configuration Files for gnatxref and gnatfind} for the syntax
-of this configuration file.
-@end table
+The result is that if you use the @code{next} command from a return
+statement that is not the last return statement of the function you
+may see a strange apparent jump to the last return statement or to
+the start of the function. You should simply ignore this odd jump.
+The value returned is always that from the first return statement
+that was stepped through.
 
-@geindex -r (gnatfind)
+@node Stopping When Ada Exceptions Are Raised,Ada Tasks,Using the next Command in a Function,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution stopping-when-ada-exceptions-are-raised}@anchor{15a}@anchor{gnat_ugn/gnat_and_program_execution id9}@anchor{15b}
+@subsection Stopping When Ada Exceptions Are Raised
 
 
-@table @asis
+@geindex Exceptions (in gdb)
 
-@item @code{-r}
+You can set catchpoints that stop the program execution when your program
+raises selected exceptions.
 
-By default, @code{gnatfind} will output only the information about the
-declaration, body or type completion of the entities. If this switch is
-set, the @code{gnatfind} will locate every reference to the entities in
-the files specified on the command line (or in every file in the search
-path if no file is given on the command line).
-@end table
 
-@geindex -s (gnatfind)
+@itemize *
 
+@item 
 
 @table @asis
 
-@item @code{-s}
+@item @code{catch exception}
 
-If this switch is set, then @code{gnatfind} will output the content
-of the Ada source file lines were the entity was found.
+Set a catchpoint that stops execution whenever (any task in the) program
+raises any exception.
 @end table
 
-@geindex -t (gnatfind)
-
+@item 
 
 @table @asis
 
-@item @code{-t}
+@item @code{catch exception @emph{name}}
 
-If this switch is set, then @code{gnatfind} will output the type hierarchy for
-the specified type. It act like -d option but recursively from parent
-type to parent type. When this switch is set it is not possible to
-specify more than one file.
+Set a catchpoint that stops execution whenever (any task in the) program
+raises the exception @emph{name}.
 @end table
 
-All these switches may be in any order on the command line, and may even
-appear after the file names. They need not be separated by spaces, thus
-you can say @code{gnatxref -ag} instead of
-@code{gnatxref -a -g}.
-
-As stated previously, @code{gnatfind} will search in every directory in the
-search path. You can force it to look only in the current directory if
-you specify @code{*} at the end of the command line.
-
-@node Configuration Files for gnatxref and gnatfind,Regular Expressions in gnatfind and gnatxref,gnatfind Switches,The Cross-Referencing Tools gnatxref and gnatfind
-@anchor{gnat_ugn/gnat_utility_programs configuration-files-for-gnatxref-and-gnatfind}@anchor{154}@anchor{gnat_ugn/gnat_utility_programs id12}@anchor{15a}
-@subsection Configuration Files for @code{gnatxref} and @code{gnatfind}
-
-
-Configuration files are used by @code{gnatxref} and @code{gnatfind} to specify
-the list of source and object directories to consider. They can be
-specified via the @code{-p} switch.
-
-The following lines can be included, in any order in the file:
-
-
-@itemize *
-
 @item 
 
 @table @asis
 
-@item @emph{src_dir=DIR}
+@item @code{catch exception unhandled}
 
-[default: @code{"./"}].
-Specifies a directory where to look for source files. Multiple @code{src_dir}
-lines can be specified and they will be searched in the order they
-are specified.
+Set a catchpoint that stops executing whenever (any task in the) program
+raises an exception for which there is no handler.
 @end table
 
 @item 
 
 @table @asis
 
-@item @emph{obj_dir=DIR}
+@item @code{info exceptions}, @code{info exceptions @emph{regexp}}
 
-[default: @code{"./"}].
-Specifies a directory where to look for object and library files. Multiple
-@code{obj_dir} lines can be specified, and they will be searched in the order
-they are specified
+The @code{info exceptions} command permits the user to examine all defined
+exceptions within Ada programs. With a regular expression, @emph{regexp}, as
+argument, prints out only those exceptions whose name matches @emph{regexp}.
 @end table
 @end itemize
 
-Any other line will be silently ignored.
+@geindex Tasks (in gdb)
 
-@node Regular Expressions in gnatfind and gnatxref,Examples of gnatxref Usage,Configuration Files for gnatxref and gnatfind,The Cross-Referencing Tools gnatxref and gnatfind
-@anchor{gnat_ugn/gnat_utility_programs id13}@anchor{15b}@anchor{gnat_ugn/gnat_utility_programs regular-expressions-in-gnatfind-and-gnatxref}@anchor{158}
-@subsection Regular Expressions in @code{gnatfind} and @code{gnatxref}
+@node Ada Tasks,Debugging Generic Units,Stopping When Ada Exceptions Are Raised,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution ada-tasks}@anchor{15c}@anchor{gnat_ugn/gnat_and_program_execution id10}@anchor{15d}
+@subsection Ada Tasks
 
 
-As specified in the section about @code{gnatfind}, the pattern can be a
-regular expression. Two kinds of regular expressions
-are recognized:
+@code{GDB} allows the following task-related commands:
 
 
 @itemize *
@@ -18399,7953 +18425,6843 @@ are recognized:
 
 @table @asis
 
-@item @emph{Globbing pattern}
-
-These are the most common regular expression. They are the same as are
-generally used in a Unix shell command line, or in a DOS session.
+@item @code{info tasks}
 
-Here is a more formal grammar:
+This command shows a list of current Ada tasks, as in the following example:
 
 @example
-regexp ::= term
-term   ::= elmt            -- matches elmt
-term   ::= elmt elmt       -- concatenation (elmt then elmt)
-term   ::= *               -- any string of 0 or more characters
-term   ::= ?               -- matches any character
-term   ::= [char @{char@}]   -- matches any character listed
-term   ::= [char - char]   -- matches any character in range
+(gdb) info tasks
+  ID       TID P-ID   Thread Pri State                 Name
+   1   8088000   0   807e000  15 Child Activation Wait main_task
+   2   80a4000   1   80ae000  15 Accept/Select Wait    b
+   3   809a800   1   80a4800  15 Child Activation Wait a
+*  4   80ae800   3   80b8000  15 Running               c
 @end example
-@end table
-
-@item 
-
-@table @asis
-
-@item @emph{Full regular expression}
-
-The second set of regular expressions is much more powerful. This is the
-type of regular expressions recognized by utilities such as @code{grep}.
 
-The following is the form of a regular expression, expressed in same BNF
-style as is found in the Ada Reference Manual:
+In this listing, the asterisk before the first task indicates it to be the
+currently running task. The first column lists the task ID that is used
+to refer to tasks in the following commands.
+@end table
+@end itemize
 
-@example
-regexp ::= term @{| term@}   -- alternation (term or term ...)
+@geindex Breakpoints and tasks
 
-term ::= item @{item@}       -- concatenation (item then item)
 
-item ::= elmt              -- match elmt
-item ::= elmt *            -- zero or more elmt's
-item ::= elmt +            -- one or more elmt's
-item ::= elmt ?            -- matches elmt or nothing
+@itemize *
 
-elmt ::= nschar            -- matches given character
-elmt ::= [nschar @{nschar@}]   -- matches any character listed
-elmt ::= [^ nschar @{nschar@}] -- matches any character not listed
-elmt ::= [char - char]     -- matches chars in given range
-elmt ::= \\ char            -- matches given character
-elmt ::= .                 -- matches any single character
-elmt ::= ( regexp )        -- parens used for grouping
+@item 
+@code{break`@w{`}*linespec* `@w{`}task} @emph{taskid}, @code{break} @emph{linespec} @code{task} @emph{taskid} @code{if} ...
 
-char ::= any character, including special characters
-nschar ::= any character except ()[].*+?^
-@end example
+@quotation
 
-Here are a few examples:
+These commands are like the @code{break ... thread ...}.
+@emph{linespec} specifies source lines.
 
-@quotation
+Use the qualifier @code{task @emph{taskid}} with a breakpoint command
+to specify that you only want @code{GDB} to stop the program when a
+particular Ada task reaches this breakpoint. @emph{taskid} is one of the
+numeric task identifiers assigned by @code{GDB}, shown in the first
+column of the @code{info tasks} display.
 
+If you do not specify @code{task @emph{taskid}} when you set a
+breakpoint, the breakpoint applies to @emph{all} tasks of your
+program.
 
-@table @asis
+You can use the @code{task} qualifier on conditional breakpoints as
+well; in this case, place @code{task @emph{taskid}} before the
+breakpoint condition (before the @code{if}).
+@end quotation
+@end itemize
 
-@item @code{abcde|fghi}
+@geindex Task switching (in gdb)
 
-will match any of the two strings @code{abcde} and @code{fghi},
 
-@item @code{abc*d}
+@itemize *
 
-will match any string like @code{abd}, @code{abcd}, @code{abccd},
-@code{abcccd}, and so on,
+@item 
+@code{task @emph{taskno}}
 
-@item @code{[a-z]+}
+@quotation
 
-will match any string which has only lowercase characters in it (and at
-least one character.
-@end table
+This command allows switching to the task referred by @emph{taskno}. In
+particular, this allows browsing of the backtrace of the specified
+task. It is advisable to switch back to the original task before
+continuing execution otherwise the scheduling of the program may be
+perturbed.
 @end quotation
-@end table
 @end itemize
 
-@node Examples of gnatxref Usage,Examples of gnatfind Usage,Regular Expressions in gnatfind and gnatxref,The Cross-Referencing Tools gnatxref and gnatfind
-@anchor{gnat_ugn/gnat_utility_programs examples-of-gnatxref-usage}@anchor{155}@anchor{gnat_ugn/gnat_utility_programs id14}@anchor{15c}
-@subsection Examples of @code{gnatxref} Usage
+For more detailed information on the tasking support,
+see @cite{Debugging with GDB}.
 
+@geindex Debugging Generic Units
 
-@menu
-* General Usage:: 
-* Using gnatxref with vi:: 
+@geindex Generics
 
-@end menu
+@node Debugging Generic Units,Remote Debugging with gdbserver,Ada Tasks,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution debugging-generic-units}@anchor{15e}@anchor{gnat_ugn/gnat_and_program_execution id11}@anchor{15f}
+@subsection Debugging Generic Units
 
-@node General Usage,Using gnatxref with vi,,Examples of gnatxref Usage
-@anchor{gnat_ugn/gnat_utility_programs general-usage}@anchor{15d}
-@subsubsection General Usage
 
+GNAT always uses code expansion for generic instantiation. This means that
+each time an instantiation occurs, a complete copy of the original code is
+made, with appropriate substitutions of formals by actuals.
 
-For the following examples, we will consider the following units:
+It is not possible to refer to the original generic entities in
+@code{GDB}, but it is always possible to debug a particular instance of
+a generic, by using the appropriate expanded names. For example, if we have
 
 @quotation
 
 @example
-main.ads:
-1: with Bar;
-2: package Main is
-3:     procedure Foo (B : in Integer);
-4:     C : Integer;
-5: private
-6:     D : Integer;
-7: end Main;
-
-main.adb:
-1: package body Main is
-2:     procedure Foo (B : in Integer) is
-3:     begin
-4:        C := B;
-5:        D := B;
-6:        Bar.Print (B);
-7:        Bar.Print (C);
-8:     end Foo;
-9: end Main;
-
-bar.ads:
-1: package Bar is
-2:     procedure Print (B : Integer);
-3: end bar;
-@end example
-@end quotation
+procedure g is
 
-The first thing to do is to recompile your application (for instance, in
-that case just by doing a @code{gnatmake main}, so that GNAT generates
-the cross-referencing information.
-You can then issue any of the following commands:
+   generic package k is
+      procedure kp (v1 : in out integer);
+   end k;
 
-@quotation
+   package body k is
+      procedure kp (v1 : in out integer) is
+      begin
+         v1 := v1 + 1;
+      end kp;
+   end k;
 
+   package k1 is new k;
+   package k2 is new k;
 
-@itemize *
+   var : integer := 1;
 
-@item 
-@code{gnatxref main.adb}
-@code{gnatxref} generates cross-reference information for main.adb
-and every unit 'with'ed by main.adb.
+begin
+   k1.kp (var);
+   k2.kp (var);
+   k1.kp (var);
+   k2.kp (var);
+end;
+@end example
+@end quotation
 
-The output would be:
+Then to break on a call to procedure kp in the k2 instance, simply
+use the command:
 
 @quotation
 
 @example
-B                                                      Type: Integer
-  Decl: bar.ads           2:22
-B                                                      Type: Integer
-  Decl: main.ads          3:20
-  Body: main.adb          2:20
-  Ref:  main.adb          4:13     5:13     6:19
-Bar                                                    Type: Unit
-  Decl: bar.ads           1:9
-  Ref:  main.adb          6:8      7:8
-       main.ads           1:6
-C                                                      Type: Integer
-  Decl: main.ads          4:5
-  Modi: main.adb          4:8
-  Ref:  main.adb          7:19
-D                                                      Type: Integer
-  Decl: main.ads          6:5
-  Modi: main.adb          5:8
-Foo                                                    Type: Unit
-  Decl: main.ads          3:15
-  Body: main.adb          2:15
-Main                                                    Type: Unit
-  Decl: main.ads          2:9
-  Body: main.adb          1:14
-Print                                                   Type: Unit
-  Decl: bar.ads           2:15
-  Ref:  main.adb          6:12     7:12
+(gdb) break g.k2.kp
 @end example
 @end quotation
 
-This shows that the entity @code{Main} is declared in main.ads, line 2, column 9,
-its body is in main.adb, line 1, column 14 and is not referenced any where.
+When the breakpoint occurs, you can step through the code of the
+instance in the normal manner and examine the values of local variables, as for
+other units.
 
-The entity @code{Print} is declared in @code{bar.ads}, line 2, column 15 and it
-is referenced in @code{main.adb}, line 6 column 12 and line 7 column 12.
+@geindex Remote Debugging with gdbserver
 
-@item 
-@code{gnatxref package1.adb package2.ads}
-@code{gnatxref} will generates cross-reference information for
-@code{package1.adb}, @code{package2.ads} and any other package @code{with}ed by any
-of these.
-@end itemize
-@end quotation
+@node Remote Debugging with gdbserver,GNAT Abnormal Termination or Failure to Terminate,Debugging Generic Units,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution remote-debugging-with-gdbserver}@anchor{160}@anchor{gnat_ugn/gnat_and_program_execution id12}@anchor{161}
+@subsection Remote Debugging with gdbserver
 
-@node Using gnatxref with vi,,General Usage,Examples of gnatxref Usage
-@anchor{gnat_ugn/gnat_utility_programs using-gnatxref-with-vi}@anchor{15e}
-@subsubsection Using @code{gnatxref} with @code{vi}
 
+On platforms where gdbserver is supported, it is possible to use this tool
+to debug your application remotely.  This can be useful in situations
+where the program needs to be run on a target host that is different
+from the host used for development, particularly when the target has
+a limited amount of resources (either CPU and/or memory).
 
-@code{gnatxref} can generate a tags file output, which can be used
-directly from @code{vi}. Note that the standard version of @code{vi}
-will not work properly with overloaded symbols. Consider using another
-free implementation of @code{vi}, such as @code{vim}.
+To do so, start your program using gdbserver on the target machine.
+gdbserver then automatically suspends the execution of your program
+at its entry point, waiting for a debugger to connect to it.  The
+following commands starts an application and tells gdbserver to
+wait for a connection with the debugger on localhost port 4444.
 
 @quotation
 
 @example
-$ gnatxref -v gnatfind.adb > tags
+$ gdbserver localhost:4444 program
+Process program created; pid = 5685
+Listening on port 4444
 @end example
 @end quotation
 
-The following command will generate the tags file for @code{gnatfind} itself
-(if the sources are in the search path!):
+Once gdbserver has started listening, we can tell the debugger to establish
+a connection with this gdbserver, and then start the same debugging session
+as if the program was being debugged on the same host, directly under
+the control of GDB.
 
 @quotation
 
 @example
-$ gnatxref -v gnatfind.adb > tags
-@end example
-@end quotation
+$ gdb program
+(gdb) target remote targethost:4444
+Remote debugging using targethost:4444
+0x00007f29936d0af0 in ?? () from /lib64/ld-linux-x86-64.so.
+(gdb) b foo.adb:3
+Breakpoint 1 at 0x401f0c: file foo.adb, line 3.
+(gdb) continue
+Continuing.
 
-From @code{vi}, you can then use the command @code{:tag @emph{entity}}
-(replacing @code{entity} by whatever you are looking for), and vi will
-display a new file with the corresponding declaration of entity.
-
-@node Examples of gnatfind Usage,,Examples of gnatxref Usage,The Cross-Referencing Tools gnatxref and gnatfind
-@anchor{gnat_ugn/gnat_utility_programs id15}@anchor{15f}@anchor{gnat_ugn/gnat_utility_programs examples-of-gnatfind-usage}@anchor{159}
-@subsection Examples of @code{gnatfind} Usage
+Breakpoint 1, foo () at foo.adb:4
+4       end foo;
+@end example
+@end quotation
 
+It is also possible to use gdbserver to attach to an already running
+program, in which case the execution of that program is simply suspended
+until the connection between the debugger and gdbserver is established.
 
+For more information on how to use gdbserver, see the @emph{Using the gdbserver Program}
+section in @cite{Debugging with GDB}.
+GNAT provides support for gdbserver on x86-linux, x86-windows and x86_64-linux.
 
-@itemize *
+@geindex Abnormal Termination or Failure to Terminate
 
-@item 
-@code{gnatfind -f xyz:main.adb}
-Find declarations for all entities xyz referenced at least once in
-main.adb. The references are search in every library file in the search
-path.
+@node GNAT Abnormal Termination or Failure to Terminate,Naming Conventions for GNAT Source Files,Remote Debugging with gdbserver,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution gnat-abnormal-termination-or-failure-to-terminate}@anchor{162}@anchor{gnat_ugn/gnat_and_program_execution id13}@anchor{163}
+@subsection GNAT Abnormal Termination or Failure to Terminate
 
-The directories will be printed as well (as the @code{-f}
-switch is set)
 
-The output will look like:
+When presented with programs that contain serious errors in syntax
+or semantics,
+GNAT may on rare occasions  experience problems in operation, such
+as aborting with a
+segmentation fault or illegal memory access, raising an internal
+exception, terminating abnormally, or failing to terminate at all.
+In such cases, you can activate
+various features of GNAT that can help you pinpoint the construct in your
+program that is the likely source of the problem.
 
-@quotation
+The following strategies are presented in increasing order of
+difficulty, corresponding to your experience in using GNAT and your
+familiarity with compiler internals.
 
-@example
-directory/main.ads:106:14: xyz <= declaration
-directory/main.adb:24:10: xyz <= body
-directory/foo.ads:45:23: xyz <= declaration
-@end example
-@end quotation
 
-I.e., one of the entities xyz found in main.adb is declared at
-line 12 of main.ads (and its body is in main.adb), and another one is
-declared at line 45 of foo.ads
+@itemize *
 
 @item 
-@code{gnatfind -fs xyz:main.adb}
-This is the same command as the previous one, but @code{gnatfind} will
-display the content of the Ada source file lines.
-
-The output will look like:
-
-@example
-directory/main.ads:106:14: xyz <= declaration
-   procedure xyz;
-directory/main.adb:24:10: xyz <= body
-   procedure xyz is
-directory/foo.ads:45:23: xyz <= declaration
-   xyz : Integer;
-@end example
+Run @code{gcc} with the @code{-gnatf}. This first
+switch causes all errors on a given line to be reported. In its absence,
+only the first error on a line is displayed.
 
-This can make it easier to find exactly the location your are looking
-for.
+The @code{-gnatdO} switch causes errors to be displayed as soon as they
+are encountered, rather than after compilation is terminated. If GNAT
+terminates prematurely or goes into an infinite loop, the last error
+message displayed may help to pinpoint the culprit.
 
 @item 
-@code{gnatfind -r "*x*":main.ads:123 foo.adb}
-Find references to all entities containing an x that are
-referenced on line 123 of main.ads.
-The references will be searched only in main.ads and foo.adb.
+Run @code{gcc} with the @code{-v} (verbose) switch. In this
+mode, @code{gcc} produces ongoing information about the progress of the
+compilation and provides the name of each procedure as code is
+generated. This switch allows you to find which Ada procedure was being
+compiled when it encountered a code generation problem.
+@end itemize
 
-@item 
-@code{gnatfind main.ads:123}
-Find declarations and bodies for all entities that are referenced on
-line 123 of main.ads.
+@geindex -gnatdc switch
 
-This is the same as @code{gnatfind "*":main.adb:123`}
+
+@itemize *
 
 @item 
-@code{gnatfind mydir/main.adb:123:45}
-Find the declaration for the entity referenced at column 45 in
-line 123 of file main.adb in directory mydir. Note that it
-is usual to omit the identifier name when the column is given,
-since the column position identifies a unique reference.
+Run @code{gcc} with the @code{-gnatdc} switch. This is a GNAT specific
+switch that does for the front-end what @code{-v} does
+for the back end. The system prints the name of each unit,
+either a compilation unit or nested unit, as it is being analyzed.
 
-The column has to be the beginning of the identifier, and should not
-point to any character in the middle of the identifier.
+@item 
+Finally, you can start
+@code{gdb} directly on the @code{gnat1} executable. @code{gnat1} is the
+front-end of GNAT, and can be run independently (normally it is just
+called from @code{gcc}). You can use @code{gdb} on @code{gnat1} as you
+would on a C program (but @ref{14e,,The GNAT Debugger GDB} for caveats). The
+@code{where} command is the first line of attack; the variable
+@code{lineno} (seen by @code{print lineno}), used by the second phase of
+@code{gnat1} and by the @code{gcc} backend, indicates the source line at
+which the execution stopped, and @code{input_file name} indicates the name of
+the source file.
 @end itemize
 
-@node The Ada to HTML Converter gnathtml,,The Cross-Referencing Tools gnatxref and gnatfind,GNAT Utility Programs
-@anchor{gnat_ugn/gnat_utility_programs the-ada-to-html-converter-gnathtml}@anchor{23}@anchor{gnat_ugn/gnat_utility_programs id16}@anchor{160}
-@section The Ada to HTML Converter @code{gnathtml}
-
+@node Naming Conventions for GNAT Source Files,Getting Internal Debugging Information,GNAT Abnormal Termination or Failure to Terminate,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution naming-conventions-for-gnat-source-files}@anchor{164}@anchor{gnat_ugn/gnat_and_program_execution id14}@anchor{165}
+@subsection Naming Conventions for GNAT Source Files
 
-@geindex gnathtml
 
-@code{gnathtml} is a Perl script that allows Ada source files to be browsed using
-standard Web browsers. For installation information, see @ref{161,,Installing gnathtml}.
+In order to examine the workings of the GNAT system, the following
+brief description of its organization may be helpful:
 
-Ada reserved keywords are highlighted in a bold font and Ada comments in
-a blue font. Unless your program was compiled with the gcc @code{-gnatx}
-switch to suppress the generation of cross-referencing information, user
-defined variables and types will appear in a different color; you will
-be able to click on any identifier and go to its declaration.
 
-@menu
-* Invoking gnathtml:: 
-* Installing gnathtml:: 
+@itemize *
 
-@end menu
+@item 
+Files with prefix @code{sc} contain the lexical scanner.
 
-@node Invoking gnathtml,Installing gnathtml,,The Ada to HTML Converter gnathtml
-@anchor{gnat_ugn/gnat_utility_programs invoking-gnathtml}@anchor{162}@anchor{gnat_ugn/gnat_utility_programs id17}@anchor{163}
-@subsection Invoking @code{gnathtml}
+@item 
+All files prefixed with @code{par} are components of the parser. The
+numbers correspond to chapters of the Ada Reference Manual. For example,
+parsing of select statements can be found in @code{par-ch9.adb}.
 
+@item 
+All files prefixed with @code{sem} perform semantic analysis. The
+numbers correspond to chapters of the Ada standard. For example, all
+issues involving context clauses can be found in @code{sem_ch10.adb}. In
+addition, some features of the language require sufficient special processing
+to justify their own semantic files: sem_aggr for aggregates, sem_disp for
+dynamic dispatching, etc.
 
-The command line is as follows:
+@item 
+All files prefixed with @code{exp} perform normalization and
+expansion of the intermediate representation (abstract syntax tree, or AST).
+these files use the same numbering scheme as the parser and semantics files.
+For example, the construction of record initialization procedures is done in
+@code{exp_ch3.adb}.
 
-@quotation
+@item 
+The files prefixed with @code{bind} implement the binder, which
+verifies the consistency of the compilation, determines an order of
+elaboration, and generates the bind file.
 
-@example
-$ perl gnathtml.pl [ switches ] ada-files
-@end example
-@end quotation
+@item 
+The files @code{atree.ads} and @code{atree.adb} detail the low-level
+data structures used by the front-end.
 
-You can specify as many Ada files as you want. @code{gnathtml} will generate
-an html file for every ada file, and a global file called @code{index.htm}.
-This file is an index of every identifier defined in the files.
+@item 
+The files @code{sinfo.ads} and @code{sinfo.adb} detail the structure of
+the abstract syntax tree as produced by the parser.
 
-The following switches are available:
+@item 
+The files @code{einfo.ads} and @code{einfo.adb} detail the attributes of
+all entities, computed during semantic analysis.
 
-@geindex -83 (gnathtml)
+@item 
+Library management issues are dealt with in files with prefix
+@code{lib}.
 
+@geindex Annex A (in Ada Reference Manual)
 
-@table @asis
+@item 
+Ada files with the prefix @code{a-} are children of @code{Ada}, as
+defined in Annex A.
 
-@item @code{83}
+@geindex Annex B (in Ada reference Manual)
 
-Only the Ada 83 subset of keywords will be highlighted.
-@end table
+@item 
+Files with prefix @code{i-} are children of @code{Interfaces}, as
+defined in Annex B.
 
-@geindex -cc (gnathtml)
+@geindex System (package in Ada Reference Manual)
 
+@item 
+Files with prefix @code{s-} are children of @code{System}. This includes
+both language-defined children and GNAT run-time routines.
 
-@table @asis
+@geindex GNAT (package)
 
-@item @code{cc @emph{color}}
+@item 
+Files with prefix @code{g-} are children of @code{GNAT}. These are useful
+general-purpose packages, fully documented in their specs. All
+the other @code{.c} files are modifications of common @code{gcc} files.
+@end itemize
 
-This option allows you to change the color used for comments. The default
-value is green. The color argument can be any name accepted by html.
-@end table
+@node Getting Internal Debugging Information,Stack Traceback,Naming Conventions for GNAT Source Files,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution id15}@anchor{166}@anchor{gnat_ugn/gnat_and_program_execution getting-internal-debugging-information}@anchor{167}
+@subsection Getting Internal Debugging Information
 
-@geindex -d (gnathtml)
 
+Most compilers have internal debugging switches and modes. GNAT
+does also, except GNAT internal debugging switches and modes are not
+secret. A summary and full description of all the compiler and binder
+debug flags are in the file @code{debug.adb}. You must obtain the
+sources of the compiler to see the full detailed effects of these flags.
 
-@table @asis
+The switches that print the source of the program (reconstructed from
+the internal tree) are of general interest for user programs, as are the
+options to print
+the full internal tree, and the entity table (the symbol table
+information). The reconstructed source provides a readable version of the
+program after the front-end has completed analysis and  expansion,
+and is useful when studying the performance of specific constructs.
+For example, constraint checks are indicated, complex aggregates
+are replaced with loops and assignments, and tasking primitives
+are replaced with run-time calls.
 
-@item @code{d}
+@geindex traceback
 
-If the Ada files depend on some other files (for instance through
-@code{with} clauses, the latter files will also be converted to html.
-Only the files in the user project will be converted to html, not the files
-in the run-time library itself.
-@end table
+@geindex stack traceback
 
-@geindex -D (gnathtml)
+@geindex stack unwinding
 
+@node Stack Traceback,Pretty-Printers for the GNAT runtime,Getting Internal Debugging Information,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution stack-traceback}@anchor{168}@anchor{gnat_ugn/gnat_and_program_execution id16}@anchor{169}
+@subsection Stack Traceback
 
-@table @asis
 
-@item @code{D}
+Traceback is a mechanism to display the sequence of subprogram calls that
+leads to a specified execution point in a program. Often (but not always)
+the execution point is an instruction at which an exception has been raised.
+This mechanism is also known as @emph{stack unwinding} because it obtains
+its information by scanning the run-time stack and recovering the activation
+records of all active subprograms. Stack unwinding is one of the most
+important tools for program debugging.
 
-This command is the same as @code{-d} above, but @code{gnathtml} will
-also look for files in the run-time library, and generate html files for them.
-@end table
+The first entry stored in traceback corresponds to the deepest calling level,
+that is to say the subprogram currently executing the instruction
+from which we want to obtain the traceback.
 
-@geindex -ext (gnathtml)
+Note that there is no runtime performance penalty when stack traceback
+is enabled, and no exception is raised during program execution.
 
+@geindex traceback
+@geindex non-symbolic
 
-@table @asis
+@menu
+* Non-Symbolic Traceback:: 
+* Symbolic Traceback:: 
 
-@item @code{ext @emph{extension}}
+@end menu
 
-This option allows you to change the extension of the generated HTML files.
-If you do not specify an extension, it will default to @code{htm}.
-@end table
+@node Non-Symbolic Traceback,Symbolic Traceback,,Stack Traceback
+@anchor{gnat_ugn/gnat_and_program_execution non-symbolic-traceback}@anchor{16a}@anchor{gnat_ugn/gnat_and_program_execution id17}@anchor{16b}
+@subsubsection Non-Symbolic Traceback
 
-@geindex -f (gnathtml)
 
+Note: this feature is not supported on all platforms. See
+@code{GNAT.Traceback} spec in @code{g-traceb.ads}
+for a complete list of supported platforms.
 
-@table @asis
+@subsubheading Tracebacks From an Unhandled Exception
 
-@item @code{f}
 
-By default, gnathtml will generate html links only for global entities
-('with'ed units, global variables and types,...).  If you specify
-@code{-f} on the command line, then links will be generated for local
-entities too.
-@end table
+A runtime non-symbolic traceback is a list of addresses of call instructions.
+To enable this feature you must use the @code{-E}
+@code{gnatbind} option. With this option a stack traceback is stored as part
+of exception information. You can retrieve this information using the
+@code{addr2line} tool.
 
-@geindex -l (gnathtml)
+Here is a simple example:
 
+@quotation
 
-@table @asis
+@example
+procedure STB is
 
-@item @code{l @emph{number}}
+   procedure P1 is
+   begin
+      raise Constraint_Error;
+   end P1;
 
-If this switch is provided and @code{number} is not 0, then
-@code{gnathtml} will number the html files every @code{number} line.
-@end table
+   procedure P2 is
+   begin
+      P1;
+   end P2;
 
-@geindex -I (gnathtml)
+begin
+   P2;
+end STB;
+@end example
 
+@example
+$ gnatmake stb -bargs -E
+$ stb
 
-@table @asis
+Execution terminated by unhandled exception
+Exception name: CONSTRAINT_ERROR
+Message: stb.adb:5
+Call stack traceback locations:
+0x401373 0x40138b 0x40139c 0x401335 0x4011c4 0x4011f1 0x77e892a4
+@end example
+@end quotation
 
-@item @code{I @emph{dir}}
+As we see the traceback lists a sequence of addresses for the unhandled
+exception @code{CONSTRAINT_ERROR} raised in procedure P1. It is easy to
+guess that this exception come from procedure P1. To translate these
+addresses into the source lines where the calls appear, the
+@code{addr2line} tool, described below, is invaluable. The use of this tool
+requires the program to be compiled with debug information.
 
-Specify a directory to search for library files (@code{.ALI} files) and
-source files. You can provide several -I switches on the command line,
-and the directories will be parsed in the order of the command line.
-@end table
+@quotation
 
-@geindex -o (gnathtml)
+@example
+$ gnatmake -g stb -bargs -E
+$ stb
 
+Execution terminated by unhandled exception
+Exception name: CONSTRAINT_ERROR
+Message: stb.adb:5
+Call stack traceback locations:
+0x401373 0x40138b 0x40139c 0x401335 0x4011c4 0x4011f1 0x77e892a4
 
-@table @asis
+$ addr2line --exe=stb 0x401373 0x40138b 0x40139c 0x401335 0x4011c4
+   0x4011f1 0x77e892a4
 
-@item @code{o @emph{dir}}
+00401373 at d:/stb/stb.adb:5
+0040138B at d:/stb/stb.adb:10
+0040139C at d:/stb/stb.adb:14
+00401335 at d:/stb/b~stb.adb:104
+004011C4 at /build/.../crt1.c:200
+004011F1 at /build/.../crt1.c:222
+77E892A4 in ?? at ??:0
+@end example
+@end quotation
 
-Specify the output directory for html files. By default, gnathtml will
-saved the generated html files in a subdirectory named @code{html/}.
-@end table
+The @code{addr2line} tool has several other useful options:
 
-@geindex -p (gnathtml)
+@quotation
 
 
-@table @asis
-
-@item @code{p @emph{file}}
-
-If you are using Emacs and the most recent Emacs Ada mode, which provides
-a full Integrated Development Environment for compiling, checking,
-running and debugging applications, you may use @code{.gpr} files
-to give the directories where Emacs can find sources and object files.
-
-Using this switch, you can tell gnathtml to use these files.
-This allows you to get an html version of your application, even if it
-is spread over multiple directories.
-@end table
-
-@geindex -sc (gnathtml)
+@multitable {xxxxxxxxxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx} 
+@item
 
+@code{--functions}
 
-@table @asis
+@tab
 
-@item @code{sc @emph{color}}
+to get the function name corresponding to any location
 
-This switch allows you to change the color used for symbol
-definitions.
-The default value is red. The color argument can be any name accepted by html.
-@end table
+@item
 
-@geindex -t (gnathtml)
+@code{--demangle=gnat}
 
+@tab
 
-@table @asis
+to use the gnat decoding mode for the function names.
+Note that for binutils version 2.9.x the option is
+simply @code{--demangle}.
 
-@item @code{t @emph{file}}
+@end multitable
 
-This switch provides the name of a file. This file contains a list of
-file names to be converted, and the effect is exactly as though they had
-appeared explicitly on the command line. This
-is the recommended way to work around the command line length limit on some
-systems.
-@end table
 
-@node Installing gnathtml,,Invoking gnathtml,The Ada to HTML Converter gnathtml
-@anchor{gnat_ugn/gnat_utility_programs installing-gnathtml}@anchor{161}@anchor{gnat_ugn/gnat_utility_programs id18}@anchor{164}
-@subsection Installing @code{gnathtml}
+@example
+$ addr2line --exe=stb --functions --demangle=gnat 0x401373 0x40138b
+   0x40139c 0x401335 0x4011c4 0x4011f1
 
+00401373 in stb.p1 at d:/stb/stb.adb:5
+0040138B in stb.p2 at d:/stb/stb.adb:10
+0040139C in stb at d:/stb/stb.adb:14
+00401335 in main at d:/stb/b~stb.adb:104
+004011C4 in <__mingw_CRTStartup> at /build/.../crt1.c:200
+004011F1 in <mainCRTStartup> at /build/.../crt1.c:222
+@end example
+@end quotation
 
-@code{Perl} needs to be installed on your machine to run this script.
-@code{Perl} is freely available for almost every architecture and
-operating system via the Internet.
+From this traceback we can see that the exception was raised in
+@code{stb.adb} at line 5, which was reached from a procedure call in
+@code{stb.adb} at line 10, and so on. The @code{b~std.adb} is the binder file,
+which contains the call to the main program.
+@ref{10d,,Running gnatbind}. The remaining entries are assorted runtime routines,
+and the output will vary from platform to platform.
 
-On Unix systems, you  may want to modify  the  first line of  the script
-@code{gnathtml},  to explicitly  specify  where Perl
-is located. The syntax of this line is:
+It is also possible to use @code{GDB} with these traceback addresses to debug
+the program. For example, we can break at a given code location, as reported
+in the stack traceback:
 
 @quotation
 
 @example
-#!full_path_name_to_perl
+$ gdb -nw stb
 @end example
 @end quotation
 
-Alternatively, you may run the script using the following command line:
+Furthermore, this feature is not implemented inside Windows DLL. Only
+the non-symbolic traceback is reported in this case.
 
 @quotation
 
 @example
-$ perl gnathtml.pl [ switches ] files
+(gdb) break *0x401373
+Breakpoint 1 at 0x401373: file stb.adb, line 5.
 @end example
 @end quotation
 
-@c -- +---------------------------------------------------------------------+
+It is important to note that the stack traceback addresses
+do not change when debug information is included. This is particularly useful
+because it makes it possible to release software without debug information (to
+minimize object size), get a field report that includes a stack traceback
+whenever an internal bug occurs, and then be able to retrieve the sequence
+of calls with the same program compiled with debug information.
 
-@c -- | The following sections are present only in the PRO and GPL editions |
+@subsubheading Tracebacks From Exception Occurrences
 
-@c -- +---------------------------------------------------------------------+
 
+Non-symbolic tracebacks are obtained by using the @code{-E} binder argument.
+The stack traceback is attached to the exception information string, and can
+be retrieved in an exception handler within the Ada program, by means of the
+Ada facilities defined in @code{Ada.Exceptions}. Here is a simple example:
 
+@quotation
 
+@example
+with Ada.Text_IO;
+with Ada.Exceptions;
 
+procedure STB is
 
+   use Ada;
+   use Ada.Exceptions;
 
+   procedure P1 is
+      K : Positive := 1;
+   begin
+      K := K - 1;
+   exception
+      when E : others =>
+         Text_IO.Put_Line (Exception_Information (E));
+   end P1;
 
+   procedure P2 is
+   begin
+      P1;
+   end P2;
 
-@c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit
+begin
+   P2;
+end STB;
+@end example
+@end quotation
 
-@node GNAT and Program Execution,Platform-Specific Information,GNAT Utility Programs,Top
-@anchor{gnat_ugn/gnat_and_program_execution gnat-and-program-execution}@anchor{c}@anchor{gnat_ugn/gnat_and_program_execution doc}@anchor{165}@anchor{gnat_ugn/gnat_and_program_execution id1}@anchor{166}
-@chapter GNAT and Program Execution
+This program will output:
 
+@quotation
 
-This chapter covers several topics:
+@example
+$ stb
 
+Exception name: CONSTRAINT_ERROR
+Message: stb.adb:12
+Call stack traceback locations:
+0x4015e4 0x401633 0x401644 0x401461 0x4011c4 0x4011f1 0x77e892a4
+@end example
+@end quotation
 
-@itemize *
+@subsubheading Tracebacks From Anywhere in a Program
 
-@item 
-@ref{167,,Running and Debugging Ada Programs}
 
-@item 
-@ref{168,,Code Coverage and Profiling}
+It is also possible to retrieve a stack traceback from anywhere in a
+program. For this you need to
+use the @code{GNAT.Traceback} API. This package includes a procedure called
+@code{Call_Chain} that computes a complete stack traceback, as well as useful
+display procedures described below. It is not necessary to use the
+@code{-E} @code{gnatbind} option in this case, because the stack traceback mechanism
+is invoked explicitly.
 
-@item 
-@ref{169,,Improving Performance}
+In the following example we compute a traceback at a specific location in
+the program, and we display it using @code{GNAT.Debug_Utilities.Image} to
+convert addresses to strings:
 
-@item 
-@ref{16a,,Overflow Check Handling in GNAT}
+@quotation
 
-@item 
-@ref{16b,,Performing Dimensionality Analysis in GNAT}
+@example
+with Ada.Text_IO;
+with GNAT.Traceback;
+with GNAT.Debug_Utilities;
 
-@item 
-@ref{16c,,Stack Related Facilities}
+procedure STB is
 
-@item 
-@ref{16d,,Memory Management Issues}
-@end itemize
+   use Ada;
+   use GNAT;
+   use GNAT.Traceback;
 
-@menu
-* Running and Debugging Ada Programs:: 
-* Code Coverage and Profiling:: 
-* Improving Performance:: 
-* Overflow Check Handling in GNAT:: 
-* Performing Dimensionality Analysis in GNAT:: 
-* Stack Related Facilities:: 
-* Memory Management Issues:: 
+   procedure P1 is
+      TB  : Tracebacks_Array (1 .. 10);
+      --  We are asking for a maximum of 10 stack frames.
+      Len : Natural;
+      --  Len will receive the actual number of stack frames returned.
+   begin
+      Call_Chain (TB, Len);
 
-@end menu
+      Text_IO.Put ("In STB.P1 : ");
 
-@node Running and Debugging Ada Programs,Code Coverage and Profiling,,GNAT and Program Execution
-@anchor{gnat_ugn/gnat_and_program_execution id2}@anchor{167}@anchor{gnat_ugn/gnat_and_program_execution running-and-debugging-ada-programs}@anchor{24}
-@section Running and Debugging Ada Programs
+      for K in 1 .. Len loop
+         Text_IO.Put (Debug_Utilities.Image (TB (K)));
+         Text_IO.Put (' ');
+      end loop;
 
+      Text_IO.New_Line;
+   end P1;
 
-@geindex Debugging
+   procedure P2 is
+   begin
+      P1;
+   end P2;
 
-This section discusses how to debug Ada programs.
+begin
+   P2;
+end STB;
+@end example
 
-An incorrect Ada program may be handled in three ways by the GNAT compiler:
+@example
+$ gnatmake -g stb
+$ stb
 
+In STB.P1 : 16#0040_F1E4# 16#0040_14F2# 16#0040_170B# 16#0040_171C#
+16#0040_1461# 16#0040_11C4# 16#0040_11F1# 16#77E8_92A4#
+@end example
+@end quotation
 
-@itemize *
+You can then get further information by invoking the @code{addr2line}
+tool as described earlier (note that the hexadecimal addresses
+need to be specified in C format, with a leading '0x').
 
-@item 
-The illegality may be a violation of the static semantics of Ada. In
-that case GNAT diagnoses the constructs in the program that are illegal.
-It is then a straightforward matter for the user to modify those parts of
-the program.
+@geindex traceback
+@geindex symbolic
 
-@item 
-The illegality may be a violation of the dynamic semantics of Ada. In
-that case the program compiles and executes, but may generate incorrect
-results, or may terminate abnormally with some exception.
+@node Symbolic Traceback,,Non-Symbolic Traceback,Stack Traceback
+@anchor{gnat_ugn/gnat_and_program_execution id18}@anchor{16c}@anchor{gnat_ugn/gnat_and_program_execution symbolic-traceback}@anchor{16d}
+@subsubsection Symbolic Traceback
 
-@item 
-When presented with a program that contains convoluted errors, GNAT
-itself may terminate abnormally without providing full diagnostics on
-the incorrect user program.
-@end itemize
 
-@geindex Debugger
+A symbolic traceback is a stack traceback in which procedure names are
+associated with each code location.
 
-@geindex gdb
+Note that this feature is not supported on all platforms. See
+@code{GNAT.Traceback.Symbolic} spec in @code{g-trasym.ads} for a complete
+list of currently supported platforms.
 
-@menu
-* The GNAT Debugger GDB:: 
-* Running GDB:: 
-* Introduction to GDB Commands:: 
-* Using Ada Expressions:: 
-* Calling User-Defined Subprograms:: 
-* Using the next Command in a Function:: 
-* Stopping When Ada Exceptions Are Raised:: 
-* Ada Tasks:: 
-* Debugging Generic Units:: 
-* Remote Debugging with gdbserver:: 
-* GNAT Abnormal Termination or Failure to Terminate:: 
-* Naming Conventions for GNAT Source Files:: 
-* Getting Internal Debugging Information:: 
-* Stack Traceback:: 
-* Pretty-Printers for the GNAT runtime:: 
+Note that the symbolic traceback requires that the program be compiled
+with debug information. If it is not compiled with debug information
+only the non-symbolic information will be valid.
 
-@end menu
+@subsubheading Tracebacks From Exception Occurrences
 
-@node The GNAT Debugger GDB,Running GDB,,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution the-gnat-debugger-gdb}@anchor{16e}@anchor{gnat_ugn/gnat_and_program_execution id3}@anchor{16f}
-@subsection The GNAT Debugger GDB
 
+Here is an example:
 
-@code{GDB} is a general purpose, platform-independent debugger that
-can be used to debug mixed-language programs compiled with @code{gcc},
-and in particular is capable of debugging Ada programs compiled with
-GNAT. The latest versions of @code{GDB} are Ada-aware and can handle
-complex Ada data structures.
+@quotation
 
-See @cite{Debugging with GDB},
-for full details on the usage of @code{GDB}, including a section on
-its usage on programs. This manual should be consulted for full
-details. The section that follows is a brief introduction to the
-philosophy and use of @code{GDB}.
+@example
+with Ada.Text_IO;
+with GNAT.Traceback.Symbolic;
 
-When GNAT programs are compiled, the compiler optionally writes debugging
-information into the generated object file, including information on
-line numbers, and on declared types and variables. This information is
-separate from the generated code. It makes the object files considerably
-larger, but it does not add to the size of the actual executable that
-will be loaded into memory, and has no impact on run-time performance. The
-generation of debug information is triggered by the use of the
-@code{-g} switch in the @code{gcc} or @code{gnatmake} command
-used to carry out the compilations. It is important to emphasize that
-the use of these options does not change the generated code.
+procedure STB is
 
-The debugging information is written in standard system formats that
-are used by many tools, including debuggers and profilers. The format
-of the information is typically designed to describe C types and
-semantics, but GNAT implements a translation scheme which allows full
-details about Ada types and variables to be encoded into these
-standard C formats. Details of this encoding scheme may be found in
-the file exp_dbug.ads in the GNAT source distribution. However, the
-details of this encoding are, in general, of no interest to a user,
-since @code{GDB} automatically performs the necessary decoding.
+   procedure P1 is
+   begin
+      raise Constraint_Error;
+   end P1;
 
-When a program is bound and linked, the debugging information is
-collected from the object files, and stored in the executable image of
-the program. Again, this process significantly increases the size of
-the generated executable file, but it does not increase the size of
-the executable program itself. Furthermore, if this program is run in
-the normal manner, it runs exactly as if the debug information were
-not present, and takes no more actual memory.
+   procedure P2 is
+   begin
+      P1;
+   end P2;
 
-However, if the program is run under control of @code{GDB}, the
-debugger is activated.  The image of the program is loaded, at which
-point it is ready to run.  If a run command is given, then the program
-will run exactly as it would have if @code{GDB} were not present. This
-is a crucial part of the @code{GDB} design philosophy.  @code{GDB} is
-entirely non-intrusive until a breakpoint is encountered.  If no
-breakpoint is ever hit, the program will run exactly as it would if no
-debugger were present. When a breakpoint is hit, @code{GDB} accesses
-the debugging information and can respond to user commands to inspect
-variables, and more generally to report on the state of execution.
+   procedure P3 is
+   begin
+      P2;
+   end P3;
 
-@node Running GDB,Introduction to GDB Commands,The GNAT Debugger GDB,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution id4}@anchor{170}@anchor{gnat_ugn/gnat_and_program_execution running-gdb}@anchor{171}
-@subsection Running GDB
+begin
+   P3;
+exception
+   when E : others =>
+      Ada.Text_IO.Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (E));
+end STB;
+@end example
 
+@example
+$ gnatmake -g .\stb -bargs -E
+$ stb
 
-This section describes how to initiate the debugger.
+0040149F in stb.p1 at stb.adb:8
+004014B7 in stb.p2 at stb.adb:13
+004014CF in stb.p3 at stb.adb:18
+004015DD in ada.stb at stb.adb:22
+00401461 in main at b~stb.adb:168
+004011C4 in __mingw_CRTStartup at crt1.c:200
+004011F1 in mainCRTStartup at crt1.c:222
+77E892A4 in ?? at ??:0
+@end example
+@end quotation
 
-The debugger can be launched from a @code{GPS} menu or
-directly from the command line. The description below covers the latter use.
-All the commands shown can be used in the @code{GPS} debug console window,
-but there are usually more GUI-based ways to achieve the same effect.
+In the above example the @code{.\} syntax in the @code{gnatmake} command
+is currently required by @code{addr2line} for files that are in
+the current working directory.
+Moreover, the exact sequence of linker options may vary from platform
+to platform.
+The above @code{-largs} section is for Windows platforms. By contrast,
+under Unix there is no need for the @code{-largs} section.
+Differences across platforms are due to details of linker implementation.
 
-The command to run @code{GDB} is
+@subsubheading Tracebacks From Anywhere in a Program
+
+
+It is possible to get a symbolic stack traceback
+from anywhere in a program, just as for non-symbolic tracebacks.
+The first step is to obtain a non-symbolic
+traceback, and then call @code{Symbolic_Traceback} to compute the symbolic
+information. Here is an example:
 
 @quotation
 
 @example
-$ gdb program
-@end example
-@end quotation
+with Ada.Text_IO;
+with GNAT.Traceback;
+with GNAT.Traceback.Symbolic;
 
-where @code{program} is the name of the executable file. This
-activates the debugger and results in a prompt for debugger commands.
-The simplest command is simply @code{run}, which causes the program to run
-exactly as if the debugger were not present. The following section
-describes some of the additional commands that can be given to @code{GDB}.
+procedure STB is
 
-@node Introduction to GDB Commands,Using Ada Expressions,Running GDB,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution introduction-to-gdb-commands}@anchor{172}@anchor{gnat_ugn/gnat_and_program_execution id5}@anchor{173}
-@subsection Introduction to GDB Commands
+   use Ada;
+   use GNAT.Traceback;
+   use GNAT.Traceback.Symbolic;
 
+   procedure P1 is
+      TB  : Tracebacks_Array (1 .. 10);
+      --  We are asking for a maximum of 10 stack frames.
+      Len : Natural;
+      --  Len will receive the actual number of stack frames returned.
+   begin
+      Call_Chain (TB, Len);
+      Text_IO.Put_Line (Symbolic_Traceback (TB (1 .. Len)));
+   end P1;
 
-@code{GDB} contains a large repertoire of commands.
-See @cite{Debugging with GDB} for extensive documentation on the use
-of these commands, together with examples of their use. Furthermore,
-the command @emph{help} invoked from within GDB activates a simple help
-facility which summarizes the available commands and their options.
-In this section we summarize a few of the most commonly
-used commands to give an idea of what @code{GDB} is about. You should create
-a simple program with debugging information and experiment with the use of
-these @code{GDB} commands on the program as you read through the
-following section.
+   procedure P2 is
+   begin
+      P1;
+   end P2;
 
+begin
+   P2;
+end STB;
+@end example
+@end quotation
 
-@itemize *
+@subsubheading Automatic Symbolic Tracebacks
 
-@item 
 
-@table @asis
+Symbolic tracebacks may also be enabled by using the -Es switch to gnatbind (as
+in @code{gprbuild -g ... -bargs -Es}).
+This will cause the Exception_Information to contain a symbolic traceback,
+which will also be printed if an unhandled exception terminates the
+program.
 
-@item @code{set args @emph{arguments}}
+@node Pretty-Printers for the GNAT runtime,,Stack Traceback,Running and Debugging Ada Programs
+@anchor{gnat_ugn/gnat_and_program_execution id19}@anchor{16e}@anchor{gnat_ugn/gnat_and_program_execution pretty-printers-for-the-gnat-runtime}@anchor{16f}
+@subsection Pretty-Printers for the GNAT runtime
 
-The @emph{arguments} list above is a list of arguments to be passed to
-the program on a subsequent run command, just as though the arguments
-had been entered on a normal invocation of the program. The @code{set args}
-command is not needed if the program does not require arguments.
-@end table
 
-@item 
+As discussed in @cite{Calling User-Defined Subprograms}, GDB's
+@code{print} command only knows about the physical layout of program data
+structures and therefore normally displays only low-level dumps, which
+are often hard to understand.
 
-@table @asis
+An example of this is when trying to display the contents of an Ada
+standard container, such as @code{Ada.Containers.Ordered_Maps.Map}:
 
-@item @code{run}
+@quotation
 
-The @code{run} command causes execution of the program to start from
-the beginning. If the program is already running, that is to say if
-you are currently positioned at a breakpoint, then a prompt will ask
-for confirmation that you want to abandon the current execution and
-restart.
-@end table
+@example
+with Ada.Containers.Ordered_Maps;
 
-@item 
+procedure PP is
+   package Int_To_Nat is
+      new Ada.Containers.Ordered_Maps (Integer, Natural);
 
-@table @asis
+   Map : Int_To_Nat.Map;
+begin
+   Map.Insert (1, 10);
+   Map.Insert (2, 20);
+   Map.Insert (3, 30);
 
-@item @code{breakpoint @emph{location}}
+   Map.Clear; --  BREAK HERE
+end PP;
+@end example
+@end quotation
 
-The breakpoint command sets a breakpoint, that is to say a point at which
-execution will halt and @code{GDB} will await further
-commands. @emph{location} is
-either a line number within a file, given in the format @code{file:linenumber},
-or it is the name of a subprogram. If you request that a breakpoint be set on
-a subprogram that is overloaded, a prompt will ask you to specify on which of
-those subprograms you want to breakpoint. You can also
-specify that all of them should be breakpointed. If the program is run
-and execution encounters the breakpoint, then the program
-stops and @code{GDB} signals that the breakpoint was encountered by
-printing the line of code before which the program is halted.
-@end table
+When this program is built with debugging information and run under
+GDB up to the @code{Map.Clear} statement, trying to print @code{Map} will
+yield information that is only relevant to the developers of our standard
+containers:
 
-@item 
+@quotation
 
-@table @asis
+@example
+(gdb) print map
+$1 = (
+  tree => (
+    first => 0x64e010,
+    last => 0x64e070,
+    root => 0x64e040,
+    length => 3,
+    tc => (
+      busy => 0,
+      lock => 0
+    )
+  )
+)
+@end example
+@end quotation
 
-@item @code{catch exception @emph{name}}
+Fortunately, GDB has a feature called pretty-printers@footnote{http://docs.adacore.com/gdb-docs/html/gdb.html#Pretty_002dPrinter-Introduction},
+which allows customizing how GDB displays data structures. The GDB
+shipped with GNAT embeds such pretty-printers for the most common
+containers in the standard library.  To enable them, either run the
+following command manually under GDB or add it to your @code{.gdbinit} file:
 
-This command causes the program execution to stop whenever exception
-@code{name} is raised.  If @code{name} is omitted, then the execution is
-suspended when any exception is raised.
-@end table
+@quotation
 
-@item 
+@example
+python import gnatdbg; gnatdbg.setup()
+@end example
+@end quotation
 
-@table @asis
+Once this is done, GDB's @code{print} command will automatically use
+these pretty-printers when appropriate. Using the previous example:
 
-@item @code{print @emph{expression}}
+@quotation
 
-This will print the value of the given expression. Most simple
-Ada expression formats are properly handled by @code{GDB}, so the expression
-can contain function calls, variables, operators, and attribute references.
-@end table
+@example
+(gdb) print map
+$1 = pp.int_to_nat.map of length 3 = @{
+  [1] = 10,
+  [2] = 20,
+  [3] = 30
+@}
+@end example
+@end quotation
 
-@item 
+Pretty-printers are invoked each time GDB tries to display a value,
+including when displaying the arguments of a called subprogram (in
+GDB's @code{backtrace} command) or when printing the value returned by a
+function (in GDB's @code{finish} command).
 
-@table @asis
+To display a value without involving pretty-printers, @code{print} can be
+invoked with its @code{/r} option:
 
-@item @code{continue}
+@quotation
 
-Continues execution following a breakpoint, until the next breakpoint or the
-termination of the program.
-@end table
+@example
+(gdb) print/r map
+$1 = (
+  tree => (...
+@end example
+@end quotation
 
-@item 
+Finer control of pretty-printers is also possible: see GDB's online documentation@footnote{http://docs.adacore.com/gdb-docs/html/gdb.html#Pretty_002dPrinter-Commands}
+for more information.
 
-@table @asis
+@geindex Profiling
 
-@item @code{step}
+@node Profiling,Improving Performance,Running and Debugging Ada Programs,GNAT and Program Execution
+@anchor{gnat_ugn/gnat_and_program_execution profiling}@anchor{147}@anchor{gnat_ugn/gnat_and_program_execution id20}@anchor{170}
+@section Profiling
 
-Executes a single line after a breakpoint. If the next statement
-is a subprogram call, execution continues into (the first statement of)
-the called subprogram.
-@end table
 
-@item 
+This section describes how to use the @code{gprof} profiler tool on Ada programs.
 
-@table @asis
+@geindex gprof
 
-@item @code{next}
+@geindex Profiling
 
-Executes a single line. If this line is a subprogram call, executes and
-returns from the call.
-@end table
+@menu
+* Profiling an Ada Program with gprof:: 
 
-@item 
+@end menu
 
-@table @asis
+@node Profiling an Ada Program with gprof,,,Profiling
+@anchor{gnat_ugn/gnat_and_program_execution id21}@anchor{171}@anchor{gnat_ugn/gnat_and_program_execution profiling-an-ada-program-with-gprof}@anchor{172}
+@subsection Profiling an Ada Program with gprof
 
-@item @code{list}
 
-Lists a few lines around the current source location. In practice, it
-is usually more convenient to have a separate edit window open with the
-relevant source file displayed. Successive applications of this command
-print subsequent lines. The command can be given an argument which is a
-line number, in which case it displays a few lines around the specified one.
-@end table
+This section is not meant to be an exhaustive documentation of @code{gprof}.
+Full documentation for it can be found in the @cite{GNU Profiler User's Guide}
+documentation that is part of this GNAT distribution.
 
-@item 
+Profiling a program helps determine the parts of a program that are executed
+most often, and are therefore the most time-consuming.
 
-@table @asis
+@code{gprof} is the standard GNU profiling tool; it has been enhanced to
+better handle Ada programs and multitasking.
+It is currently supported on the following platforms
 
-@item @code{backtrace}
 
-Displays a backtrace of the call chain. This command is typically
-used after a breakpoint has occurred, to examine the sequence of calls that
-leads to the current breakpoint. The display includes one line for each
-activation record (frame) corresponding to an active subprogram.
-@end table
+@itemize *
 
 @item 
-
-@table @asis
-
-@item @code{up}
-
-At a breakpoint, @code{GDB} can display the values of variables local
-to the current frame. The command @code{up} can be used to
-examine the contents of other active frames, by moving the focus up
-the stack, that is to say from callee to caller, one frame at a time.
-@end table
+linux x86/x86_64
 
 @item 
+windows x86
+@end itemize
 
-@table @asis
+In order to profile a program using @code{gprof}, several steps are needed:
 
-@item @code{down}
 
-Moves the focus of @code{GDB} down from the frame currently being
-examined to the frame of its callee (the reverse of the previous command),
-@end table
+@enumerate 
 
 @item 
+Instrument the code, which requires a full recompilation of the project with the
+proper switches.
 
-@table @asis
+@item 
+Execute the program under the analysis conditions, i.e. with the desired
+input.
 
-@item @code{frame @emph{n}}
+@item 
+Analyze the results using the @code{gprof} tool.
+@end enumerate
 
-Inspect the frame with the given number. The value 0 denotes the frame
-of the current breakpoint, that is to say the top of the call stack.
-@end table
+The following sections detail the different steps, and indicate how
+to interpret the results.
 
-@item 
+@menu
+* Compilation for profiling:: 
+* Program execution:: 
+* Running gprof:: 
+* Interpretation of profiling results:: 
 
-@table @asis
+@end menu
 
-@item @code{kill}
+@node Compilation for profiling,Program execution,,Profiling an Ada Program with gprof
+@anchor{gnat_ugn/gnat_and_program_execution id22}@anchor{173}@anchor{gnat_ugn/gnat_and_program_execution compilation-for-profiling}@anchor{174}
+@subsubsection Compilation for profiling
 
-Kills the child process in which the program is running under GDB.
-This may be useful for several purposes:
 
+@geindex -pg (gcc)
+@geindex for profiling
 
-@itemize *
+@geindex -pg (gnatlink)
+@geindex for profiling
 
-@item 
-It allows you to recompile and relink your program, since on many systems
-you cannot regenerate an executable file while it is running in a process.
+In order to profile a program the first step is to tell the compiler
+to generate the necessary profiling information. The compiler switch to be used
+is @code{-pg}, which must be added to other compilation switches. This
+switch needs to be specified both during compilation and link stages, and can
+be specified once when using gnatmake:
 
-@item 
-You can run your program outside the debugger, on systems that do not
-permit executing a program outside GDB while breakpoints are set
-within GDB.
+@quotation
 
-@item 
-It allows you to debug a core dump rather than a running process.
-@end itemize
-@end table
-@end itemize
+@example
+$ gnatmake -f -pg -P my_project
+@end example
+@end quotation
 
-The above list is a very short introduction to the commands that
-@code{GDB} provides. Important additional capabilities, including conditional
-breakpoints, the ability to execute command sequences on a breakpoint,
-the ability to debug at the machine instruction level and many other
-features are described in detail in @cite{Debugging with GDB}.
-Note that most commands can be abbreviated
-(for example, c for continue, bt for backtrace).
+Note that only the objects that were compiled with the @code{-pg} switch will
+be profiled; if you need to profile your whole project, use the @code{-f}
+gnatmake switch to force full recompilation.
 
-@node Using Ada Expressions,Calling User-Defined Subprograms,Introduction to GDB Commands,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution id6}@anchor{174}@anchor{gnat_ugn/gnat_and_program_execution using-ada-expressions}@anchor{175}
-@subsection Using Ada Expressions
+@node Program execution,Running gprof,Compilation for profiling,Profiling an Ada Program with gprof
+@anchor{gnat_ugn/gnat_and_program_execution program-execution}@anchor{175}@anchor{gnat_ugn/gnat_and_program_execution id23}@anchor{176}
+@subsubsection Program execution
 
 
-@geindex Ada expressions (in gdb)
+Once the program has been compiled for profiling, you can run it as usual.
 
-@code{GDB} supports a fairly large subset of Ada expression syntax, with some
-extensions. The philosophy behind the design of this subset is
+The only constraint imposed by profiling is that the program must terminate
+normally. An interrupted program (via a Ctrl-C, kill, etc.) will not be
+properly analyzed.
 
-@quotation
+Once the program completes execution, a data file called @code{gmon.out} is
+generated in the directory where the program was launched from. If this file
+already exists, it will be overwritten.
 
+@node Running gprof,Interpretation of profiling results,Program execution,Profiling an Ada Program with gprof
+@anchor{gnat_ugn/gnat_and_program_execution running-gprof}@anchor{177}@anchor{gnat_ugn/gnat_and_program_execution id24}@anchor{178}
+@subsubsection Running gprof
 
-@itemize *
 
-@item 
-That @code{GDB} should provide basic literals and access to operations for
-arithmetic, dereferencing, field selection, indexing, and subprogram calls,
-leaving more sophisticated computations to subprograms written into the
-program (which therefore may be called from @code{GDB}).
+The @code{gprof} tool is called as follow:
 
-@item 
-That type safety and strict adherence to Ada language restrictions
-are not particularly relevant in a debugging context.
+@quotation
 
-@item 
-That brevity is important to the @code{GDB} user.
-@end itemize
+@example
+$ gprof my_prog gmon.out
+@end example
 @end quotation
 
-Thus, for brevity, the debugger acts as if there were
-implicit @code{with} and @code{use} clauses in effect for all user-written
-packages, thus making it unnecessary to fully qualify most names with
-their packages, regardless of context. Where this causes ambiguity,
-@code{GDB} asks the user's intent.
-
-For details on the supported Ada syntax, see @cite{Debugging with GDB}.
+or simply:
 
-@node Calling User-Defined Subprograms,Using the next Command in a Function,Using Ada Expressions,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution id7}@anchor{176}@anchor{gnat_ugn/gnat_and_program_execution calling-user-defined-subprograms}@anchor{177}
-@subsection Calling User-Defined Subprograms
+@quotation
 
+@example
+$  gprof my_prog
+@end example
+@end quotation
 
-An important capability of @code{GDB} is the ability to call user-defined
-subprograms while debugging. This is achieved simply by entering
-a subprogram call statement in the form:
+The complete form of the gprof command line is the following:
 
 @quotation
 
 @example
-call subprogram-name (parameters)
+$ gprof [switches] [executable [data-file]]
 @end example
 @end quotation
 
-The keyword @code{call} can be omitted in the normal case where the
-@code{subprogram-name} does not coincide with any of the predefined
-@code{GDB} commands.
+@code{gprof} supports numerous switches. The order of these
+switch does not matter. The full list of options can be found in
+the GNU Profiler User's Guide documentation that comes with this documentation.
 
-The effect is to invoke the given subprogram, passing it the
-list of parameters that is supplied. The parameters can be expressions and
-can include variables from the program being debugged. The
-subprogram must be defined
-at the library level within your program, and @code{GDB} will call the
-subprogram within the environment of your program execution (which
-means that the subprogram is free to access or even modify variables
-within your program).
+The following is the subset of those switches that is most relevant:
 
-The most important use of this facility is in allowing the inclusion of
-debugging routines that are tailored to particular data structures
-in your program. Such debugging routines can be written to provide a suitably
-high-level description of an abstract type, rather than a low-level dump
-of its physical layout. After all, the standard
-@code{GDB print} command only knows the physical layout of your
-types, not their abstract meaning. Debugging routines can provide information
-at the desired semantic level and are thus enormously useful.
+@geindex --demangle (gprof)
 
-For example, when debugging GNAT itself, it is crucial to have access to
-the contents of the tree nodes used to represent the program internally.
-But tree nodes are represented simply by an integer value (which in turn
-is an index into a table of nodes).
-Using the @code{print} command on a tree node would simply print this integer
-value, which is not very useful. But the PN routine (defined in file
-treepr.adb in the GNAT sources) takes a tree node as input, and displays
-a useful high level representation of the tree node, which includes the
-syntactic category of the node, its position in the source, the integers
-that denote descendant nodes and parent node, as well as varied
-semantic information. To study this example in more detail, you might want to
-look at the body of the PN procedure in the stated file.
 
-Another useful application of this capability is to deal with situations of
-complex data which are not handled suitably by GDB. For example, if you specify
-Convention Fortran for a multi-dimensional array, GDB does not know that
-the ordering of array elements has been switched and will not properly
-address the array elements. In such a case, instead of trying to print the
-elements directly from GDB, you can write a callable procedure that prints
-the elements in the desired format.
+@table @asis
 
-@node Using the next Command in a Function,Stopping When Ada Exceptions Are Raised,Calling User-Defined Subprograms,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution using-the-next-command-in-a-function}@anchor{178}@anchor{gnat_ugn/gnat_and_program_execution id8}@anchor{179}
-@subsection Using the @emph{next} Command in a Function
+@item @code{--demangle[=@emph{style}]}, @code{--no-demangle}
 
+These options control whether symbol names should be demangled when
+printing output.  The default is to demangle C++ symbols.  The
+@code{--no-demangle} option may be used to turn off demangling. Different
+compilers have different mangling styles.  The optional demangling style
+argument can be used to choose an appropriate demangling style for your
+compiler, in particular Ada symbols generated by GNAT can be demangled using
+@code{--demangle=gnat}.
+@end table
 
-When you use the @code{next} command in a function, the current source
-location will advance to the next statement as usual. A special case
-arises in the case of a @code{return} statement.
+@geindex -e (gprof)
 
-Part of the code for a return statement is the 'epilogue' of the function.
-This is the code that returns to the caller. There is only one copy of
-this epilogue code, and it is typically associated with the last return
-statement in the function if there is more than one return. In some
-implementations, this epilogue is associated with the first statement
-of the function.
 
-The result is that if you use the @code{next} command from a return
-statement that is not the last return statement of the function you
-may see a strange apparent jump to the last return statement or to
-the start of the function. You should simply ignore this odd jump.
-The value returned is always that from the first return statement
-that was stepped through.
+@table @asis
 
-@node Stopping When Ada Exceptions Are Raised,Ada Tasks,Using the next Command in a Function,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution stopping-when-ada-exceptions-are-raised}@anchor{17a}@anchor{gnat_ugn/gnat_and_program_execution id9}@anchor{17b}
-@subsection Stopping When Ada Exceptions Are Raised
-
-
-@geindex Exceptions (in gdb)
-
-You can set catchpoints that stop the program execution when your program
-raises selected exceptions.
+@item @code{-e @emph{function_name}}
 
+The @code{-e @emph{function}} option tells @code{gprof} not to print
+information about the function @code{function_name} (and its
+children...) in the call graph.  The function will still be listed
+as a child of any functions that call it, but its index number will be
+shown as @code{[not printed]}.  More than one @code{-e} option may be
+given; only one @code{function_name} may be indicated with each @code{-e}
+option.
+@end table
 
-@itemize *
+@geindex -E (gprof)
 
-@item 
 
 @table @asis
 
-@item @code{catch exception}
+@item @code{-E @emph{function_name}}
 
-Set a catchpoint that stops execution whenever (any task in the) program
-raises any exception.
+The @code{-E @emph{function}} option works like the @code{-e} option, but
+execution time spent in the function (and children who were not called from
+anywhere else), will not be used to compute the percentages-of-time for
+the call graph.  More than one @code{-E} option may be given; only one
+@code{function_name} may be indicated with each @code{-E`} option.
 @end table
 
-@item 
+@geindex -f (gprof)
+
 
 @table @asis
 
-@item @code{catch exception @emph{name}}
+@item @code{-f @emph{function_name}}
 
-Set a catchpoint that stops execution whenever (any task in the) program
-raises the exception @emph{name}.
+The @code{-f @emph{function}} option causes @code{gprof} to limit the
+call graph to the function @code{function_name} and its children (and
+their children...).  More than one @code{-f} option may be given;
+only one @code{function_name} may be indicated with each @code{-f}
+option.
 @end table
 
-@item 
+@geindex -F (gprof)
+
 
 @table @asis
 
-@item @code{catch exception unhandled}
+@item @code{-F @emph{function_name}}
 
-Set a catchpoint that stops executing whenever (any task in the) program
-raises an exception for which there is no handler.
+The @code{-F @emph{function}} option works like the @code{-f} option, but
+only time spent in the function and its children (and their
+children...) will be used to determine total-time and
+percentages-of-time for the call graph.  More than one @code{-F} option
+may be given; only one @code{function_name} may be indicated with each
+@code{-F} option.  The @code{-F} option overrides the @code{-E} option.
 @end table
 
-@item 
-
-@table @asis
-
-@item @code{info exceptions}, @code{info exceptions @emph{regexp}}
+@node Interpretation of profiling results,,Running gprof,Profiling an Ada Program with gprof
+@anchor{gnat_ugn/gnat_and_program_execution id25}@anchor{179}@anchor{gnat_ugn/gnat_and_program_execution interpretation-of-profiling-results}@anchor{17a}
+@subsubsection Interpretation of profiling results
 
-The @code{info exceptions} command permits the user to examine all defined
-exceptions within Ada programs. With a regular expression, @emph{regexp}, as
-argument, prints out only those exceptions whose name matches @emph{regexp}.
-@end table
-@end itemize
 
-@geindex Tasks (in gdb)
+The results of the profiling analysis are represented by two arrays: the
+'flat profile' and the 'call graph'. Full documentation of those outputs
+can be found in the GNU Profiler User's Guide.
 
-@node Ada Tasks,Debugging Generic Units,Stopping When Ada Exceptions Are Raised,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution ada-tasks}@anchor{17c}@anchor{gnat_ugn/gnat_and_program_execution id10}@anchor{17d}
-@subsection Ada Tasks
+The flat profile shows the time spent in each function of the program, and how
+many time it has been called. This allows you to locate easily the most
+time-consuming functions.
 
+The call graph shows, for each subprogram, the subprograms that call it,
+and the subprograms that it calls. It also provides an estimate of the time
+spent in each of those callers/called subprograms.
 
-@code{GDB} allows the following task-related commands:
+@node Improving Performance,Overflow Check Handling in GNAT,Profiling,GNAT and Program Execution
+@anchor{gnat_ugn/gnat_and_program_execution improving-performance}@anchor{17b}@anchor{gnat_ugn/gnat_and_program_execution id26}@anchor{148}
+@section Improving Performance
 
 
-@itemize *
+@geindex Improving performance
 
-@item 
+This section presents several topics related to program performance.
+It first describes some of the tradeoffs that need to be considered
+and some of the techniques for making your program run faster.
 
-@table @asis
+It then documents the unused subprogram/data elimination feature,
+which can reduce the size of program executables.
 
-@item @code{info tasks}
+@menu
+* Performance Considerations:: 
+* Text_IO Suggestions:: 
+* Reducing Size of Executables with Unused Subprogram/Data Elimination:: 
 
-This command shows a list of current Ada tasks, as in the following example:
+@end menu
 
-@example
-(gdb) info tasks
-  ID       TID P-ID   Thread Pri State                 Name
-   1   8088000   0   807e000  15 Child Activation Wait main_task
-   2   80a4000   1   80ae000  15 Accept/Select Wait    b
-   3   809a800   1   80a4800  15 Child Activation Wait a
-*  4   80ae800   3   80b8000  15 Running               c
-@end example
+@node Performance Considerations,Text_IO Suggestions,,Improving Performance
+@anchor{gnat_ugn/gnat_and_program_execution performance-considerations}@anchor{17c}@anchor{gnat_ugn/gnat_and_program_execution id27}@anchor{17d}
+@subsection Performance Considerations
 
-In this listing, the asterisk before the first task indicates it to be the
-currently running task. The first column lists the task ID that is used
-to refer to tasks in the following commands.
-@end table
-@end itemize
 
-@geindex Breakpoints and tasks
+The GNAT system provides a number of options that allow a trade-off
+between
 
 
 @itemize *
 
 @item 
-@code{break`@w{`}*linespec* `@w{`}task} @emph{taskid}, @code{break} @emph{linespec} @code{task} @emph{taskid} @code{if} ...
-
-@quotation
-
-These commands are like the @code{break ... thread ...}.
-@emph{linespec} specifies source lines.
+performance of the generated code
 
-Use the qualifier @code{task @emph{taskid}} with a breakpoint command
-to specify that you only want @code{GDB} to stop the program when a
-particular Ada task reaches this breakpoint. @emph{taskid} is one of the
-numeric task identifiers assigned by @code{GDB}, shown in the first
-column of the @code{info tasks} display.
+@item 
+speed of compilation
 
-If you do not specify @code{task @emph{taskid}} when you set a
-breakpoint, the breakpoint applies to @emph{all} tasks of your
-program.
+@item 
+minimization of dependences and recompilation
 
-You can use the @code{task} qualifier on conditional breakpoints as
-well; in this case, place @code{task @emph{taskid}} before the
-breakpoint condition (before the @code{if}).
-@end quotation
+@item 
+the degree of run-time checking.
 @end itemize
 
-@geindex Task switching (in gdb)
+The defaults (if no options are selected) aim at improving the speed
+of compilation and minimizing dependences, at the expense of performance
+of the generated code:
 
 
 @itemize *
 
 @item 
-@code{task @emph{taskno}}
+no optimization
 
-@quotation
+@item 
+no inlining of subprogram calls
 
-This command allows switching to the task referred by @emph{taskno}. In
-particular, this allows browsing of the backtrace of the specified
-task. It is advisable to switch back to the original task before
-continuing execution otherwise the scheduling of the program may be
-perturbed.
-@end quotation
+@item 
+all run-time checks enabled except overflow and elaboration checks
 @end itemize
 
-For more detailed information on the tasking support,
-see @cite{Debugging with GDB}.
+These options are suitable for most program development purposes. This
+section describes how you can modify these choices, and also provides
+some guidelines on debugging optimized code.
 
-@geindex Debugging Generic Units
+@menu
+* Controlling Run-Time Checks:: 
+* Use of Restrictions:: 
+* Optimization Levels:: 
+* Debugging Optimized Code:: 
+* Inlining of Subprograms:: 
+* Floating Point Operations:: 
+* Vectorization of loops:: 
+* Other Optimization Switches:: 
+* Optimization and Strict Aliasing:: 
+* Aliased Variables and Optimization:: 
+* Atomic Variables and Optimization:: 
+* Passive Task Optimization:: 
 
-@geindex Generics
+@end menu
 
-@node Debugging Generic Units,Remote Debugging with gdbserver,Ada Tasks,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution debugging-generic-units}@anchor{17e}@anchor{gnat_ugn/gnat_and_program_execution id11}@anchor{17f}
-@subsection Debugging Generic Units
+@node Controlling Run-Time Checks,Use of Restrictions,,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution id28}@anchor{17e}@anchor{gnat_ugn/gnat_and_program_execution controlling-run-time-checks}@anchor{17f}
+@subsubsection Controlling Run-Time Checks
 
 
-GNAT always uses code expansion for generic instantiation. This means that
-each time an instantiation occurs, a complete copy of the original code is
-made, with appropriate substitutions of formals by actuals.
+By default, GNAT generates all run-time checks, except stack overflow
+checks, and checks for access before elaboration on subprogram
+calls. The latter are not required in default mode, because all
+necessary checking is done at compile time.
 
-It is not possible to refer to the original generic entities in
-@code{GDB}, but it is always possible to debug a particular instance of
-a generic, by using the appropriate expanded names. For example, if we have
+@geindex -gnatp (gcc)
 
-@quotation
+@geindex -gnato (gcc)
 
-@example
-procedure g is
+The gnat switch, @code{-gnatp} allows this default to be modified. See
+@ref{ea,,Run-Time Checks}.
 
-   generic package k is
-      procedure kp (v1 : in out integer);
-   end k;
+Our experience is that the default is suitable for most development
+purposes.
 
-   package body k is
-      procedure kp (v1 : in out integer) is
-      begin
-         v1 := v1 + 1;
-      end kp;
-   end k;
+Elaboration checks are off by default, and also not needed by default, since
+GNAT uses a static elaboration analysis approach that avoids the need for
+run-time checking. This manual contains a full chapter discussing the issue
+of elaboration checks, and if the default is not satisfactory for your use,
+you should read this chapter.
 
-   package k1 is new k;
-   package k2 is new k;
+For validity checks, the minimal checks required by the Ada Reference
+Manual (for case statements and assignments to array elements) are on
+by default. These can be suppressed by use of the @code{-gnatVn} switch.
+Note that in Ada 83, there were no validity checks, so if the Ada 83 mode
+is acceptable (or when comparing GNAT performance with an Ada 83 compiler),
+it may be reasonable to routinely use @code{-gnatVn}. Validity checks
+are also suppressed entirely if @code{-gnatp} is used.
 
-   var : integer := 1;
+@geindex Overflow checks
 
-begin
-   k1.kp (var);
-   k2.kp (var);
-   k1.kp (var);
-   k2.kp (var);
-end;
-@end example
-@end quotation
+@geindex Checks
+@geindex overflow
 
-Then to break on a call to procedure kp in the k2 instance, simply
-use the command:
+@geindex Suppress
 
-@quotation
+@geindex Unsuppress
 
-@example
-(gdb) break g.k2.kp
-@end example
-@end quotation
+@geindex pragma Suppress
 
-When the breakpoint occurs, you can step through the code of the
-instance in the normal manner and examine the values of local variables, as for
-other units.
+@geindex pragma Unsuppress
 
-@geindex Remote Debugging with gdbserver
+Note that the setting of the switches controls the default setting of
+the checks. They may be modified using either @code{pragma Suppress} (to
+remove checks) or @code{pragma Unsuppress} (to add back suppressed
+checks) in the program source.
 
-@node Remote Debugging with gdbserver,GNAT Abnormal Termination or Failure to Terminate,Debugging Generic Units,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution remote-debugging-with-gdbserver}@anchor{180}@anchor{gnat_ugn/gnat_and_program_execution id12}@anchor{181}
-@subsection Remote Debugging with gdbserver
+@node Use of Restrictions,Optimization Levels,Controlling Run-Time Checks,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution id29}@anchor{180}@anchor{gnat_ugn/gnat_and_program_execution use-of-restrictions}@anchor{181}
+@subsubsection Use of Restrictions
 
 
-On platforms where gdbserver is supported, it is possible to use this tool
-to debug your application remotely.  This can be useful in situations
-where the program needs to be run on a target host that is different
-from the host used for development, particularly when the target has
-a limited amount of resources (either CPU and/or memory).
-
-To do so, start your program using gdbserver on the target machine.
-gdbserver then automatically suspends the execution of your program
-at its entry point, waiting for a debugger to connect to it.  The
-following commands starts an application and tells gdbserver to
-wait for a connection with the debugger on localhost port 4444.
-
-@quotation
+The use of pragma Restrictions allows you to control which features are
+permitted in your program. Apart from the obvious point that if you avoid
+relatively expensive features like finalization (enforceable by the use
+of pragma Restrictions (No_Finalization), the use of this pragma does not
+affect the generated code in most cases.
 
-@example
-$ gdbserver localhost:4444 program
-Process program created; pid = 5685
-Listening on port 4444
-@end example
-@end quotation
+One notable exception to this rule is that the possibility of task abort
+results in some distributed overhead, particularly if finalization or
+exception handlers are used. The reason is that certain sections of code
+have to be marked as non-abortable.
 
-Once gdbserver has started listening, we can tell the debugger to establish
-a connection with this gdbserver, and then start the same debugging session
-as if the program was being debugged on the same host, directly under
-the control of GDB.
+If you use neither the @code{abort} statement, nor asynchronous transfer
+of control (@code{select ... then abort}), then this distributed overhead
+is removed, which may have a general positive effect in improving
+overall performance.  Especially code involving frequent use of tasking
+constructs and controlled types will show much improved performance.
+The relevant restrictions pragmas are
 
 @quotation
 
 @example
-$ gdb program
-(gdb) target remote targethost:4444
-Remote debugging using targethost:4444
-0x00007f29936d0af0 in ?? () from /lib64/ld-linux-x86-64.so.
-(gdb) b foo.adb:3
-Breakpoint 1 at 0x401f0c: file foo.adb, line 3.
-(gdb) continue
-Continuing.
-
-Breakpoint 1, foo () at foo.adb:4
-4       end foo;
+pragma Restrictions (No_Abort_Statements);
+pragma Restrictions (Max_Asynchronous_Select_Nesting => 0);
 @end example
 @end quotation
 
-It is also possible to use gdbserver to attach to an already running
-program, in which case the execution of that program is simply suspended
-until the connection between the debugger and gdbserver is established.
-
-For more information on how to use gdbserver, see the @emph{Using the gdbserver Program}
-section in @cite{Debugging with GDB}.
-GNAT provides support for gdbserver on x86-linux, x86-windows and x86_64-linux.
+It is recommended that these restriction pragmas be used if possible. Note
+that this also means that you can write code without worrying about the
+possibility of an immediate abort at any point.
 
-@geindex Abnormal Termination or Failure to Terminate
+@node Optimization Levels,Debugging Optimized Code,Use of Restrictions,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution id30}@anchor{182}@anchor{gnat_ugn/gnat_and_program_execution optimization-levels}@anchor{ed}
+@subsubsection Optimization Levels
 
-@node GNAT Abnormal Termination or Failure to Terminate,Naming Conventions for GNAT Source Files,Remote Debugging with gdbserver,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution gnat-abnormal-termination-or-failure-to-terminate}@anchor{182}@anchor{gnat_ugn/gnat_and_program_execution id13}@anchor{183}
-@subsection GNAT Abnormal Termination or Failure to Terminate
 
+@geindex -O (gcc)
 
-When presented with programs that contain serious errors in syntax
-or semantics,
-GNAT may on rare occasions  experience problems in operation, such
-as aborting with a
-segmentation fault or illegal memory access, raising an internal
-exception, terminating abnormally, or failing to terminate at all.
-In such cases, you can activate
-various features of GNAT that can help you pinpoint the construct in your
-program that is the likely source of the problem.
+Without any optimization option,
+the compiler's goal is to reduce the cost of
+compilation and to make debugging produce the expected results.
+Statements are independent: if you stop the program with a breakpoint between
+statements, you can then assign a new value to any variable or change
+the program counter to any other statement in the subprogram and get exactly
+the results you would expect from the source code.
 
-The following strategies are presented in increasing order of
-difficulty, corresponding to your experience in using GNAT and your
-familiarity with compiler internals.
+Turning on optimization makes the compiler attempt to improve the
+performance and/or code size at the expense of compilation time and
+possibly the ability to debug the program.
 
+If you use multiple
+-O options, with or without level numbers,
+the last such option is the one that is effective.
 
-@itemize *
+The default is optimization off. This results in the fastest compile
+times, but GNAT makes absolutely no attempt to optimize, and the
+generated programs are considerably larger and slower than when
+optimization is enabled. You can use the
+@code{-O} switch (the permitted forms are @code{-O0}, @code{-O1}
+@code{-O2}, @code{-O3}, and @code{-Os})
+to @code{gcc} to control the optimization level:
 
-@item 
-Run @code{gcc} with the @code{-gnatf}. This first
-switch causes all errors on a given line to be reported. In its absence,
-only the first error on a line is displayed.
 
-The @code{-gnatdO} switch causes errors to be displayed as soon as they
-are encountered, rather than after compilation is terminated. If GNAT
-terminates prematurely or goes into an infinite loop, the last error
-message displayed may help to pinpoint the culprit.
+@itemize *
 
 @item 
-Run @code{gcc} with the @code{-v} (verbose) switch. In this
-mode, @code{gcc} produces ongoing information about the progress of the
-compilation and provides the name of each procedure as code is
-generated. This switch allows you to find which Ada procedure was being
-compiled when it encountered a code generation problem.
-@end itemize
 
-@geindex -gnatdc switch
+@table @asis
 
+@item @code{-O0}
 
-@itemize *
+No optimization (the default);
+generates unoptimized code but has
+the fastest compilation time.
 
-@item 
-Run @code{gcc} with the @code{-gnatdc} switch. This is a GNAT specific
-switch that does for the front-end what @code{-v} does
-for the back end. The system prints the name of each unit,
-either a compilation unit or nested unit, as it is being analyzed.
+Note that many other compilers do substantial optimization even
+if 'no optimization' is specified. With gcc, it is very unusual
+to use @code{-O0} for production if execution time is of any concern,
+since @code{-O0} means (almost) no optimization. This difference
+between gcc and other compilers should be kept in mind when
+doing performance comparisons.
+@end table
 
 @item 
-Finally, you can start
-@code{gdb} directly on the @code{gnat1} executable. @code{gnat1} is the
-front-end of GNAT, and can be run independently (normally it is just
-called from @code{gcc}). You can use @code{gdb} on @code{gnat1} as you
-would on a C program (but @ref{16e,,The GNAT Debugger GDB} for caveats). The
-@code{where} command is the first line of attack; the variable
-@code{lineno} (seen by @code{print lineno}), used by the second phase of
-@code{gnat1} and by the @code{gcc} backend, indicates the source line at
-which the execution stopped, and @code{input_file name} indicates the name of
-the source file.
-@end itemize
-
-@node Naming Conventions for GNAT Source Files,Getting Internal Debugging Information,GNAT Abnormal Termination or Failure to Terminate,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution naming-conventions-for-gnat-source-files}@anchor{184}@anchor{gnat_ugn/gnat_and_program_execution id14}@anchor{185}
-@subsection Naming Conventions for GNAT Source Files
-
 
-In order to examine the workings of the GNAT system, the following
-brief description of its organization may be helpful:
+@table @asis
 
+@item @code{-O1}
 
-@itemize *
+Moderate optimization;
+optimizes reasonably well but does not
+degrade compilation time significantly.
+@end table
 
 @item 
-Files with prefix @code{sc} contain the lexical scanner.
 
-@item 
-All files prefixed with @code{par} are components of the parser. The
-numbers correspond to chapters of the Ada Reference Manual. For example,
-parsing of select statements can be found in @code{par-ch9.adb}.
+@table @asis
 
-@item 
-All files prefixed with @code{sem} perform semantic analysis. The
-numbers correspond to chapters of the Ada standard. For example, all
-issues involving context clauses can be found in @code{sem_ch10.adb}. In
-addition, some features of the language require sufficient special processing
-to justify their own semantic files: sem_aggr for aggregates, sem_disp for
-dynamic dispatching, etc.
+@item @code{-O2}
 
-@item 
-All files prefixed with @code{exp} perform normalization and
-expansion of the intermediate representation (abstract syntax tree, or AST).
-these files use the same numbering scheme as the parser and semantics files.
-For example, the construction of record initialization procedures is done in
-@code{exp_ch3.adb}.
+Full optimization;
+generates highly optimized code and has
+the slowest compilation time.
+@end table
 
 @item 
-The files prefixed with @code{bind} implement the binder, which
-verifies the consistency of the compilation, determines an order of
-elaboration, and generates the bind file.
 
-@item 
-The files @code{atree.ads} and @code{atree.adb} detail the low-level
-data structures used by the front-end.
+@table @asis
 
-@item 
-The files @code{sinfo.ads} and @code{sinfo.adb} detail the structure of
-the abstract syntax tree as produced by the parser.
+@item @code{-O3}
 
-@item 
-The files @code{einfo.ads} and @code{einfo.adb} detail the attributes of
-all entities, computed during semantic analysis.
+Full optimization as in @code{-O2};
+also uses more aggressive automatic inlining of subprograms within a unit
+(@ref{100,,Inlining of Subprograms}) and attempts to vectorize loops.
+@end table
 
 @item 
-Library management issues are dealt with in files with prefix
-@code{lib}.
 
-@geindex Annex A (in Ada Reference Manual)
+@table @asis
 
-@item 
-Ada files with the prefix @code{a-} are children of @code{Ada}, as
-defined in Annex A.
+@item @code{-Os}
 
-@geindex Annex B (in Ada reference Manual)
+Optimize space usage (code and data) of resulting program.
+@end table
+@end itemize
 
-@item 
-Files with prefix @code{i-} are children of @code{Interfaces}, as
-defined in Annex B.
+Higher optimization levels perform more global transformations on the
+program and apply more expensive analysis algorithms in order to generate
+faster and more compact code. The price in compilation time, and the
+resulting improvement in execution time,
+both depend on the particular application and the hardware environment.
+You should experiment to find the best level for your application.
 
-@geindex System (package in Ada Reference Manual)
+Since the precise set of optimizations done at each level will vary from
+release to release (and sometime from target to target), it is best to think
+of the optimization settings in general terms.
+See the @emph{Options That Control Optimization} section in
+@cite{Using the GNU Compiler Collection (GCC)}
+for details about
+the @code{-O} settings and a number of @code{-f} options that
+individually enable or disable specific optimizations.
 
-@item 
-Files with prefix @code{s-} are children of @code{System}. This includes
-both language-defined children and GNAT run-time routines.
+Unlike some other compilation systems, @code{gcc} has
+been tested extensively at all optimization levels. There are some bugs
+which appear only with optimization turned on, but there have also been
+bugs which show up only in @emph{unoptimized} code. Selecting a lower
+level of optimization does not improve the reliability of the code
+generator, which in practice is highly reliable at all optimization
+levels.
 
-@geindex GNAT (package)
+Note regarding the use of @code{-O3}: The use of this optimization level
+ought not to be automatically preferred over that of level @code{-O2},
+since it often results in larger executables which may run more slowly.
+See further discussion of this point in @ref{100,,Inlining of Subprograms}.
 
-@item 
-Files with prefix @code{g-} are children of @code{GNAT}. These are useful
-general-purpose packages, fully documented in their specs. All
-the other @code{.c} files are modifications of common @code{gcc} files.
-@end itemize
+@node Debugging Optimized Code,Inlining of Subprograms,Optimization Levels,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution debugging-optimized-code}@anchor{183}@anchor{gnat_ugn/gnat_and_program_execution id31}@anchor{184}
+@subsubsection Debugging Optimized Code
 
-@node Getting Internal Debugging Information,Stack Traceback,Naming Conventions for GNAT Source Files,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution id15}@anchor{186}@anchor{gnat_ugn/gnat_and_program_execution getting-internal-debugging-information}@anchor{187}
-@subsection Getting Internal Debugging Information
 
+@geindex Debugging optimized code
 
-Most compilers have internal debugging switches and modes. GNAT
-does also, except GNAT internal debugging switches and modes are not
-secret. A summary and full description of all the compiler and binder
-debug flags are in the file @code{debug.adb}. You must obtain the
-sources of the compiler to see the full detailed effects of these flags.
+@geindex Optimization and debugging
 
-The switches that print the source of the program (reconstructed from
-the internal tree) are of general interest for user programs, as are the
-options to print
-the full internal tree, and the entity table (the symbol table
-information). The reconstructed source provides a readable version of the
-program after the front-end has completed analysis and  expansion,
-and is useful when studying the performance of specific constructs.
-For example, constraint checks are indicated, complex aggregates
-are replaced with loops and assignments, and tasking primitives
-are replaced with run-time calls.
-
-@geindex traceback
-
-@geindex stack traceback
-
-@geindex stack unwinding
+Although it is possible to do a reasonable amount of debugging at
+nonzero optimization levels,
+the higher the level the more likely that
+source-level constructs will have been eliminated by optimization.
+For example, if a loop is strength-reduced, the loop
+control variable may be completely eliminated and thus cannot be
+displayed in the debugger.
+This can only happen at @code{-O2} or @code{-O3}.
+Explicit temporary variables that you code might be eliminated at
+level @code{-O1} or higher.
 
-@node Stack Traceback,Pretty-Printers for the GNAT runtime,Getting Internal Debugging Information,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution stack-traceback}@anchor{188}@anchor{gnat_ugn/gnat_and_program_execution id16}@anchor{189}
-@subsection Stack Traceback
+@geindex -g (gcc)
 
+The use of the @code{-g} switch,
+which is needed for source-level debugging,
+affects the size of the program executable on disk,
+and indeed the debugging information can be quite large.
+However, it has no effect on the generated code (and thus does not
+degrade performance)
 
-Traceback is a mechanism to display the sequence of subprogram calls that
-leads to a specified execution point in a program. Often (but not always)
-the execution point is an instruction at which an exception has been raised.
-This mechanism is also known as @emph{stack unwinding} because it obtains
-its information by scanning the run-time stack and recovering the activation
-records of all active subprograms. Stack unwinding is one of the most
-important tools for program debugging.
+Since the compiler generates debugging tables for a compilation unit before
+it performs optimizations, the optimizing transformations may invalidate some
+of the debugging data.  You therefore need to anticipate certain
+anomalous situations that may arise while debugging optimized code.
+These are the most common cases:
 
-The first entry stored in traceback corresponds to the deepest calling level,
-that is to say the subprogram currently executing the instruction
-from which we want to obtain the traceback.
 
-Note that there is no runtime performance penalty when stack traceback
-is enabled, and no exception is raised during program execution.
+@itemize *
 
-@geindex traceback
-@geindex non-symbolic
+@item 
+@emph{The 'hopping Program Counter':}  Repeated @code{step} or @code{next}
+commands show
+the PC bouncing back and forth in the code.  This may result from any of
+the following optimizations:
 
-@menu
-* Non-Symbolic Traceback:: 
-* Symbolic Traceback:: 
 
-@end menu
+@itemize -
 
-@node Non-Symbolic Traceback,Symbolic Traceback,,Stack Traceback
-@anchor{gnat_ugn/gnat_and_program_execution non-symbolic-traceback}@anchor{18a}@anchor{gnat_ugn/gnat_and_program_execution id17}@anchor{18b}
-@subsubsection Non-Symbolic Traceback
+@item 
+@emph{Common subexpression elimination:} using a single instance of code for a
+quantity that the source computes several times.  As a result you
+may not be able to stop on what looks like a statement.
 
+@item 
+@emph{Invariant code motion:} moving an expression that does not change within a
+loop, to the beginning of the loop.
 
-Note: this feature is not supported on all platforms. See
-@code{GNAT.Traceback} spec in @code{g-traceb.ads}
-for a complete list of supported platforms.
+@item 
+@emph{Instruction scheduling:} moving instructions so as to
+overlap loads and stores (typically) with other code, or in
+general to move computations of values closer to their uses. Often
+this causes you to pass an assignment statement without the assignment
+happening and then later bounce back to the statement when the
+value is actually needed.  Placing a breakpoint on a line of code
+and then stepping over it may, therefore, not always cause all the
+expected side-effects.
+@end itemize
 
-@subsubheading Tracebacks From an Unhandled Exception
+@item 
+@emph{The 'big leap':} More commonly known as @emph{cross-jumping}, in which
+two identical pieces of code are merged and the program counter suddenly
+jumps to a statement that is not supposed to be executed, simply because
+it (and the code following) translates to the same thing as the code
+that @emph{was} supposed to be executed.  This effect is typically seen in
+sequences that end in a jump, such as a @code{goto}, a @code{return}, or
+a @code{break} in a C @code{switch} statement.
 
+@item 
+@emph{The 'roving variable':} The symptom is an unexpected value in a variable.
+There are various reasons for this effect:
 
-A runtime non-symbolic traceback is a list of addresses of call instructions.
-To enable this feature you must use the @code{-E}
-@code{gnatbind} option. With this option a stack traceback is stored as part
-of exception information. You can retrieve this information using the
-@code{addr2line} tool.
 
-Here is a simple example:
+@itemize -
 
-@quotation
+@item 
+In a subprogram prologue, a parameter may not yet have been moved to its
+'home'.
 
-@example
-procedure STB is
+@item 
+A variable may be dead, and its register re-used.  This is
+probably the most common cause.
 
-   procedure P1 is
-   begin
-      raise Constraint_Error;
-   end P1;
+@item 
+As mentioned above, the assignment of a value to a variable may
+have been moved.
 
-   procedure P2 is
-   begin
-      P1;
-   end P2;
+@item 
+A variable may be eliminated entirely by value propagation or
+other means.  In this case, GCC may incorrectly generate debugging
+information for the variable
+@end itemize
 
-begin
-   P2;
-end STB;
-@end example
+In general, when an unexpected value appears for a local variable or parameter
+you should first ascertain if that value was actually computed by
+your program, as opposed to being incorrectly reported by the debugger.
+Record fields or
+array elements in an object designated by an access value
+are generally less of a problem, once you have ascertained that the access
+value is sensible.
+Typically, this means checking variables in the preceding code and in the
+calling subprogram to verify that the value observed is explainable from other
+values (one must apply the procedure recursively to those
+other values); or re-running the code and stopping a little earlier
+(perhaps before the call) and stepping to better see how the variable obtained
+the value in question; or continuing to step @emph{from} the point of the
+strange value to see if code motion had simply moved the variable's
+assignments later.
+@end itemize
 
-@example
-$ gnatmake stb -bargs -E
-$ stb
+In light of such anomalies, a recommended technique is to use @code{-O0}
+early in the software development cycle, when extensive debugging capabilities
+are most needed, and then move to @code{-O1} and later @code{-O2} as
+the debugger becomes less critical.
+Whether to use the @code{-g} switch in the release version is
+a release management issue.
+Note that if you use @code{-g} you can then use the @code{strip} program
+on the resulting executable,
+which removes both debugging information and global symbols.
 
-Execution terminated by unhandled exception
-Exception name: CONSTRAINT_ERROR
-Message: stb.adb:5
-Call stack traceback locations:
-0x401373 0x40138b 0x40139c 0x401335 0x4011c4 0x4011f1 0x77e892a4
-@end example
-@end quotation
+@node Inlining of Subprograms,Floating Point Operations,Debugging Optimized Code,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution id32}@anchor{185}@anchor{gnat_ugn/gnat_and_program_execution inlining-of-subprograms}@anchor{100}
+@subsubsection Inlining of Subprograms
 
-As we see the traceback lists a sequence of addresses for the unhandled
-exception @code{CONSTRAINT_ERROR} raised in procedure P1. It is easy to
-guess that this exception come from procedure P1. To translate these
-addresses into the source lines where the calls appear, the
-@code{addr2line} tool, described below, is invaluable. The use of this tool
-requires the program to be compiled with debug information.
 
-@quotation
+A call to a subprogram in the current unit is inlined if all the
+following conditions are met:
 
-@example
-$ gnatmake -g stb -bargs -E
-$ stb
 
-Execution terminated by unhandled exception
-Exception name: CONSTRAINT_ERROR
-Message: stb.adb:5
-Call stack traceback locations:
-0x401373 0x40138b 0x40139c 0x401335 0x4011c4 0x4011f1 0x77e892a4
+@itemize *
 
-$ addr2line --exe=stb 0x401373 0x40138b 0x40139c 0x401335 0x4011c4
-   0x4011f1 0x77e892a4
+@item 
+The optimization level is at least @code{-O1}.
 
-00401373 at d:/stb/stb.adb:5
-0040138B at d:/stb/stb.adb:10
-0040139C at d:/stb/stb.adb:14
-00401335 at d:/stb/b~stb.adb:104
-004011C4 at /build/.../crt1.c:200
-004011F1 at /build/.../crt1.c:222
-77E892A4 in ?? at ??:0
-@end example
-@end quotation
+@item 
+The called subprogram is suitable for inlining: It must be small enough
+and not contain something that @code{gcc} cannot support in inlined
+subprograms.
 
-The @code{addr2line} tool has several other useful options:
+@geindex pragma Inline
 
-@quotation
+@geindex Inline
 
+@item 
+Any one of the following applies: @code{pragma Inline} is applied to the
+subprogram; the subprogram is local to the unit and called once from
+within it; the subprogram is small and optimization level @code{-O2} is
+specified; optimization level @code{-O3} is specified.
+@end itemize
 
-@multitable {xxxxxxxxxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx} 
-@item
+Calls to subprograms in @emph{with}ed units are normally not inlined.
+To achieve actual inlining (that is, replacement of the call by the code
+in the body of the subprogram), the following conditions must all be true:
 
-@code{--functions}
 
-@tab
+@itemize *
 
-to get the function name corresponding to any location
+@item 
+The optimization level is at least @code{-O1}.
 
-@item
+@item 
+The called subprogram is suitable for inlining: It must be small enough
+and not contain something that @code{gcc} cannot support in inlined
+subprograms.
 
-@code{--demangle=gnat}
+@item 
+There is a @code{pragma Inline} for the subprogram.
 
-@tab
+@item 
+The @code{-gnatn} switch is used on the command line.
+@end itemize
 
-to use the gnat decoding mode for the function names.
-Note that for binutils version 2.9.x the option is
-simply @code{--demangle}.
+Even if all these conditions are met, it may not be possible for
+the compiler to inline the call, due to the length of the body,
+or features in the body that make it impossible for the compiler
+to do the inlining.
 
-@end multitable
+Note that specifying the @code{-gnatn} switch causes additional
+compilation dependencies. Consider the following:
 
+@quotation
 
 @example
-$ addr2line --exe=stb --functions --demangle=gnat 0x401373 0x40138b
-   0x40139c 0x401335 0x4011c4 0x4011f1
-
-00401373 in stb.p1 at d:/stb/stb.adb:5
-0040138B in stb.p2 at d:/stb/stb.adb:10
-0040139C in stb at d:/stb/stb.adb:14
-00401335 in main at d:/stb/b~stb.adb:104
-004011C4 in <__mingw_CRTStartup> at /build/.../crt1.c:200
-004011F1 in <mainCRTStartup> at /build/.../crt1.c:222
+package R is
+   procedure Q;
+   pragma Inline (Q);
+end R;
+package body R is
+   ...
+end R;
+
+with R;
+procedure Main is
+begin
+   ...
+   R.Q;
+end Main;
 @end example
 @end quotation
 
-From this traceback we can see that the exception was raised in
-@code{stb.adb} at line 5, which was reached from a procedure call in
-@code{stb.adb} at line 10, and so on. The @code{b~std.adb} is the binder file,
-which contains the call to the main program.
-@ref{11c,,Running gnatbind}. The remaining entries are assorted runtime routines,
-and the output will vary from platform to platform.
+With the default behavior (no @code{-gnatn} switch specified), the
+compilation of the @code{Main} procedure depends only on its own source,
+@code{main.adb}, and the spec of the package in file @code{r.ads}. This
+means that editing the body of @code{R} does not require recompiling
+@code{Main}.
 
-It is also possible to use @code{GDB} with these traceback addresses to debug
-the program. For example, we can break at a given code location, as reported
-in the stack traceback:
+On the other hand, the call @code{R.Q} is not inlined under these
+circumstances. If the @code{-gnatn} switch is present when @code{Main}
+is compiled, the call will be inlined if the body of @code{Q} is small
+enough, but now @code{Main} depends on the body of @code{R} in
+@code{r.adb} as well as on the spec. This means that if this body is edited,
+the main program must be recompiled. Note that this extra dependency
+occurs whether or not the call is in fact inlined by @code{gcc}.
 
-@quotation
+The use of front end inlining with @code{-gnatN} generates similar
+additional dependencies.
 
-@example
-$ gdb -nw stb
-@end example
-@end quotation
+@geindex -fno-inline (gcc)
 
-Furthermore, this feature is not implemented inside Windows DLL. Only
-the non-symbolic traceback is reported in this case.
+Note: The @code{-fno-inline} switch overrides all other conditions and ensures that
+no inlining occurs, unless requested with pragma Inline_Always for @code{gcc}
+back-ends. The extra dependences resulting from @code{-gnatn} will still be active,
+even if this switch is used to suppress the resulting inlining actions.
 
-@quotation
+@geindex -fno-inline-functions (gcc)
 
-@example
-(gdb) break *0x401373
-Breakpoint 1 at 0x401373: file stb.adb, line 5.
-@end example
-@end quotation
+Note: The @code{-fno-inline-functions} switch can be used to prevent
+automatic inlining of subprograms if @code{-O3} is used.
 
-It is important to note that the stack traceback addresses
-do not change when debug information is included. This is particularly useful
-because it makes it possible to release software without debug information (to
-minimize object size), get a field report that includes a stack traceback
-whenever an internal bug occurs, and then be able to retrieve the sequence
-of calls with the same program compiled with debug information.
+@geindex -fno-inline-small-functions (gcc)
 
-@subsubheading Tracebacks From Exception Occurrences
+Note: The @code{-fno-inline-small-functions} switch can be used to prevent
+automatic inlining of small subprograms if @code{-O2} is used.
 
+@geindex -fno-inline-functions-called-once (gcc)
 
-Non-symbolic tracebacks are obtained by using the @code{-E} binder argument.
-The stack traceback is attached to the exception information string, and can
-be retrieved in an exception handler within the Ada program, by means of the
-Ada facilities defined in @code{Ada.Exceptions}. Here is a simple example:
+Note: The @code{-fno-inline-functions-called-once} switch
+can be used to prevent inlining of subprograms local to the unit
+and called once from within it if @code{-O1} is used.
+
+Note regarding the use of @code{-O3}: @code{-gnatn} is made up of two
+sub-switches @code{-gnatn1} and @code{-gnatn2} that can be directly
+specified in lieu of it, @code{-gnatn} being translated into one of them
+based on the optimization level. With @code{-O2} or below, @code{-gnatn}
+is equivalent to @code{-gnatn1} which activates pragma @code{Inline} with
+moderate inlining across modules. With @code{-O3}, @code{-gnatn} is
+equivalent to @code{-gnatn2} which activates pragma @code{Inline} with
+full inlining across modules. If you have used pragma @code{Inline} in
+appropriate cases, then it is usually much better to use @code{-O2}
+and @code{-gnatn} and avoid the use of @code{-O3} which has the additional
+effect of inlining subprograms you did not think should be inlined. We have
+found that the use of @code{-O3} may slow down the compilation and increase
+the code size by performing excessive inlining, leading to increased
+instruction cache pressure from the increased code size and thus minor
+performance improvements. So the bottom line here is that you should not
+automatically assume that @code{-O3} is better than @code{-O2}, and
+indeed you should use @code{-O3} only if tests show that it actually
+improves performance for your program.
+
+@node Floating Point Operations,Vectorization of loops,Inlining of Subprograms,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution floating-point-operations}@anchor{186}@anchor{gnat_ugn/gnat_and_program_execution id33}@anchor{187}
+@subsubsection Floating Point Operations
+
+
+@geindex Floating-Point Operations
+
+On almost all targets, GNAT maps Float and Long_Float to the 32-bit and
+64-bit standard IEEE floating-point representations, and operations will
+use standard IEEE arithmetic as provided by the processor. On most, but
+not all, architectures, the attribute Machine_Overflows is False for these
+types, meaning that the semantics of overflow is implementation-defined.
+In the case of GNAT, these semantics correspond to the normal IEEE
+treatment of infinities and NaN (not a number) values. For example,
+1.0 / 0.0 yields plus infinitiy and 0.0 / 0.0 yields a NaN. By
+avoiding explicit overflow checks, the performance is greatly improved
+on many targets. However, if required, floating-point overflow can be
+enabled by the use of the pragma Check_Float_Overflow.
+
+Another consideration that applies specifically to x86 32-bit
+architectures is which form of floating-point arithmetic is used.
+By default the operations use the old style x86 floating-point,
+which implements an 80-bit extended precision form (on these
+architectures the type Long_Long_Float corresponds to that form).
+In addition, generation of efficient code in this mode means that
+the extended precision form will be used for intermediate results.
+This may be helpful in improving the final precision of a complex
+expression. However it means that the results obtained on the x86
+will be different from those on other architectures, and for some
+algorithms, the extra intermediate precision can be detrimental.
+
+In addition to this old-style floating-point, all modern x86 chips
+implement an alternative floating-point operation model referred
+to as SSE2. In this model there is no extended form, and furthermore
+execution performance is significantly enhanced. To force GNAT to use
+this more modern form, use both of the switches:
 
 @quotation
 
-@example
-with Ada.Text_IO;
-with Ada.Exceptions;
+-msse2 -mfpmath=sse
+@end quotation
 
-procedure STB is
+A unit compiled with these switches will automatically use the more
+efficient SSE2 instruction set for Float and Long_Float operations.
+Note that the ABI has the same form for both floating-point models,
+so it is permissible to mix units compiled with and without these
+switches.
 
-   use Ada;
-   use Ada.Exceptions;
+@node Vectorization of loops,Other Optimization Switches,Floating Point Operations,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution id34}@anchor{188}@anchor{gnat_ugn/gnat_and_program_execution vectorization-of-loops}@anchor{189}
+@subsubsection Vectorization of loops
 
-   procedure P1 is
-      K : Positive := 1;
-   begin
-      K := K - 1;
-   exception
-      when E : others =>
-         Text_IO.Put_Line (Exception_Information (E));
-   end P1;
 
-   procedure P2 is
-   begin
-      P1;
-   end P2;
+@geindex Optimization Switches
+
+You can take advantage of the auto-vectorizer present in the @code{gcc}
+back end to vectorize loops with GNAT.  The corresponding command line switch
+is @code{-ftree-vectorize} but, as it is enabled by default at @code{-O3}
+and other aggressive optimizations helpful for vectorization also are enabled
+by default at this level, using @code{-O3} directly is recommended.
+
+You also need to make sure that the target architecture features a supported
+SIMD instruction set.  For example, for the x86 architecture, you should at
+least specify @code{-msse2} to get significant vectorization (but you don't
+need to specify it for x86-64 as it is part of the base 64-bit architecture).
+Similarly, for the PowerPC architecture, you should specify @code{-maltivec}.
+
+The preferred loop form for vectorization is the @code{for} iteration scheme.
+Loops with a @code{while} iteration scheme can also be vectorized if they are
+very simple, but the vectorizer will quickly give up otherwise.  With either
+iteration scheme, the flow of control must be straight, in particular no
+@code{exit} statement may appear in the loop body.  The loop may however
+contain a single nested loop, if it can be vectorized when considered alone:
+
+@quotation
+
+@example
+A : array (1..4, 1..4) of Long_Float;
+S : array (1..4) of Long_Float;
 
+procedure Sum is
 begin
-   P2;
-end STB;
+   for I in A'Range(1) loop
+      for J in A'Range(2) loop
+         S (I) := S (I) + A (I, J);
+      end loop;
+   end loop;
+end Sum;
 @end example
 @end quotation
 
-This program will output:
+The vectorizable operations depend on the targeted SIMD instruction set, but
+the adding and some of the multiplying operators are generally supported, as
+well as the logical operators for modular types. Note that compiling
+with @code{-gnatp} might well reveal cases where some checks do thwart
+vectorization.
+
+Type conversions may also prevent vectorization if they involve semantics that
+are not directly supported by the code generator or the SIMD instruction set.
+A typical example is direct conversion from floating-point to integer types.
+The solution in this case is to use the following idiom:
 
 @quotation
 
 @example
-$ stb
-
-Exception name: CONSTRAINT_ERROR
-Message: stb.adb:12
-Call stack traceback locations:
-0x4015e4 0x401633 0x401644 0x401461 0x4011c4 0x4011f1 0x77e892a4
+Integer (S'Truncation (F))
 @end example
 @end quotation
 
-@subsubheading Tracebacks From Anywhere in a Program
+if @code{S} is the subtype of floating-point object @code{F}.
 
+In most cases, the vectorizable loops are loops that iterate over arrays.
+All kinds of array types are supported, i.e. constrained array types with
+static bounds:
 
-It is also possible to retrieve a stack traceback from anywhere in a
-program. For this you need to
-use the @code{GNAT.Traceback} API. This package includes a procedure called
-@code{Call_Chain} that computes a complete stack traceback, as well as useful
-display procedures described below. It is not necessary to use the
-@code{-E} @code{gnatbind} option in this case, because the stack traceback mechanism
-is invoked explicitly.
+@quotation
 
-In the following example we compute a traceback at a specific location in
-the program, and we display it using @code{GNAT.Debug_Utilities.Image} to
-convert addresses to strings:
+@example
+type Array_Type is array (1 .. 4) of Long_Float;
+@end example
+@end quotation
+
+constrained array types with dynamic bounds:
 
 @quotation
 
 @example
-with Ada.Text_IO;
-with GNAT.Traceback;
-with GNAT.Debug_Utilities;
+type Array_Type is array (1 .. Q.N) of Long_Float;
 
-procedure STB is
+type Array_Type is array (Q.K .. 4) of Long_Float;
 
-   use Ada;
-   use GNAT;
-   use GNAT.Traceback;
+type Array_Type is array (Q.K .. Q.N) of Long_Float;
+@end example
+@end quotation
 
-   procedure P1 is
-      TB  : Tracebacks_Array (1 .. 10);
-      --  We are asking for a maximum of 10 stack frames.
-      Len : Natural;
-      --  Len will receive the actual number of stack frames returned.
-   begin
-      Call_Chain (TB, Len);
+or unconstrained array types:
 
-      Text_IO.Put ("In STB.P1 : ");
-
-      for K in 1 .. Len loop
-         Text_IO.Put (Debug_Utilities.Image (TB (K)));
-         Text_IO.Put (' ');
-      end loop;
-
-      Text_IO.New_Line;
-   end P1;
-
-   procedure P2 is
-   begin
-      P1;
-   end P2;
-
-begin
-   P2;
-end STB;
-@end example
+@quotation
 
 @example
-$ gnatmake -g stb
-$ stb
-
-In STB.P1 : 16#0040_F1E4# 16#0040_14F2# 16#0040_170B# 16#0040_171C#
-16#0040_1461# 16#0040_11C4# 16#0040_11F1# 16#77E8_92A4#
+type Array_Type is array (Positive range <>) of Long_Float;
 @end example
 @end quotation
 
-You can then get further information by invoking the @code{addr2line}
-tool as described earlier (note that the hexadecimal addresses
-need to be specified in C format, with a leading '0x').
-
-@geindex traceback
-@geindex symbolic
-
-@node Symbolic Traceback,,Non-Symbolic Traceback,Stack Traceback
-@anchor{gnat_ugn/gnat_and_program_execution id18}@anchor{18c}@anchor{gnat_ugn/gnat_and_program_execution symbolic-traceback}@anchor{18d}
-@subsubsection Symbolic Traceback
-
-
-A symbolic traceback is a stack traceback in which procedure names are
-associated with each code location.
-
-Note that this feature is not supported on all platforms. See
-@code{GNAT.Traceback.Symbolic} spec in @code{g-trasym.ads} for a complete
-list of currently supported platforms.
-
-Note that the symbolic traceback requires that the program be compiled
-with debug information. If it is not compiled with debug information
-only the non-symbolic information will be valid.
-
-@subsubheading Tracebacks From Exception Occurrences
-
+The quality of the generated code decreases when the dynamic aspect of the
+array type increases, the worst code being generated for unconstrained array
+types.  This is so because, the less information the compiler has about the
+bounds of the array, the more fallback code it needs to generate in order to
+fix things up at run time.
 
-Here is an example:
+It is possible to specify that a given loop should be subject to vectorization
+preferably to other optimizations by means of pragma @code{Loop_Optimize}:
 
 @quotation
 
 @example
-with Ada.Text_IO;
-with GNAT.Traceback.Symbolic;
-
-procedure STB is
-
-   procedure P1 is
-   begin
-      raise Constraint_Error;
-   end P1;
+pragma Loop_Optimize (Vector);
+@end example
+@end quotation
 
-   procedure P2 is
-   begin
-      P1;
-   end P2;
+placed immediately within the loop will convey the appropriate hint to the
+compiler for this loop.
 
-   procedure P3 is
-   begin
-      P2;
-   end P3;
+It is also possible to help the compiler generate better vectorized code
+for a given loop by asserting that there are no loop-carried dependencies
+in the loop.  Consider for example the procedure:
 
-begin
-   P3;
-exception
-   when E : others =>
-      Ada.Text_IO.Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (E));
-end STB;
-@end example
+@quotation
 
 @example
-$ gnatmake -g .\stb -bargs -E
-$ stb
+type Arr is array (1 .. 4) of Long_Float;
 
-0040149F in stb.p1 at stb.adb:8
-004014B7 in stb.p2 at stb.adb:13
-004014CF in stb.p3 at stb.adb:18
-004015DD in ada.stb at stb.adb:22
-00401461 in main at b~stb.adb:168
-004011C4 in __mingw_CRTStartup at crt1.c:200
-004011F1 in mainCRTStartup at crt1.c:222
-77E892A4 in ?? at ??:0
+procedure Add (X, Y : not null access Arr; R : not null access Arr) is
+begin
+  for I in Arr'Range loop
+    R(I) := X(I) + Y(I);
+  end loop;
+end;
 @end example
 @end quotation
 
-In the above example the @code{.\} syntax in the @code{gnatmake} command
-is currently required by @code{addr2line} for files that are in
-the current working directory.
-Moreover, the exact sequence of linker options may vary from platform
-to platform.
-The above @code{-largs} section is for Windows platforms. By contrast,
-under Unix there is no need for the @code{-largs} section.
-Differences across platforms are due to details of linker implementation.
-
-@subsubheading Tracebacks From Anywhere in a Program
-
-
-It is possible to get a symbolic stack traceback
-from anywhere in a program, just as for non-symbolic tracebacks.
-The first step is to obtain a non-symbolic
-traceback, and then call @code{Symbolic_Traceback} to compute the symbolic
-information. Here is an example:
+By default, the compiler cannot unconditionally vectorize the loop because
+assigning to a component of the array designated by R in one iteration could
+change the value read from the components of the array designated by X or Y
+in a later iteration.  As a result, the compiler will generate two versions
+of the loop in the object code, one vectorized and the other not vectorized,
+as well as a test to select the appropriate version at run time.  This can
+be overcome by another hint:
 
 @quotation
 
 @example
-with Ada.Text_IO;
-with GNAT.Traceback;
-with GNAT.Traceback.Symbolic;
-
-procedure STB is
+pragma Loop_Optimize (Ivdep);
+@end example
+@end quotation
 
-   use Ada;
-   use GNAT.Traceback;
-   use GNAT.Traceback.Symbolic;
+placed immediately within the loop will tell the compiler that it can safely
+omit the non-vectorized version of the loop as well as the run-time test.
 
-   procedure P1 is
-      TB  : Tracebacks_Array (1 .. 10);
-      --  We are asking for a maximum of 10 stack frames.
-      Len : Natural;
-      --  Len will receive the actual number of stack frames returned.
-   begin
-      Call_Chain (TB, Len);
-      Text_IO.Put_Line (Symbolic_Traceback (TB (1 .. Len)));
-   end P1;
+@node Other Optimization Switches,Optimization and Strict Aliasing,Vectorization of loops,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution other-optimization-switches}@anchor{18a}@anchor{gnat_ugn/gnat_and_program_execution id35}@anchor{18b}
+@subsubsection Other Optimization Switches
 
-   procedure P2 is
-   begin
-      P1;
-   end P2;
 
-begin
-   P2;
-end STB;
-@end example
-@end quotation
+@geindex Optimization Switches
 
-@subsubheading Automatic Symbolic Tracebacks
+Since GNAT uses the @code{gcc} back end, all the specialized
+@code{gcc} optimization switches are potentially usable. These switches
+have not been extensively tested with GNAT but can generally be expected
+to work. Examples of switches in this category are @code{-funroll-loops}
+and the various target-specific @code{-m} options (in particular, it has
+been observed that @code{-march=xxx} can significantly improve performance
+on appropriate machines). For full details of these switches, see
+the @emph{Submodel Options} section in the @emph{Hardware Models and Configurations}
+chapter of @cite{Using the GNU Compiler Collection (GCC)}.
 
+@node Optimization and Strict Aliasing,Aliased Variables and Optimization,Other Optimization Switches,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution optimization-and-strict-aliasing}@anchor{e4}@anchor{gnat_ugn/gnat_and_program_execution id36}@anchor{18c}
+@subsubsection Optimization and Strict Aliasing
 
-Symbolic tracebacks may also be enabled by using the -Es switch to gnatbind (as
-in @code{gprbuild -g ... -bargs -Es}).
-This will cause the Exception_Information to contain a symbolic traceback,
-which will also be printed if an unhandled exception terminates the
-program.
 
-@node Pretty-Printers for the GNAT runtime,,Stack Traceback,Running and Debugging Ada Programs
-@anchor{gnat_ugn/gnat_and_program_execution id19}@anchor{18e}@anchor{gnat_ugn/gnat_and_program_execution pretty-printers-for-the-gnat-runtime}@anchor{18f}
-@subsection Pretty-Printers for the GNAT runtime
+@geindex Aliasing
 
+@geindex Strict Aliasing
 
-As discussed in @cite{Calling User-Defined Subprograms}, GDB's
-@code{print} command only knows about the physical layout of program data
-structures and therefore normally displays only low-level dumps, which
-are often hard to understand.
+@geindex No_Strict_Aliasing
 
-An example of this is when trying to display the contents of an Ada
-standard container, such as @code{Ada.Containers.Ordered_Maps.Map}:
+The strong typing capabilities of Ada allow an optimizer to generate
+efficient code in situations where other languages would be forced to
+make worst case assumptions preventing such optimizations. Consider
+the following example:
 
 @quotation
 
 @example
-with Ada.Containers.Ordered_Maps;
-
-procedure PP is
-   package Int_To_Nat is
-      new Ada.Containers.Ordered_Maps (Integer, Natural);
+procedure R is
+   type Int1 is new Integer;
+   type Int2 is new Integer;
+   type Int1A is access Int1;
+   type Int2A is access Int2;
+   Int1V : Int1A;
+   Int2V : Int2A;
+   ...
 
-   Map : Int_To_Nat.Map;
 begin
-   Map.Insert (1, 10);
-   Map.Insert (2, 20);
-   Map.Insert (3, 30);
-
-   Map.Clear; --  BREAK HERE
-end PP;
+   ...
+   for J in Data'Range loop
+      if Data (J) = Int1V.all then
+         Int2V.all := Int2V.all + 1;
+      end if;
+   end loop;
+   ...
+end R;
 @end example
 @end quotation
 
-When this program is built with debugging information and run under
-GDB up to the @code{Map.Clear} statement, trying to print @code{Map} will
-yield information that is only relevant to the developers of our standard
-containers:
+In this example, since the variable @code{Int1V} can only access objects
+of type @code{Int1}, and @code{Int2V} can only access objects of type
+@code{Int2}, there is no possibility that the assignment to
+@code{Int2V.all} affects the value of @code{Int1V.all}. This means that
+the compiler optimizer can "know" that the value @code{Int1V.all} is constant
+for all iterations of the loop and avoid the extra memory reference
+required to dereference it each time through the loop.
+
+This kind of optimization, called strict aliasing analysis, is
+triggered by specifying an optimization level of @code{-O2} or
+higher or @code{-Os} and allows GNAT to generate more efficient code
+when access values are involved.
+
+However, although this optimization is always correct in terms of
+the formal semantics of the Ada Reference Manual, difficulties can
+arise if features like @code{Unchecked_Conversion} are used to break
+the typing system. Consider the following complete program example:
 
 @quotation
 
 @example
-(gdb) print map
-$1 = (
-  tree => (
-    first => 0x64e010,
-    last => 0x64e070,
-    root => 0x64e040,
-    length => 3,
-    tc => (
-      busy => 0,
-      lock => 0
-    )
-  )
-)
-@end example
-@end quotation
+package p1 is
+   type int1 is new integer;
+   type int2 is new integer;
+   type a1 is access int1;
+   type a2 is access int2;
+end p1;
 
-Fortunately, GDB has a feature called pretty-printers@footnote{http://docs.adacore.com/gdb-docs/html/gdb.html#Pretty_002dPrinter-Introduction},
-which allows customizing how GDB displays data structures. The GDB
-shipped with GNAT embeds such pretty-printers for the most common
-containers in the standard library.  To enable them, either run the
-following command manually under GDB or add it to your @code{.gdbinit} file:
+with p1; use p1;
+package p2 is
+   function to_a2 (Input : a1) return a2;
+end p2;
 
-@quotation
+with Unchecked_Conversion;
+package body p2 is
+   function to_a2 (Input : a1) return a2 is
+      function to_a2u is
+        new Unchecked_Conversion (a1, a2);
+   begin
+      return to_a2u (Input);
+   end to_a2;
+end p2;
 
-@example
-python import gnatdbg; gnatdbg.setup()
+with p2; use p2;
+with p1; use p1;
+with Text_IO; use Text_IO;
+procedure m is
+   v1 : a1 := new int1;
+   v2 : a2 := to_a2 (v1);
+begin
+   v1.all := 1;
+   v2.all := 0;
+   put_line (int1'image (v1.all));
+end;
 @end example
 @end quotation
 
-Once this is done, GDB's @code{print} command will automatically use
-these pretty-printers when appropriate. Using the previous example:
-
-@quotation
+This program prints out 0 in @code{-O0} or @code{-O1}
+mode, but it prints out 1 in @code{-O2} mode. That's
+because in strict aliasing mode, the compiler can and
+does assume that the assignment to @code{v2.all} could not
+affect the value of @code{v1.all}, since different types
+are involved.
 
-@example
-(gdb) print map
-$1 = pp.int_to_nat.map of length 3 = @{
-  [1] = 10,
-  [2] = 20,
-  [3] = 30
-@}
-@end example
-@end quotation
+This behavior is not a case of non-conformance with the standard, since
+the Ada RM specifies that an unchecked conversion where the resulting
+bit pattern is not a correct value of the target type can result in an
+abnormal value and attempting to reference an abnormal value makes the
+execution of a program erroneous.  That's the case here since the result
+does not point to an object of type @code{int2}.  This means that the
+effect is entirely unpredictable.
 
-Pretty-printers are invoked each time GDB tries to display a value,
-including when displaying the arguments of a called subprogram (in
-GDB's @code{backtrace} command) or when printing the value returned by a
-function (in GDB's @code{finish} command).
+However, although that explanation may satisfy a language
+lawyer, in practice an applications programmer expects an
+unchecked conversion involving pointers to create true
+aliases and the behavior of printing 1 seems plain wrong.
+In this case, the strict aliasing optimization is unwelcome.
 
-To display a value without involving pretty-printers, @code{print} can be
-invoked with its @code{/r} option:
+Indeed the compiler recognizes this possibility, and the
+unchecked conversion generates a warning:
 
 @quotation
 
 @example
-(gdb) print/r map
-$1 = (
-  tree => (...
+p2.adb:5:07: warning: possible aliasing problem with type "a2"
+p2.adb:5:07: warning: use -fno-strict-aliasing switch for references
+p2.adb:5:07: warning:  or use "pragma No_Strict_Aliasing (a2);"
 @end example
 @end quotation
 
-Finer control of pretty-printers is also possible: see GDB's online documentation@footnote{http://docs.adacore.com/gdb-docs/html/gdb.html#Pretty_002dPrinter-Commands}
-for more information.
-
-@geindex Code Coverage
-
-@geindex Profiling
-
-@node Code Coverage and Profiling,Improving Performance,Running and Debugging Ada Programs,GNAT and Program Execution
-@anchor{gnat_ugn/gnat_and_program_execution id20}@anchor{168}@anchor{gnat_ugn/gnat_and_program_execution code-coverage-and-profiling}@anchor{25}
-@section Code Coverage and Profiling
+Unfortunately the problem is recognized when compiling the body of
+package @code{p2}, but the actual "bad" code is generated while
+compiling the body of @code{m} and this latter compilation does not see
+the suspicious @code{Unchecked_Conversion}.
 
+As implied by the warning message, there are approaches you can use to
+avoid the unwanted strict aliasing optimization in a case like this.
 
-This section describes how to use the @code{gcov} coverage testing tool and
-the @code{gprof} profiler tool on Ada programs.
+One possibility is to simply avoid the use of @code{-O2}, but
+that is a bit drastic, since it throws away a number of useful
+optimizations that do not involve strict aliasing assumptions.
 
-@geindex gcov
+A less drastic approach is to compile the program using the
+option @code{-fno-strict-aliasing}. Actually it is only the
+unit containing the dereferencing of the suspicious pointer
+that needs to be compiled. So in this case, if we compile
+unit @code{m} with this switch, then we get the expected
+value of zero printed. Analyzing which units might need
+the switch can be painful, so a more reasonable approach
+is to compile the entire program with options @code{-O2}
+and @code{-fno-strict-aliasing}. If the performance is
+satisfactory with this combination of options, then the
+advantage is that the entire issue of possible "wrong"
+optimization due to strict aliasing is avoided.
 
-@menu
-* Code Coverage of Ada Programs with gcov:: 
-* Profiling an Ada Program with gprof:: 
+To avoid the use of compiler switches, the configuration
+pragma @code{No_Strict_Aliasing} with no parameters may be
+used to specify that for all access types, the strict
+aliasing optimization should be suppressed.
 
-@end menu
+However, these approaches are still overkill, in that they causes
+all manipulations of all access values to be deoptimized. A more
+refined approach is to concentrate attention on the specific
+access type identified as problematic.
 
-@node Code Coverage of Ada Programs with gcov,Profiling an Ada Program with gprof,,Code Coverage and Profiling
-@anchor{gnat_ugn/gnat_and_program_execution id21}@anchor{190}@anchor{gnat_ugn/gnat_and_program_execution code-coverage-of-ada-programs-with-gcov}@anchor{191}
-@subsection Code Coverage of Ada Programs with gcov
+First, if a careful analysis of uses of the pointer shows
+that there are no possible problematic references, then
+the warning can be suppressed by bracketing the
+instantiation of @code{Unchecked_Conversion} to turn
+the warning off:
 
+@quotation
 
-@code{gcov} is a test coverage program: it analyzes the execution of a given
-program on selected tests, to help you determine the portions of the program
-that are still untested.
+@example
+pragma Warnings (Off);
+function to_a2u is
+  new Unchecked_Conversion (a1, a2);
+pragma Warnings (On);
+@end example
+@end quotation
 
-@code{gcov} is part of the GCC suite, and is described in detail in the GCC
-User's Guide. You can refer to this documentation for a more complete
-description.
+Of course that approach is not appropriate for this particular
+example, since indeed there is a problematic reference. In this
+case we can take one of two other approaches.
 
-This chapter provides a quick startup guide, and
-details some GNAT-specific features.
+The first possibility is to move the instantiation of unchecked
+conversion to the unit in which the type is declared. In
+this example, we would move the instantiation of
+@code{Unchecked_Conversion} from the body of package
+@code{p2} to the spec of package @code{p1}. Now the
+warning disappears. That's because any use of the
+access type knows there is a suspicious unchecked
+conversion, and the strict aliasing optimization
+is automatically suppressed for the type.
 
-@menu
-* Quick startup guide:: 
-* GNAT specifics:: 
+If it is not practical to move the unchecked conversion to the same unit
+in which the destination access type is declared (perhaps because the
+source type is not visible in that unit), you may use pragma
+@code{No_Strict_Aliasing} for the type. This pragma must occur in the
+same declarative sequence as the declaration of the access type:
 
-@end menu
+@quotation
 
-@node Quick startup guide,GNAT specifics,,Code Coverage of Ada Programs with gcov
-@anchor{gnat_ugn/gnat_and_program_execution id22}@anchor{192}@anchor{gnat_ugn/gnat_and_program_execution quick-startup-guide}@anchor{193}
-@subsubsection Quick startup guide
+@example
+type a2 is access int2;
+pragma No_Strict_Aliasing (a2);
+@end example
+@end quotation
 
+Here again, the compiler now knows that the strict aliasing optimization
+should be suppressed for any reference to type @code{a2} and the
+expected behavior is obtained.
 
-In order to perform coverage analysis of a program using @code{gcov}, several
-steps are needed:
+Finally, note that although the compiler can generate warnings for
+simple cases of unchecked conversions, there are tricker and more
+indirect ways of creating type incorrect aliases which the compiler
+cannot detect. Examples are the use of address overlays and unchecked
+conversions involving composite types containing access types as
+components. In such cases, no warnings are generated, but there can
+still be aliasing problems. One safe coding practice is to forbid the
+use of address clauses for type overlaying, and to allow unchecked
+conversion only for primitive types. This is not really a significant
+restriction since any possible desired effect can be achieved by
+unchecked conversion of access values.
 
+The aliasing analysis done in strict aliasing mode can certainly
+have significant benefits. We have seen cases of large scale
+application code where the time is increased by up to 5% by turning
+this optimization off. If you have code that includes significant
+usage of unchecked conversion, you might want to just stick with
+@code{-O1} and avoid the entire issue. If you get adequate
+performance at this level of optimization level, that's probably
+the safest approach. If tests show that you really need higher
+levels of optimization, then you can experiment with @code{-O2}
+and @code{-O2 -fno-strict-aliasing} to see how much effect this
+has on size and speed of the code. If you really need to use
+@code{-O2} with strict aliasing in effect, then you should
+review any uses of unchecked conversion of access types,
+particularly if you are getting the warnings described above.
 
-@enumerate 
+@node Aliased Variables and Optimization,Atomic Variables and Optimization,Optimization and Strict Aliasing,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution id37}@anchor{18d}@anchor{gnat_ugn/gnat_and_program_execution aliased-variables-and-optimization}@anchor{18e}
+@subsubsection Aliased Variables and Optimization
 
-@item 
-Instrument the code during the compilation process,
 
-@item 
-Execute the instrumented program, and
+@geindex Aliasing
 
-@item 
-Invoke the @code{gcov} tool to generate the coverage results.
-@end enumerate
+There are scenarios in which programs may
+use low level techniques to modify variables
+that otherwise might be considered to be unassigned. For example,
+a variable can be passed to a procedure by reference, which takes
+the address of the parameter and uses the address to modify the
+variable's value, even though it is passed as an IN parameter.
+Consider the following example:
 
-@geindex -fprofile-arcs (gcc)
+@quotation
 
-@geindex -ftest-coverage (gcc
+@example
+procedure P is
+   Max_Length : constant Natural := 16;
+   type Char_Ptr is access all Character;
 
-@geindex -fprofile-arcs (gnatbind)
+   procedure Get_String(Buffer: Char_Ptr; Size : Integer);
+   pragma Import (C, Get_String, "get_string");
 
-The code instrumentation needed by gcov is created at the object level.
-The source code is not modified in any way, because the instrumentation code is
-inserted by gcc during the compilation process. To compile your code with code
-coverage activated, you need to recompile your whole project using the
-switches
-@code{-fprofile-arcs} and @code{-ftest-coverage}, and link it using
-@code{-fprofile-arcs}.
+   Name : aliased String (1 .. Max_Length) := (others => ' ');
+   Temp : Char_Ptr;
 
-@quotation
+   function Addr (S : String) return Char_Ptr is
+      function To_Char_Ptr is
+        new Ada.Unchecked_Conversion (System.Address, Char_Ptr);
+   begin
+      return To_Char_Ptr (S (S'First)'Address);
+   end;
 
-@example
-$ gnatmake -P my_project.gpr -f -cargs -fprofile-arcs -ftest-coverage \\
-   -largs -fprofile-arcs
+begin
+   Temp := Addr (Name);
+   Get_String (Temp, Max_Length);
+end;
 @end example
 @end quotation
 
-This compilation process will create @code{.gcno} files together with
-the usual object files.
+where Get_String is a C function that uses the address in Temp to
+modify the variable @code{Name}. This code is dubious, and arguably
+erroneous, and the compiler would be entitled to assume that
+@code{Name} is never modified, and generate code accordingly.
 
-Once the program is compiled with coverage instrumentation, you can
-run it as many times as needed -- on portions of a test suite for
-example. The first execution will produce @code{.gcda} files at the
-same location as the @code{.gcno} files.  Subsequent executions
-will update those files, so that a cumulative result of the covered
-portions of the program is generated.
+However, in practice, this would cause some existing code that
+seems to work with no optimization to start failing at high
+levels of optimzization.
 
-Finally, you need to call the @code{gcov} tool. The different options of
-@code{gcov} are described in the GCC User's Guide, section @emph{Invoking gcov}.
+What the compiler does for such cases is to assume that marking
+a variable as aliased indicates that some "funny business" may
+be going on. The optimizer recognizes the aliased keyword and
+inhibits optimizations that assume the value cannot be assigned.
+This means that the above example will in fact "work" reliably,
+that is, it will produce the expected results.
 
-This will create annotated source files with a @code{.gcov} extension:
-@code{my_main.adb} file will be analyzed in @code{my_main.adb.gcov}.
+@node Atomic Variables and Optimization,Passive Task Optimization,Aliased Variables and Optimization,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution atomic-variables-and-optimization}@anchor{18f}@anchor{gnat_ugn/gnat_and_program_execution id38}@anchor{190}
+@subsubsection Atomic Variables and Optimization
 
-@node GNAT specifics,,Quick startup guide,Code Coverage of Ada Programs with gcov
-@anchor{gnat_ugn/gnat_and_program_execution gnat-specifics}@anchor{194}@anchor{gnat_ugn/gnat_and_program_execution id23}@anchor{195}
-@subsubsection GNAT specifics
 
+@geindex Atomic
 
-Because of Ada semantics, portions of the source code may be shared among
-several object files. This is the case for example when generics are
-involved, when inlining is active  or when declarations generate  initialisation
-calls. In order to take
-into account this shared code, you need to call @code{gcov} on all
-source files of the tested program at once.
+There are two considerations with regard to performance when
+atomic variables are used.
 
-The list of source files might exceed the system's maximum command line
-length. In order to bypass this limitation, a new mechanism has been
-implemented in @code{gcov}: you can now list all your project's files into a
-text file, and provide this file to gcov as a parameter,  preceded by a @code{@@}
-(e.g. @code{gcov @@mysrclist.txt}).
+First, the RM only guarantees that access to atomic variables
+be atomic, it has nothing to say about how this is achieved,
+though there is a strong implication that this should not be
+achieved by explicit locking code. Indeed GNAT will never
+generate any locking code for atomic variable access (it will
+simply reject any attempt to make a variable or type atomic
+if the atomic access cannot be achieved without such locking code).
 
-Note that on AIX compiling a static library with @code{-fprofile-arcs} is
-not supported as there can be unresolved symbols during the final link.
+That being said, it is important to understand that you cannot
+assume that the entire variable will always be accessed. Consider
+this example:
 
-@geindex gprof
+@quotation
 
-@geindex Profiling
+@example
+type R is record
+   A,B,C,D : Character;
+end record;
+for R'Size use 32;
+for R'Alignment use 4;
 
-@node Profiling an Ada Program with gprof,,Code Coverage of Ada Programs with gcov,Code Coverage and Profiling
-@anchor{gnat_ugn/gnat_and_program_execution profiling-an-ada-program-with-gprof}@anchor{196}@anchor{gnat_ugn/gnat_and_program_execution id24}@anchor{197}
-@subsection Profiling an Ada Program with gprof
+RV : R;
+pragma Atomic (RV);
+X : Character;
+...
+X := RV.B;
+@end example
+@end quotation
 
+You cannot assume that the reference to @code{RV.B}
+will read the entire 32-bit
+variable with a single load instruction. It is perfectly legitimate if
+the hardware allows it to do a byte read of just the B field. This read
+is still atomic, which is all the RM requires. GNAT can and does take
+advantage of this, depending on the architecture and optimization level.
+Any assumption to the contrary is non-portable and risky. Even if you
+examine the assembly language and see a full 32-bit load, this might
+change in a future version of the compiler.
 
-This section is not meant to be an exhaustive documentation of @code{gprof}.
-Full documentation for it can be found in the @cite{GNU Profiler User's Guide}
-documentation that is part of this GNAT distribution.
+If your application requires that all accesses to @code{RV} in this
+example be full 32-bit loads, you need to make a copy for the access
+as in:
 
-Profiling a program helps determine the parts of a program that are executed
-most often, and are therefore the most time-consuming.
+@quotation
 
-@code{gprof} is the standard GNU profiling tool; it has been enhanced to
-better handle Ada programs and multitasking.
-It is currently supported on the following platforms
+@example
+declare
+   RV_Copy : constant R := RV;
+begin
+   X := RV_Copy.B;
+end;
+@end example
+@end quotation
 
+Now the reference to RV must read the whole variable.
+Actually one can imagine some compiler which figures
+out that the whole copy is not required (because only
+the B field is actually accessed), but GNAT
+certainly won't do that, and we don't know of any
+compiler that would not handle this right, and the
+above code will in practice work portably across
+all architectures (that permit the Atomic declaration).
 
-@itemize *
+The second issue with atomic variables has to do with
+the possible requirement of generating synchronization
+code. For more details on this, consult the sections on
+the pragmas Enable/Disable_Atomic_Synchronization in the
+GNAT Reference Manual. If performance is critical, and
+such synchronization code is not required, it may be
+useful to disable it.
 
-@item 
-linux x86/x86_64
+@node Passive Task Optimization,,Atomic Variables and Optimization,Performance Considerations
+@anchor{gnat_ugn/gnat_and_program_execution passive-task-optimization}@anchor{191}@anchor{gnat_ugn/gnat_and_program_execution id39}@anchor{192}
+@subsubsection Passive Task Optimization
 
-@item 
-solaris sparc/sparc64/x86
 
-@item 
-windows x86
-@end itemize
+@geindex Passive Task
 
-In order to profile a program using @code{gprof}, several steps are needed:
+A passive task is one which is sufficiently simple that
+in theory a compiler could recognize it an implement it
+efficiently without creating a new thread. The original design
+of Ada 83 had in mind this kind of passive task optimization, but
+only a few Ada 83 compilers attempted it. The problem was that
+it was difficult to determine the exact conditions under which
+the optimization was possible. The result is a very fragile
+optimization where a very minor change in the program can
+suddenly silently make a task non-optimizable.
 
+With the revisiting of this issue in Ada 95, there was general
+agreement that this approach was fundamentally flawed, and the
+notion of protected types was introduced. When using protected
+types, the restrictions are well defined, and you KNOW that the
+operations will be optimized, and furthermore this optimized
+performance is fully portable.
 
-@enumerate 
+Although it would theoretically be possible for GNAT to attempt to
+do this optimization, but it really doesn't make sense in the
+context of Ada 95, and none of the Ada 95 compilers implement
+this optimization as far as we know. In particular GNAT never
+attempts to perform this optimization.
 
-@item 
-Instrument the code, which requires a full recompilation of the project with the
-proper switches.
+In any new Ada 95 code that is written, you should always
+use protected types in place of tasks that might be able to
+be optimized in this manner.
+Of course this does not help if you have legacy Ada 83 code
+that depends on this optimization, but it is unusual to encounter
+a case where the performance gains from this optimization
+are significant.
 
-@item 
-Execute the program under the analysis conditions, i.e. with the desired
-input.
+Your program should work correctly without this optimization. If
+you have performance problems, then the most practical
+approach is to figure out exactly where these performance problems
+arise, and update those particular tasks to be protected types. Note
+that typically clients of the tasks who call entries, will not have
+to be modified, only the task definition itself.
 
-@item 
-Analyze the results using the @code{gprof} tool.
-@end enumerate
+@node Text_IO Suggestions,Reducing Size of Executables with Unused Subprogram/Data Elimination,Performance Considerations,Improving Performance
+@anchor{gnat_ugn/gnat_and_program_execution text-io-suggestions}@anchor{193}@anchor{gnat_ugn/gnat_and_program_execution id40}@anchor{194}
+@subsection @code{Text_IO} Suggestions
 
-The following sections detail the different steps, and indicate how
-to interpret the results.
 
-@menu
-* Compilation for profiling:: 
-* Program execution:: 
-* Running gprof:: 
-* Interpretation of profiling results:: 
+@geindex Text_IO and performance
 
-@end menu
+The @code{Ada.Text_IO} package has fairly high overheads due in part to
+the requirement of maintaining page and line counts. If performance
+is critical, a recommendation is to use @code{Stream_IO} instead of
+@code{Text_IO} for volume output, since this package has less overhead.
 
-@node Compilation for profiling,Program execution,,Profiling an Ada Program with gprof
-@anchor{gnat_ugn/gnat_and_program_execution id25}@anchor{198}@anchor{gnat_ugn/gnat_and_program_execution compilation-for-profiling}@anchor{199}
-@subsubsection Compilation for profiling
+If @code{Text_IO} must be used, note that by default output to the standard
+output and standard error files is unbuffered (this provides better
+behavior when output statements are used for debugging, or if the
+progress of a program is observed by tracking the output, e.g. by
+using the Unix @emph{tail -f} command to watch redirected output.
 
+If you are generating large volumes of output with @code{Text_IO} and
+performance is an important factor, use a designated file instead
+of the standard output file, or change the standard output file to
+be buffered using @code{Interfaces.C_Streams.setvbuf}.
 
-@geindex -pg (gcc)
-@geindex for profiling
+@node Reducing Size of Executables with Unused Subprogram/Data Elimination,,Text_IO Suggestions,Improving Performance
+@anchor{gnat_ugn/gnat_and_program_execution id41}@anchor{195}@anchor{gnat_ugn/gnat_and_program_execution reducing-size-of-executables-with-unused-subprogram-data-elimination}@anchor{196}
+@subsection Reducing Size of Executables with Unused Subprogram/Data Elimination
 
-@geindex -pg (gnatlink)
-@geindex for profiling
 
-In order to profile a program the first step is to tell the compiler
-to generate the necessary profiling information. The compiler switch to be used
-is @code{-pg}, which must be added to other compilation switches. This
-switch needs to be specified both during compilation and link stages, and can
-be specified once when using gnatmake:
+@geindex Uunused subprogram/data elimination
 
-@quotation
+This section describes how you can eliminate unused subprograms and data from
+your executable just by setting options at compilation time.
 
-@example
-$ gnatmake -f -pg -P my_project
-@end example
-@end quotation
+@menu
+* About unused subprogram/data elimination:: 
+* Compilation options:: 
+* Example of unused subprogram/data elimination:: 
 
-Note that only the objects that were compiled with the @code{-pg} switch will
-be profiled; if you need to profile your whole project, use the @code{-f}
-gnatmake switch to force full recompilation.
+@end menu
 
-@node Program execution,Running gprof,Compilation for profiling,Profiling an Ada Program with gprof
-@anchor{gnat_ugn/gnat_and_program_execution program-execution}@anchor{19a}@anchor{gnat_ugn/gnat_and_program_execution id26}@anchor{19b}
-@subsubsection Program execution
+@node About unused subprogram/data elimination,Compilation options,,Reducing Size of Executables with Unused Subprogram/Data Elimination
+@anchor{gnat_ugn/gnat_and_program_execution id42}@anchor{197}@anchor{gnat_ugn/gnat_and_program_execution about-unused-subprogram-data-elimination}@anchor{198}
+@subsubsection About unused subprogram/data elimination
 
 
-Once the program has been compiled for profiling, you can run it as usual.
+By default, an executable contains all code and data of its composing objects
+(directly linked or coming from statically linked libraries), even data or code
+never used by this executable.
 
-The only constraint imposed by profiling is that the program must terminate
-normally. An interrupted program (via a Ctrl-C, kill, etc.) will not be
-properly analyzed.
+This feature will allow you to eliminate such unused code from your
+executable, making it smaller (in disk and in memory).
 
-Once the program completes execution, a data file called @code{gmon.out} is
-generated in the directory where the program was launched from. If this file
-already exists, it will be overwritten.
+This functionality is available on all Linux platforms except for the IA-64
+architecture and on all cross platforms using the ELF binary file format.
+In both cases GNU binutils version 2.16 or later are required to enable it.
 
-@node Running gprof,Interpretation of profiling results,Program execution,Profiling an Ada Program with gprof
-@anchor{gnat_ugn/gnat_and_program_execution running-gprof}@anchor{19c}@anchor{gnat_ugn/gnat_and_program_execution id27}@anchor{19d}
-@subsubsection Running gprof
+@node Compilation options,Example of unused subprogram/data elimination,About unused subprogram/data elimination,Reducing Size of Executables with Unused Subprogram/Data Elimination
+@anchor{gnat_ugn/gnat_and_program_execution id43}@anchor{199}@anchor{gnat_ugn/gnat_and_program_execution compilation-options}@anchor{19a}
+@subsubsection Compilation options
 
 
-The @code{gprof} tool is called as follow:
+The operation of eliminating the unused code and data from the final executable
+is directly performed by the linker.
 
-@quotation
+@geindex -ffunction-sections (gcc)
 
-@example
-$ gprof my_prog gmon.out
-@end example
-@end quotation
+@geindex -fdata-sections (gcc)
 
-or simply:
+In order to do this, it has to work with objects compiled with the
+following options:
+@code{-ffunction-sections} @code{-fdata-sections}.
 
-@quotation
+These options are usable with C and Ada files.
+They will place respectively each
+function or data in a separate section in the resulting object file.
 
-@example
-$  gprof my_prog
-@end example
-@end quotation
+Once the objects and static libraries are created with these options, the
+linker can perform the dead code elimination. You can do this by setting
+the @code{-Wl,--gc-sections} option to gcc command or in the
+@code{-largs} section of @code{gnatmake}. This will perform a
+garbage collection of code and data never referenced.
 
-The complete form of the gprof command line is the following:
+If the linker performs a partial link (@code{-r} linker option), then you
+will need to provide the entry point using the @code{-e} / @code{--entry}
+linker option.
 
-@quotation
+Note that objects compiled without the @code{-ffunction-sections} and
+@code{-fdata-sections} options can still be linked with the executable.
+However, no dead code elimination will be performed on those objects (they will
+be linked as is).
 
-@example
-$ gprof [switches] [executable [data-file]]
-@end example
-@end quotation
+The GNAT static library is now compiled with -ffunction-sections and
+-fdata-sections on some platforms. This allows you to eliminate the unused code
+and data of the GNAT library from your executable.
 
-@code{gprof} supports numerous switches. The order of these
-switch does not matter. The full list of options can be found in
-the GNU Profiler User's Guide documentation that comes with this documentation.
+@node Example of unused subprogram/data elimination,,Compilation options,Reducing Size of Executables with Unused Subprogram/Data Elimination
+@anchor{gnat_ugn/gnat_and_program_execution example-of-unused-subprogram-data-elimination}@anchor{19b}@anchor{gnat_ugn/gnat_and_program_execution id44}@anchor{19c}
+@subsubsection Example of unused subprogram/data elimination
 
-The following is the subset of those switches that is most relevant:
 
-@geindex --demangle (gprof)
+Here is a simple example:
 
+@quotation
 
-@table @asis
+@example
+with Aux;
 
-@item @code{--demangle[=@emph{style}]}, @code{--no-demangle}
+procedure Test is
+begin
+   Aux.Used (10);
+end Test;
 
-These options control whether symbol names should be demangled when
-printing output.  The default is to demangle C++ symbols.  The
-@code{--no-demangle} option may be used to turn off demangling. Different
-compilers have different mangling styles.  The optional demangling style
-argument can be used to choose an appropriate demangling style for your
-compiler, in particular Ada symbols generated by GNAT can be demangled using
-@code{--demangle=gnat}.
-@end table
-
-@geindex -e (gprof)
-
-
-@table @asis
-
-@item @code{-e @emph{function_name}}
-
-The @code{-e @emph{function}} option tells @code{gprof} not to print
-information about the function @code{function_name} (and its
-children...) in the call graph.  The function will still be listed
-as a child of any functions that call it, but its index number will be
-shown as @code{[not printed]}.  More than one @code{-e} option may be
-given; only one @code{function_name} may be indicated with each @code{-e}
-option.
-@end table
-
-@geindex -E (gprof)
-
-
-@table @asis
+package Aux is
+   Used_Data   : Integer;
+   Unused_Data : Integer;
 
-@item @code{-E @emph{function_name}}
+   procedure Used   (Data : Integer);
+   procedure Unused (Data : Integer);
+end Aux;
 
-The @code{-E @emph{function}} option works like the @code{-e} option, but
-execution time spent in the function (and children who were not called from
-anywhere else), will not be used to compute the percentages-of-time for
-the call graph.  More than one @code{-E} option may be given; only one
-@code{function_name} may be indicated with each @code{-E`} option.
-@end table
+package body Aux is
+   procedure Used (Data : Integer) is
+   begin
+      Used_Data := Data;
+   end Used;
 
-@geindex -f (gprof)
+   procedure Unused (Data : Integer) is
+   begin
+      Unused_Data := Data;
+   end Unused;
+end Aux;
+@end example
+@end quotation
 
+@code{Unused} and @code{Unused_Data} are never referenced in this code
+excerpt, and hence they may be safely removed from the final executable.
 
-@table @asis
+@quotation
 
-@item @code{-f @emph{function_name}}
+@example
+$ gnatmake test
 
-The @code{-f @emph{function}} option causes @code{gprof} to limit the
-call graph to the function @code{function_name} and its children (and
-their children...).  More than one @code{-f} option may be given;
-only one @code{function_name} may be indicated with each @code{-f}
-option.
-@end table
+$ nm test | grep used
+020015f0 T aux__unused
+02005d88 B aux__unused_data
+020015cc T aux__used
+02005d84 B aux__used_data
 
-@geindex -F (gprof)
+$ gnatmake test -cargs -fdata-sections -ffunction-sections \\
+     -largs -Wl,--gc-sections
 
+$ nm test | grep used
+02005350 T aux__used
+0201ffe0 B aux__used_data
+@end example
+@end quotation
 
-@table @asis
+It can be observed that the procedure @code{Unused} and the object
+@code{Unused_Data} are removed by the linker when using the
+appropriate options.
 
-@item @code{-F @emph{function_name}}
+@geindex Overflow checks
 
-The @code{-F @emph{function}} option works like the @code{-f} option, but
-only time spent in the function and its children (and their
-children...) will be used to determine total-time and
-percentages-of-time for the call graph.  More than one @code{-F} option
-may be given; only one @code{function_name} may be indicated with each
-@code{-F} option.  The @code{-F} option overrides the @code{-E} option.
-@end table
+@geindex Checks (overflow)
 
-@node Interpretation of profiling results,,Running gprof,Profiling an Ada Program with gprof
-@anchor{gnat_ugn/gnat_and_program_execution id28}@anchor{19e}@anchor{gnat_ugn/gnat_and_program_execution interpretation-of-profiling-results}@anchor{19f}
-@subsubsection Interpretation of profiling results
+@node Overflow Check Handling in GNAT,Performing Dimensionality Analysis in GNAT,Improving Performance,GNAT and Program Execution
+@anchor{gnat_ugn/gnat_and_program_execution id45}@anchor{149}@anchor{gnat_ugn/gnat_and_program_execution overflow-check-handling-in-gnat}@anchor{19d}
+@section Overflow Check Handling in GNAT
 
 
-The results of the profiling analysis are represented by two arrays: the
-'flat profile' and the 'call graph'. Full documentation of those outputs
-can be found in the GNU Profiler User's Guide.
+This section explains how to control the handling of overflow checks.
 
-The flat profile shows the time spent in each function of the program, and how
-many time it has been called. This allows you to locate easily the most
-time-consuming functions.
+@menu
+* Background:: 
+* Management of Overflows in GNAT:: 
+* Specifying the Desired Mode:: 
+* Default Settings:: 
+* Implementation Notes:: 
 
-The call graph shows, for each subprogram, the subprograms that call it,
-and the subprograms that it calls. It also provides an estimate of the time
-spent in each of those callers/called subprograms.
+@end menu
 
-@node Improving Performance,Overflow Check Handling in GNAT,Code Coverage and Profiling,GNAT and Program Execution
-@anchor{gnat_ugn/gnat_and_program_execution id29}@anchor{169}@anchor{gnat_ugn/gnat_and_program_execution improving-performance}@anchor{26}
-@section Improving Performance
+@node Background,Management of Overflows in GNAT,,Overflow Check Handling in GNAT
+@anchor{gnat_ugn/gnat_and_program_execution id46}@anchor{19e}@anchor{gnat_ugn/gnat_and_program_execution background}@anchor{19f}
+@subsection Background
 
 
-@geindex Improving performance
+Overflow checks are checks that the compiler may make to ensure
+that intermediate results are not out of range. For example:
 
-This section presents several topics related to program performance.
-It first describes some of the tradeoffs that need to be considered
-and some of the techniques for making your program run faster.
+@quotation
 
+@example
+A : Integer;
+...
+A := A + 1;
+@end example
+@end quotation
 
-It then documents the unused subprogram/data elimination feature,
-which can reduce the size of program executables.
+If @code{A} has the value @code{Integer'Last}, then the addition may cause
+overflow since the result is out of range of the type @code{Integer}.
+In this case @code{Constraint_Error} will be raised if checks are
+enabled.
 
-@menu
-* Performance Considerations:: 
-* Text_IO Suggestions:: 
-* Reducing Size of Executables with Unused Subprogram/Data Elimination:: 
+A trickier situation arises in examples like the following:
 
-@end menu
+@quotation
 
-@node Performance Considerations,Text_IO Suggestions,,Improving Performance
-@anchor{gnat_ugn/gnat_and_program_execution performance-considerations}@anchor{1a0}@anchor{gnat_ugn/gnat_and_program_execution id30}@anchor{1a1}
-@subsection Performance Considerations
+@example
+A, C : Integer;
+...
+A := (A + 1) + C;
+@end example
+@end quotation
 
+where @code{A} is @code{Integer'Last} and @code{C} is @code{-1}.
+Now the final result of the expression on the right hand side is
+@code{Integer'Last} which is in range, but the question arises whether the
+intermediate addition of @code{(A + 1)} raises an overflow error.
 
-The GNAT system provides a number of options that allow a trade-off
-between
+The (perhaps surprising) answer is that the Ada language
+definition does not answer this question. Instead it leaves
+it up to the implementation to do one of two things if overflow
+checks are enabled.
 
 
 @itemize *
 
 @item 
-performance of the generated code
-
-@item 
-speed of compilation
-
-@item 
-minimization of dependences and recompilation
+raise an exception (@code{Constraint_Error}), or
 
 @item 
-the degree of run-time checking.
+yield the correct mathematical result which is then used in
+subsequent operations.
 @end itemize
 
-The defaults (if no options are selected) aim at improving the speed
-of compilation and minimizing dependences, at the expense of performance
-of the generated code:
+If the compiler chooses the first approach, then the assignment of this
+example will indeed raise @code{Constraint_Error} if overflow checking is
+enabled, or result in erroneous execution if overflow checks are suppressed.
 
+But if the compiler
+chooses the second approach, then it can perform both additions yielding
+the correct mathematical result, which is in range, so no exception
+will be raised, and the right result is obtained, regardless of whether
+overflow checks are suppressed.
 
-@itemize *
+Note that in the first example an
+exception will be raised in either case, since if the compiler
+gives the correct mathematical result for the addition, it will
+be out of range of the target type of the assignment, and thus
+fails the range check.
 
-@item 
-no optimization
+This lack of specified behavior in the handling of overflow for
+intermediate results is a source of non-portability, and can thus
+be problematic when programs are ported. Most typically this arises
+in a situation where the original compiler did not raise an exception,
+and then the application is moved to a compiler where the check is
+performed on the intermediate result and an unexpected exception is
+raised.
 
-@item 
-no inlining of subprogram calls
+Furthermore, when using Ada 2012's preconditions and other
+assertion forms, another issue arises. Consider:
 
-@item 
-all run-time checks enabled except overflow and elaboration checks
-@end itemize
+@quotation
 
-These options are suitable for most program development purposes. This
-section describes how you can modify these choices, and also provides
-some guidelines on debugging optimized code.
+@example
+procedure P (A, B : Integer) with
+  Pre => A + B <= Integer'Last;
+@end example
+@end quotation
 
-@menu
-* Controlling Run-Time Checks:: 
-* Use of Restrictions:: 
-* Optimization Levels:: 
-* Debugging Optimized Code:: 
-* Inlining of Subprograms:: 
-* Floating_Point_Operations:: 
-* Vectorization of loops:: 
-* Other Optimization Switches:: 
-* Optimization and Strict Aliasing:: 
-* Aliased Variables and Optimization:: 
-* Atomic Variables and Optimization:: 
-* Passive Task Optimization:: 
+One often wants to regard arithmetic in a context like this from
+a mathematical point of view. So for example, if the two actual parameters
+for a call to @code{P} are both @code{Integer'Last}, then
+the precondition should be regarded as False. If we are executing
+in a mode with run-time checks enabled for preconditions, then we would
+like this precondition to fail, rather than raising an exception
+because of the intermediate overflow.
 
-@end menu
+However, the language definition leaves the specification of
+whether the above condition fails (raising @code{Assert_Error}) or
+causes an intermediate overflow (raising @code{Constraint_Error})
+up to the implementation.
 
-@node Controlling Run-Time Checks,Use of Restrictions,,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution controlling-run-time-checks}@anchor{1a2}@anchor{gnat_ugn/gnat_and_program_execution id31}@anchor{1a3}
-@subsubsection Controlling Run-Time Checks
+The situation is worse in a case such as the following:
 
+@quotation
 
-By default, GNAT generates all run-time checks, except stack overflow
-checks, and checks for access before elaboration on subprogram
-calls. The latter are not required in default mode, because all
-necessary checking is done at compile time.
+@example
+procedure Q (A, B, C : Integer) with
+  Pre => A + B + C <= Integer'Last;
+@end example
+@end quotation
 
-@geindex -gnatp (gcc)
+Consider the call
 
-@geindex -gnato (gcc)
+@quotation
 
-The gnat switch, @code{-gnatp} allows this default to be modified. See
-@ref{f9,,Run-Time Checks}.
+@example
+Q (A => Integer'Last, B => 1, C => -1);
+@end example
+@end quotation
 
-Our experience is that the default is suitable for most development
-purposes.
-
-Elaboration checks are off by default, and also not needed by default, since
-GNAT uses a static elaboration analysis approach that avoids the need for
-run-time checking. This manual contains a full chapter discussing the issue
-of elaboration checks, and if the default is not satisfactory for your use,
-you should read this chapter.
-
-For validity checks, the minimal checks required by the Ada Reference
-Manual (for case statements and assignments to array elements) are on
-by default. These can be suppressed by use of the @code{-gnatVn} switch.
-Note that in Ada 83, there were no validity checks, so if the Ada 83 mode
-is acceptable (or when comparing GNAT performance with an Ada 83 compiler),
-it may be reasonable to routinely use @code{-gnatVn}. Validity checks
-are also suppressed entirely if @code{-gnatp} is used.
-
-@geindex Overflow checks
+From a mathematical point of view the precondition
+is True, but at run time we may (but are not guaranteed to) get an
+exception raised because of the intermediate overflow (and we really
+would prefer this precondition to be considered True at run time).
 
-@geindex Checks
-@geindex overflow
+@node Management of Overflows in GNAT,Specifying the Desired Mode,Background,Overflow Check Handling in GNAT
+@anchor{gnat_ugn/gnat_and_program_execution id47}@anchor{1a0}@anchor{gnat_ugn/gnat_and_program_execution management-of-overflows-in-gnat}@anchor{1a1}
+@subsection Management of Overflows in GNAT
 
-@geindex Suppress
 
-@geindex Unsuppress
+To deal with the portability issue, and with the problem of
+mathematical versus run-time interpretation of the expressions in
+assertions, GNAT provides comprehensive control over the handling
+of intermediate overflow. GNAT can operate in three modes, and
+furthemore, permits separate selection of operating modes for
+the expressions within assertions (here the term 'assertions'
+is used in the technical sense, which includes preconditions and so forth)
+and for expressions appearing outside assertions.
 
-@geindex pragma Suppress
+The three modes are:
 
-@geindex pragma Unsuppress
 
-Note that the setting of the switches controls the default setting of
-the checks. They may be modified using either @code{pragma Suppress} (to
-remove checks) or @code{pragma Unsuppress} (to add back suppressed
-checks) in the program source.
+@itemize *
 
-@node Use of Restrictions,Optimization Levels,Controlling Run-Time Checks,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution id32}@anchor{1a4}@anchor{gnat_ugn/gnat_and_program_execution use-of-restrictions}@anchor{1a5}
-@subsubsection Use of Restrictions
+@item 
+@emph{Use base type for intermediate operations} (@code{STRICT})
 
+In this mode, all intermediate results for predefined arithmetic
+operators are computed using the base type, and the result must
+be in range of the base type. If this is not the
+case then either an exception is raised (if overflow checks are
+enabled) or the execution is erroneous (if overflow checks are suppressed).
+This is the normal default mode.
 
-The use of pragma Restrictions allows you to control which features are
-permitted in your program. Apart from the obvious point that if you avoid
-relatively expensive features like finalization (enforceable by the use
-of pragma Restrictions (No_Finalization), the use of this pragma does not
-affect the generated code in most cases.
+@item 
+@emph{Most intermediate overflows avoided} (@code{MINIMIZED})
 
-One notable exception to this rule is that the possibility of task abort
-results in some distributed overhead, particularly if finalization or
-exception handlers are used. The reason is that certain sections of code
-have to be marked as non-abortable.
+In this mode, the compiler attempts to avoid intermediate overflows by
+using a larger integer type, typically @code{Long_Long_Integer},
+as the type in which arithmetic is
+performed for predefined arithmetic operators. This may be slightly more
+expensive at
+run time (compared to suppressing intermediate overflow checks), though
+the cost is negligible on modern 64-bit machines. For the examples given
+earlier, no intermediate overflows would have resulted in exceptions,
+since the intermediate results are all in the range of
+@code{Long_Long_Integer} (typically 64-bits on nearly all implementations
+of GNAT). In addition, if checks are enabled, this reduces the number of
+checks that must be made, so this choice may actually result in an
+improvement in space and time behavior.
 
-If you use neither the @code{abort} statement, nor asynchronous transfer
-of control (@code{select ... then abort}), then this distributed overhead
-is removed, which may have a general positive effect in improving
-overall performance.  Especially code involving frequent use of tasking
-constructs and controlled types will show much improved performance.
-The relevant restrictions pragmas are
+However, there are cases where @code{Long_Long_Integer} is not large
+enough, consider the following example:
 
 @quotation
 
 @example
-pragma Restrictions (No_Abort_Statements);
-pragma Restrictions (Max_Asynchronous_Select_Nesting => 0);
+procedure R (A, B, C, D : Integer) with
+  Pre => (A**2 * B**2) / (C**2 * D**2) <= 10;
 @end example
 @end quotation
 
-It is recommended that these restriction pragmas be used if possible. Note
-that this also means that you can write code without worrying about the
-possibility of an immediate abort at any point.
+where @code{A} = @code{B} = @code{C} = @code{D} = @code{Integer'Last}.
+Now the intermediate results are
+out of the range of @code{Long_Long_Integer} even though the final result
+is in range and the precondition is True (from a mathematical point
+of view). In such a case, operating in this mode, an overflow occurs
+for the intermediate computation (which is why this mode
+says @emph{most} intermediate overflows are avoided). In this case,
+an exception is raised if overflow checks are enabled, and the
+execution is erroneous if overflow checks are suppressed.
 
-@node Optimization Levels,Debugging Optimized Code,Use of Restrictions,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution id33}@anchor{1a6}@anchor{gnat_ugn/gnat_and_program_execution optimization-levels}@anchor{fc}
-@subsubsection Optimization Levels
+@item 
+@emph{All intermediate overflows avoided} (@code{ELIMINATED})
 
+In this mode, the compiler  avoids all intermediate overflows
+by using arbitrary precision arithmetic as required. In this
+mode, the above example with @code{A**2 * B**2} would
+not cause intermediate overflow, because the intermediate result
+would be evaluated using sufficient precision, and the result
+of evaluating the precondition would be True.
 
-@geindex -O (gcc)
+This mode has the advantage of avoiding any intermediate
+overflows, but at the expense of significant run-time overhead,
+including the use of a library (included automatically in this
+mode) for multiple-precision arithmetic.
 
-Without any optimization option,
-the compiler's goal is to reduce the cost of
-compilation and to make debugging produce the expected results.
-Statements are independent: if you stop the program with a breakpoint between
-statements, you can then assign a new value to any variable or change
-the program counter to any other statement in the subprogram and get exactly
-the results you would expect from the source code.
+This mode provides cleaner semantics for assertions, since now
+the run-time behavior emulates true arithmetic behavior for the
+predefined arithmetic operators, meaning that there is never a
+conflict between the mathematical view of the assertion, and its
+run-time behavior.
 
-Turning on optimization makes the compiler attempt to improve the
-performance and/or code size at the expense of compilation time and
-possibly the ability to debug the program.
+Note that in this mode, the behavior is unaffected by whether or
+not overflow checks are suppressed, since overflow does not occur.
+It is possible for gigantic intermediate expressions to raise
+@code{Storage_Error} as a result of attempting to compute the
+results of such expressions (e.g. @code{Integer'Last ** Integer'Last})
+but overflow is impossible.
+@end itemize
 
-If you use multiple
--O options, with or without level numbers,
-the last such option is the one that is effective.
+Note that these modes apply only to the evaluation of predefined
+arithmetic, membership, and comparison operators for signed integer
+arithmetic.
 
-The default is optimization off. This results in the fastest compile
-times, but GNAT makes absolutely no attempt to optimize, and the
-generated programs are considerably larger and slower than when
-optimization is enabled. You can use the
-@code{-O} switch (the permitted forms are @code{-O0}, @code{-O1}
-@code{-O2}, @code{-O3}, and @code{-Os})
-to @code{gcc} to control the optimization level:
+For fixed-point arithmetic, checks can be suppressed. But if checks
+are enabled
+then fixed-point values are always checked for overflow against the
+base type for intermediate expressions (that is such checks always
+operate in the equivalent of @code{STRICT} mode).
 
+For floating-point, on nearly all architectures, @code{Machine_Overflows}
+is False, and IEEE infinities are generated, so overflow exceptions
+are never raised. If you want to avoid infinities, and check that
+final results of expressions are in range, then you can declare a
+constrained floating-point type, and range checks will be carried
+out in the normal manner (with infinite values always failing all
+range checks).
 
-@itemize *
+@node Specifying the Desired Mode,Default Settings,Management of Overflows in GNAT,Overflow Check Handling in GNAT
+@anchor{gnat_ugn/gnat_and_program_execution specifying-the-desired-mode}@anchor{e9}@anchor{gnat_ugn/gnat_and_program_execution id48}@anchor{1a2}
+@subsection Specifying the Desired Mode
 
-@item 
 
-@table @asis
+@geindex pragma Overflow_Mode
 
-@item @code{-O0}
+The desired mode of for handling intermediate overflow can be specified using
+either the @code{Overflow_Mode} pragma or an equivalent compiler switch.
+The pragma has the form
 
-No optimization (the default);
-generates unoptimized code but has
-the fastest compilation time.
+@quotation
 
-Note that many other compilers do substantial optimization even
-if 'no optimization' is specified. With gcc, it is very unusual
-to use @code{-O0} for production if execution time is of any concern,
-since @code{-O0} means (almost) no optimization. This difference
-between gcc and other compilers should be kept in mind when
-doing performance comparisons.
-@end table
+@example
+pragma Overflow_Mode ([General =>] MODE [, [Assertions =>] MODE]);
+@end example
+@end quotation
 
-@item 
+where @code{MODE} is one of
 
-@table @asis
 
-@item @code{-O1}
+@itemize *
 
-Moderate optimization;
-optimizes reasonably well but does not
-degrade compilation time significantly.
-@end table
+@item 
+@code{STRICT}:  intermediate overflows checked (using base type)
 
 @item 
+@code{MINIMIZED}: minimize intermediate overflows
 
-@table @asis
+@item 
+@code{ELIMINATED}: eliminate intermediate overflows
+@end itemize
 
-@item @code{-O2}
+The case is ignored, so @code{MINIMIZED}, @code{Minimized} and
+@code{minimized} all have the same effect.
 
-Full optimization;
-generates highly optimized code and has
-the slowest compilation time.
-@end table
+If only the @code{General} parameter is present, then the given @code{MODE} applies
+to expressions both within and outside assertions. If both arguments
+are present, then @code{General} applies to expressions outside assertions,
+and @code{Assertions} applies to expressions within assertions. For example:
 
-@item 
+@quotation
 
-@table @asis
+@example
+pragma Overflow_Mode
+  (General => Minimized, Assertions => Eliminated);
+@end example
+@end quotation
 
-@item @code{-O3}
+specifies that general expressions outside assertions be evaluated
+in 'minimize intermediate overflows' mode, and expressions within
+assertions be evaluated in 'eliminate intermediate overflows' mode.
+This is often a reasonable choice, avoiding excessive overhead
+outside assertions, but assuring a high degree of portability
+when importing code from another compiler, while incurring
+the extra overhead for assertion expressions to ensure that
+the behavior at run time matches the expected mathematical
+behavior.
 
-Full optimization as in @code{-O2};
-also uses more aggressive automatic inlining of subprograms within a unit
-(@ref{10f,,Inlining of Subprograms}) and attempts to vectorize loops.
-@end table
+The @code{Overflow_Mode} pragma has the same scoping and placement
+rules as pragma @code{Suppress}, so it can occur either as a
+configuration pragma, specifying a default for the whole
+program, or in a declarative scope, where it applies to the
+remaining declarations and statements in that scope.
 
-@item 
+Note that pragma @code{Overflow_Mode} does not affect whether
+overflow checks are enabled or suppressed. It only controls the
+method used to compute intermediate values. To control whether
+overflow checking is enabled or suppressed, use pragma @code{Suppress}
+or @code{Unsuppress} in the usual manner.
 
-@table @asis
+@geindex -gnato? (gcc)
 
-@item @code{-Os}
+@geindex -gnato?? (gcc)
 
-Optimize space usage (code and data) of resulting program.
-@end table
-@end itemize
+Additionally, a compiler switch @code{-gnato?} or @code{-gnato??}
+can be used to control the checking mode default (which can be subsequently
+overridden using pragmas).
 
-Higher optimization levels perform more global transformations on the
-program and apply more expensive analysis algorithms in order to generate
-faster and more compact code. The price in compilation time, and the
-resulting improvement in execution time,
-both depend on the particular application and the hardware environment.
-You should experiment to find the best level for your application.
-
-Since the precise set of optimizations done at each level will vary from
-release to release (and sometime from target to target), it is best to think
-of the optimization settings in general terms.
-See the @emph{Options That Control Optimization} section in
-@cite{Using the GNU Compiler Collection (GCC)}
-for details about
-the @code{-O} settings and a number of @code{-f} options that
-individually enable or disable specific optimizations.
-
-Unlike some other compilation systems, @code{gcc} has
-been tested extensively at all optimization levels. There are some bugs
-which appear only with optimization turned on, but there have also been
-bugs which show up only in @emph{unoptimized} code. Selecting a lower
-level of optimization does not improve the reliability of the code
-generator, which in practice is highly reliable at all optimization
-levels.
+Here @code{?} is one of the digits @code{1} through @code{3}:
 
-Note regarding the use of @code{-O3}: The use of this optimization level
-ought not to be automatically preferred over that of level @code{-O2},
-since it often results in larger executables which may run more slowly.
-See further discussion of this point in @ref{10f,,Inlining of Subprograms}.
+@quotation
 
-@node Debugging Optimized Code,Inlining of Subprograms,Optimization Levels,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution id34}@anchor{1a7}@anchor{gnat_ugn/gnat_and_program_execution debugging-optimized-code}@anchor{1a8}
-@subsubsection Debugging Optimized Code
 
+@multitable {xxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx} 
+@item
 
-@geindex Debugging optimized code
+@code{1}
 
-@geindex Optimization and debugging
+@tab
 
-Although it is possible to do a reasonable amount of debugging at
-nonzero optimization levels,
-the higher the level the more likely that
-source-level constructs will have been eliminated by optimization.
-For example, if a loop is strength-reduced, the loop
-control variable may be completely eliminated and thus cannot be
-displayed in the debugger.
-This can only happen at @code{-O2} or @code{-O3}.
-Explicit temporary variables that you code might be eliminated at
-level @code{-O1} or higher.
+use base type for intermediate operations (@code{STRICT})
 
-@geindex -g (gcc)
+@item
 
-The use of the @code{-g} switch,
-which is needed for source-level debugging,
-affects the size of the program executable on disk,
-and indeed the debugging information can be quite large.
-However, it has no effect on the generated code (and thus does not
-degrade performance)
+@code{2}
 
-Since the compiler generates debugging tables for a compilation unit before
-it performs optimizations, the optimizing transformations may invalidate some
-of the debugging data.  You therefore need to anticipate certain
-anomalous situations that may arise while debugging optimized code.
-These are the most common cases:
+@tab
 
+minimize intermediate overflows (@code{MINIMIZED})
 
-@itemize *
+@item
 
-@item 
-@emph{The 'hopping Program Counter':}  Repeated @code{step} or @code{next}
-commands show
-the PC bouncing back and forth in the code.  This may result from any of
-the following optimizations:
+@code{3}
 
+@tab
 
-@itemize -
+eliminate intermediate overflows (@code{ELIMINATED})
 
-@item 
-@emph{Common subexpression elimination:} using a single instance of code for a
-quantity that the source computes several times.  As a result you
-may not be able to stop on what looks like a statement.
+@end multitable
 
-@item 
-@emph{Invariant code motion:} moving an expression that does not change within a
-loop, to the beginning of the loop.
+@end quotation
 
-@item 
-@emph{Instruction scheduling:} moving instructions so as to
-overlap loads and stores (typically) with other code, or in
-general to move computations of values closer to their uses. Often
-this causes you to pass an assignment statement without the assignment
-happening and then later bounce back to the statement when the
-value is actually needed.  Placing a breakpoint on a line of code
-and then stepping over it may, therefore, not always cause all the
-expected side-effects.
-@end itemize
+As with the pragma, if only one digit appears then it applies to all
+cases; if two digits are given, then the first applies outside
+assertions, and the second within assertions. Thus the equivalent
+of the example pragma above would be
+@code{-gnato23}.
 
-@item 
-@emph{The 'big leap':} More commonly known as @emph{cross-jumping}, in which
-two identical pieces of code are merged and the program counter suddenly
-jumps to a statement that is not supposed to be executed, simply because
-it (and the code following) translates to the same thing as the code
-that @emph{was} supposed to be executed.  This effect is typically seen in
-sequences that end in a jump, such as a @code{goto}, a @code{return}, or
-a @code{break} in a C @code{switch} statement.
+If no digits follow the @code{-gnato}, then it is equivalent to
+@code{-gnato11},
+causing all intermediate operations to be computed using the base
+type (@code{STRICT} mode).
 
-@item 
-@emph{The 'roving variable':} The symptom is an unexpected value in a variable.
-There are various reasons for this effect:
+@node Default Settings,Implementation Notes,Specifying the Desired Mode,Overflow Check Handling in GNAT
+@anchor{gnat_ugn/gnat_and_program_execution id49}@anchor{1a3}@anchor{gnat_ugn/gnat_and_program_execution default-settings}@anchor{1a4}
+@subsection Default Settings
 
 
-@itemize -
+The default mode for overflow checks is
 
-@item 
-In a subprogram prologue, a parameter may not yet have been moved to its
-'home'.
+@quotation
 
-@item 
-A variable may be dead, and its register re-used.  This is
-probably the most common cause.
+@example
+General => Strict
+@end example
+@end quotation
 
-@item 
-As mentioned above, the assignment of a value to a variable may
-have been moved.
+which causes all computations both inside and outside assertions to use
+the base type.
 
-@item 
-A variable may be eliminated entirely by value propagation or
-other means.  In this case, GCC may incorrectly generate debugging
-information for the variable
-@end itemize
+This retains compatibility with previous versions of
+GNAT which suppressed overflow checks by default and always
+used the base type for computation of intermediate results.
 
-In general, when an unexpected value appears for a local variable or parameter
-you should first ascertain if that value was actually computed by
-your program, as opposed to being incorrectly reported by the debugger.
-Record fields or
-array elements in an object designated by an access value
-are generally less of a problem, once you have ascertained that the access
-value is sensible.
-Typically, this means checking variables in the preceding code and in the
-calling subprogram to verify that the value observed is explainable from other
-values (one must apply the procedure recursively to those
-other values); or re-running the code and stopping a little earlier
-(perhaps before the call) and stepping to better see how the variable obtained
-the value in question; or continuing to step @emph{from} the point of the
-strange value to see if code motion had simply moved the variable's
-assignments later.
-@end itemize
+@c Sphinx allows no emphasis within :index: role. As a workaround we
+@c point the index to "switch" and use emphasis for "-gnato".
 
-In light of such anomalies, a recommended technique is to use @code{-O0}
-early in the software development cycle, when extensive debugging capabilities
-are most needed, and then move to @code{-O1} and later @code{-O2} as
-the debugger becomes less critical.
-Whether to use the @code{-g} switch in the release version is
-a release management issue.
-Note that if you use @code{-g} you can then use the @code{strip} program
-on the resulting executable,
-which removes both debugging information and global symbols.
+The 
+@geindex -gnato (gcc)
+switch @code{-gnato} (with no digits following)
+is equivalent to
 
-@node Inlining of Subprograms,Floating_Point_Operations,Debugging Optimized Code,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution id35}@anchor{1a9}@anchor{gnat_ugn/gnat_and_program_execution inlining-of-subprograms}@anchor{10f}
-@subsubsection Inlining of Subprograms
+@quotation
 
+@example
+General => Strict
+@end example
+@end quotation
 
-A call to a subprogram in the current unit is inlined if all the
-following conditions are met:
+which causes overflow checking of all intermediate overflows
+both inside and outside assertions against the base type.
 
+The pragma @code{Suppress (Overflow_Check)} disables overflow
+checking, but it has no effect on the method used for computing
+intermediate results.
 
-@itemize *
+The pragma @code{Unsuppress (Overflow_Check)} enables overflow
+checking, but it has no effect on the method used for computing
+intermediate results.
 
-@item 
-The optimization level is at least @code{-O1}.
+@node Implementation Notes,,Default Settings,Overflow Check Handling in GNAT
+@anchor{gnat_ugn/gnat_and_program_execution implementation-notes}@anchor{1a5}@anchor{gnat_ugn/gnat_and_program_execution id50}@anchor{1a6}
+@subsection Implementation Notes
 
-@item 
-The called subprogram is suitable for inlining: It must be small enough
-and not contain something that @code{gcc} cannot support in inlined
-subprograms.
 
-@geindex pragma Inline
+In practice on typical 64-bit machines, the @code{MINIMIZED} mode is
+reasonably efficient, and can be generally used. It also helps
+to ensure compatibility with code imported from some other
+compiler to GNAT.
 
-@geindex Inline
+Setting all intermediate overflows checking (@code{CHECKED} mode)
+makes sense if you want to
+make sure that your code is compatible with any other possible
+Ada implementation. This may be useful in ensuring portability
+for code that is to be exported to some other compiler than GNAT.
 
-@item 
-Any one of the following applies: @code{pragma Inline} is applied to the
-subprogram; the subprogram is local to the unit and called once from
-within it; the subprogram is small and optimization level @code{-O2} is
-specified; optimization level @code{-O3} is specified.
-@end itemize
+The Ada standard allows the reassociation of expressions at
+the same precedence level if no parentheses are present. For
+example, @code{A+B+C} parses as though it were @code{(A+B)+C}, but
+the compiler can reintepret this as @code{A+(B+C)}, possibly
+introducing or eliminating an overflow exception. The GNAT
+compiler never takes advantage of this freedom, and the
+expression @code{A+B+C} will be evaluated as @code{(A+B)+C}.
+If you need the other order, you can write the parentheses
+explicitly @code{A+(B+C)} and GNAT will respect this order.
 
-Calls to subprograms in @emph{with}ed units are normally not inlined.
-To achieve actual inlining (that is, replacement of the call by the code
-in the body of the subprogram), the following conditions must all be true:
+The use of @code{ELIMINATED} mode will cause the compiler to
+automatically include an appropriate arbitrary precision
+integer arithmetic package. The compiler will make calls
+to this package, though only in cases where it cannot be
+sure that @code{Long_Long_Integer} is sufficient to guard against
+intermediate overflows. This package does not use dynamic
+allocation, but it does use the secondary stack, so an
+appropriate secondary stack package must be present (this
+is always true for standard full Ada, but may require
+specific steps for restricted run times such as ZFP).
 
+Although @code{ELIMINATED} mode causes expressions to use arbitrary
+precision arithmetic, avoiding overflow, the final result
+must be in an appropriate range. This is true even if the
+final result is of type @code{[Long_[Long_]]Integer'Base}, which
+still has the same bounds as its associated constrained
+type at run-time.
 
-@itemize *
+Currently, the @code{ELIMINATED} mode is only available on target
+platforms for which @code{Long_Long_Integer} is 64-bits (nearly all GNAT
+platforms).
 
-@item 
-The optimization level is at least @code{-O1}.
+@node Performing Dimensionality Analysis in GNAT,Stack Related Facilities,Overflow Check Handling in GNAT,GNAT and Program Execution
+@anchor{gnat_ugn/gnat_and_program_execution performing-dimensionality-analysis-in-gnat}@anchor{1a7}@anchor{gnat_ugn/gnat_and_program_execution id51}@anchor{14a}
+@section Performing Dimensionality Analysis in GNAT
 
-@item 
-The called subprogram is suitable for inlining: It must be small enough
-and not contain something that @code{gcc} cannot support in inlined
-subprograms.
 
-@item 
-There is a @code{pragma Inline} for the subprogram.
+@geindex Dimensionality analysis
 
-@item 
-The @code{-gnatn} switch is used on the command line.
-@end itemize
-
-Even if all these conditions are met, it may not be possible for
-the compiler to inline the call, due to the length of the body,
-or features in the body that make it impossible for the compiler
-to do the inlining.
-
-Note that specifying the @code{-gnatn} switch causes additional
-compilation dependencies. Consider the following:
-
-@quotation
-
-@example
-package R is
-   procedure Q;
-   pragma Inline (Q);
-end R;
-package body R is
-   ...
-end R;
-
-with R;
-procedure Main is
-begin
-   ...
-   R.Q;
-end Main;
-@end example
-@end quotation
+The GNAT compiler supports dimensionality checking. The user can
+specify physical units for objects, and the compiler will verify that uses
+of these objects are compatible with their dimensions, in a fashion that is
+familiar to engineering practice. The dimensions of algebraic expressions
+(including powers with static exponents) are computed from their constituents.
 
-With the default behavior (no @code{-gnatn} switch specified), the
-compilation of the @code{Main} procedure depends only on its own source,
-@code{main.adb}, and the spec of the package in file @code{r.ads}. This
-means that editing the body of @code{R} does not require recompiling
-@code{Main}.
+@geindex Dimension_System aspect
 
-On the other hand, the call @code{R.Q} is not inlined under these
-circumstances. If the @code{-gnatn} switch is present when @code{Main}
-is compiled, the call will be inlined if the body of @code{Q} is small
-enough, but now @code{Main} depends on the body of @code{R} in
-@code{r.adb} as well as on the spec. This means that if this body is edited,
-the main program must be recompiled. Note that this extra dependency
-occurs whether or not the call is in fact inlined by @code{gcc}.
+@geindex Dimension aspect
 
-The use of front end inlining with @code{-gnatN} generates similar
-additional dependencies.
+This feature depends on Ada 2012 aspect specifications, and is available from
+version 7.0.1 of GNAT onwards.
+The GNAT-specific aspect @code{Dimension_System}
+allows you to define a system of units; the aspect @code{Dimension}
+then allows the user to declare dimensioned quantities within a given system.
+(These aspects are described in the @emph{Implementation Defined Aspects}
+chapter of the @emph{GNAT Reference Manual}).
 
-@geindex -fno-inline (gcc)
+The major advantage of this model is that it does not require the declaration of
+multiple operators for all possible combinations of types: it is only necessary
+to use the proper subtypes in object declarations.
 
-Note: The @code{-fno-inline} switch overrides all other conditions and ensures that
-no inlining occurs, unless requested with pragma Inline_Always for @code{gcc}
-back-ends. The extra dependences resulting from @code{-gnatn} will still be active,
-even if this switch is used to suppress the resulting inlining actions.
+@geindex System.Dim.Mks package (GNAT library)
 
-@geindex -fno-inline-functions (gcc)
+@geindex MKS_Type type
 
-Note: The @code{-fno-inline-functions} switch can be used to prevent
-automatic inlining of subprograms if @code{-O3} is used.
+The simplest way to impose dimensionality checking on a computation is to make
+use of one of the instantiations of the package @code{System.Dim.Generic_Mks}, which
+are part of the GNAT library. This generic package defines a floating-point
+type @code{MKS_Type}, for which a sequence of dimension names are specified,
+together with their conventional abbreviations.  The following should be read
+together with the full specification of the package, in file
+@code{s-digemk.ads}.
 
-@geindex -fno-inline-small-functions (gcc)
+@quotation
 
-Note: The @code{-fno-inline-small-functions} switch can be used to prevent
-automatic inlining of small subprograms if @code{-O2} is used.
+@geindex s-digemk.ads file
 
-@geindex -fno-inline-functions-called-once (gcc)
+@example
+type Mks_Type is new Float_Type
+  with
+   Dimension_System => (
+     (Unit_Name => Meter,    Unit_Symbol => 'm',   Dim_Symbol => 'L'),
+     (Unit_Name => Kilogram, Unit_Symbol => "kg",  Dim_Symbol => 'M'),
+     (Unit_Name => Second,   Unit_Symbol => 's',   Dim_Symbol => 'T'),
+     (Unit_Name => Ampere,   Unit_Symbol => 'A',   Dim_Symbol => 'I'),
+     (Unit_Name => Kelvin,   Unit_Symbol => 'K',   Dim_Symbol => "Theta"),
+     (Unit_Name => Mole,     Unit_Symbol => "mol", Dim_Symbol => 'N'),
+     (Unit_Name => Candela,  Unit_Symbol => "cd",  Dim_Symbol => 'J'));
+@end example
+@end quotation
 
-Note: The @code{-fno-inline-functions-called-once} switch
-can be used to prevent inlining of subprograms local to the unit
-and called once from within it if @code{-O1} is used.
+The package then defines a series of subtypes that correspond to these
+conventional units. For example:
 
-Note regarding the use of @code{-O3}: @code{-gnatn} is made up of two
-sub-switches @code{-gnatn1} and @code{-gnatn2} that can be directly
-specified in lieu of it, @code{-gnatn} being translated into one of them
-based on the optimization level. With @code{-O2} or below, @code{-gnatn}
-is equivalent to @code{-gnatn1} which activates pragma @code{Inline} with
-moderate inlining across modules. With @code{-O3}, @code{-gnatn} is
-equivalent to @code{-gnatn2} which activates pragma @code{Inline} with
-full inlining across modules. If you have used pragma @code{Inline} in
-appropriate cases, then it is usually much better to use @code{-O2}
-and @code{-gnatn} and avoid the use of @code{-O3} which has the additional
-effect of inlining subprograms you did not think should be inlined. We have
-found that the use of @code{-O3} may slow down the compilation and increase
-the code size by performing excessive inlining, leading to increased
-instruction cache pressure from the increased code size and thus minor
-performance improvements. So the bottom line here is that you should not
-automatically assume that @code{-O3} is better than @code{-O2}, and
-indeed you should use @code{-O3} only if tests show that it actually
-improves performance for your program.
+@quotation
 
-@node Floating_Point_Operations,Vectorization of loops,Inlining of Subprograms,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution id36}@anchor{1aa}@anchor{gnat_ugn/gnat_and_program_execution floating-point-operations}@anchor{1ab}
-@subsubsection Floating_Point_Operations
+@example
+subtype Length is Mks_Type
+  with
+   Dimension => (Symbol => 'm', Meter  => 1, others => 0);
+@end example
+@end quotation
 
+and similarly for @code{Mass}, @code{Time}, @code{Electric_Current},
+@code{Thermodynamic_Temperature}, @code{Amount_Of_Substance}, and
+@code{Luminous_Intensity} (the standard set of units of the SI system).
 
-@geindex Floating-Point Operations
+The package also defines conventional names for values of each unit, for
+example:
 
-On almost all targets, GNAT maps Float and Long_Float to the 32-bit and
-64-bit standard IEEE floating-point representations, and operations will
-use standard IEEE arithmetic as provided by the processor. On most, but
-not all, architectures, the attribute Machine_Overflows is False for these
-types, meaning that the semantics of overflow is implementation-defined.
-In the case of GNAT, these semantics correspond to the normal IEEE
-treatment of infinities and NaN (not a number) values. For example,
-1.0 / 0.0 yields plus infinitiy and 0.0 / 0.0 yields a NaN. By
-avoiding explicit overflow checks, the performance is greatly improved
-on many targets. However, if required, floating-point overflow can be
-enabled by the use of the pragma Check_Float_Overflow.
+@quotation
 
-Another consideration that applies specifically to x86 32-bit
-architectures is which form of floating-point arithmetic is used.
-By default the operations use the old style x86 floating-point,
-which implements an 80-bit extended precision form (on these
-architectures the type Long_Long_Float corresponds to that form).
-In addition, generation of efficient code in this mode means that
-the extended precision form will be used for intermediate results.
-This may be helpful in improving the final precision of a complex
-expression. However it means that the results obtained on the x86
-will be different from those on other architectures, and for some
-algorithms, the extra intermediate precision can be detrimental.
+@example
+m   : constant Length           := 1.0;
+kg  : constant Mass             := 1.0;
+s   : constant Time             := 1.0;
+A   : constant Electric_Current := 1.0;
+@end example
+@end quotation
 
-In addition to this old-style floating-point, all modern x86 chips
-implement an alternative floating-point operation model referred
-to as SSE2. In this model there is no extended form, and furthermore
-execution performance is significantly enhanced. To force GNAT to use
-this more modern form, use both of the switches:
+as well as useful multiples of these units:
 
 @quotation
 
--msse2 -mfpmath=sse
+@example
+ cm  : constant Length := 1.0E-02;
+ g   : constant Mass   := 1.0E-03;
+ min : constant Time   := 60.0;
+ day : constant Time   := 60.0 * 24.0 * min;
+...
+@end example
 @end quotation
 
-A unit compiled with these switches will automatically use the more
-efficient SSE2 instruction set for Float and Long_Float operations.
-Note that the ABI has the same form for both floating-point models,
-so it is permissible to mix units compiled with and without these
-switches.
+There are three instantiations of @code{System.Dim.Generic_Mks} defined in the
+GNAT library:
 
-@node Vectorization of loops,Other Optimization Switches,Floating_Point_Operations,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution id37}@anchor{1ac}@anchor{gnat_ugn/gnat_and_program_execution vectorization-of-loops}@anchor{1ad}
-@subsubsection Vectorization of loops
 
+@itemize *
 
-@geindex Optimization Switches
+@item 
+@code{System.Dim.Float_Mks} based on @code{Float} defined in @code{s-diflmk.ads}.
 
-You can take advantage of the auto-vectorizer present in the @code{gcc}
-back end to vectorize loops with GNAT.  The corresponding command line switch
-is @code{-ftree-vectorize} but, as it is enabled by default at @code{-O3}
-and other aggressive optimizations helpful for vectorization also are enabled
-by default at this level, using @code{-O3} directly is recommended.
+@item 
+@code{System.Dim.Long_Mks} based on @code{Long_Float} defined in @code{s-dilomk.ads}.
 
-You also need to make sure that the target architecture features a supported
-SIMD instruction set.  For example, for the x86 architecture, you should at
-least specify @code{-msse2} to get significant vectorization (but you don't
-need to specify it for x86-64 as it is part of the base 64-bit architecture).
-Similarly, for the PowerPC architecture, you should specify @code{-maltivec}.
+@item 
+@code{System.Dim.Mks} based on @code{Long_Long_Float} defined in @code{s-dimmks.ads}.
+@end itemize
 
-The preferred loop form for vectorization is the @code{for} iteration scheme.
-Loops with a @code{while} iteration scheme can also be vectorized if they are
-very simple, but the vectorizer will quickly give up otherwise.  With either
-iteration scheme, the flow of control must be straight, in particular no
-@code{exit} statement may appear in the loop body.  The loop may however
-contain a single nested loop, if it can be vectorized when considered alone:
+Using one of these packages, you can then define a derived unit by providing
+the aspect that specifies its dimensions within the MKS system, as well as the
+string to be used for output of a value of that unit:
 
 @quotation
 
 @example
-A : array (1..4, 1..4) of Long_Float;
-S : array (1..4) of Long_Float;
-
-procedure Sum is
-begin
-   for I in A'Range(1) loop
-      for J in A'Range(2) loop
-         S (I) := S (I) + A (I, J);
-      end loop;
-   end loop;
-end Sum;
+subtype Acceleration is Mks_Type
+  with Dimension => ("m/sec^2",
+                     Meter => 1,
+                     Second => -2,
+                     others => 0);
 @end example
 @end quotation
 
-The vectorizable operations depend on the targeted SIMD instruction set, but
-the adding and some of the multiplying operators are generally supported, as
-well as the logical operators for modular types. Note that compiling
-with @code{-gnatp} might well reveal cases where some checks do thwart
-vectorization.
-
-Type conversions may also prevent vectorization if they involve semantics that
-are not directly supported by the code generator or the SIMD instruction set.
-A typical example is direct conversion from floating-point to integer types.
-The solution in this case is to use the following idiom:
+Here is a complete example of use:
 
 @quotation
 
 @example
-Integer (S'Truncation (F))
+with System.Dim.MKS; use System.Dim.Mks;
+with System.Dim.Mks_IO; use System.Dim.Mks_IO;
+with Text_IO; use Text_IO;
+procedure Free_Fall is
+  subtype Acceleration is Mks_Type
+    with Dimension => ("m/sec^2", 1, 0, -2, others => 0);
+  G : constant acceleration := 9.81 * m / (s ** 2);
+  T : Time := 10.0*s;
+  Distance : Length;
+
+begin
+  Put ("Gravitational constant: ");
+  Put (G, Aft => 2, Exp => 0); Put_Line ("");
+  Distance := 0.5 * G * T ** 2;
+  Put ("distance travelled in 10 seconds of free fall ");
+  Put (Distance, Aft => 2, Exp => 0);
+  Put_Line ("");
+end Free_Fall;
 @end example
 @end quotation
 
-if @code{S} is the subtype of floating-point object @code{F}.
-
-In most cases, the vectorizable loops are loops that iterate over arrays.
-All kinds of array types are supported, i.e. constrained array types with
-static bounds:
+Execution of this program yields:
 
 @quotation
 
 @example
-type Array_Type is array (1 .. 4) of Long_Float;
+Gravitational constant:  9.81 m/sec^2
+distance travelled in 10 seconds of free fall 490.50 m
 @end example
 @end quotation
 
-constrained array types with dynamic bounds:
+However, incorrect assignments such as:
 
 @quotation
 
 @example
-type Array_Type is array (1 .. Q.N) of Long_Float;
+Distance := 5.0;
+Distance := 5.0 * kg;
+@end example
+@end quotation
 
-type Array_Type is array (Q.K .. 4) of Long_Float;
+are rejected with the following diagnoses:
 
-type Array_Type is array (Q.K .. Q.N) of Long_Float;
+@quotation
+
+@example
+Distance := 5.0;
+   >>> dimensions mismatch in assignment
+   >>> left-hand side has dimension [L]
+   >>> right-hand side is dimensionless
+
+Distance := 5.0 * kg:
+   >>> dimensions mismatch in assignment
+   >>> left-hand side has dimension [L]
+   >>> right-hand side has dimension [M]
 @end example
 @end quotation
 
-or unconstrained array types:
+The dimensions of an expression are properly displayed, even if there is
+no explicit subtype for it. If we add to the program:
 
 @quotation
 
 @example
-type Array_Type is array (Positive range <>) of Long_Float;
+Put ("Final velocity: ");
+Put (G * T, Aft =>2, Exp =>0);
+Put_Line ("");
 @end example
 @end quotation
 
-The quality of the generated code decreases when the dynamic aspect of the
-array type increases, the worst code being generated for unconstrained array
-types.  This is so because, the less information the compiler has about the
-bounds of the array, the more fallback code it needs to generate in order to
-fix things up at run time.
-
-It is possible to specify that a given loop should be subject to vectorization
-preferably to other optimizations by means of pragma @code{Loop_Optimize}:
+then the output includes:
 
 @quotation
 
 @example
-pragma Loop_Optimize (Vector);
+Final velocity: 98.10 m.s**(-1)
 @end example
-@end quotation
 
-placed immediately within the loop will convey the appropriate hint to the
-compiler for this loop.
+@geindex Dimensionable type
 
-It is also possible to help the compiler generate better vectorized code
-for a given loop by asserting that there are no loop-carried dependencies
-in the loop.  Consider for example the procedure:
+@geindex Dimensioned subtype
+@end quotation
+
+The type @code{Mks_Type} is said to be a @emph{dimensionable type} since it has a
+@code{Dimension_System} aspect, and the subtypes @code{Length}, @code{Mass}, etc.,
+are said to be @emph{dimensioned subtypes} since each one has a @code{Dimension}
+aspect.
 
 @quotation
 
-@example
-type Arr is array (1 .. 4) of Long_Float;
+@geindex Dimension Vector (for a dimensioned subtype)
 
-procedure Add (X, Y : not null access Arr; R : not null access Arr) is
-begin
-  for I in Arr'Range loop
-    R(I) := X(I) + Y(I);
-  end loop;
-end;
-@end example
+@geindex Dimension aspect
+
+@geindex Dimension_System aspect
 @end quotation
 
-By default, the compiler cannot unconditionally vectorize the loop because
-assigning to a component of the array designated by R in one iteration could
-change the value read from the components of the array designated by X or Y
-in a later iteration.  As a result, the compiler will generate two versions
-of the loop in the object code, one vectorized and the other not vectorized,
-as well as a test to select the appropriate version at run time.  This can
-be overcome by another hint:
+The @code{Dimension} aspect of a dimensioned subtype @code{S} defines a mapping
+from the base type's Unit_Names to integer (or, more generally, rational)
+values. This mapping is the @emph{dimension vector} (also referred to as the
+@emph{dimensionality}) for that subtype, denoted by @code{DV(S)}, and thus for each
+object of that subtype. Intuitively, the value specified for each
+@code{Unit_Name} is the exponent associated with that unit; a zero value
+means that the unit is not used. For example:
 
 @quotation
 
 @example
-pragma Loop_Optimize (Ivdep);
+declare
+   Acc : Acceleration;
+   ...
+begin
+   ...
+end;
 @end example
 @end quotation
 
-placed immediately within the loop will tell the compiler that it can safely
-omit the non-vectorized version of the loop as well as the run-time test.
+Here @code{DV(Acc)} = @code{DV(Acceleration)} =
+@code{(Meter=>1, Kilogram=>0, Second=>-2, Ampere=>0, Kelvin=>0, Mole=>0, Candela=>0)}.
+Symbolically, we can express this as @code{Meter / Second**2}.
 
-@node Other Optimization Switches,Optimization and Strict Aliasing,Vectorization of loops,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution other-optimization-switches}@anchor{1ae}@anchor{gnat_ugn/gnat_and_program_execution id38}@anchor{1af}
-@subsubsection Other Optimization Switches
+The dimension vector of an arithmetic expression is synthesized from the
+dimension vectors of its components, with compile-time dimensionality checks
+that help prevent mismatches such as using an @code{Acceleration} where a
+@code{Length} is required.
 
+The dimension vector of the result of an arithmetic expression @emph{expr}, or
+@code{DV(@emph{expr})}, is defined as follows, assuming conventional
+mathematical definitions for the vector operations that are used:
 
-@geindex Optimization Switches
 
-Since GNAT uses the @code{gcc} back end, all the specialized
-@code{gcc} optimization switches are potentially usable. These switches
-have not been extensively tested with GNAT but can generally be expected
-to work. Examples of switches in this category are @code{-funroll-loops}
-and the various target-specific @code{-m} options (in particular, it has
-been observed that @code{-march=xxx} can significantly improve performance
-on appropriate machines). For full details of these switches, see
-the @emph{Submodel Options} section in the @emph{Hardware Models and Configurations}
-chapter of @cite{Using the GNU Compiler Collection (GCC)}.
+@itemize *
 
-@node Optimization and Strict Aliasing,Aliased Variables and Optimization,Other Optimization Switches,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution optimization-and-strict-aliasing}@anchor{f3}@anchor{gnat_ugn/gnat_and_program_execution id39}@anchor{1b0}
-@subsubsection Optimization and Strict Aliasing
+@item 
+If @emph{expr} is of the type @emph{universal_real}, or is not of a dimensioned subtype,
+then @emph{expr} is dimensionless; @code{DV(@emph{expr})} is the empty vector.
 
+@item 
+@code{DV(@emph{op expr})}, where @emph{op} is a unary operator, is @code{DV(@emph{expr})}
 
-@geindex Aliasing
+@item 
+@code{DV(@emph{expr1 op expr2})} where @emph{op} is "+" or "-" is @code{DV(@emph{expr1})}
+provided that @code{DV(@emph{expr1})} = @code{DV(@emph{expr2})}.
+If this condition is not met then the construct is illegal.
 
-@geindex Strict Aliasing
+@item 
+@code{DV(@emph{expr1} * @emph{expr2})} is @code{DV(@emph{expr1})} + @code{DV(@emph{expr2})},
+and @code{DV(@emph{expr1} / @emph{expr2})} = @code{DV(@emph{expr1})} - @code{DV(@emph{expr2})}.
+In this context if one of the @emph{expr}s is dimensionless then its empty
+dimension vector is treated as @code{(others => 0)}.
 
-@geindex No_Strict_Aliasing
+@item 
+@code{DV(@emph{expr} ** @emph{power})} is @emph{power} * @code{DV(@emph{expr})},
+provided that @emph{power} is a static rational value. If this condition is not
+met then the construct is illegal.
+@end itemize
 
-The strong typing capabilities of Ada allow an optimizer to generate
-efficient code in situations where other languages would be forced to
-make worst case assumptions preventing such optimizations. Consider
-the following example:
+Note that, by the above rules, it is illegal to use binary "+" or "-" to
+combine a dimensioned and dimensionless value.  Thus an expression such as
+@code{acc-10.0} is illegal, where @code{acc} is an object of subtype
+@code{Acceleration}.
+
+The dimensionality checks for relationals use the same rules as
+for "+" and "-", except when comparing to a literal; thus
 
 @quotation
 
 @example
-procedure R is
-   type Int1 is new Integer;
-   type Int2 is new Integer;
-   type Int1A is access Int1;
-   type Int2A is access Int2;
-   Int1V : Int1A;
-   Int2V : Int2A;
-   ...
-
-begin
-   ...
-   for J in Data'Range loop
-      if Data (J) = Int1V.all then
-         Int2V.all := Int2V.all + 1;
-      end if;
-   end loop;
-   ...
-end R;
+acc > len
 @end example
 @end quotation
 
-In this example, since the variable @code{Int1V} can only access objects
-of type @code{Int1}, and @code{Int2V} can only access objects of type
-@code{Int2}, there is no possibility that the assignment to
-@code{Int2V.all} affects the value of @code{Int1V.all}. This means that
-the compiler optimizer can "know" that the value @code{Int1V.all} is constant
-for all iterations of the loop and avoid the extra memory reference
-required to dereference it each time through the loop.
-
-This kind of optimization, called strict aliasing analysis, is
-triggered by specifying an optimization level of @code{-O2} or
-higher or @code{-Os} and allows GNAT to generate more efficient code
-when access values are involved.
-
-However, although this optimization is always correct in terms of
-the formal semantics of the Ada Reference Manual, difficulties can
-arise if features like @code{Unchecked_Conversion} are used to break
-the typing system. Consider the following complete program example:
+is equivalent to
 
 @quotation
 
 @example
-package p1 is
-   type int1 is new integer;
-   type int2 is new integer;
-   type a1 is access int1;
-   type a2 is access int2;
-end p1;
-
-with p1; use p1;
-package p2 is
-   function to_a2 (Input : a1) return a2;
-end p2;
-
-with Unchecked_Conversion;
-package body p2 is
-   function to_a2 (Input : a1) return a2 is
-      function to_a2u is
-        new Unchecked_Conversion (a1, a2);
-   begin
-      return to_a2u (Input);
-   end to_a2;
-end p2;
-
-with p2; use p2;
-with p1; use p1;
-with Text_IO; use Text_IO;
-procedure m is
-   v1 : a1 := new int1;
-   v2 : a2 := to_a2 (v1);
-begin
-   v1.all := 1;
-   v2.all := 0;
-   put_line (int1'image (v1.all));
-end;
+acc-len > 0.0
 @end example
 @end quotation
 
-This program prints out 0 in @code{-O0} or @code{-O1}
-mode, but it prints out 1 in @code{-O2} mode. That's
-because in strict aliasing mode, the compiler can and
-does assume that the assignment to @code{v2.all} could not
-affect the value of @code{v1.all}, since different types
-are involved.
-
-This behavior is not a case of non-conformance with the standard, since
-the Ada RM specifies that an unchecked conversion where the resulting
-bit pattern is not a correct value of the target type can result in an
-abnormal value and attempting to reference an abnormal value makes the
-execution of a program erroneous.  That's the case here since the result
-does not point to an object of type @code{int2}.  This means that the
-effect is entirely unpredictable.
-
-However, although that explanation may satisfy a language
-lawyer, in practice an applications programmer expects an
-unchecked conversion involving pointers to create true
-aliases and the behavior of printing 1 seems plain wrong.
-In this case, the strict aliasing optimization is unwelcome.
-
-Indeed the compiler recognizes this possibility, and the
-unchecked conversion generates a warning:
+and is thus illegal, but
 
 @quotation
 
 @example
-p2.adb:5:07: warning: possible aliasing problem with type "a2"
-p2.adb:5:07: warning: use -fno-strict-aliasing switch for references
-p2.adb:5:07: warning:  or use "pragma No_Strict_Aliasing (a2);"
+acc > 10.0
 @end example
 @end quotation
 
-Unfortunately the problem is recognized when compiling the body of
-package @code{p2}, but the actual "bad" code is generated while
-compiling the body of @code{m} and this latter compilation does not see
-the suspicious @code{Unchecked_Conversion}.
+is accepted with a warning. Analogously a conditional expression requires the
+same dimension vector for each branch (with no exception for literals).
 
-As implied by the warning message, there are approaches you can use to
-avoid the unwanted strict aliasing optimization in a case like this.
+The dimension vector of a type conversion @code{T(@emph{expr})} is defined
+as follows, based on the nature of @code{T}:
 
-One possibility is to simply avoid the use of @code{-O2}, but
-that is a bit drastic, since it throws away a number of useful
-optimizations that do not involve strict aliasing assumptions.
 
-A less drastic approach is to compile the program using the
-option @code{-fno-strict-aliasing}. Actually it is only the
-unit containing the dereferencing of the suspicious pointer
-that needs to be compiled. So in this case, if we compile
-unit @code{m} with this switch, then we get the expected
-value of zero printed. Analyzing which units might need
-the switch can be painful, so a more reasonable approach
-is to compile the entire program with options @code{-O2}
-and @code{-fno-strict-aliasing}. If the performance is
-satisfactory with this combination of options, then the
-advantage is that the entire issue of possible "wrong"
-optimization due to strict aliasing is avoided.
-
-To avoid the use of compiler switches, the configuration
-pragma @code{No_Strict_Aliasing} with no parameters may be
-used to specify that for all access types, the strict
-aliasing optimization should be suppressed.
+@itemize *
 
-However, these approaches are still overkill, in that they causes
-all manipulations of all access values to be deoptimized. A more
-refined approach is to concentrate attention on the specific
-access type identified as problematic.
+@item 
+If @code{T} is a dimensioned subtype then @code{DV(T(@emph{expr}))} is @code{DV(T)}
+provided that either @emph{expr} is dimensionless or
+@code{DV(T)} = @code{DV(@emph{expr})}. The conversion is illegal
+if @emph{expr} is dimensioned and @code{DV(@emph{expr})} /= @code{DV(T)}.
+Note that vector equality does not require that the corresponding
+Unit_Names be the same.
 
-First, if a careful analysis of uses of the pointer shows
-that there are no possible problematic references, then
-the warning can be suppressed by bracketing the
-instantiation of @code{Unchecked_Conversion} to turn
-the warning off:
+As a consequence of the above rule, it is possible to convert between
+different dimension systems that follow the same international system
+of units, with the seven physical components given in the standard order
+(length, mass, time, etc.). Thus a length in meters can be converted to
+a length in inches (with a suitable conversion factor) but cannot be
+converted, for example, to a mass in pounds.
 
-@quotation
+@item 
+If @code{T} is the base type for @emph{expr} (and the dimensionless root type of
+the dimension system), then @code{DV(T(@emph{expr}))} is @code{DV(expr)}.
+Thus, if @emph{expr} is of a dimensioned subtype of @code{T}, the conversion may
+be regarded as a "view conversion" that preserves dimensionality.
 
-@example
-pragma Warnings (Off);
-function to_a2u is
-  new Unchecked_Conversion (a1, a2);
-pragma Warnings (On);
-@end example
-@end quotation
+This rule makes it possible to write generic code that can be instantiated
+with compatible dimensioned subtypes.  The generic unit will contain
+conversions that will consequently be present in instantiations, but
+conversions to the base type will preserve dimensionality and make it
+possible to write generic code that is correct with respect to
+dimensionality.
 
-Of course that approach is not appropriate for this particular
-example, since indeed there is a problematic reference. In this
-case we can take one of two other approaches.
+@item 
+Otherwise (i.e., @code{T} is neither a dimensioned subtype nor a dimensionable
+base type), @code{DV(T(@emph{expr}))} is the empty vector. Thus a dimensioned
+value can be explicitly converted to a non-dimensioned subtype, which
+of course then escapes dimensionality analysis.
+@end itemize
 
-The first possibility is to move the instantiation of unchecked
-conversion to the unit in which the type is declared. In
-this example, we would move the instantiation of
-@code{Unchecked_Conversion} from the body of package
-@code{p2} to the spec of package @code{p1}. Now the
-warning disappears. That's because any use of the
-access type knows there is a suspicious unchecked
-conversion, and the strict aliasing optimization
-is automatically suppressed for the type.
+The dimension vector for a type qualification @code{T'(@emph{expr})} is the same
+as for the type conversion @code{T(@emph{expr})}.
 
-If it is not practical to move the unchecked conversion to the same unit
-in which the destination access type is declared (perhaps because the
-source type is not visible in that unit), you may use pragma
-@code{No_Strict_Aliasing} for the type. This pragma must occur in the
-same declarative sequence as the declaration of the access type:
+An assignment statement
 
 @quotation
 
 @example
-type a2 is access int2;
-pragma No_Strict_Aliasing (a2);
+Source := Target;
 @end example
 @end quotation
 
-Here again, the compiler now knows that the strict aliasing optimization
-should be suppressed for any reference to type @code{a2} and the
-expected behavior is obtained.
+requires @code{DV(Source)} = @code{DV(Target)}, and analogously for parameter
+passing (the dimension vector for the actual parameter must be equal to the
+dimension vector for the formal parameter).
 
-Finally, note that although the compiler can generate warnings for
-simple cases of unchecked conversions, there are tricker and more
-indirect ways of creating type incorrect aliases which the compiler
-cannot detect. Examples are the use of address overlays and unchecked
-conversions involving composite types containing access types as
-components. In such cases, no warnings are generated, but there can
-still be aliasing problems. One safe coding practice is to forbid the
-use of address clauses for type overlaying, and to allow unchecked
-conversion only for primitive types. This is not really a significant
-restriction since any possible desired effect can be achieved by
-unchecked conversion of access values.
+@node Stack Related Facilities,Memory Management Issues,Performing Dimensionality Analysis in GNAT,GNAT and Program Execution
+@anchor{gnat_ugn/gnat_and_program_execution stack-related-facilities}@anchor{1a8}@anchor{gnat_ugn/gnat_and_program_execution id52}@anchor{14b}
+@section Stack Related Facilities
 
-The aliasing analysis done in strict aliasing mode can certainly
-have significant benefits. We have seen cases of large scale
-application code where the time is increased by up to 5% by turning
-this optimization off. If you have code that includes significant
-usage of unchecked conversion, you might want to just stick with
-@code{-O1} and avoid the entire issue. If you get adequate
-performance at this level of optimization level, that's probably
-the safest approach. If tests show that you really need higher
-levels of optimization, then you can experiment with @code{-O2}
-and @code{-O2 -fno-strict-aliasing} to see how much effect this
-has on size and speed of the code. If you really need to use
-@code{-O2} with strict aliasing in effect, then you should
-review any uses of unchecked conversion of access types,
-particularly if you are getting the warnings described above.
 
-@node Aliased Variables and Optimization,Atomic Variables and Optimization,Optimization and Strict Aliasing,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution aliased-variables-and-optimization}@anchor{1b1}@anchor{gnat_ugn/gnat_and_program_execution id40}@anchor{1b2}
-@subsubsection Aliased Variables and Optimization
+This section describes some useful tools associated with stack
+checking and analysis. In
+particular, it deals with dynamic and static stack usage measurements.
 
+@menu
+* Stack Overflow Checking:: 
+* Static Stack Usage Analysis:: 
+* Dynamic Stack Usage Analysis:: 
 
-@geindex Aliasing
+@end menu
 
-There are scenarios in which programs may
-use low level techniques to modify variables
-that otherwise might be considered to be unassigned. For example,
-a variable can be passed to a procedure by reference, which takes
-the address of the parameter and uses the address to modify the
-variable's value, even though it is passed as an IN parameter.
-Consider the following example:
+@node Stack Overflow Checking,Static Stack Usage Analysis,,Stack Related Facilities
+@anchor{gnat_ugn/gnat_and_program_execution id53}@anchor{1a9}@anchor{gnat_ugn/gnat_and_program_execution stack-overflow-checking}@anchor{e5}
+@subsection Stack Overflow Checking
 
-@quotation
 
-@example
-procedure P is
-   Max_Length : constant Natural := 16;
-   type Char_Ptr is access all Character;
+@geindex Stack Overflow Checking
 
-   procedure Get_String(Buffer: Char_Ptr; Size : Integer);
-   pragma Import (C, Get_String, "get_string");
+@geindex -fstack-check (gcc)
 
-   Name : aliased String (1 .. Max_Length) := (others => ' ');
-   Temp : Char_Ptr;
+For most operating systems, @code{gcc} does not perform stack overflow
+checking by default. This means that if the main environment task or
+some other task exceeds the available stack space, then unpredictable
+behavior will occur. Most native systems offer some level of protection by
+adding a guard page at the end of each task stack. This mechanism is usually
+not enough for dealing properly with stack overflow situations because
+a large local variable could "jump" above the guard page.
+Furthermore, when the
+guard page is hit, there may not be any space left on the stack for executing
+the exception propagation code. Enabling stack checking avoids
+such situations.
 
-   function Addr (S : String) return Char_Ptr is
-      function To_Char_Ptr is
-        new Ada.Unchecked_Conversion (System.Address, Char_Ptr);
-   begin
-      return To_Char_Ptr (S (S'First)'Address);
-   end;
+To activate stack checking, compile all units with the @code{gcc} option
+@code{-fstack-check}. For example:
 
-begin
-   Temp := Addr (Name);
-   Get_String (Temp, Max_Length);
-end;
+@quotation
+
+@example
+$ gcc -c -fstack-check package1.adb
 @end example
 @end quotation
 
-where Get_String is a C function that uses the address in Temp to
-modify the variable @code{Name}. This code is dubious, and arguably
-erroneous, and the compiler would be entitled to assume that
-@code{Name} is never modified, and generate code accordingly.
-
-However, in practice, this would cause some existing code that
-seems to work with no optimization to start failing at high
-levels of optimzization.
+Units compiled with this option will generate extra instructions to check
+that any use of the stack (for procedure calls or for declaring local
+variables in declare blocks) does not exceed the available stack space.
+If the space is exceeded, then a @code{Storage_Error} exception is raised.
 
-What the compiler does for such cases is to assume that marking
-a variable as aliased indicates that some "funny business" may
-be going on. The optimizer recognizes the aliased keyword and
-inhibits optimizations that assume the value cannot be assigned.
-This means that the above example will in fact "work" reliably,
-that is, it will produce the expected results.
+For declared tasks, the default stack size is defined by the GNAT runtime,
+whose size may be modified at bind time through the @code{-d} bind switch
+(@ref{110,,Switches for gnatbind}). Task specific stack sizes may be set using the
+@code{Storage_Size} pragma.
 
-@node Atomic Variables and Optimization,Passive Task Optimization,Aliased Variables and Optimization,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution atomic-variables-and-optimization}@anchor{1b3}@anchor{gnat_ugn/gnat_and_program_execution id41}@anchor{1b4}
-@subsubsection Atomic Variables and Optimization
+For the environment task, the stack size is determined by the operating system.
+Consequently, to modify the size of the environment task please refer to your
+operating system documentation.
 
+@node Static Stack Usage Analysis,Dynamic Stack Usage Analysis,Stack Overflow Checking,Stack Related Facilities
+@anchor{gnat_ugn/gnat_and_program_execution id54}@anchor{1aa}@anchor{gnat_ugn/gnat_and_program_execution static-stack-usage-analysis}@anchor{e6}
+@subsection Static Stack Usage Analysis
 
-@geindex Atomic
 
-There are two considerations with regard to performance when
-atomic variables are used.
+@geindex Static Stack Usage Analysis
 
-First, the RM only guarantees that access to atomic variables
-be atomic, it has nothing to say about how this is achieved,
-though there is a strong implication that this should not be
-achieved by explicit locking code. Indeed GNAT will never
-generate any locking code for atomic variable access (it will
-simply reject any attempt to make a variable or type atomic
-if the atomic access cannot be achieved without such locking code).
+@geindex -fstack-usage
 
-That being said, it is important to understand that you cannot
-assume that the entire variable will always be accessed. Consider
-this example:
+A unit compiled with @code{-fstack-usage} will generate an extra file
+that specifies
+the maximum amount of stack used, on a per-function basis.
+The file has the same
+basename as the target object file with a @code{.su} extension.
+Each line of this file is made up of three fields:
 
-@quotation
 
-@example
-type R is record
-   A,B,C,D : Character;
-end record;
-for R'Size use 32;
-for R'Alignment use 4;
+@itemize *
 
-RV : R;
-pragma Atomic (RV);
-X : Character;
-...
-X := RV.B;
-@end example
-@end quotation
+@item 
+The name of the function.
 
-You cannot assume that the reference to @code{RV.B}
-will read the entire 32-bit
-variable with a single load instruction. It is perfectly legitimate if
-the hardware allows it to do a byte read of just the B field. This read
-is still atomic, which is all the RM requires. GNAT can and does take
-advantage of this, depending on the architecture and optimization level.
-Any assumption to the contrary is non-portable and risky. Even if you
-examine the assembly language and see a full 32-bit load, this might
-change in a future version of the compiler.
+@item 
+A number of bytes.
 
-If your application requires that all accesses to @code{RV} in this
-example be full 32-bit loads, you need to make a copy for the access
-as in:
+@item 
+One or more qualifiers: @code{static}, @code{dynamic}, @code{bounded}.
+@end itemize
 
-@quotation
-
-@example
-declare
-   RV_Copy : constant R := RV;
-begin
-   X := RV_Copy.B;
-end;
-@end example
-@end quotation
-
-Now the reference to RV must read the whole variable.
-Actually one can imagine some compiler which figures
-out that the whole copy is not required (because only
-the B field is actually accessed), but GNAT
-certainly won't do that, and we don't know of any
-compiler that would not handle this right, and the
-above code will in practice work portably across
-all architectures (that permit the Atomic declaration).
-
-The second issue with atomic variables has to do with
-the possible requirement of generating synchronization
-code. For more details on this, consult the sections on
-the pragmas Enable/Disable_Atomic_Synchronization in the
-GNAT Reference Manual. If performance is critical, and
-such synchronization code is not required, it may be
-useful to disable it.
-
-@node Passive Task Optimization,,Atomic Variables and Optimization,Performance Considerations
-@anchor{gnat_ugn/gnat_and_program_execution id42}@anchor{1b5}@anchor{gnat_ugn/gnat_and_program_execution passive-task-optimization}@anchor{1b6}
-@subsubsection Passive Task Optimization
+The second field corresponds to the size of the known part of the function
+frame.
 
+The qualifier @code{static} means that the function frame size
+is purely static.
+It usually means that all local variables have a static size.
+In this case, the second field is a reliable measure of the function stack
+utilization.
 
-@geindex Passive Task
+The qualifier @code{dynamic} means that the function frame size is not static.
+It happens mainly when some local variables have a dynamic size. When this
+qualifier appears alone, the second field is not a reliable measure
+of the function stack analysis. When it is qualified with  @code{bounded}, it
+means that the second field is a reliable maximum of the function stack
+utilization.
 
-A passive task is one which is sufficiently simple that
-in theory a compiler could recognize it an implement it
-efficiently without creating a new thread. The original design
-of Ada 83 had in mind this kind of passive task optimization, but
-only a few Ada 83 compilers attempted it. The problem was that
-it was difficult to determine the exact conditions under which
-the optimization was possible. The result is a very fragile
-optimization where a very minor change in the program can
-suddenly silently make a task non-optimizable.
+A unit compiled with @code{-Wstack-usage} will issue a warning for each
+subprogram whose stack usage might be larger than the specified amount of
+bytes.  The wording is in keeping with the qualifier documented above.
 
-With the revisiting of this issue in Ada 95, there was general
-agreement that this approach was fundamentally flawed, and the
-notion of protected types was introduced. When using protected
-types, the restrictions are well defined, and you KNOW that the
-operations will be optimized, and furthermore this optimized
-performance is fully portable.
+@node Dynamic Stack Usage Analysis,,Static Stack Usage Analysis,Stack Related Facilities
+@anchor{gnat_ugn/gnat_and_program_execution id55}@anchor{1ab}@anchor{gnat_ugn/gnat_and_program_execution dynamic-stack-usage-analysis}@anchor{113}
+@subsection Dynamic Stack Usage Analysis
 
-Although it would theoretically be possible for GNAT to attempt to
-do this optimization, but it really doesn't make sense in the
-context of Ada 95, and none of the Ada 95 compilers implement
-this optimization as far as we know. In particular GNAT never
-attempts to perform this optimization.
 
-In any new Ada 95 code that is written, you should always
-use protected types in place of tasks that might be able to
-be optimized in this manner.
-Of course this does not help if you have legacy Ada 83 code
-that depends on this optimization, but it is unusual to encounter
-a case where the performance gains from this optimization
-are significant.
+It is possible to measure the maximum amount of stack used by a task, by
+adding a switch to @code{gnatbind}, as:
 
-Your program should work correctly without this optimization. If
-you have performance problems, then the most practical
-approach is to figure out exactly where these performance problems
-arise, and update those particular tasks to be protected types. Note
-that typically clients of the tasks who call entries, will not have
-to be modified, only the task definition itself.
+@quotation
 
-@node Text_IO Suggestions,Reducing Size of Executables with Unused Subprogram/Data Elimination,Performance Considerations,Improving Performance
-@anchor{gnat_ugn/gnat_and_program_execution text-io-suggestions}@anchor{1b7}@anchor{gnat_ugn/gnat_and_program_execution id43}@anchor{1b8}
-@subsection @code{Text_IO} Suggestions
+@example
+$ gnatbind -u0 file
+@end example
+@end quotation
 
+With this option, at each task termination, its stack usage is output on
+@code{stderr}.
+Note that this switch is not compatible with tools like
+Valgrind and DrMemory; they will report errors.
 
-@geindex Text_IO and performance
+It is not always convenient to output the stack usage when the program
+is still running. Hence, it is possible to delay this output until program
+termination. for a given number of tasks specified as the argument of the
+@code{-u} option. For instance:
 
-The @code{Ada.Text_IO} package has fairly high overheads due in part to
-the requirement of maintaining page and line counts. If performance
-is critical, a recommendation is to use @code{Stream_IO} instead of
-@code{Text_IO} for volume output, since this package has less overhead.
+@quotation
 
-If @code{Text_IO} must be used, note that by default output to the standard
-output and standard error files is unbuffered (this provides better
-behavior when output statements are used for debugging, or if the
-progress of a program is observed by tracking the output, e.g. by
-using the Unix @emph{tail -f} command to watch redirected output.
+@example
+$ gnatbind -u100 file
+@end example
+@end quotation
 
-If you are generating large volumes of output with @code{Text_IO} and
-performance is an important factor, use a designated file instead
-of the standard output file, or change the standard output file to
-be buffered using @code{Interfaces.C_Streams.setvbuf}.
+will buffer the stack usage information of the first 100 tasks to terminate and
+output this info at program termination. Results are displayed in four
+columns:
 
-@node Reducing Size of Executables with Unused Subprogram/Data Elimination,,Text_IO Suggestions,Improving Performance
-@anchor{gnat_ugn/gnat_and_program_execution id44}@anchor{1b9}@anchor{gnat_ugn/gnat_and_program_execution reducing-size-of-executables-with-unused-subprogram-data-elimination}@anchor{1ba}
-@subsection Reducing Size of Executables with Unused Subprogram/Data Elimination
+@quotation
 
+@example
+Index | Task Name | Stack Size | Stack Usage
+@end example
+@end quotation
 
-@geindex Uunused subprogram/data elimination
+where:
 
-This section describes how you can eliminate unused subprograms and data from
-your executable just by setting options at compilation time.
 
-@menu
-* About unused subprogram/data elimination:: 
-* Compilation options:: 
-* Example of unused subprogram/data elimination:: 
+@itemize *
 
-@end menu
+@item 
+@emph{Index} is a number associated with each task.
 
-@node About unused subprogram/data elimination,Compilation options,,Reducing Size of Executables with Unused Subprogram/Data Elimination
-@anchor{gnat_ugn/gnat_and_program_execution id45}@anchor{1bb}@anchor{gnat_ugn/gnat_and_program_execution about-unused-subprogram-data-elimination}@anchor{1bc}
-@subsubsection About unused subprogram/data elimination
+@item 
+@emph{Task Name} is the name of the task analyzed.
 
+@item 
+@emph{Stack Size} is the maximum size for the stack.
 
-By default, an executable contains all code and data of its composing objects
-(directly linked or coming from statically linked libraries), even data or code
-never used by this executable.
+@item 
+@emph{Stack Usage} is the measure done by the stack analyzer.
+In order to prevent overflow, the stack
+is not entirely analyzed, and it's not possible to know exactly how
+much has actually been used.
+@end itemize
 
-This feature will allow you to eliminate such unused code from your
-executable, making it smaller (in disk and in memory).
+By default the environment task stack, the stack that contains the main unit,
+is not processed. To enable processing of the environment task stack, the
+environment variable GNAT_STACK_LIMIT needs to be set to the maximum size of
+the environment task stack. This amount is given in kilobytes. For example:
 
-This functionality is available on all Linux platforms except for the IA-64
-architecture and on all cross platforms using the ELF binary file format.
-In both cases GNU binutils version 2.16 or later are required to enable it.
+@quotation
 
-@node Compilation options,Example of unused subprogram/data elimination,About unused subprogram/data elimination,Reducing Size of Executables with Unused Subprogram/Data Elimination
-@anchor{gnat_ugn/gnat_and_program_execution id46}@anchor{1bd}@anchor{gnat_ugn/gnat_and_program_execution compilation-options}@anchor{1be}
-@subsubsection Compilation options
+@example
+$ set GNAT_STACK_LIMIT 1600
+@end example
+@end quotation
 
+would specify to the analyzer that the environment task stack has a limit
+of 1.6 megabytes. Any stack usage beyond this will be ignored by the analysis.
 
-The operation of eliminating the unused code and data from the final executable
-is directly performed by the linker.
+The package @code{GNAT.Task_Stack_Usage} provides facilities to get
+stack-usage reports at run time. See its body for the details.
 
-@geindex -ffunction-sections (gcc)
+@node Memory Management Issues,,Stack Related Facilities,GNAT and Program Execution
+@anchor{gnat_ugn/gnat_and_program_execution id56}@anchor{14c}@anchor{gnat_ugn/gnat_and_program_execution memory-management-issues}@anchor{1ac}
+@section Memory Management Issues
 
-@geindex -fdata-sections (gcc)
 
-In order to do this, it has to work with objects compiled with the
-following options:
-@code{-ffunction-sections} @code{-fdata-sections}.
+This section describes some useful memory pools provided in the GNAT library
+and in particular the GNAT Debug Pool facility, which can be used to detect
+incorrect uses of access values (including 'dangling references').
 
-These options are usable with C and Ada files.
-They will place respectively each
-function or data in a separate section in the resulting object file.
 
-Once the objects and static libraries are created with these options, the
-linker can perform the dead code elimination. You can do this by setting
-the @code{-Wl,--gc-sections} option to gcc command or in the
-@code{-largs} section of @code{gnatmake}. This will perform a
-garbage collection of code and data never referenced.
+@menu
+* Some Useful Memory Pools:: 
+* The GNAT Debug Pool Facility:: 
 
-If the linker performs a partial link (@code{-r} linker option), then you
-will need to provide the entry point using the @code{-e} / @code{--entry}
-linker option.
+@end menu
 
-Note that objects compiled without the @code{-ffunction-sections} and
-@code{-fdata-sections} options can still be linked with the executable.
-However, no dead code elimination will be performed on those objects (they will
-be linked as is).
+@node Some Useful Memory Pools,The GNAT Debug Pool Facility,,Memory Management Issues
+@anchor{gnat_ugn/gnat_and_program_execution id57}@anchor{1ad}@anchor{gnat_ugn/gnat_and_program_execution some-useful-memory-pools}@anchor{1ae}
+@subsection Some Useful Memory Pools
 
-The GNAT static library is now compiled with -ffunction-sections and
--fdata-sections on some platforms. This allows you to eliminate the unused code
-and data of the GNAT library from your executable.
 
-@node Example of unused subprogram/data elimination,,Compilation options,Reducing Size of Executables with Unused Subprogram/Data Elimination
-@anchor{gnat_ugn/gnat_and_program_execution id47}@anchor{1bf}@anchor{gnat_ugn/gnat_and_program_execution example-of-unused-subprogram-data-elimination}@anchor{1c0}
-@subsubsection Example of unused subprogram/data elimination
+@geindex Memory Pool
 
+@geindex storage
+@geindex pool
 
-Here is a simple example:
+The @code{System.Pool_Global} package offers the Unbounded_No_Reclaim_Pool
+storage pool. Allocations use the standard system call @code{malloc} while
+deallocations use the standard system call @code{free}. No reclamation is
+performed when the pool goes out of scope. For performance reasons, the
+standard default Ada allocators/deallocators do not use any explicit storage
+pools but if they did, they could use this storage pool without any change in
+behavior. That is why this storage pool is used  when the user
+manages to make the default implicit allocator explicit as in this example:
 
 @quotation
 
 @example
-with Aux;
-
-procedure Test is
-begin
-   Aux.Used (10);
-end Test;
-
-package Aux is
-   Used_Data   : Integer;
-   Unused_Data : Integer;
-
-   procedure Used   (Data : Integer);
-   procedure Unused (Data : Integer);
-end Aux;
-
-package body Aux is
-   procedure Used (Data : Integer) is
-   begin
-      Used_Data := Data;
-   end Used;
+type T1 is access Something;
+ -- no Storage pool is defined for T2
 
-   procedure Unused (Data : Integer) is
-   begin
-      Unused_Data := Data;
-   end Unused;
-end Aux;
+type T2 is access Something_Else;
+for T2'Storage_Pool use T1'Storage_Pool;
+-- the above is equivalent to
+for T2'Storage_Pool use System.Pool_Global.Global_Pool_Object;
 @end example
 @end quotation
 
-@code{Unused} and @code{Unused_Data} are never referenced in this code
-excerpt, and hence they may be safely removed from the final executable.
+The @code{System.Pool_Local} package offers the @code{Unbounded_Reclaim_Pool} storage
+pool. The allocation strategy is similar to @code{Pool_Local}
+except that the all
+storage allocated with this pool is reclaimed when the pool object goes out of
+scope. This pool provides a explicit mechanism similar to the implicit one
+provided by several Ada 83 compilers for allocations performed through a local
+access type and whose purpose was to reclaim memory when exiting the
+scope of a given local access. As an example, the following program does not
+leak memory even though it does not perform explicit deallocation:
 
 @quotation
 
 @example
-$ gnatmake test
-
-$ nm test | grep used
-020015f0 T aux__unused
-02005d88 B aux__unused_data
-020015cc T aux__used
-02005d84 B aux__used_data
-
-$ gnatmake test -cargs -fdata-sections -ffunction-sections \\
-     -largs -Wl,--gc-sections
-
-$ nm test | grep used
-02005350 T aux__used
-0201ffe0 B aux__used_data
+with System.Pool_Local;
+procedure Pooloc1 is
+   procedure Internal is
+      type A is access Integer;
+      X : System.Pool_Local.Unbounded_Reclaim_Pool;
+      for A'Storage_Pool use X;
+      v : A;
+   begin
+      for I in  1 .. 50 loop
+         v := new Integer;
+      end loop;
+   end Internal;
+begin
+   for I in  1 .. 100 loop
+      Internal;
+   end loop;
+end Pooloc1;
 @end example
 @end quotation
 
-It can be observed that the procedure @code{Unused} and the object
-@code{Unused_Data} are removed by the linker when using the
-appropriate options.
-
-@geindex Overflow checks
-
-@geindex Checks (overflow)
-
-
-@node Overflow Check Handling in GNAT,Performing Dimensionality Analysis in GNAT,Improving Performance,GNAT and Program Execution
-@anchor{gnat_ugn/gnat_and_program_execution id55}@anchor{16a}@anchor{gnat_ugn/gnat_and_program_execution overflow-check-handling-in-gnat}@anchor{27}
-@section Overflow Check Handling in GNAT
-
-
-This section explains how to control the handling of overflow checks.
-
-@menu
-* Background:: 
-* Management of Overflows in GNAT:: 
-* Specifying the Desired Mode:: 
-* Default Settings:: 
-* Implementation Notes:: 
-
-@end menu
-
-@node Background,Management of Overflows in GNAT,,Overflow Check Handling in GNAT
-@anchor{gnat_ugn/gnat_and_program_execution id56}@anchor{1c1}@anchor{gnat_ugn/gnat_and_program_execution background}@anchor{1c2}
-@subsection Background
-
-
-Overflow checks are checks that the compiler may make to ensure
-that intermediate results are not out of range. For example:
+The @code{System.Pool_Size} package implements the @code{Stack_Bounded_Pool} used when
+@code{Storage_Size} is specified for an access type.
+The whole storage for the pool is
+allocated at once, usually on the stack at the point where the access type is
+elaborated. It is automatically reclaimed when exiting the scope where the
+access type is defined. This package is not intended to be used directly by the
+user and it is implicitly used for each such declaration:
 
 @quotation
 
 @example
-A : Integer;
-...
-A := A + 1;
+type T1 is access Something;
+for T1'Storage_Size use 10_000;
 @end example
 @end quotation
 
-If @code{A} has the value @code{Integer'Last}, then the addition may cause
-overflow since the result is out of range of the type @code{Integer}.
-In this case @code{Constraint_Error} will be raised if checks are
-enabled.
+@node The GNAT Debug Pool Facility,,Some Useful Memory Pools,Memory Management Issues
+@anchor{gnat_ugn/gnat_and_program_execution id58}@anchor{1af}@anchor{gnat_ugn/gnat_and_program_execution the-gnat-debug-pool-facility}@anchor{1b0}
+@subsection The GNAT Debug Pool Facility
 
-A trickier situation arises in examples like the following:
+
+@geindex Debug Pool
+
+@geindex storage
+@geindex pool
+@geindex memory corruption
+
+The use of unchecked deallocation and unchecked conversion can easily
+lead to incorrect memory references. The problems generated by such
+references are usually difficult to tackle because the symptoms can be
+very remote from the origin of the problem. In such cases, it is
+very helpful to detect the problem as early as possible. This is the
+purpose of the Storage Pool provided by @code{GNAT.Debug_Pools}.
+
+In order to use the GNAT specific debugging pool, the user must
+associate a debug pool object with each of the access types that may be
+related to suspected memory problems. See Ada Reference Manual 13.11.
 
 @quotation
 
 @example
-A, C : Integer;
-...
-A := (A + 1) + C;
+type Ptr is access Some_Type;
+Pool : GNAT.Debug_Pools.Debug_Pool;
+for Ptr'Storage_Pool use Pool;
 @end example
 @end quotation
 
-where @code{A} is @code{Integer'Last} and @code{C} is @code{-1}.
-Now the final result of the expression on the right hand side is
-@code{Integer'Last} which is in range, but the question arises whether the
-intermediate addition of @code{(A + 1)} raises an overflow error.
+@code{GNAT.Debug_Pools} is derived from a GNAT-specific kind of
+pool: the @code{Checked_Pool}. Such pools, like standard Ada storage pools,
+allow the user to redefine allocation and deallocation strategies. They
+also provide a checkpoint for each dereference, through the use of
+the primitive operation @code{Dereference} which is implicitly called at
+each dereference of an access value.
 
-The (perhaps surprising) answer is that the Ada language
-definition does not answer this question. Instead it leaves
-it up to the implementation to do one of two things if overflow
-checks are enabled.
+Once an access type has been associated with a debug pool, operations on
+values of the type may raise four distinct exceptions,
+which correspond to four potential kinds of memory corruption:
 
 
 @itemize *
 
 @item 
-raise an exception (@code{Constraint_Error}), or
+@code{GNAT.Debug_Pools.Accessing_Not_Allocated_Storage}
 
 @item 
-yield the correct mathematical result which is then used in
-subsequent operations.
-@end itemize
+@code{GNAT.Debug_Pools.Accessing_Deallocated_Storage}
 
-If the compiler chooses the first approach, then the assignment of this
-example will indeed raise @code{Constraint_Error} if overflow checking is
-enabled, or result in erroneous execution if overflow checks are suppressed.
+@item 
+@code{GNAT.Debug_Pools.Freeing_Not_Allocated_Storage}
 
-But if the compiler
-chooses the second approach, then it can perform both additions yielding
-the correct mathematical result, which is in range, so no exception
-will be raised, and the right result is obtained, regardless of whether
-overflow checks are suppressed.
+@item 
+@code{GNAT.Debug_Pools.Freeing_Deallocated_Storage}
+@end itemize
 
-Note that in the first example an
-exception will be raised in either case, since if the compiler
-gives the correct mathematical result for the addition, it will
-be out of range of the target type of the assignment, and thus
-fails the range check.
+For types associated with a Debug_Pool, dynamic allocation is performed using
+the standard GNAT allocation routine. References to all allocated chunks of
+memory are kept in an internal dictionary. Several deallocation strategies are
+provided, whereupon the user can choose to release the memory to the system,
+keep it allocated for further invalid access checks, or fill it with an easily
+recognizable pattern for debug sessions. The memory pattern is the old IBM
+hexadecimal convention: @code{16#DEADBEEF#}.
 
-This lack of specified behavior in the handling of overflow for
-intermediate results is a source of non-portability, and can thus
-be problematic when programs are ported. Most typically this arises
-in a situation where the original compiler did not raise an exception,
-and then the application is moved to a compiler where the check is
-performed on the intermediate result and an unexpected exception is
-raised.
+See the documentation in the file g-debpoo.ads for more information on the
+various strategies.
 
-Furthermore, when using Ada 2012's preconditions and other
-assertion forms, another issue arises. Consider:
+Upon each dereference, a check is made that the access value denotes a
+properly allocated memory location. Here is a complete example of use of
+@code{Debug_Pools}, that includes typical instances of  memory corruption:
 
 @quotation
 
 @example
-procedure P (A, B : Integer) with
-  Pre => A + B <= Integer'Last;
-@end example
-@end quotation
+with Gnat.Io; use Gnat.Io;
+with Unchecked_Deallocation;
+with Unchecked_Conversion;
+with GNAT.Debug_Pools;
+with System.Storage_Elements;
+with Ada.Exceptions; use Ada.Exceptions;
+procedure Debug_Pool_Test is
 
-One often wants to regard arithmetic in a context like this from
-a mathematical point of view. So for example, if the two actual parameters
-for a call to @code{P} are both @code{Integer'Last}, then
-the precondition should be regarded as False. If we are executing
-in a mode with run-time checks enabled for preconditions, then we would
-like this precondition to fail, rather than raising an exception
-because of the intermediate overflow.
+   type T is access Integer;
+   type U is access all T;
 
-However, the language definition leaves the specification of
-whether the above condition fails (raising @code{Assert_Error}) or
-causes an intermediate overflow (raising @code{Constraint_Error})
-up to the implementation.
+   P : GNAT.Debug_Pools.Debug_Pool;
+   for T'Storage_Pool use P;
 
-The situation is worse in a case such as the following:
+   procedure Free is new Unchecked_Deallocation (Integer, T);
+   function UC is new Unchecked_Conversion (U, T);
+   A, B : aliased T;
 
-@quotation
+   procedure Info is new GNAT.Debug_Pools.Print_Info(Put_Line);
 
-@example
-procedure Q (A, B, C : Integer) with
-  Pre => A + B + C <= Integer'Last;
+begin
+   Info (P);
+   A := new Integer;
+   B := new Integer;
+   B := A;
+   Info (P);
+   Free (A);
+   begin
+      Put_Line (Integer'Image(B.all));
+   exception
+      when E : others => Put_Line ("raised: " & Exception_Name (E));
+   end;
+   begin
+      Free (B);
+   exception
+      when E : others => Put_Line ("raised: " & Exception_Name (E));
+   end;
+   B := UC(A'Access);
+   begin
+      Put_Line (Integer'Image(B.all));
+   exception
+      when E : others => Put_Line ("raised: " & Exception_Name (E));
+   end;
+   begin
+      Free (B);
+   exception
+      when E : others => Put_Line ("raised: " & Exception_Name (E));
+   end;
+   Info (P);
+end Debug_Pool_Test;
 @end example
 @end quotation
 
-Consider the call
+The debug pool mechanism provides the following precise diagnostics on the
+execution of this erroneous program:
 
 @quotation
 
 @example
-Q (A => Integer'Last, B => 1, C => -1);
+Debug Pool info:
+  Total allocated bytes :  0
+  Total deallocated bytes :  0
+  Current Water Mark:  0
+  High Water Mark:  0
+
+Debug Pool info:
+  Total allocated bytes :  8
+  Total deallocated bytes :  0
+  Current Water Mark:  8
+  High Water Mark:  8
+
+raised: GNAT.DEBUG_POOLS.ACCESSING_DEALLOCATED_STORAGE
+raised: GNAT.DEBUG_POOLS.FREEING_DEALLOCATED_STORAGE
+raised: GNAT.DEBUG_POOLS.ACCESSING_NOT_ALLOCATED_STORAGE
+raised: GNAT.DEBUG_POOLS.FREEING_NOT_ALLOCATED_STORAGE
+Debug Pool info:
+  Total allocated bytes :  8
+  Total deallocated bytes :  4
+  Current Water Mark:  4
+  High Water Mark:  8
 @end example
 @end quotation
 
-From a mathematical point of view the precondition
-is True, but at run time we may (but are not guaranteed to) get an
-exception raised because of the intermediate overflow (and we really
-would prefer this precondition to be considered True at run time).
 
-@node Management of Overflows in GNAT,Specifying the Desired Mode,Background,Overflow Check Handling in GNAT
-@anchor{gnat_ugn/gnat_and_program_execution id57}@anchor{1c3}@anchor{gnat_ugn/gnat_and_program_execution management-of-overflows-in-gnat}@anchor{1c4}
-@subsection Management of Overflows in GNAT
+@c -- Non-breaking space in running text
+@c -- E.g. Ada |nbsp| 95
 
+@node Platform-Specific Information,Example of Binder Output File,GNAT and Program Execution,Top
+@anchor{gnat_ugn/platform_specific_information platform-specific-information}@anchor{d}@anchor{gnat_ugn/platform_specific_information doc}@anchor{1b1}@anchor{gnat_ugn/platform_specific_information id1}@anchor{1b2}
+@chapter Platform-Specific Information
 
-To deal with the portability issue, and with the problem of
-mathematical versus run-time interpretation of the expressions in
-assertions, GNAT provides comprehensive control over the handling
-of intermediate overflow. GNAT can operate in three modes, and
-furthemore, permits separate selection of operating modes for
-the expressions within assertions (here the term 'assertions'
-is used in the technical sense, which includes preconditions and so forth)
-and for expressions appearing outside assertions.
 
-The three modes are:
+This appendix contains information relating to the implementation
+of run-time libraries on various platforms and also covers
+topics related to the GNAT implementation on Windows and Mac OS.
 
+@menu
+* Run-Time Libraries:: 
+* Specifying a Run-Time Library:: 
+* GNU/Linux Topics:: 
+* Microsoft Windows Topics:: 
+* Mac OS Topics:: 
 
-@itemize *
+@end menu
 
-@item 
-@emph{Use base type for intermediate operations} (@code{STRICT})
+@node Run-Time Libraries,Specifying a Run-Time Library,,Platform-Specific Information
+@anchor{gnat_ugn/platform_specific_information id2}@anchor{1b3}@anchor{gnat_ugn/platform_specific_information run-time-libraries}@anchor{1b4}
+@section Run-Time Libraries
 
-In this mode, all intermediate results for predefined arithmetic
-operators are computed using the base type, and the result must
-be in range of the base type. If this is not the
-case then either an exception is raised (if overflow checks are
-enabled) or the execution is erroneous (if overflow checks are suppressed).
-This is the normal default mode.
 
-@item 
-@emph{Most intermediate overflows avoided} (@code{MINIMIZED})
+@geindex Tasking and threads libraries
 
-In this mode, the compiler attempts to avoid intermediate overflows by
-using a larger integer type, typically @code{Long_Long_Integer},
-as the type in which arithmetic is
-performed for predefined arithmetic operators. This may be slightly more
-expensive at
-run time (compared to suppressing intermediate overflow checks), though
-the cost is negligible on modern 64-bit machines. For the examples given
-earlier, no intermediate overflows would have resulted in exceptions,
-since the intermediate results are all in the range of
-@code{Long_Long_Integer} (typically 64-bits on nearly all implementations
-of GNAT). In addition, if checks are enabled, this reduces the number of
-checks that must be made, so this choice may actually result in an
-improvement in space and time behavior.
+@geindex Threads libraries and tasking
 
-However, there are cases where @code{Long_Long_Integer} is not large
-enough, consider the following example:
+@geindex Run-time libraries (platform-specific information)
+
+The GNAT run-time implementation may vary with respect to both the
+underlying threads library and the exception-handling scheme.
+For threads support, the default run-time will bind to the thread
+package of the underlying operating system.
+
+For exception handling, either or both of two models are supplied:
 
 @quotation
 
-@example
-procedure R (A, B, C, D : Integer) with
-  Pre => (A**2 * B**2) / (C**2 * D**2) <= 10;
-@end example
+@geindex Zero-Cost Exceptions
+
+@geindex ZCX (Zero-Cost Exceptions)
 @end quotation
 
-where @code{A} = @code{B} = @code{C} = @code{D} = @code{Integer'Last}.
-Now the intermediate results are
-out of the range of @code{Long_Long_Integer} even though the final result
-is in range and the precondition is True (from a mathematical point
-of view). In such a case, operating in this mode, an overflow occurs
-for the intermediate computation (which is why this mode
-says @emph{most} intermediate overflows are avoided). In this case,
-an exception is raised if overflow checks are enabled, and the
-execution is erroneous if overflow checks are suppressed.
 
-@item 
-@emph{All intermediate overflows avoided} (@code{ELIMINATED})
+@itemize *
 
-In this mode, the compiler  avoids all intermediate overflows
-by using arbitrary precision arithmetic as required. In this
-mode, the above example with @code{A**2 * B**2} would
-not cause intermediate overflow, because the intermediate result
-would be evaluated using sufficient precision, and the result
-of evaluating the precondition would be True.
+@item 
+@strong{Zero-Cost Exceptions} ("ZCX"),
+which uses binder-generated tables that
+are interrogated at run time to locate a handler.
 
-This mode has the advantage of avoiding any intermediate
-overflows, but at the expense of significant run-time overhead,
-including the use of a library (included automatically in this
-mode) for multiple-precision arithmetic.
+@geindex setjmp/longjmp Exception Model
 
-This mode provides cleaner semantics for assertions, since now
-the run-time behavior emulates true arithmetic behavior for the
-predefined arithmetic operators, meaning that there is never a
-conflict between the mathematical view of the assertion, and its
-run-time behavior.
+@geindex SJLJ (setjmp/longjmp Exception Model)
 
-Note that in this mode, the behavior is unaffected by whether or
-not overflow checks are suppressed, since overflow does not occur.
-It is possible for gigantic intermediate expressions to raise
-@code{Storage_Error} as a result of attempting to compute the
-results of such expressions (e.g. @code{Integer'Last ** Integer'Last})
-but overflow is impossible.
+@item 
+@strong{setjmp / longjmp} ('SJLJ'),
+which uses dynamically-set data to establish
+the set of handlers
 @end itemize
 
-Note that these modes apply only to the evaluation of predefined
-arithmetic, membership, and comparison operators for signed integer
-arithmetic.
+Most programs should experience a substantial speed improvement by
+being compiled with a ZCX run-time.
+This is especially true for
+tasking applications or applications with many exception handlers.
+Note however that the ZCX run-time does not support asynchronous abort
+of tasks (@code{abort} and @code{select-then-abort} constructs) and will instead
+implement abort by polling points in the runtime. You can also add additional
+polling points explicitly if needed in your application via @code{pragma
+Abort_Defer}.
 
-For fixed-point arithmetic, checks can be suppressed. But if checks
-are enabled
-then fixed-point values are always checked for overflow against the
-base type for intermediate expressions (that is such checks always
-operate in the equivalent of @code{STRICT} mode).
+This section summarizes which combinations of threads and exception support
+are supplied on various GNAT platforms.
 
-For floating-point, on nearly all architectures, @code{Machine_Overflows}
-is False, and IEEE infinities are generated, so overflow exceptions
-are never raised. If you want to avoid infinities, and check that
-final results of expressions are in range, then you can declare a
-constrained floating-point type, and range checks will be carried
-out in the normal manner (with infinite values always failing all
-range checks).
+@menu
+* Summary of Run-Time Configurations:: 
 
-@node Specifying the Desired Mode,Default Settings,Management of Overflows in GNAT,Overflow Check Handling in GNAT
-@anchor{gnat_ugn/gnat_and_program_execution specifying-the-desired-mode}@anchor{f8}@anchor{gnat_ugn/gnat_and_program_execution id58}@anchor{1c5}
-@subsection Specifying the Desired Mode
+@end menu
 
+@node Summary of Run-Time Configurations,,,Run-Time Libraries
+@anchor{gnat_ugn/platform_specific_information summary-of-run-time-configurations}@anchor{1b5}@anchor{gnat_ugn/platform_specific_information id3}@anchor{1b6}
+@subsection Summary of Run-Time Configurations
 
-@geindex pragma Overflow_Mode
 
-The desired mode of for handling intermediate overflow can be specified using
-either the @code{Overflow_Mode} pragma or an equivalent compiler switch.
-The pragma has the form
 
-@quotation
+@multitable {xxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxx} 
+@headitem
 
-@example
-pragma Overflow_Mode ([General =>] MODE [, [Assertions =>] MODE]);
-@end example
-@end quotation
+Platform
 
-where @code{MODE} is one of
+@tab
 
+Run-Time
 
-@itemize *
+@tab
 
-@item 
-@code{STRICT}:  intermediate overflows checked (using base type)
+Tasking
 
-@item 
-@code{MINIMIZED}: minimize intermediate overflows
+@tab
 
-@item 
-@code{ELIMINATED}: eliminate intermediate overflows
-@end itemize
+Exceptions
 
-The case is ignored, so @code{MINIMIZED}, @code{Minimized} and
-@code{minimized} all have the same effect.
+@item
 
-If only the @code{General} parameter is present, then the given @code{MODE} applies
-to expressions both within and outside assertions. If both arguments
-are present, then @code{General} applies to expressions outside assertions,
-and @code{Assertions} applies to expressions within assertions. For example:
+GNU/Linux
 
-@quotation
+@tab
 
-@example
-pragma Overflow_Mode
-  (General => Minimized, Assertions => Eliminated);
-@end example
-@end quotation
+rts-native
+(default)
 
-specifies that general expressions outside assertions be evaluated
-in 'minimize intermediate overflows' mode, and expressions within
-assertions be evaluated in 'eliminate intermediate overflows' mode.
-This is often a reasonable choice, avoiding excessive overhead
-outside assertions, but assuring a high degree of portability
-when importing code from another compiler, while incurring
-the extra overhead for assertion expressions to ensure that
-the behavior at run time matches the expected mathematical
-behavior.
+@tab
 
-The @code{Overflow_Mode} pragma has the same scoping and placement
-rules as pragma @code{Suppress}, so it can occur either as a
-configuration pragma, specifying a default for the whole
-program, or in a declarative scope, where it applies to the
-remaining declarations and statements in that scope.
+pthread library
 
-Note that pragma @code{Overflow_Mode} does not affect whether
-overflow checks are enabled or suppressed. It only controls the
-method used to compute intermediate values. To control whether
-overflow checking is enabled or suppressed, use pragma @code{Suppress}
-or @code{Unsuppress} in the usual manner.
+@tab
 
-@geindex -gnato? (gcc)
+ZCX
 
-@geindex -gnato?? (gcc)
+@item
 
-Additionally, a compiler switch @code{-gnato?} or @code{-gnato??}
-can be used to control the checking mode default (which can be subsequently
-overridden using pragmas).
+rts-sjlj
 
-Here @code{?} is one of the digits @code{1} through @code{3}:
+@tab
 
-@quotation
+pthread library
+
+@tab
 
+SJLJ
 
-@multitable {xxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx} 
 @item
 
-@code{1}
+Windows
 
 @tab
 
-use base type for intermediate operations (@code{STRICT})
+rts-native
+(default)
 
-@item
+@tab
 
-@code{2}
+native Win32 threads
 
 @tab
 
-minimize intermediate overflows (@code{MINIMIZED})
+ZCX
 
 @item
 
-@code{3}
+rts-sjlj
 
 @tab
 
-eliminate intermediate overflows (@code{ELIMINATED})
+native Win32 threads
 
-@end multitable
+@tab
 
-@end quotation
+SJLJ
 
-As with the pragma, if only one digit appears then it applies to all
-cases; if two digits are given, then the first applies outside
-assertions, and the second within assertions. Thus the equivalent
-of the example pragma above would be
-@code{-gnato23}.
+@item
 
-If no digits follow the @code{-gnato}, then it is equivalent to
-@code{-gnato11},
-causing all intermediate operations to be computed using the base
-type (@code{STRICT} mode).
+Mac OS
 
-@node Default Settings,Implementation Notes,Specifying the Desired Mode,Overflow Check Handling in GNAT
-@anchor{gnat_ugn/gnat_and_program_execution id59}@anchor{1c6}@anchor{gnat_ugn/gnat_and_program_execution default-settings}@anchor{1c7}
-@subsection Default Settings
+@tab
 
+rts-native
 
-The default mode for overflow checks is
+@tab
 
-@quotation
+pthread library
+
+@tab
+
+ZCX
+
+@end multitable
+
+
+@node Specifying a Run-Time Library,GNU/Linux Topics,Run-Time Libraries,Platform-Specific Information
+@anchor{gnat_ugn/platform_specific_information specifying-a-run-time-library}@anchor{1b7}@anchor{gnat_ugn/platform_specific_information id4}@anchor{1b8}
+@section Specifying a Run-Time Library
+
+
+The @code{adainclude} subdirectory containing the sources of the GNAT
+run-time library, and the @code{adalib} subdirectory containing the
+@code{ALI} files and the static and/or shared GNAT library, are located
+in the gcc target-dependent area:
+
+@quotation
 
 @example
-General => Strict
+target=$prefix/lib/gcc/gcc-*dumpmachine*/gcc-*dumpversion*/
 @end example
 @end quotation
 
-which causes all computations both inside and outside assertions to use
-the base type.
+As indicated above, on some platforms several run-time libraries are supplied.
+These libraries are installed in the target dependent area and
+contain a complete source and binary subdirectory. The detailed description
+below explains the differences between the different libraries in terms of
+their thread support.
 
-This retains compatibility with previous versions of
-GNAT which suppressed overflow checks by default and always
-used the base type for computation of intermediate results.
+The default run-time library (when GNAT is installed) is @emph{rts-native}.
+This default run-time is selected by the means of soft links.
+For example on x86-linux:
 
-@c Sphinx allows no emphasis within :index: role. As a workaround we
-@c point the index to "switch" and use emphasis for "-gnato".
+@c --
+@c --  $(target-dir)
+@c --      |
+@c --      +--- adainclude----------+
+@c --      |                        |
+@c --      +--- adalib-----------+  |
+@c --      |                     |  |
+@c --      +--- rts-native       |  |
+@c --      |    |                |  |
+@c --      |    +--- adainclude <---+
+@c --      |    |                |
+@c --      |    +--- adalib <----+
+@c --      |
+@c --      +--- rts-sjlj
+@c --           |
+@c --           +--- adainclude
+@c --           |
+@c --           +--- adalib
 
-The 
-@geindex -gnato (gcc)
-switch @code{-gnato} (with no digits following)
-is equivalent to
+
+@example
+               $(target-dir)
+              __/ /      \ \___
+      _______/   /        \    \_________________
+     /          /          \                     \
+    /          /            \                     \
+ADAINCLUDE  ADALIB      rts-native             rts-sjlj
+   :          :            /    \                 /   \
+   :          :           /      \               /     \
+   :          :          /        \             /       \
+   :          :         /          \           /         \
+   +-------------> adainclude     adalib   adainclude   adalib
+              :                     ^
+              :                     :
+              +---------------------+
+
+              Run-Time Library Directory Structure
+   (Upper-case names and dotted/dashed arrows represent soft links)
+@end example
+
+If the @emph{rts-sjlj} library is to be selected on a permanent basis,
+these soft links can be modified with the following commands:
 
 @quotation
 
 @example
-General => Strict
+$ cd $target
+$ rm -f adainclude adalib
+$ ln -s rts-sjlj/adainclude adainclude
+$ ln -s rts-sjlj/adalib adalib
 @end example
 @end quotation
 
-which causes overflow checking of all intermediate overflows
-both inside and outside assertions against the base type.
+Alternatively, you can specify @code{rts-sjlj/adainclude} in the file
+@code{$target/ada_source_path} and @code{rts-sjlj/adalib} in
+@code{$target/ada_object_path}.
 
-The pragma @code{Suppress (Overflow_Check)} disables overflow
-checking, but it has no effect on the method used for computing
-intermediate results.
+@geindex --RTS option
 
-The pragma @code{Unsuppress (Overflow_Check)} enables overflow
-checking, but it has no effect on the method used for computing
-intermediate results.
+Selecting another run-time library temporarily can be
+achieved by using the @code{--RTS} switch, e.g., @code{--RTS=sjlj}
+@anchor{gnat_ugn/platform_specific_information choosing-the-scheduling-policy}@anchor{1b9}
+@geindex SCHED_FIFO scheduling policy
 
-@node Implementation Notes,,Default Settings,Overflow Check Handling in GNAT
-@anchor{gnat_ugn/gnat_and_program_execution implementation-notes}@anchor{1c8}@anchor{gnat_ugn/gnat_and_program_execution id60}@anchor{1c9}
-@subsection Implementation Notes
+@geindex SCHED_RR scheduling policy
 
+@geindex SCHED_OTHER scheduling policy
 
-In practice on typical 64-bit machines, the @code{MINIMIZED} mode is
-reasonably efficient, and can be generally used. It also helps
-to ensure compatibility with code imported from some other
-compiler to GNAT.
+@menu
+* Choosing the Scheduling Policy:: 
 
-Setting all intermediate overflows checking (@code{CHECKED} mode)
-makes sense if you want to
-make sure that your code is compatible with any other possible
-Ada implementation. This may be useful in ensuring portability
-for code that is to be exported to some other compiler than GNAT.
+@end menu
 
-The Ada standard allows the reassociation of expressions at
-the same precedence level if no parentheses are present. For
-example, @code{A+B+C} parses as though it were @code{(A+B)+C}, but
-the compiler can reintepret this as @code{A+(B+C)}, possibly
-introducing or eliminating an overflow exception. The GNAT
-compiler never takes advantage of this freedom, and the
-expression @code{A+B+C} will be evaluated as @code{(A+B)+C}.
-If you need the other order, you can write the parentheses
-explicitly @code{A+(B+C)} and GNAT will respect this order.
+@node Choosing the Scheduling Policy,,,Specifying a Run-Time Library
+@anchor{gnat_ugn/platform_specific_information id5}@anchor{1ba}
+@subsection Choosing the Scheduling Policy
 
-The use of @code{ELIMINATED} mode will cause the compiler to
-automatically include an appropriate arbitrary precision
-integer arithmetic package. The compiler will make calls
-to this package, though only in cases where it cannot be
-sure that @code{Long_Long_Integer} is sufficient to guard against
-intermediate overflows. This package does not use dynamic
-alllocation, but it does use the secondary stack, so an
-appropriate secondary stack package must be present (this
-is always true for standard full Ada, but may require
-specific steps for restricted run times such as ZFP).
 
-Although @code{ELIMINATED} mode causes expressions to use arbitrary
-precision arithmetic, avoiding overflow, the final result
-must be in an appropriate range. This is true even if the
-final result is of type @code{[Long_[Long_]]Integer'Base}, which
-still has the same bounds as its associated constrained
-type at run-time.
+When using a POSIX threads implementation, you have a choice of several
+scheduling policies: @code{SCHED_FIFO}, @code{SCHED_RR} and @code{SCHED_OTHER}.
 
-Currently, the @code{ELIMINATED} mode is only available on target
-platforms for which @code{Long_Long_Integer} is 64-bits (nearly all GNAT
-platforms).
+Typically, the default is @code{SCHED_OTHER}, while using @code{SCHED_FIFO}
+or @code{SCHED_RR} requires special (e.g., root) privileges.
 
-@node Performing Dimensionality Analysis in GNAT,Stack Related Facilities,Overflow Check Handling in GNAT,GNAT and Program Execution
-@anchor{gnat_ugn/gnat_and_program_execution id61}@anchor{16b}@anchor{gnat_ugn/gnat_and_program_execution performing-dimensionality-analysis-in-gnat}@anchor{28}
-@section Performing Dimensionality Analysis in GNAT
+@geindex pragma Time_Slice
 
+@geindex -T0 option
 
-@geindex Dimensionality analysis
+@geindex pragma Task_Dispatching_Policy
 
-The GNAT compiler supports dimensionality checking. The user can
-specify physical units for objects, and the compiler will verify that uses
-of these objects are compatible with their dimensions, in a fashion that is
-familiar to engineering practice. The dimensions of algebraic expressions
-(including powers with static exponents) are computed from their constituents.
+By default, GNAT uses the @code{SCHED_OTHER} policy. To specify
+@code{SCHED_FIFO},
+you can use one of the following:
 
-@geindex Dimension_System aspect
 
-@geindex Dimension aspect
+@itemize *
 
-This feature depends on Ada 2012 aspect specifications, and is available from
-version 7.0.1 of GNAT onwards.
-The GNAT-specific aspect @code{Dimension_System}
-allows you to define a system of units; the aspect @code{Dimension}
-then allows the user to declare dimensioned quantities within a given system.
-(These aspects are described in the @emph{Implementation Defined Aspects}
-chapter of the @emph{GNAT Reference Manual}).
+@item 
+@code{pragma Time_Slice (0.0)}
 
-The major advantage of this model is that it does not require the declaration of
-multiple operators for all possible combinations of types: it is only necessary
-to use the proper subtypes in object declarations.
+@item 
+the corresponding binder option @code{-T0}
 
-@geindex System.Dim.Mks package (GNAT library)
+@item 
+@code{pragma Task_Dispatching_Policy (FIFO_Within_Priorities)}
+@end itemize
 
-@geindex MKS_Type type
+To specify @code{SCHED_RR},
+you should use @code{pragma Time_Slice} with a
+value greater than 0.0, or else use the corresponding @code{-T}
+binder option.
 
-The simplest way to impose dimensionality checking on a computation is to make
-use of the package @code{System.Dim.Mks},
-which is part of the GNAT library. This
-package defines a floating-point type @code{MKS_Type},
-for which a sequence of
-dimension names are specified, together with their conventional abbreviations.
-The following should be read together with the full specification of the
-package, in file @code{s-dimmks.ads}.
+To make sure a program is running as root, you can put something like
+this in a library package body in your application:
 
 @quotation
 
-@geindex s-dimmks.ads file
-
 @example
-type Mks_Type is new Long_Long_Float
-  with
-   Dimension_System => (
-     (Unit_Name => Meter,    Unit_Symbol => 'm',   Dim_Symbol => 'L'),
-     (Unit_Name => Kilogram, Unit_Symbol => "kg",  Dim_Symbol => 'M'),
-     (Unit_Name => Second,   Unit_Symbol => 's',   Dim_Symbol => 'T'),
-     (Unit_Name => Ampere,   Unit_Symbol => 'A',   Dim_Symbol => 'I'),
-     (Unit_Name => Kelvin,   Unit_Symbol => 'K',   Dim_Symbol => "Theta"),
-     (Unit_Name => Mole,     Unit_Symbol => "mol", Dim_Symbol => 'N'),
-     (Unit_Name => Candela,  Unit_Symbol => "cd",  Dim_Symbol => 'J'));
+function geteuid return Integer;
+pragma Import (C, geteuid, "geteuid");
+Ignore : constant Boolean :=
+  (if geteuid = 0 then True else raise Program_Error with "must be root");
 @end example
 @end quotation
 
-The package then defines a series of subtypes that correspond to these
-conventional units. For example:
-
-@quotation
+It gets the effective user id, and if it's not 0 (i.e. root), it raises
+Program_Error.
 
-@example
-subtype Length is Mks_Type
-  with
-   Dimension => (Symbol => 'm', Meter  => 1, others => 0);
-@end example
-@end quotation
+@geindex Linux
 
-and similarly for @code{Mass}, @code{Time}, @code{Electric_Current},
-@code{Thermodynamic_Temperature}, @code{Amount_Of_Substance}, and
-@code{Luminous_Intensity} (the standard set of units of the SI system).
+@geindex GNU/Linux
 
-The package also defines conventional names for values of each unit, for
-example:
+@node GNU/Linux Topics,Microsoft Windows Topics,Specifying a Run-Time Library,Platform-Specific Information
+@anchor{gnat_ugn/platform_specific_information id6}@anchor{1bb}@anchor{gnat_ugn/platform_specific_information gnu-linux-topics}@anchor{1bc}
+@section GNU/Linux Topics
 
-@quotation
 
-@example
-m   : constant Length           := 1.0;
-kg  : constant Mass             := 1.0;
-s   : constant Time             := 1.0;
-A   : constant Electric_Current := 1.0;
-@end example
-@end quotation
+This section describes topics that are specific to GNU/Linux platforms.
 
-as well as useful multiples of these units:
+@menu
+* Required Packages on GNU/Linux:: 
 
-@quotation
+@end menu
 
-@example
- cm  : constant Length := 1.0E-02;
- g   : constant Mass   := 1.0E-03;
- min : constant Time   := 60.0;
- day : constant Time   := 60.0 * 24.0 * min;
-...
-@end example
-@end quotation
+@node Required Packages on GNU/Linux,,,GNU/Linux Topics
+@anchor{gnat_ugn/platform_specific_information id7}@anchor{1bd}@anchor{gnat_ugn/platform_specific_information required-packages-on-gnu-linux}@anchor{1be}
+@subsection Required Packages on GNU/Linux
 
-Using this package, you can then define a derived unit by
-providing the aspect that
-specifies its dimensions within the MKS system, as well as the string to
-be used for output of a value of that unit:
 
-@quotation
+GNAT requires the C library developer's package to be installed.
+The name of of that package depends on your GNU/Linux distribution:
 
-@example
-subtype Acceleration is Mks_Type
-  with Dimension => ("m/sec^2",
-                     Meter => 1,
-                     Second => -2,
-                     others => 0);
-@end example
-@end quotation
 
-Here is a complete example of use:
+@itemize *
 
-@quotation
+@item 
+RedHat, SUSE: @code{glibc-devel};
 
-@example
-with System.Dim.MKS; use System.Dim.Mks;
-with System.Dim.Mks_IO; use System.Dim.Mks_IO;
-with Text_IO; use Text_IO;
-procedure Free_Fall is
-  subtype Acceleration is Mks_Type
-    with Dimension => ("m/sec^2", 1, 0, -2, others => 0);
-  G : constant acceleration := 9.81 * m / (s ** 2);
-  T : Time := 10.0*s;
-  Distance : Length;
-
-begin
-  Put ("Gravitational constant: ");
-  Put (G, Aft => 2, Exp => 0); Put_Line ("");
-  Distance := 0.5 * G * T ** 2;
-  Put ("distance travelled in 10 seconds of free fall ");
-  Put (Distance, Aft => 2, Exp => 0);
-  Put_Line ("");
-end Free_Fall;
-@end example
-@end quotation
-
-Execution of this program yields:
-
-@quotation
-
-@example
-Gravitational constant:  9.81 m/sec^2
-distance travelled in 10 seconds of free fall 490.50 m
-@end example
-@end quotation
-
-However, incorrect assignments such as:
+@item 
+Debian, Ubuntu: @code{libc6-dev} (normally installed by default).
+@end itemize
 
-@quotation
+If using the 32-bit version of GNAT on a 64-bit version of GNU/Linux,
+you'll need the 32-bit version of the following packages:
 
-@example
-Distance := 5.0;
-Distance := 5.0 * kg;
-@end example
-@end quotation
 
-are rejected with the following diagnoses:
+@itemize *
 
-@quotation
+@item 
+RedHat, SUSE: @code{glibc.i686}, @code{glibc-devel.i686}, @code{ncurses-libs.i686}
 
-@example
-Distance := 5.0;
-   >>> dimensions mismatch in assignment
-   >>> left-hand side has dimension [L]
-   >>> right-hand side is dimensionless
+@item 
+Debian, Ubuntu: @code{libc6:i386}, @code{libc6-dev:i386}, @code{lib32ncursesw5}
+@end itemize
 
-Distance := 5.0 * kg:
-   >>> dimensions mismatch in assignment
-   >>> left-hand side has dimension [L]
-   >>> right-hand side has dimension [M]
-@end example
-@end quotation
+Other GNU/Linux distributions might be choosing a different name
+for those packages.
 
-The dimensions of an expression are properly displayed, even if there is
-no explicit subtype for it. If we add to the program:
+@geindex Windows
 
-@quotation
+@node Microsoft Windows Topics,Mac OS Topics,GNU/Linux Topics,Platform-Specific Information
+@anchor{gnat_ugn/platform_specific_information microsoft-windows-topics}@anchor{1bf}@anchor{gnat_ugn/platform_specific_information id8}@anchor{1c0}
+@section Microsoft Windows Topics
 
-@example
-Put ("Final velocity: ");
-Put (G * T, Aft =>2, Exp =>0);
-Put_Line ("");
-@end example
-@end quotation
 
-then the output includes:
+This section describes topics that are specific to the Microsoft Windows
+platforms.
 
-@quotation
 
-@example
-Final velocity: 98.10 m.s**(-1)
-@end example
+@menu
+* Using GNAT on Windows:: 
+* Using a network installation of GNAT:: 
+* CONSOLE and WINDOWS subsystems:: 
+* Temporary Files:: 
+* Disabling Command Line Argument Expansion:: 
+* Windows Socket Timeouts:: 
+* Mixed-Language Programming on Windows:: 
+* Windows Specific Add-Ons:: 
 
-@geindex Dimensionable type
+@end menu
 
-@geindex Dimensioned subtype
-@end quotation
+@node Using GNAT on Windows,Using a network installation of GNAT,,Microsoft Windows Topics
+@anchor{gnat_ugn/platform_specific_information using-gnat-on-windows}@anchor{1c1}@anchor{gnat_ugn/platform_specific_information id9}@anchor{1c2}
+@subsection Using GNAT on Windows
 
-The type @code{Mks_Type} is said to be a @emph{dimensionable type} since it has a
-@code{Dimension_System} aspect, and the subtypes @code{Length}, @code{Mass}, etc.,
-are said to be @emph{dimensioned subtypes} since each one has a @code{Dimension}
-aspect.
 
-@quotation
+One of the strengths of the GNAT technology is that its tool set
+(@code{gcc}, @code{gnatbind}, @code{gnatlink}, @code{gnatmake}, the
+@code{gdb} debugger, etc.) is used in the same way regardless of the
+platform.
 
-@geindex Dimension Vector (for a dimensioned subtype)
+On Windows this tool set is complemented by a number of Microsoft-specific
+tools that have been provided to facilitate interoperability with Windows
+when this is required. With these tools:
 
-@geindex Dimension aspect
 
-@geindex Dimension_System aspect
-@end quotation
+@itemize *
 
-The @code{Dimension} aspect of a dimensioned subtype @code{S} defines a mapping
-from the base type's Unit_Names to integer (or, more generally, rational)
-values. This mapping is the @emph{dimension vector} (also referred to as the
-@emph{dimensionality}) for that subtype, denoted by @code{DV(S)}, and thus for each
-object of that subtype. Intuitively, the value specified for each
-@code{Unit_Name} is the exponent associated with that unit; a zero value
-means that the unit is not used. For example:
+@item 
+You can build applications using the @code{CONSOLE} or @code{WINDOWS}
+subsystems.
 
-@quotation
+@item 
+You can use any Dynamically Linked Library (DLL) in your Ada code (both
+relocatable and non-relocatable DLLs are supported).
 
-@example
-declare
-   Acc : Acceleration;
-   ...
-begin
-   ...
-end;
-@end example
-@end quotation
+@item 
+You can build Ada DLLs for use in other applications. These applications
+can be written in a language other than Ada (e.g., C, C++, etc). Again both
+relocatable and non-relocatable Ada DLLs are supported.
 
-Here @code{DV(Acc)} = @code{DV(Acceleration)} =
-@code{(Meter=>1, Kilogram=>0, Second=>-2, Ampere=>0, Kelvin=>0, Mole=>0, Candela=>0)}.
-Symbolically, we can express this as @code{Meter / Second**2}.
+@item 
+You can include Windows resources in your Ada application.
 
-The dimension vector of an arithmetic expression is synthesized from the
-dimension vectors of its components, with compile-time dimensionality checks
-that help prevent mismatches such as using an @code{Acceleration} where a
-@code{Length} is required.
+@item 
+You can use or create COM/DCOM objects.
+@end itemize
 
-The dimension vector of the result of an arithmetic expression @emph{expr}, or
-@code{DV(@emph{expr})}, is defined as follows, assuming conventional
-mathematical definitions for the vector operations that are used:
+Immediately below are listed all known general GNAT-for-Windows restrictions.
+Other restrictions about specific features like Windows Resources and DLLs
+are listed in separate sections below.
 
 
 @itemize *
 
 @item 
-If @emph{expr} is of the type @emph{universal_real}, or is not of a dimensioned subtype,
-then @emph{expr} is dimensionless; @code{DV(@emph{expr})} is the empty vector.
+It is not possible to use @code{GetLastError} and @code{SetLastError}
+when tasking, protected records, or exceptions are used. In these
+cases, in order to implement Ada semantics, the GNAT run-time system
+calls certain Win32 routines that set the last error variable to 0 upon
+success. It should be possible to use @code{GetLastError} and
+@code{SetLastError} when tasking, protected record, and exception
+features are not used, but it is not guaranteed to work.
 
 @item 
-@code{DV(@emph{op expr})}, where @emph{op} is a unary operator, is @code{DV(@emph{expr})}
+It is not possible to link against Microsoft C++ libraries except for
+import libraries. Interfacing must be done by the mean of DLLs.
 
 @item 
-@code{DV(@emph{expr1 op expr2})} where @emph{op} is "+" or "-" is @code{DV(@emph{expr1})}
-provided that @code{DV(@emph{expr1})} = @code{DV(@emph{expr2})}.
-If this condition is not met then the construct is illegal.
+It is possible to link against Microsoft C libraries. Yet the preferred
+solution is to use C/C++ compiler that comes with GNAT, since it
+doesn't require having two different development environments and makes the
+inter-language debugging experience smoother.
 
 @item 
-@code{DV(@emph{expr1} * @emph{expr2})} is @code{DV(@emph{expr1})} + @code{DV(@emph{expr2})},
-and @code{DV(@emph{expr1} / @emph{expr2})} = @code{DV(@emph{expr1})} - @code{DV(@emph{expr2})}.
-In this context if one of the @emph{expr}s is dimensionless then its empty
-dimension vector is treated as @code{(others => 0)}.
+When the compilation environment is located on FAT32 drives, users may
+experience recompilations of the source files that have not changed if
+Daylight Saving Time (DST) state has changed since the last time files
+were compiled. NTFS drives do not have this problem.
 
 @item 
-@code{DV(@emph{expr} ** @emph{power})} is @emph{power} * @code{DV(@emph{expr})},
-provided that @emph{power} is a static rational value. If this condition is not
-met then the construct is illegal.
+No components of the GNAT toolset use any entries in the Windows
+registry. The only entries that can be created are file associations and
+PATH settings, provided the user has chosen to create them at installation
+time, as well as some minimal book-keeping information needed to correctly
+uninstall or integrate different GNAT products.
 @end itemize
 
-Note that, by the above rules, it is illegal to use binary "+" or "-" to
-combine a dimensioned and dimensionless value.  Thus an expression such as
-@code{acc-10.0} is illegal, where @code{acc} is an object of subtype
-@code{Acceleration}.
+@node Using a network installation of GNAT,CONSOLE and WINDOWS subsystems,Using GNAT on Windows,Microsoft Windows Topics
+@anchor{gnat_ugn/platform_specific_information id10}@anchor{1c3}@anchor{gnat_ugn/platform_specific_information using-a-network-installation-of-gnat}@anchor{1c4}
+@subsection Using a network installation of GNAT
 
-The dimensionality checks for relationals use the same rules as
-for "+" and "-"; thus
+
+Make sure the system on which GNAT is installed is accessible from the
+current machine, i.e., the install location is shared over the network.
+Shared resources are accessed on Windows by means of UNC paths, which
+have the format @code{\\\\server\\sharename\\path}
+
+In order to use such a network installation, simply add the UNC path of the
+@code{bin} directory of your GNAT installation in front of your PATH. For
+example, if GNAT is installed in @code{\GNAT} directory of a share location
+called @code{c-drive} on a machine @code{LOKI}, the following command will
+make it available:
 
 @quotation
 
 @example
-acc > 10.0
+$ path \\loki\c-drive\gnat\bin;%path%`
 @end example
 @end quotation
 
-is equivalent to
+Be aware that every compilation using the network installation results in the
+transfer of large amounts of data across the network and will likely cause
+serious performance penalty.
+
+@node CONSOLE and WINDOWS subsystems,Temporary Files,Using a network installation of GNAT,Microsoft Windows Topics
+@anchor{gnat_ugn/platform_specific_information id11}@anchor{1c5}@anchor{gnat_ugn/platform_specific_information console-and-windows-subsystems}@anchor{1c6}
+@subsection CONSOLE and WINDOWS subsystems
+
+
+@geindex CONSOLE Subsystem
+
+@geindex WINDOWS Subsystem
+
+@geindex -mwindows
+
+There are two main subsystems under Windows. The @code{CONSOLE} subsystem
+(which is the default subsystem) will always create a console when
+launching the application. This is not something desirable when the
+application has a Windows GUI. To get rid of this console the
+application must be using the @code{WINDOWS} subsystem. To do so
+the @code{-mwindows} linker option must be specified.
 
 @quotation
 
 @example
-acc-10.0 > 0.0
+$ gnatmake winprog -largs -mwindows
 @end example
 @end quotation
 
-and is thus illegal. Analogously a conditional expression
-requires the same dimension vector for each branch.
+@node Temporary Files,Disabling Command Line Argument Expansion,CONSOLE and WINDOWS subsystems,Microsoft Windows Topics
+@anchor{gnat_ugn/platform_specific_information id12}@anchor{1c7}@anchor{gnat_ugn/platform_specific_information temporary-files}@anchor{1c8}
+@subsection Temporary Files
 
-The dimension vector of a type conversion @code{T(@emph{expr})} is defined
-as follows, based on the nature of @code{T}:
 
+@geindex Temporary files
 
-@itemize *
+It is possible to control where temporary files gets created by setting
+the 
+@geindex TMP
+@geindex environment variable; TMP
+@code{TMP} environment variable. The file will be created:
 
-@item 
-If @code{T} is a dimensioned subtype then @code{DV(T(@emph{expr}))} is @code{DV(T)}
-provided that either @emph{expr} is dimensionless or
-@code{DV(T)} = @code{DV(@emph{expr})}. The conversion is illegal
-if @emph{expr} is dimensioned and @code{DV(@emph{expr})} /= @code{DV(T)}.
-Note that vector equality does not require that the corresponding
-Unit_Names be the same.
 
-As a consequence of the above rule, it is possible to convert between
-different dimension systems that follow the same international system
-of units, with the seven physical components given in the standard order
-(length, mass, time, etc.). Thus a length in meters can be converted to
-a length in inches (with a suitable conversion factor) but cannot be
-converted, for example, to a mass in pounds.
+@itemize *
 
 @item 
-If @code{T} is the base type for @emph{expr} (and the dimensionless root type of
-the dimension system), then @code{DV(T(@emph{expr}))} is @code{DV(expr)}.
-Thus, if @emph{expr} is of a dimensioned subtype of @code{T}, the conversion may
-be regarded as a "view conversion" that preserves dimensionality.
+Under the directory pointed to by the 
+@geindex TMP
+@geindex environment variable; TMP
+@code{TMP} environment variable if
+this directory exists.
 
-This rule makes it possible to write generic code that can be instantiated
-with compatible dimensioned subtypes.  The generic unit will contain
-conversions that will consequently be present in instantiations, but
-conversions to the base type will preserve dimensionality and make it
-possible to write generic code that is correct with respect to
-dimensionality.
+@item 
+Under @code{c:\temp}, if the 
+@geindex TMP
+@geindex environment variable; TMP
+@code{TMP} environment variable is not
+set (or not pointing to a directory) and if this directory exists.
 
 @item 
-Otherwise (i.e., @code{T} is neither a dimensioned subtype nor a dimensionable
-base type), @code{DV(T(@emph{expr}))} is the empty vector. Thus a dimensioned
-value can be explicitly converted to a non-dimensioned subtype, which
-of course then escapes dimensionality analysis.
+Under the current working directory otherwise.
 @end itemize
 
-The dimension vector for a type qualification @code{T'(@emph{expr})} is the same
-as for the type conversion @code{T(@emph{expr})}.
-
-An assignment statement
-
-@quotation
-
-@example
-Source := Target;
-@end example
-@end quotation
+This allows you to determine exactly where the temporary
+file will be created. This is particularly useful in networked
+environments where you may not have write access to some
+directories.
 
-requires @code{DV(Source)} = @code{DV(Target)}, and analogously for parameter
-passing (the dimension vector for the actual parameter must be equal to the
-dimension vector for the formal parameter).
+@node Disabling Command Line Argument Expansion,Windows Socket Timeouts,Temporary Files,Microsoft Windows Topics
+@anchor{gnat_ugn/platform_specific_information disabling-command-line-argument-expansion}@anchor{1c9}
+@subsection Disabling Command Line Argument Expansion
 
-@node Stack Related Facilities,Memory Management Issues,Performing Dimensionality Analysis in GNAT,GNAT and Program Execution
-@anchor{gnat_ugn/gnat_and_program_execution stack-related-facilities}@anchor{29}@anchor{gnat_ugn/gnat_and_program_execution id62}@anchor{16c}
-@section Stack Related Facilities
 
+@geindex Command Line Argument Expansion
 
-This section describes some useful tools associated with stack
-checking and analysis. In
-particular, it deals with dynamic and static stack usage measurements.
+By default, an executable compiled for the Windows platform will do
+the following postprocessing on the arguments passed on the command
+line:
 
-@menu
-* Stack Overflow Checking:: 
-* Static Stack Usage Analysis:: 
-* Dynamic Stack Usage Analysis:: 
 
-@end menu
+@itemize *
 
-@node Stack Overflow Checking,Static Stack Usage Analysis,,Stack Related Facilities
-@anchor{gnat_ugn/gnat_and_program_execution id63}@anchor{1ca}@anchor{gnat_ugn/gnat_and_program_execution stack-overflow-checking}@anchor{f4}
-@subsection Stack Overflow Checking
+@item 
+If the argument contains the characters @code{*} and/or @code{?}, then
+file expansion will be attempted. For example, if the current directory
+contains @code{a.txt} and @code{b.txt}, then when calling:
 
+@example
+$ my_ada_program *.txt
+@end example
 
-@geindex Stack Overflow Checking
+The following arguments will effectively be passed to the main program
+(for example when using @code{Ada.Command_Line.Argument}):
 
-@geindex -fstack-check (gcc)
+@example
+Ada.Command_Line.Argument (1) -> "a.txt"
+Ada.Command_Line.Argument (2) -> "b.txt"
+@end example
 
-For most operating systems, @code{gcc} does not perform stack overflow
-checking by default. This means that if the main environment task or
-some other task exceeds the available stack space, then unpredictable
-behavior will occur. Most native systems offer some level of protection by
-adding a guard page at the end of each task stack. This mechanism is usually
-not enough for dealing properly with stack overflow situations because
-a large local variable could "jump" above the guard page.
-Furthermore, when the
-guard page is hit, there may not be any space left on the stack for executing
-the exception propagation code. Enabling stack checking avoids
-such situations.
+@item 
+Filename expansion can be disabled for a given argument by using single
+quotes. Thus, calling:
 
-To activate stack checking, compile all units with the @code{gcc} option
-@code{-fstack-check}. For example:
+@example
+$ my_ada_program '*.txt'
+@end example
 
-@quotation
+will result in:
 
 @example
-$ gcc -c -fstack-check package1.adb
+Ada.Command_Line.Argument (1) -> "*.txt"
 @end example
-@end quotation
-
-Units compiled with this option will generate extra instructions to check
-that any use of the stack (for procedure calls or for declaring local
-variables in declare blocks) does not exceed the available stack space.
-If the space is exceeded, then a @code{Storage_Error} exception is raised.
+@end itemize
 
-For declared tasks, the stack size is controlled by the size
-given in an applicable @code{Storage_Size} pragma or by the value specified
-at bind time with @code{-d} (@ref{11f,,Switches for gnatbind}) or is set to
-the default size as defined in the GNAT runtime otherwise.
+Note that if the program is launched from a shell such as Cygwin Bash
+then quote removal might be performed by the shell.
 
-@geindex GNAT_STACK_LIMIT
+In some contexts it might be useful to disable this feature (for example if
+the program performs its own argument expansion). In order to do this, a C
+symbol needs to be defined and set to @code{0}. You can do this by
+adding the following code fragment in one of your Ada units:
 
-For the environment task, the stack size depends on
-system defaults and is unknown to the compiler. Stack checking
-may still work correctly if a fixed
-size stack is allocated, but this cannot be guaranteed.
-To ensure that a clean exception is signalled for stack
-overflow, set the environment variable
-@geindex GNAT_STACK_LIMIT
-@geindex environment variable; GNAT_STACK_LIMIT
-@code{GNAT_STACK_LIMIT} to indicate the maximum
-stack area that can be used, as in:
+@example
+Do_Argv_Expansion : Integer := 0;
+pragma Export (C, Do_Argv_Expansion, "__gnat_do_argv_expansion");
+@end example
 
-@quotation
+The results of previous examples will be respectively:
 
 @example
-$ SET GNAT_STACK_LIMIT 1600
+Ada.Command_Line.Argument (1) -> "*.txt"
 @end example
-@end quotation
 
-The limit is given in kilobytes, so the above declaration would
-set the stack limit of the environment task to 1.6 megabytes.
-Note that the only purpose of this usage is to limit the amount
-of stack used by the environment task. If it is necessary to
-increase the amount of stack for the environment task, then this
-is an operating systems issue, and must be addressed with the
-appropriate operating systems commands.
+and:
 
-@node Static Stack Usage Analysis,Dynamic Stack Usage Analysis,Stack Overflow Checking,Stack Related Facilities
-@anchor{gnat_ugn/gnat_and_program_execution id64}@anchor{1cb}@anchor{gnat_ugn/gnat_and_program_execution static-stack-usage-analysis}@anchor{f5}
-@subsection Static Stack Usage Analysis
+@example
+Ada.Command_Line.Argument (1) -> "'*.txt'"
+@end example
 
+@node Windows Socket Timeouts,Mixed-Language Programming on Windows,Disabling Command Line Argument Expansion,Microsoft Windows Topics
+@anchor{gnat_ugn/platform_specific_information windows-socket-timeouts}@anchor{1ca}
+@subsection Windows Socket Timeouts
+
+
+Microsoft Windows desktops older than @code{8.0} and Microsoft Windows Servers
+older than @code{2019} set a socket timeout 500 milliseconds longer than the value
+set by setsockopt with @code{SO_RCVTIMEO} and @code{SO_SNDTIMEO} options. The GNAT
+runtime makes a correction for the difference in the corresponding Windows
+versions. For Windows Server starting with version @code{2019}, the user must
+provide a manifest file for the GNAT runtime to be able to recognize that
+the Windows version does not need the timeout correction. The manifest file
+should be located in the same directory as the executable file, and its file
+name must match the executable name suffixed by @code{.manifest}. For example,
+if the executable name is @code{sock_wto.exe}, then the manifest file name
+has to be @code{sock_wto.exe.manifest}. The manifest file must contain at
+least the following data:
+
+@example
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+<application>
+   <!-- Windows Vista -->
+   <supportedOS Id="@{e2011457-1546-43c5-a5fe-008deee3d3f0@}"/>
+   <!-- Windows 7 -->
+   <supportedOS Id="@{35138b9a-5d96-4fbd-8e2d-a2440225f93a@}"/>
+   <!-- Windows 8 -->
+   <supportedOS Id="@{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38@}"/>
+   <!-- Windows 8.1 -->
+   <supportedOS Id="@{1f676c76-80e1-4239-95bb-83d0f6d0da78@}"/>
+   <!-- Windows 10 -->
+   <supportedOS Id="@{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a@}"/>
+</application>
+</compatibility>
+</assembly>
+@end example
+
+Without the manifest file, the socket timeout is going to be overcorrected on
+these Windows Server versions and the actual time is going to be 500
+milliseconds shorter than what was set with GNAT.Sockets.Set_Socket_Option.
+Note that on Microsoft Windows versions where correction is necessary, there
+is no way to set a socket timeout shorter than 500 ms. If a socket timeout
+shorter than 500 ms is needed on these Windows versions, a call to
+Check_Selector should be added before any socket read or write operations.
+
+@node Mixed-Language Programming on Windows,Windows Specific Add-Ons,Windows Socket Timeouts,Microsoft Windows Topics
+@anchor{gnat_ugn/platform_specific_information id13}@anchor{1cb}@anchor{gnat_ugn/platform_specific_information mixed-language-programming-on-windows}@anchor{1cc}
+@subsection Mixed-Language Programming on Windows
 
-@geindex Static Stack Usage Analysis
 
-@geindex -fstack-usage
+Developing pure Ada applications on Windows is no different than on
+other GNAT-supported platforms. However, when developing or porting an
+application that contains a mix of Ada and C/C++, the choice of your
+Windows C/C++ development environment conditions your overall
+interoperability strategy.
 
-A unit compiled with @code{-fstack-usage} will generate an extra file
-that specifies
-the maximum amount of stack used, on a per-function basis.
-The file has the same
-basename as the target object file with a @code{.su} extension.
-Each line of this file is made up of three fields:
+If you use @code{gcc} or Microsoft C to compile the non-Ada part of
+your application, there are no Windows-specific restrictions that
+affect the overall interoperability with your Ada code. If you do want
+to use the Microsoft tools for your C++ code, you have two choices:
 
 
 @itemize *
 
 @item 
-The name of the function.
-
-@item 
-A number of bytes.
+Encapsulate your C++ code in a DLL to be linked with your Ada
+application. In this case, use the Microsoft or whatever environment to
+build the DLL and use GNAT to build your executable
+(@ref{1cd,,Using DLLs with GNAT}).
 
 @item 
-One or more qualifiers: @code{static}, @code{dynamic}, @code{bounded}.
+Or you can encapsulate your Ada code in a DLL to be linked with the
+other part of your application. In this case, use GNAT to build the DLL
+(@ref{1ce,,Building DLLs with GNAT Project files}) and use the Microsoft
+or whatever environment to build your executable.
 @end itemize
 
-The second field corresponds to the size of the known part of the function
-frame.
+In addition to the description about C main in
+@ref{2c,,Mixed Language Programming} section, if the C main uses a
+stand-alone library it is required on x86-windows to
+setup the SEH context. For this the C main must looks like this:
 
-The qualifier @code{static} means that the function frame size
-is purely static.
-It usually means that all local variables have a static size.
-In this case, the second field is a reliable measure of the function stack
-utilization.
+@quotation
 
-The qualifier @code{dynamic} means that the function frame size is not static.
-It happens mainly when some local variables have a dynamic size. When this
-qualifier appears alone, the second field is not a reliable measure
-of the function stack analysis. When it is qualified with  @code{bounded}, it
-means that the second field is a reliable maximum of the function stack
-utilization.
+@example
+/* main.c */
+extern void adainit (void);
+extern void adafinal (void);
+extern void __gnat_initialize(void*);
+extern void call_to_ada (void);
 
-A unit compiled with @code{-Wstack-usage} will issue a warning for each
-subprogram whose stack usage might be larger than the specified amount of
-bytes.  The wording is in keeping with the qualifier documented above.
+int main (int argc, char *argv[])
+@{
+  int SEH [2];
 
-@node Dynamic Stack Usage Analysis,,Static Stack Usage Analysis,Stack Related Facilities
-@anchor{gnat_ugn/gnat_and_program_execution id65}@anchor{1cc}@anchor{gnat_ugn/gnat_and_program_execution dynamic-stack-usage-analysis}@anchor{121}
-@subsection Dynamic Stack Usage Analysis
+  /* Initialize the SEH context */
+  __gnat_initialize (&SEH);
 
+  adainit();
 
-It is possible to measure the maximum amount of stack used by a task, by
-adding a switch to @code{gnatbind}, as:
+  /* Then call Ada services in the stand-alone library */
 
-@quotation
+  call_to_ada();
 
-@example
-$ gnatbind -u0 file
+  adafinal();
+@}
 @end example
 @end quotation
 
-With this option, at each task termination, its stack usage is  output on
-@code{stderr}.
-It is not always convenient to output the stack usage when the program
-is still running. Hence, it is possible to delay this output until program
-termination. for a given number of tasks specified as the argument of the
-@code{-u} option. For instance:
+Note that this is not needed on x86_64-windows where the Windows
+native SEH support is used.
 
-@quotation
+@menu
+* Windows Calling Conventions:: 
+* Introduction to Dynamic Link Libraries (DLLs): Introduction to Dynamic Link Libraries DLLs. 
+* Using DLLs with GNAT:: 
+* Building DLLs with GNAT Project files:: 
+* Building DLLs with GNAT:: 
+* Building DLLs with gnatdll:: 
+* Ada DLLs and Finalization:: 
+* Creating a Spec for Ada DLLs:: 
+* GNAT and Windows Resources:: 
+* Using GNAT DLLs from Microsoft Visual Studio Applications:: 
+* Debugging a DLL:: 
+* Setting Stack Size from gnatlink:: 
+* Setting Heap Size from gnatlink:: 
 
-@example
-$ gnatbind -u100 file
-@end example
-@end quotation
+@end menu
 
-will buffer the stack usage information of the first 100 tasks to terminate and
-output this info at program termination. Results are displayed in four
-columns:
+@node Windows Calling Conventions,Introduction to Dynamic Link Libraries DLLs,,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information windows-calling-conventions}@anchor{1cf}@anchor{gnat_ugn/platform_specific_information id14}@anchor{1d0}
+@subsubsection Windows Calling Conventions
 
-@quotation
 
-@example
-Index | Task Name | Stack Size | Stack Usage
-@end example
-@end quotation
+@geindex Stdcall
 
-where:
+@geindex APIENTRY
+
+This section pertain only to Win32. On Win64 there is a single native
+calling convention. All convention specifiers are ignored on this
+platform.
+
+When a subprogram @code{F} (caller) calls a subprogram @code{G}
+(callee), there are several ways to push @code{G}'s parameters on the
+stack and there are several possible scenarios to clean up the stack
+upon @code{G}'s return. A calling convention is an agreed upon software
+protocol whereby the responsibilities between the caller (@code{F}) and
+the callee (@code{G}) are clearly defined. Several calling conventions
+are available for Windows:
 
 
 @itemize *
 
 @item 
-@emph{Index} is a number associated with each task.
+@code{C} (Microsoft defined)
 
 @item 
-@emph{Task Name} is the name of the task analyzed.
+@code{Stdcall} (Microsoft defined)
 
 @item 
-@emph{Stack Size} is the maximum size for the stack.
+@code{Win32} (GNAT specific)
 
 @item 
-@emph{Stack Usage} is the measure done by the stack analyzer.
-In order to prevent overflow, the stack
-is not entirely analyzed, and it's not possible to know exactly how
-much has actually been used.
+@code{DLL} (GNAT specific)
 @end itemize
 
-The environment task stack, e.g., the stack that contains the main unit, is
-only processed when the environment variable GNAT_STACK_LIMIT is set.
+@menu
+* C Calling Convention:: 
+* Stdcall Calling Convention:: 
+* Win32 Calling Convention:: 
+* DLL Calling Convention:: 
 
-The package @code{GNAT.Task_Stack_Usage} provides facilities to get
-stack usage reports at run-time. See its body for the details.
+@end menu
 
-@node Memory Management Issues,,Stack Related Facilities,GNAT and Program Execution
-@anchor{gnat_ugn/gnat_and_program_execution id66}@anchor{16d}@anchor{gnat_ugn/gnat_and_program_execution memory-management-issues}@anchor{2a}
-@section Memory Management Issues
+@node C Calling Convention,Stdcall Calling Convention,,Windows Calling Conventions
+@anchor{gnat_ugn/platform_specific_information c-calling-convention}@anchor{1d1}@anchor{gnat_ugn/platform_specific_information id15}@anchor{1d2}
+@subsubsection @code{C} Calling Convention
 
 
-This section describes some useful memory pools provided in the GNAT library
-and in particular the GNAT Debug Pool facility, which can be used to detect
-incorrect uses of access values (including 'dangling references').
+This is the default calling convention used when interfacing to C/C++
+routines compiled with either @code{gcc} or Microsoft Visual C++.
 
+In the @code{C} calling convention subprogram parameters are pushed on the
+stack by the caller from right to left. The caller itself is in charge of
+cleaning up the stack after the call. In addition, the name of a routine
+with @code{C} calling convention is mangled by adding a leading underscore.
 
-@menu
-* Some Useful Memory Pools:: 
-* The GNAT Debug Pool Facility:: 
+The name to use on the Ada side when importing (or exporting) a routine
+with @code{C} calling convention is the name of the routine. For
+instance the C function:
 
-@end menu
+@quotation
 
-@node Some Useful Memory Pools,The GNAT Debug Pool Facility,,Memory Management Issues
-@anchor{gnat_ugn/gnat_and_program_execution id67}@anchor{1cd}@anchor{gnat_ugn/gnat_and_program_execution some-useful-memory-pools}@anchor{1ce}
-@subsection Some Useful Memory Pools
+@example
+int get_val (long);
+@end example
+@end quotation
 
+should be imported from Ada as follows:
 
-@geindex Memory Pool
+@quotation
 
-@geindex storage
-@geindex pool
+@example
+function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
+pragma Import (C, Get_Val, External_Name => "get_val");
+@end example
+@end quotation
 
-The @code{System.Pool_Global} package offers the Unbounded_No_Reclaim_Pool
-storage pool. Allocations use the standard system call @code{malloc} while
-deallocations use the standard system call @code{free}. No reclamation is
-performed when the pool goes out of scope. For performance reasons, the
-standard default Ada allocators/deallocators do not use any explicit storage
-pools but if they did, they could use this storage pool without any change in
-behavior. That is why this storage pool is used  when the user
-manages to make the default implicit allocator explicit as in this example:
+Note that in this particular case the @code{External_Name} parameter could
+have been omitted since, when missing, this parameter is taken to be the
+name of the Ada entity in lower case. When the @code{Link_Name} parameter
+is missing, as in the above example, this parameter is set to be the
+@code{External_Name} with a leading underscore.
+
+When importing a variable defined in C, you should always use the @code{C}
+calling convention unless the object containing the variable is part of a
+DLL (in which case you should use the @code{Stdcall} calling
+convention, @ref{1d3,,Stdcall Calling Convention}).
+
+@node Stdcall Calling Convention,Win32 Calling Convention,C Calling Convention,Windows Calling Conventions
+@anchor{gnat_ugn/platform_specific_information stdcall-calling-convention}@anchor{1d3}@anchor{gnat_ugn/platform_specific_information id16}@anchor{1d4}
+@subsubsection @code{Stdcall} Calling Convention
+
+
+This convention, which was the calling convention used for Pascal
+programs, is used by Microsoft for all the routines in the Win32 API for
+efficiency reasons. It must be used to import any routine for which this
+convention was specified.
+
+In the @code{Stdcall} calling convention subprogram parameters are pushed
+on the stack by the caller from right to left. The callee (and not the
+caller) is in charge of cleaning the stack on routine exit. In addition,
+the name of a routine with @code{Stdcall} calling convention is mangled by
+adding a leading underscore (as for the @code{C} calling convention) and a
+trailing @code{@@@emph{nn}}, where @code{nn} is the overall size (in
+bytes) of the parameters passed to the routine.
+
+The name to use on the Ada side when importing a C routine with a
+@code{Stdcall} calling convention is the name of the C routine. The leading
+underscore and trailing @code{@@@emph{nn}} are added automatically by
+the compiler. For instance the Win32 function:
 
 @quotation
 
 @example
-type T1 is access Something;
- -- no Storage pool is defined for T2
-
-type T2 is access Something_Else;
-for T2'Storage_Pool use T1'Storage_Pool;
--- the above is equivalent to
-for T2'Storage_Pool use System.Pool_Global.Global_Pool_Object;
+APIENTRY int get_val (long);
 @end example
 @end quotation
 
-The @code{System.Pool_Local} package offers the @code{Unbounded_Reclaim_Pool} storage
-pool. The allocation strategy is similar to @code{Pool_Local}
-except that the all
-storage allocated with this pool is reclaimed when the pool object goes out of
-scope. This pool provides a explicit mechanism similar to the implicit one
-provided by several Ada 83 compilers for allocations performed through a local
-access type and whose purpose was to reclaim memory when exiting the
-scope of a given local access. As an example, the following program does not
-leak memory even though it does not perform explicit deallocation:
+should be imported from Ada as follows:
 
 @quotation
 
 @example
-with System.Pool_Local;
-procedure Pooloc1 is
-   procedure Internal is
-      type A is access Integer;
-      X : System.Pool_Local.Unbounded_Reclaim_Pool;
-      for A'Storage_Pool use X;
-      v : A;
-   begin
-      for I in  1 .. 50 loop
-         v := new Integer;
-      end loop;
-   end Internal;
-begin
-   for I in  1 .. 100 loop
-      Internal;
-   end loop;
-end Pooloc1;
+function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
+pragma Import (Stdcall, Get_Val);
+--  On the x86 a long is 4 bytes, so the Link_Name is "_get_val@@4"
 @end example
 @end quotation
 
-The @code{System.Pool_Size} package implements the @code{Stack_Bounded_Pool} used when
-@code{Storage_Size} is specified for an access type.
-The whole storage for the pool is
-allocated at once, usually on the stack at the point where the access type is
-elaborated. It is automatically reclaimed when exiting the scope where the
-access type is defined. This package is not intended to be used directly by the
-user and it is implicitly used for each such declaration:
+As for the @code{C} calling convention, when the @code{External_Name}
+parameter is missing, it is taken to be the name of the Ada entity in lower
+case. If instead of writing the above import pragma you write:
 
 @quotation
 
 @example
-type T1 is access Something;
-for T1'Storage_Size use 10_000;
+function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
+pragma Import (Stdcall, Get_Val, External_Name => "retrieve_val");
 @end example
 @end quotation
 
-@node The GNAT Debug Pool Facility,,Some Useful Memory Pools,Memory Management Issues
-@anchor{gnat_ugn/gnat_and_program_execution id68}@anchor{1cf}@anchor{gnat_ugn/gnat_and_program_execution the-gnat-debug-pool-facility}@anchor{1d0}
-@subsection The GNAT Debug Pool Facility
+then the imported routine is @code{_retrieve_val@@4}. However, if instead
+of specifying the @code{External_Name} parameter you specify the
+@code{Link_Name} as in the following example:
 
+@quotation
 
-@geindex Debug Pool
+@example
+function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
+pragma Import (Stdcall, Get_Val, Link_Name => "retrieve_val");
+@end example
+@end quotation
 
-@geindex storage
-@geindex pool
-@geindex memory corruption
+then the imported routine is @code{retrieve_val}, that is, there is no
+decoration at all. No leading underscore and no Stdcall suffix
+@code{@@@emph{nn}}.
 
-The use of unchecked deallocation and unchecked conversion can easily
-lead to incorrect memory references. The problems generated by such
-references are usually difficult to tackle because the symptoms can be
-very remote from the origin of the problem. In such cases, it is
-very helpful to detect the problem as early as possible. This is the
-purpose of the Storage Pool provided by @code{GNAT.Debug_Pools}.
+This is especially important as in some special cases a DLL's entry
+point name lacks a trailing @code{@@@emph{nn}} while the exported
+name generated for a call has it.
 
-In order to use the GNAT specific debugging pool, the user must
-associate a debug pool object with each of the access types that may be
-related to suspected memory problems. See Ada Reference Manual 13.11.
+It is also possible to import variables defined in a DLL by using an
+import pragma for a variable. As an example, if a DLL contains a
+variable defined as:
 
 @quotation
 
 @example
-type Ptr is access Some_Type;
-Pool : GNAT.Debug_Pools.Debug_Pool;
-for Ptr'Storage_Pool use Pool;
+int my_var;
 @end example
 @end quotation
 
-@code{GNAT.Debug_Pools} is derived from a GNAT-specific kind of
-pool: the @code{Checked_Pool}. Such pools, like standard Ada storage pools,
-allow the user to redefine allocation and deallocation strategies. They
-also provide a checkpoint for each dereference, through the use of
-the primitive operation @code{Dereference} which is implicitly called at
-each dereference of an access value.
-
-Once an access type has been associated with a debug pool, operations on
-values of the type may raise four distinct exceptions,
-which correspond to four potential kinds of memory corruption:
-
+then, to access this variable from Ada you should write:
 
-@itemize *
+@quotation
 
-@item 
-@code{GNAT.Debug_Pools.Accessing_Not_Allocated_Storage}
+@example
+My_Var : Interfaces.C.int;
+pragma Import (Stdcall, My_Var);
+@end example
+@end quotation
 
-@item 
-@code{GNAT.Debug_Pools.Accessing_Deallocated_Storage}
+Note that to ease building cross-platform bindings this convention
+will be handled as a @code{C} calling convention on non-Windows platforms.
 
-@item 
-@code{GNAT.Debug_Pools.Freeing_Not_Allocated_Storage}
+@node Win32 Calling Convention,DLL Calling Convention,Stdcall Calling Convention,Windows Calling Conventions
+@anchor{gnat_ugn/platform_specific_information win32-calling-convention}@anchor{1d5}@anchor{gnat_ugn/platform_specific_information id17}@anchor{1d6}
+@subsubsection @code{Win32} Calling Convention
 
-@item 
-@code{GNAT.Debug_Pools.Freeing_Deallocated_Storage}
-@end itemize
 
-For types associated with a Debug_Pool, dynamic allocation is performed using
-the standard GNAT allocation routine. References to all allocated chunks of
-memory are kept in an internal dictionary. Several deallocation strategies are
-provided, whereupon the user can choose to release the memory to the system,
-keep it allocated for further invalid access checks, or fill it with an easily
-recognizable pattern for debug sessions. The memory pattern is the old IBM
-hexadecimal convention: @code{16#DEADBEEF#}.
+This convention, which is GNAT-specific is fully equivalent to the
+@code{Stdcall} calling convention described above.
 
-See the documentation in the file g-debpoo.ads for more information on the
-various strategies.
+@node DLL Calling Convention,,Win32 Calling Convention,Windows Calling Conventions
+@anchor{gnat_ugn/platform_specific_information id18}@anchor{1d7}@anchor{gnat_ugn/platform_specific_information dll-calling-convention}@anchor{1d8}
+@subsubsection @code{DLL} Calling Convention
 
-Upon each dereference, a check is made that the access value denotes a
-properly allocated memory location. Here is a complete example of use of
-@code{Debug_Pools}, that includes typical instances of  memory corruption:
 
-@quotation
+This convention, which is GNAT-specific is fully equivalent to the
+@code{Stdcall} calling convention described above.
 
-@example
-with Gnat.Io; use Gnat.Io;
-with Unchecked_Deallocation;
-with Unchecked_Conversion;
-with GNAT.Debug_Pools;
-with System.Storage_Elements;
-with Ada.Exceptions; use Ada.Exceptions;
-procedure Debug_Pool_Test is
+@node Introduction to Dynamic Link Libraries DLLs,Using DLLs with GNAT,Windows Calling Conventions,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information id19}@anchor{1d9}@anchor{gnat_ugn/platform_specific_information introduction-to-dynamic-link-libraries-dlls}@anchor{1da}
+@subsubsection Introduction to Dynamic Link Libraries (DLLs)
 
-   type T is access Integer;
-   type U is access all T;
 
-   P : GNAT.Debug_Pools.Debug_Pool;
-   for T'Storage_Pool use P;
+@geindex DLL
 
-   procedure Free is new Unchecked_Deallocation (Integer, T);
-   function UC is new Unchecked_Conversion (U, T);
-   A, B : aliased T;
+A Dynamically Linked Library (DLL) is a library that can be shared by
+several applications running under Windows. A DLL can contain any number of
+routines and variables.
 
-   procedure Info is new GNAT.Debug_Pools.Print_Info(Put_Line);
+One advantage of DLLs is that you can change and enhance them without
+forcing all the applications that depend on them to be relinked or
+recompiled. However, you should be aware than all calls to DLL routines are
+slower since, as you will understand below, such calls are indirect.
 
-begin
-   Info (P);
-   A := new Integer;
-   B := new Integer;
-   B := A;
-   Info (P);
-   Free (A);
-   begin
-      Put_Line (Integer'Image(B.all));
-   exception
-      when E : others => Put_Line ("raised: " & Exception_Name (E));
-   end;
-   begin
-      Free (B);
-   exception
-      when E : others => Put_Line ("raised: " & Exception_Name (E));
-   end;
-   B := UC(A'Access);
-   begin
-      Put_Line (Integer'Image(B.all));
-   exception
-      when E : others => Put_Line ("raised: " & Exception_Name (E));
-   end;
-   begin
-      Free (B);
-   exception
-      when E : others => Put_Line ("raised: " & Exception_Name (E));
-   end;
-   Info (P);
-end Debug_Pool_Test;
-@end example
-@end quotation
-
-The debug pool mechanism provides the following precise diagnostics on the
-execution of this erroneous program:
-
-@quotation
-
-@example
-Debug Pool info:
-  Total allocated bytes :  0
-  Total deallocated bytes :  0
-  Current Water Mark:  0
-  High Water Mark:  0
-
-Debug Pool info:
-  Total allocated bytes :  8
-  Total deallocated bytes :  0
-  Current Water Mark:  8
-  High Water Mark:  8
+To illustrate the remainder of this section, suppose that an application
+wants to use the services of a DLL @code{API.dll}. To use the services
+provided by @code{API.dll} you must statically link against the DLL or
+an import library which contains a jump table with an entry for each
+routine and variable exported by the DLL. In the Microsoft world this
+import library is called @code{API.lib}. When using GNAT this import
+library is called either @code{libAPI.dll.a}, @code{libapi.dll.a},
+@code{libAPI.a} or @code{libapi.a} (names are case insensitive).
 
-raised: GNAT.DEBUG_POOLS.ACCESSING_DEALLOCATED_STORAGE
-raised: GNAT.DEBUG_POOLS.FREEING_DEALLOCATED_STORAGE
-raised: GNAT.DEBUG_POOLS.ACCESSING_NOT_ALLOCATED_STORAGE
-raised: GNAT.DEBUG_POOLS.FREEING_NOT_ALLOCATED_STORAGE
-Debug Pool info:
-  Total allocated bytes :  8
-  Total deallocated bytes :  4
-  Current Water Mark:  4
-  High Water Mark:  8
-@end example
-@end quotation
+After you have linked your application with the DLL or the import library
+and you run your application, here is what happens:
 
 
-@c -- Non-breaking space in running text
-@c -- E.g. Ada |nbsp| 95
+@itemize *
 
-@node Platform-Specific Information,Example of Binder Output File,GNAT and Program Execution,Top
-@anchor{gnat_ugn/platform_specific_information platform-specific-information}@anchor{d}@anchor{gnat_ugn/platform_specific_information doc}@anchor{1d1}@anchor{gnat_ugn/platform_specific_information id1}@anchor{1d2}
-@chapter Platform-Specific Information
+@item 
+Your application is loaded into memory.
 
+@item 
+The DLL @code{API.dll} is mapped into the address space of your
+application. This means that:
 
-This appendix contains information relating to the implementation
-of run-time libraries on various platforms and also covers
-topics related to the GNAT implementation on Windows and Mac OS.
 
-@menu
-* Run-Time Libraries:: 
-* Specifying a Run-Time Library:: 
-* Microsoft Windows Topics:: 
-* Mac OS Topics:: 
+@itemize -
 
-@end menu
+@item 
+The DLL will use the stack of the calling thread.
 
-@node Run-Time Libraries,Specifying a Run-Time Library,,Platform-Specific Information
-@anchor{gnat_ugn/platform_specific_information id2}@anchor{1d3}@anchor{gnat_ugn/platform_specific_information run-time-libraries}@anchor{2b}
-@section Run-Time Libraries
+@item 
+The DLL will use the virtual address space of the calling process.
 
+@item 
+The DLL will allocate memory from the virtual address space of the calling
+process.
 
-@geindex Tasking and threads libraries
+@item 
+Handles (pointers) can be safely exchanged between routines in the DLL
+routines and routines in the application using the DLL.
+@end itemize
 
-@geindex Threads libraries and tasking
+@item 
+The entries in the jump table (from the import library @code{libAPI.dll.a}
+or @code{API.lib} or automatically created when linking against a DLL)
+which is part of your application are initialized with the addresses
+of the routines and variables in @code{API.dll}.
 
-@geindex Run-time libraries (platform-specific information)
+@item 
+If present in @code{API.dll}, routines @code{DllMain} or
+@code{DllMainCRTStartup} are invoked. These routines typically contain
+the initialization code needed for the well-being of the routines and
+variables exported by the DLL.
+@end itemize
 
-The GNAT run-time implementation may vary with respect to both the
-underlying threads library and the exception-handling scheme.
-For threads support, the default run-time will bind to the thread
-package of the underlying operating system.
+There is an additional point which is worth mentioning. In the Windows
+world there are two kind of DLLs: relocatable and non-relocatable
+DLLs. Non-relocatable DLLs can only be loaded at a very specific address
+in the target application address space. If the addresses of two
+non-relocatable DLLs overlap and these happen to be used by the same
+application, a conflict will occur and the application will run
+incorrectly. Hence, when possible, it is always preferable to use and
+build relocatable DLLs. Both relocatable and non-relocatable DLLs are
+supported by GNAT. Note that the @code{-s} linker option (see GNU Linker
+User's Guide) removes the debugging symbols from the DLL but the DLL can
+still be relocated.
 
-For exception handling, either or both of two models are supplied:
+As a side note, an interesting difference between Microsoft DLLs and
+Unix shared libraries, is the fact that on most Unix systems all public
+routines are exported by default in a Unix shared library, while under
+Windows it is possible (but not required) to list exported routines in
+a definition file (see @ref{1db,,The Definition File}).
 
-@quotation
+@node Using DLLs with GNAT,Building DLLs with GNAT Project files,Introduction to Dynamic Link Libraries DLLs,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information id20}@anchor{1dc}@anchor{gnat_ugn/platform_specific_information using-dlls-with-gnat}@anchor{1cd}
+@subsubsection Using DLLs with GNAT
 
-@geindex Zero-Cost Exceptions
 
-@geindex ZCX (Zero-Cost Exceptions)
-@end quotation
+To use the services of a DLL, say @code{API.dll}, in your Ada application
+you must have:
 
 
 @itemize *
 
 @item 
-@strong{Zero-Cost Exceptions} ("ZCX"),
-which uses binder-generated tables that
-are interrogated at run time to locate a handler.
-
-@geindex setjmp/longjmp Exception Model
+The Ada spec for the routines and/or variables you want to access in
+@code{API.dll}. If not available this Ada spec must be built from the C/C++
+header files provided with the DLL.
 
-@geindex SJLJ (setjmp/longjmp Exception Model)
+@item 
+The import library (@code{libAPI.dll.a} or @code{API.lib}). As previously
+mentioned an import library is a statically linked library containing the
+import table which will be filled at load time to point to the actual
+@code{API.dll} routines. Sometimes you don't have an import library for the
+DLL you want to use. The following sections will explain how to build
+one. Note that this is optional.
 
 @item 
-@strong{setjmp / longjmp} ('SJLJ'),
-which uses dynamically-set data to establish
-the set of handlers
+The actual DLL, @code{API.dll}.
 @end itemize
 
-Most programs should experience a substantial speed improvement by
-being compiled with a ZCX run-time.
-This is especially true for
-tasking applications or applications with many exception handlers.@}
+Once you have all the above, to compile an Ada application that uses the
+services of @code{API.dll} and whose main subprogram is @code{My_Ada_App},
+you simply issue the command
 
-This section summarizes which combinations of threads and exception support
-are supplied on various GNAT platforms.
-It then shows how to select a particular library either
-permanently or temporarily,
-explains the properties of (and tradeoffs among) the various threads
-libraries, and provides some additional
-information about several specific platforms.
+@quotation
 
-@menu
-* Summary of Run-Time Configurations:: 
+@example
+$ gnatmake my_ada_app -largs -lAPI
+@end example
+@end quotation
 
-@end menu
+The argument @code{-largs -lAPI} at the end of the @code{gnatmake} command
+tells the GNAT linker to look for an import library. The linker will
+look for a library name in this specific order:
 
-@node Summary of Run-Time Configurations,,,Run-Time Libraries
-@anchor{gnat_ugn/platform_specific_information summary-of-run-time-configurations}@anchor{1d4}@anchor{gnat_ugn/platform_specific_information id3}@anchor{1d5}
-@subsection Summary of Run-Time Configurations
 
+@itemize *
 
+@item 
+@code{libAPI.dll.a}
 
-@multitable {xxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxx} 
-@headitem
+@item 
+@code{API.dll.a}
 
-Platform
+@item 
+@code{libAPI.a}
 
-@tab
+@item 
+@code{API.lib}
 
-Run-Time
+@item 
+@code{libAPI.dll}
 
-@tab
+@item 
+@code{API.dll}
+@end itemize
 
-Tasking
+The first three are the GNU style import libraries. The third is the
+Microsoft style import libraries. The last two are the actual DLL names.
 
-@tab
+Note that if the Ada package spec for @code{API.dll} contains the
+following pragma
 
-Exceptions
+@quotation
 
-@item
+@example
+pragma Linker_Options ("-lAPI");
+@end example
+@end quotation
 
-GNU/Linux
+you do not have to add @code{-largs -lAPI} at the end of the
+@code{gnatmake} command.
 
-@tab
+If any one of the items above is missing you will have to create it
+yourself. The following sections explain how to do so using as an
+example a fictitious DLL called @code{API.dll}.
 
-rts-native
-(default)
+@menu
+* Creating an Ada Spec for the DLL Services:: 
+* Creating an Import Library:: 
 
-@tab
+@end menu
 
-pthread library
+@node Creating an Ada Spec for the DLL Services,Creating an Import Library,,Using DLLs with GNAT
+@anchor{gnat_ugn/platform_specific_information id21}@anchor{1dd}@anchor{gnat_ugn/platform_specific_information creating-an-ada-spec-for-the-dll-services}@anchor{1de}
+@subsubsection Creating an Ada Spec for the DLL Services
 
-@tab
 
-ZCX
+A DLL typically comes with a C/C++ header file which provides the
+definitions of the routines and variables exported by the DLL. The Ada
+equivalent of this header file is a package spec that contains definitions
+for the imported entities. If the DLL you intend to use does not come with
+an Ada spec you have to generate one such spec yourself. For example if
+the header file of @code{API.dll} is a file @code{api.h} containing the
+following two definitions:
 
-@item
+@quotation
 
-rts-sjlj
+@example
+int some_var;
+int get (char *);
+@end example
+@end quotation
 
-@tab
+then the equivalent Ada spec could be:
 
-pthread library
+@quotation
 
-@tab
-
-SJLJ
-
-@item
-
-Windows
-
-@tab
+@example
+with Interfaces.C.Strings;
+package API is
+   use Interfaces;
 
-rts-native
-(default)
+   Some_Var : C.int;
+   function Get (Str : C.Strings.Chars_Ptr) return C.int;
 
-@tab
+private
+   pragma Import (C, Get);
+   pragma Import (DLL, Some_Var);
+end API;
+@end example
+@end quotation
 
-native Win32 threads
+@node Creating an Import Library,,Creating an Ada Spec for the DLL Services,Using DLLs with GNAT
+@anchor{gnat_ugn/platform_specific_information id22}@anchor{1df}@anchor{gnat_ugn/platform_specific_information creating-an-import-library}@anchor{1e0}
+@subsubsection Creating an Import Library
 
-@tab
 
-ZCX
+@geindex Import library
 
-@item
+If a Microsoft-style import library @code{API.lib} or a GNAT-style
+import library @code{libAPI.dll.a} or @code{libAPI.a} is available
+with @code{API.dll} you can skip this section. You can also skip this
+section if @code{API.dll} or @code{libAPI.dll} is built with GNU tools
+as in this case it is possible to link directly against the
+DLL. Otherwise read on.
 
-rts-sjlj
+@geindex Definition file
+@anchor{gnat_ugn/platform_specific_information the-definition-file}@anchor{1db}
+@subsubheading The Definition File
 
-@tab
 
-native Win32 threads
+As previously mentioned, and unlike Unix systems, the list of symbols
+that are exported from a DLL must be provided explicitly in Windows.
+The main goal of a definition file is precisely that: list the symbols
+exported by a DLL. A definition file (usually a file with a @code{.def}
+suffix) has the following structure:
 
-@tab
+@quotation
 
-SJLJ
+@example
+[LIBRARY `@w{`}name`@w{`}]
+[DESCRIPTION `@w{`}string`@w{`}]
+EXPORTS
+   `@w{`}symbol1`@w{`}
+   `@w{`}symbol2`@w{`}
+   ...
+@end example
+@end quotation
 
-@item
 
-Mac OS
+@table @asis
 
-@tab
+@item @emph{LIBRARY name}
 
-rts-native
+This section, which is optional, gives the name of the DLL.
 
-@tab
+@item @emph{DESCRIPTION string}
 
-pthread library
+This section, which is optional, gives a description string that will be
+embedded in the import library.
 
-@tab
+@item @emph{EXPORTS}
 
-ZCX
+This section gives the list of exported symbols (procedures, functions or
+variables). For instance in the case of @code{API.dll} the @code{EXPORTS}
+section of @code{API.def} looks like:
 
-@end multitable
+@example
+EXPORTS
+   some_var
+   get
+@end example
+@end table
 
+Note that you must specify the correct suffix (@code{@@@emph{nn}})
+(see @ref{1cf,,Windows Calling Conventions}) for a Stdcall
+calling convention function in the exported symbols list.
 
-@node Specifying a Run-Time Library,Microsoft Windows Topics,Run-Time Libraries,Platform-Specific Information
-@anchor{gnat_ugn/platform_specific_information specifying-a-run-time-library}@anchor{1d6}@anchor{gnat_ugn/platform_specific_information id4}@anchor{1d7}
-@section Specifying a Run-Time Library
+There can actually be other sections in a definition file, but these
+sections are not relevant to the discussion at hand.
+@anchor{gnat_ugn/platform_specific_information create-def-file-automatically}@anchor{1e1}
+@subsubheading Creating a Definition File Automatically
 
 
-The @code{adainclude} subdirectory containing the sources of the GNAT
-run-time library, and the @code{adalib} subdirectory containing the
-@code{ALI} files and the static and/or shared GNAT library, are located
-in the gcc target-dependent area:
+You can automatically create the definition file @code{API.def}
+(see @ref{1db,,The Definition File}) from a DLL.
+For that use the @code{dlltool} program as follows:
 
 @quotation
 
 @example
-target=$prefix/lib/gcc/gcc-*dumpmachine*/gcc-*dumpversion*/
+$ dlltool API.dll -z API.def --export-all-symbols
 @end example
-@end quotation
 
-As indicated above, on some platforms several run-time libraries are supplied.
-These libraries are installed in the target dependent area and
-contain a complete source and binary subdirectory. The detailed description
-below explains the differences between the different libraries in terms of
-their thread support.
+Note that if some routines in the DLL have the @code{Stdcall} convention
+(@ref{1cf,,Windows Calling Conventions}) with stripped @code{@@@emph{nn}}
+suffix then you'll have to edit @code{api.def} to add it, and specify
+@code{-k} to @code{gnatdll} when creating the import library.
 
-The default run-time library (when GNAT is installed) is @emph{rts-native}.
-This default run-time is selected by the means of soft links.
-For example on x86-linux:
+Here are some hints to find the right @code{@@@emph{nn}} suffix.
 
-@c --
-@c --  $(target-dir)
-@c --      |
-@c --      +--- adainclude----------+
-@c --      |                        |
-@c --      +--- adalib-----------+  |
-@c --      |                     |  |
-@c --      +--- rts-native       |  |
-@c --      |    |                |  |
-@c --      |    +--- adainclude <---+
-@c --      |    |                |
-@c --      |    +--- adalib <----+
-@c --      |
-@c --      +--- rts-sjlj
-@c --           |
-@c --           +--- adainclude
-@c --           |
-@c --           +--- adalib
 
+@itemize -
 
-@example
-               $(target-dir)
-              __/ /      \ \___
-      _______/   /        \    \_________________
-     /          /          \                     \
-    /          /            \                     \
-ADAINCLUDE  ADALIB      rts-native             rts-sjlj
-   :          :            /    \                 /   \
-   :          :           /      \               /     \
-   :          :          /        \             /       \
-   :          :         /          \           /         \
-   +-------------> adainclude     adalib   adainclude   adalib
-              :                     ^
-              :                     :
-              +---------------------+
+@item 
+If you have the Microsoft import library (.lib), it is possible to get
+the right symbols by using Microsoft @code{dumpbin} tool (see the
+corresponding Microsoft documentation for further details).
 
-              Run-Time Library Directory Structure
-   (Upper-case names and dotted/dashed arrows represent soft links)
+@example
+$ dumpbin /exports api.lib
 @end example
 
-If the @emph{rts-sjlj} library is to be selected on a permanent basis,
-these soft links can be modified with the following commands:
+@item 
+If you have a message about a missing symbol at link time the compiler
+tells you what symbol is expected. You just have to go back to the
+definition file and add the right suffix.
+@end itemize
+@end quotation
+@anchor{gnat_ugn/platform_specific_information gnat-style-import-library}@anchor{1e2}
+@subsubheading GNAT-Style Import Library
+
+
+To create a static import library from @code{API.dll} with the GNAT tools
+you should create the .def file, then use @code{gnatdll} tool
+(see @ref{1e3,,Using gnatdll}) as follows:
 
 @quotation
 
 @example
-$ cd $target
-$ rm -f adainclude adalib
-$ ln -s rts-sjlj/adainclude adainclude
-$ ln -s rts-sjlj/adalib adalib
+$ gnatdll -e API.def -d API.dll
 @end example
+
+@code{gnatdll} takes as input a definition file @code{API.def} and the
+name of the DLL containing the services listed in the definition file
+@code{API.dll}. The name of the static import library generated is
+computed from the name of the definition file as follows: if the
+definition file name is @code{xyz.def}, the import library name will
+be @code{libxyz.a}. Note that in the previous example option
+@code{-e} could have been removed because the name of the definition
+file (before the @code{.def} suffix) is the same as the name of the
+DLL (@ref{1e3,,Using gnatdll} for more information about @code{gnatdll}).
 @end quotation
+@anchor{gnat_ugn/platform_specific_information msvs-style-import-library}@anchor{1e4}
+@subsubheading Microsoft-Style Import Library
 
-Alternatively, you can specify @code{rts-sjlj/adainclude} in the file
-@code{$target/ada_source_path} and @code{rts-sjlj/adalib} in
-@code{$target/ada_object_path}.
 
-@geindex --RTS option
+A Microsoft import library is needed only if you plan to make an
+Ada DLL available to applications developed with Microsoft
+tools (@ref{1cc,,Mixed-Language Programming on Windows}).
 
-Selecting another run-time library temporarily can be
-achieved by using the @code{--RTS} switch, e.g., @code{--RTS=sjlj}
-@anchor{gnat_ugn/platform_specific_information choosing-the-scheduling-policy}@anchor{1d8}
-@geindex SCHED_FIFO scheduling policy
+To create a Microsoft-style import library for @code{API.dll} you
+should create the .def file, then build the actual import library using
+Microsoft's @code{lib} utility:
 
-@geindex SCHED_RR scheduling policy
+@quotation
 
-@geindex SCHED_OTHER scheduling policy
+@example
+$ lib -machine:IX86 -def:API.def -out:API.lib
+@end example
 
-@menu
-* Choosing the Scheduling Policy:: 
+If you use the above command the definition file @code{API.def} must
+contain a line giving the name of the DLL:
 
-@end menu
+@example
+LIBRARY      "API"
+@end example
 
-@node Choosing the Scheduling Policy,,,Specifying a Run-Time Library
-@anchor{gnat_ugn/platform_specific_information id5}@anchor{1d9}
-@subsection Choosing the Scheduling Policy
+See the Microsoft documentation for further details about the usage of
+@code{lib}.
+@end quotation
 
+@node Building DLLs with GNAT Project files,Building DLLs with GNAT,Using DLLs with GNAT,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information id23}@anchor{1e5}@anchor{gnat_ugn/platform_specific_information building-dlls-with-gnat-project-files}@anchor{1ce}
+@subsubsection Building DLLs with GNAT Project files
 
-When using a POSIX threads implementation, you have a choice of several
-scheduling policies: @code{SCHED_FIFO}, @code{SCHED_RR} and @code{SCHED_OTHER}.
 
-Typically, the default is @code{SCHED_OTHER}, while using @code{SCHED_FIFO}
-or @code{SCHED_RR} requires special (e.g., root) privileges.
+@geindex DLLs
+@geindex building
 
-@geindex pragma Time_Slice
+There is nothing specific to Windows in the build process.
+See the @emph{Library Projects} section in the @emph{GNAT Project Manager}
+chapter of the @emph{GPRbuild User's Guide}.
 
-@geindex -T0 option
+Due to a system limitation, it is not possible under Windows to create threads
+when inside the @code{DllMain} routine which is used for auto-initialization
+of shared libraries, so it is not possible to have library level tasks in SALs.
 
-@geindex pragma Task_Dispatching_Policy
+@node Building DLLs with GNAT,Building DLLs with gnatdll,Building DLLs with GNAT Project files,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information building-dlls-with-gnat}@anchor{1e6}@anchor{gnat_ugn/platform_specific_information id24}@anchor{1e7}
+@subsubsection Building DLLs with GNAT
 
-By default, GNAT uses the @code{SCHED_OTHER} policy. To specify
-@code{SCHED_FIFO},
-you can use one of the following:
+
+@geindex DLLs
+@geindex building
+
+This section explain how to build DLLs using the GNAT built-in DLL
+support. With the following procedure it is straight forward to build
+and use DLLs with GNAT.
 
 
 @itemize *
 
 @item 
-@code{pragma Time_Slice (0.0)}
+Building object files.
+The first step is to build all objects files that are to be included
+into the DLL. This is done by using the standard @code{gnatmake} tool.
 
 @item 
-the corresponding binder option @code{-T0}
+Building the DLL.
+To build the DLL you must use the @code{gcc} @code{-shared} and
+@code{-shared-libgcc} options. It is quite simple to use this method:
 
-@item 
-@code{pragma Task_Dispatching_Policy (FIFO_Within_Priorities)}
-@end itemize
+@example
+$ gcc -shared -shared-libgcc -o api.dll obj1.o obj2.o ...
+@end example
 
-To specify @code{SCHED_RR},
-you should use @code{pragma Time_Slice} with a
-value greater than 0.0, or else use the corresponding @code{-T}
-binder option.
-
-To make sure a program is running as root, you can put something like
-this in a library package body in your application:
-
-@quotation
+It is important to note that in this case all symbols found in the
+object files are automatically exported. It is possible to restrict
+the set of symbols to export by passing to @code{gcc} a definition
+file (see @ref{1db,,The Definition File}).
+For example:
 
 @example
-function geteuid return Integer;
-pragma Import (C, geteuid, "geteuid");
-Ignore : constant Boolean :=
-  (if geteuid = 0 then True else raise Program_Error with "must be root");
+$ gcc -shared -shared-libgcc -o api.dll api.def obj1.o obj2.o ...
 @end example
-@end quotation
-
-It gets the effective user id, and if it's not 0 (i.e. root), it raises
-Program_Error.
-
-@geindex Windows
-
-@node Microsoft Windows Topics,Mac OS Topics,Specifying a Run-Time Library,Platform-Specific Information
-@anchor{gnat_ugn/platform_specific_information id6}@anchor{1da}@anchor{gnat_ugn/platform_specific_information microsoft-windows-topics}@anchor{2c}
-@section Microsoft Windows Topics
 
+If you use a definition file you must export the elaboration procedures
+for every package that required one. Elaboration procedures are named
+using the package name followed by "_E".
 
-This section describes topics that are specific to the Microsoft Windows
-platforms.
+@item 
+Preparing DLL to be used.
+For the DLL to be used by client programs the bodies must be hidden
+from it and the .ali set with read-only attribute. This is very important
+otherwise GNAT will recompile all packages and will not actually use
+the code in the DLL. For example:
 
+@example
+$ mkdir apilib
+$ copy *.ads *.ali api.dll apilib
+$ attrib +R apilib\\*.ali
+@end example
+@end itemize
 
+At this point it is possible to use the DLL by directly linking
+against it. Note that you must use the GNAT shared runtime when using
+GNAT shared libraries. This is achieved by using the @code{-shared} binder
+option.
 
+@quotation
 
+@example
+$ gnatmake main -Iapilib -bargs -shared -largs -Lapilib -lAPI
+@end example
+@end quotation
 
-@menu
-* Using GNAT on Windows:: 
-* Using a network installation of GNAT:: 
-* CONSOLE and WINDOWS subsystems:: 
-* Temporary Files:: 
-* Disabling Command Line Argument Expansion:: 
-* Mixed-Language Programming on Windows:: 
-* Windows Specific Add-Ons:: 
+@node Building DLLs with gnatdll,Ada DLLs and Finalization,Building DLLs with GNAT,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information building-dlls-with-gnatdll}@anchor{1e8}@anchor{gnat_ugn/platform_specific_information id25}@anchor{1e9}
+@subsubsection Building DLLs with gnatdll
 
-@end menu
 
-@node Using GNAT on Windows,Using a network installation of GNAT,,Microsoft Windows Topics
-@anchor{gnat_ugn/platform_specific_information using-gnat-on-windows}@anchor{1db}@anchor{gnat_ugn/platform_specific_information id7}@anchor{1dc}
-@subsection Using GNAT on Windows
+@geindex DLLs
+@geindex building
 
+Note that it is preferred to use GNAT Project files
+(@ref{1ce,,Building DLLs with GNAT Project files}) or the built-in GNAT
+DLL support (@ref{1e6,,Building DLLs with GNAT}) or to build DLLs.
 
-One of the strengths of the GNAT technology is that its tool set
-(@code{gcc}, @code{gnatbind}, @code{gnatlink}, @code{gnatmake}, the
-@code{gdb} debugger, etc.) is used in the same way regardless of the
-platform.
+This section explains how to build DLLs containing Ada code using
+@code{gnatdll}. These DLLs will be referred to as Ada DLLs in the
+remainder of this section.
 
-On Windows this tool set is complemented by a number of Microsoft-specific
-tools that have been provided to facilitate interoperability with Windows
-when this is required. With these tools:
+The steps required to build an Ada DLL that is to be used by Ada as well as
+non-Ada applications are as follows:
 
 
 @itemize *
 
 @item 
-You can build applications using the @code{CONSOLE} or @code{WINDOWS}
-subsystems.
+You need to mark each Ada entity exported by the DLL with a @code{C} or
+@code{Stdcall} calling convention to avoid any Ada name mangling for the
+entities exported by the DLL
+(see @ref{1ea,,Exporting Ada Entities}). You can
+skip this step if you plan to use the Ada DLL only from Ada applications.
 
 @item 
-You can use any Dynamically Linked Library (DLL) in your Ada code (both
-relocatable and non-relocatable DLLs are supported).
+Your Ada code must export an initialization routine which calls the routine
+@code{adainit} generated by @code{gnatbind} to perform the elaboration of
+the Ada code in the DLL (@ref{1eb,,Ada DLLs and Elaboration}). The initialization
+routine exported by the Ada DLL must be invoked by the clients of the DLL
+to initialize the DLL.
 
 @item 
-You can build Ada DLLs for use in other applications. These applications
-can be written in a language other than Ada (e.g., C, C++, etc). Again both
-relocatable and non-relocatable Ada DLLs are supported.
+When useful, the DLL should also export a finalization routine which calls
+routine @code{adafinal} generated by @code{gnatbind} to perform the
+finalization of the Ada code in the DLL (@ref{1ec,,Ada DLLs and Finalization}).
+The finalization routine exported by the Ada DLL must be invoked by the
+clients of the DLL when the DLL services are no further needed.
 
 @item 
-You can include Windows resources in your Ada application.
+You must provide a spec for the services exported by the Ada DLL in each
+of the programming languages to which you plan to make the DLL available.
 
 @item 
-You can use or create COM/DCOM objects.
+You must provide a definition file listing the exported entities
+(@ref{1db,,The Definition File}).
+
+@item 
+Finally you must use @code{gnatdll} to produce the DLL and the import
+library (@ref{1e3,,Using gnatdll}).
 @end itemize
 
-Immediately below are listed all known general GNAT-for-Windows restrictions.
-Other restrictions about specific features like Windows Resources and DLLs
-are listed in separate sections below.
+Note that a relocatable DLL stripped using the @code{strip}
+binutils tool will not be relocatable anymore. To build a DLL without
+debug information pass @code{-largs -s} to @code{gnatdll}. This
+restriction does not apply to a DLL built using a Library Project.
+See the @emph{Library Projects} section in the @emph{GNAT Project Manager}
+chapter of the @emph{GPRbuild User's Guide}.
 
+@c Limitations_When_Using_Ada_DLLs_from Ada:
 
-@itemize *
+@menu
+* Limitations When Using Ada DLLs from Ada:: 
+* Exporting Ada Entities:: 
+* Ada DLLs and Elaboration:: 
 
-@item 
-It is not possible to use @code{GetLastError} and @code{SetLastError}
-when tasking, protected records, or exceptions are used. In these
-cases, in order to implement Ada semantics, the GNAT run-time system
-calls certain Win32 routines that set the last error variable to 0 upon
-success. It should be possible to use @code{GetLastError} and
-@code{SetLastError} when tasking, protected record, and exception
-features are not used, but it is not guaranteed to work.
+@end menu
 
-@item 
-It is not possible to link against Microsoft C++ libraries except for
-import libraries. Interfacing must be done by the mean of DLLs.
+@node Limitations When Using Ada DLLs from Ada,Exporting Ada Entities,,Building DLLs with gnatdll
+@anchor{gnat_ugn/platform_specific_information limitations-when-using-ada-dlls-from-ada}@anchor{1ed}
+@subsubsection Limitations When Using Ada DLLs from Ada
 
-@item 
-It is possible to link against Microsoft C libraries. Yet the preferred
-solution is to use C/C++ compiler that comes with GNAT, since it
-doesn't require having two different development environments and makes the
-inter-language debugging experience smoother.
 
-@item 
-When the compilation environment is located on FAT32 drives, users may
-experience recompilations of the source files that have not changed if
-Daylight Saving Time (DST) state has changed since the last time files
-were compiled. NTFS drives do not have this problem.
+When using Ada DLLs from Ada applications there is a limitation users
+should be aware of. Because on Windows the GNAT run-time is not in a DLL of
+its own, each Ada DLL includes a part of the GNAT run-time. Specifically,
+each Ada DLL includes the services of the GNAT run-time that are necessary
+to the Ada code inside the DLL. As a result, when an Ada program uses an
+Ada DLL there are two independent GNAT run-times: one in the Ada DLL and
+one in the main program.
 
-@item 
-No components of the GNAT toolset use any entries in the Windows
-registry. The only entries that can be created are file associations and
-PATH settings, provided the user has chosen to create them at installation
-time, as well as some minimal book-keeping information needed to correctly
-uninstall or integrate different GNAT products.
-@end itemize
+It is therefore not possible to exchange GNAT run-time objects between the
+Ada DLL and the main Ada program. Example of GNAT run-time objects are file
+handles (e.g., @code{Text_IO.File_Type}), tasks types, protected objects
+types, etc.
 
-@node Using a network installation of GNAT,CONSOLE and WINDOWS subsystems,Using GNAT on Windows,Microsoft Windows Topics
-@anchor{gnat_ugn/platform_specific_information id8}@anchor{1dd}@anchor{gnat_ugn/platform_specific_information using-a-network-installation-of-gnat}@anchor{1de}
-@subsection Using a network installation of GNAT
+It is completely safe to exchange plain elementary, array or record types,
+Windows object handles, etc.
 
+@node Exporting Ada Entities,Ada DLLs and Elaboration,Limitations When Using Ada DLLs from Ada,Building DLLs with gnatdll
+@anchor{gnat_ugn/platform_specific_information exporting-ada-entities}@anchor{1ea}@anchor{gnat_ugn/platform_specific_information id26}@anchor{1ee}
+@subsubsection Exporting Ada Entities
 
-Make sure the system on which GNAT is installed is accessible from the
-current machine, i.e., the install location is shared over the network.
-Shared resources are accessed on Windows by means of UNC paths, which
-have the format @code{\\\\server\\sharename\\path}
 
-In order to use such a network installation, simply add the UNC path of the
-@code{bin} directory of your GNAT installation in front of your PATH. For
-example, if GNAT is installed in @code{\GNAT} directory of a share location
-called @code{c-drive} on a machine @code{LOKI}, the following command will
-make it available:
+@geindex Export table
+
+Building a DLL is a way to encapsulate a set of services usable from any
+application. As a result, the Ada entities exported by a DLL should be
+exported with the @code{C} or @code{Stdcall} calling conventions to avoid
+any Ada name mangling. As an example here is an Ada package
+@code{API}, spec and body, exporting two procedures, a function, and a
+variable:
 
 @quotation
 
 @example
-$ path \\loki\c-drive\gnat\bin;%path%`
-@end example
-@end quotation
-
-Be aware that every compilation using the network installation results in the
-transfer of large amounts of data across the network and will likely cause
-serious performance penalty.
-
-@node CONSOLE and WINDOWS subsystems,Temporary Files,Using a network installation of GNAT,Microsoft Windows Topics
-@anchor{gnat_ugn/platform_specific_information console-and-windows-subsystems}@anchor{1df}@anchor{gnat_ugn/platform_specific_information id9}@anchor{1e0}
-@subsection CONSOLE and WINDOWS subsystems
+with Interfaces.C; use Interfaces;
+package API is
+   Count : C.int := 0;
+   function Factorial (Val : C.int) return C.int;
 
+   procedure Initialize_API;
+   procedure Finalize_API;
+   --  Initialization & Finalization routines. More in the next section.
+private
+   pragma Export (C, Initialize_API);
+   pragma Export (C, Finalize_API);
+   pragma Export (C, Count);
+   pragma Export (C, Factorial);
+end API;
+@end example
 
-@geindex CONSOLE Subsystem
+@example
+package body API is
+   function Factorial (Val : C.int) return C.int is
+      Fact : C.int := 1;
+   begin
+      Count := Count + 1;
+      for K in 1 .. Val loop
+         Fact := Fact * K;
+      end loop;
+      return Fact;
+   end Factorial;
 
-@geindex WINDOWS Subsystem
+   procedure Initialize_API is
+      procedure Adainit;
+      pragma Import (C, Adainit);
+   begin
+      Adainit;
+   end Initialize_API;
 
-@geindex -mwindows
+   procedure Finalize_API is
+      procedure Adafinal;
+      pragma Import (C, Adafinal);
+   begin
+      Adafinal;
+   end Finalize_API;
+end API;
+@end example
+@end quotation
 
-There are two main subsystems under Windows. The @code{CONSOLE} subsystem
-(which is the default subsystem) will always create a console when
-launching the application. This is not something desirable when the
-application has a Windows GUI. To get rid of this console the
-application must be using the @code{WINDOWS} subsystem. To do so
-the @code{-mwindows} linker option must be specified.
+If the Ada DLL you are building will only be used by Ada applications
+you do not have to export Ada entities with a @code{C} or @code{Stdcall}
+convention. As an example, the previous package could be written as
+follows:
 
 @quotation
 
 @example
-$ gnatmake winprog -largs -mwindows
-@end example
-@end quotation
+package API is
+   Count : Integer := 0;
+   function Factorial (Val : Integer) return Integer;
 
-@node Temporary Files,Disabling Command Line Argument Expansion,CONSOLE and WINDOWS subsystems,Microsoft Windows Topics
-@anchor{gnat_ugn/platform_specific_information id10}@anchor{1e1}@anchor{gnat_ugn/platform_specific_information temporary-files}@anchor{1e2}
-@subsection Temporary Files
+   procedure Initialize_API;
+   procedure Finalize_API;
+   --  Initialization and Finalization routines.
+end API;
+@end example
 
+@example
+package body API is
+   function Factorial (Val : Integer) return Integer is
+      Fact : Integer := 1;
+   begin
+      Count := Count + 1;
+      for K in 1 .. Val loop
+         Fact := Fact * K;
+      end loop;
+      return Fact;
+   end Factorial;
 
-@geindex Temporary files
+   ...
+   --  The remainder of this package body is unchanged.
+end API;
+@end example
+@end quotation
 
-It is possible to control where temporary files gets created by setting
-the 
-@geindex TMP
-@geindex environment variable; TMP
-@code{TMP} environment variable. The file will be created:
+Note that if you do not export the Ada entities with a @code{C} or
+@code{Stdcall} convention you will have to provide the mangled Ada names
+in the definition file of the Ada DLL
+(@ref{1ef,,Creating the Definition File}).
 
+@node Ada DLLs and Elaboration,,Exporting Ada Entities,Building DLLs with gnatdll
+@anchor{gnat_ugn/platform_specific_information ada-dlls-and-elaboration}@anchor{1eb}@anchor{gnat_ugn/platform_specific_information id27}@anchor{1f0}
+@subsubsection Ada DLLs and Elaboration
 
-@itemize *
 
-@item 
-Under the directory pointed to by the 
-@geindex TMP
-@geindex environment variable; TMP
-@code{TMP} environment variable if
-this directory exists.
+@geindex DLLs and elaboration
 
-@item 
-Under @code{c:\temp}, if the 
-@geindex TMP
-@geindex environment variable; TMP
-@code{TMP} environment variable is not
-set (or not pointing to a directory) and if this directory exists.
+The DLL that you are building contains your Ada code as well as all the
+routines in the Ada library that are needed by it. The first thing a
+user of your DLL must do is elaborate the Ada code
+(@ref{f,,Elaboration Order Handling in GNAT}).
 
-@item 
-Under the current working directory otherwise.
-@end itemize
+To achieve this you must export an initialization routine
+(@code{Initialize_API} in the previous example), which must be invoked
+before using any of the DLL services. This elaboration routine must call
+the Ada elaboration routine @code{adainit} generated by the GNAT binder
+(@ref{a0,,Binding with Non-Ada Main Programs}). See the body of
+@code{Initialize_Api} for an example. Note that the GNAT binder is
+automatically invoked during the DLL build process by the @code{gnatdll}
+tool (@ref{1e3,,Using gnatdll}).
 
-This allows you to determine exactly where the temporary
-file will be created. This is particularly useful in networked
-environments where you may not have write access to some
-directories.
+When a DLL is loaded, Windows systematically invokes a routine called
+@code{DllMain}. It would therefore be possible to call @code{adainit}
+directly from @code{DllMain} without having to provide an explicit
+initialization routine. Unfortunately, it is not possible to call
+@code{adainit} from the @code{DllMain} if your program has library level
+tasks because access to the @code{DllMain} entry point is serialized by
+the system (that is, only a single thread can execute 'through' it at a
+time), which means that the GNAT run-time will deadlock waiting for the
+newly created task to complete its initialization.
 
-@node Disabling Command Line Argument Expansion,Mixed-Language Programming on Windows,Temporary Files,Microsoft Windows Topics
-@anchor{gnat_ugn/platform_specific_information disabling-command-line-argument-expansion}@anchor{1e3}
-@subsection Disabling Command Line Argument Expansion
+@node Ada DLLs and Finalization,Creating a Spec for Ada DLLs,Building DLLs with gnatdll,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information id28}@anchor{1f1}@anchor{gnat_ugn/platform_specific_information ada-dlls-and-finalization}@anchor{1ec}
+@subsubsection Ada DLLs and Finalization
 
 
-@geindex Command Line Argument Expansion
+@geindex DLLs and finalization
 
-By default, an executable compiled for the Windows platform will do
-the following postprocessing on the arguments passed on the command
-line:
+When the services of an Ada DLL are no longer needed, the client code should
+invoke the DLL finalization routine, if available. The DLL finalization
+routine is in charge of releasing all resources acquired by the DLL. In the
+case of the Ada code contained in the DLL, this is achieved by calling
+routine @code{adafinal} generated by the GNAT binder
+(@ref{a0,,Binding with Non-Ada Main Programs}).
+See the body of @code{Finalize_Api} for an
+example. As already pointed out the GNAT binder is automatically invoked
+during the DLL build process by the @code{gnatdll} tool
+(@ref{1e3,,Using gnatdll}).
 
+@node Creating a Spec for Ada DLLs,GNAT and Windows Resources,Ada DLLs and Finalization,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information id29}@anchor{1f2}@anchor{gnat_ugn/platform_specific_information creating-a-spec-for-ada-dlls}@anchor{1f3}
+@subsubsection Creating a Spec for Ada DLLs
 
-@itemize *
 
-@item 
-If the argument contains the characters @code{*} and/or @code{?}, then
-file expansion will be attempted. For example, if the current directory
-contains @code{a.txt} and @code{b.txt}, then when calling:
+To use the services exported by the Ada DLL from another programming
+language (e.g., C), you have to translate the specs of the exported Ada
+entities in that language. For instance in the case of @code{API.dll},
+the corresponding C header file could look like:
+
+@quotation
 
 @example
-$ my_ada_program *.txt
+extern int *_imp__count;
+#define count (*_imp__count)
+int factorial (int);
 @end example
+@end quotation
 
-The following arguments will effectively be passed to the main program
-(for example when using @code{Ada.Command_Line.Argument}):
+It is important to understand that when building an Ada DLL to be used by
+other Ada applications, you need two different specs for the packages
+contained in the DLL: one for building the DLL and the other for using
+the DLL. This is because the @code{DLL} calling convention is needed to
+use a variable defined in a DLL, but when building the DLL, the variable
+must have either the @code{Ada} or @code{C} calling convention. As an
+example consider a DLL comprising the following package @code{API}:
+
+@quotation
 
 @example
-Ada.Command_Line.Argument (1) -> "a.txt"
-Ada.Command_Line.Argument (2) -> "b.txt"
+package API is
+   Count : Integer := 0;
+   ...
+   --  Remainder of the package omitted.
+end API;
 @end example
+@end quotation
 
-@item 
-Filename expansion can be disabled for a given argument by using single
-quotes. Thus, calling:
+After producing a DLL containing package @code{API}, the spec that
+must be used to import @code{API.Count} from Ada code outside of the
+DLL is:
+
+@quotation
 
 @example
-$ my_ada_program '*.txt'
+package API is
+   Count : Integer;
+   pragma Import (DLL, Count);
+end API;
 @end example
+@end quotation
 
-will result in:
+@menu
+* Creating the Definition File:: 
+* Using gnatdll:: 
 
-@example
-Ada.Command_Line.Argument (1) -> "*.txt"
-@end example
-@end itemize
+@end menu
 
-Note that if the program is launched from a shell such as Cygwin Bash
-then quote removal might be performed by the shell.
+@node Creating the Definition File,Using gnatdll,,Creating a Spec for Ada DLLs
+@anchor{gnat_ugn/platform_specific_information creating-the-definition-file}@anchor{1ef}@anchor{gnat_ugn/platform_specific_information id30}@anchor{1f4}
+@subsubsection Creating the Definition File
 
-In some contexts it might be useful to disable this feature (for example if
-the program performs its own argument expansion). In order to do this, a C
-symbol needs to be defined and set to @code{0}. You can do this by
-adding the following code fragment in one of your Ada units:
 
-@example
-Do_Argv_Expansion : Integer := 0;
-pragma Export (C, Do_Argv_Expansion, "__gnat_do_argv_expansion");
-@end example
+The definition file is the last file needed to build the DLL. It lists
+the exported symbols. As an example, the definition file for a DLL
+containing only package @code{API} (where all the entities are exported
+with a @code{C} calling convention) is:
 
-The results of previous examples will be respectively:
+@quotation
 
 @example
-Ada.Command_Line.Argument (1) -> "*.txt"
+EXPORTS
+    count
+    factorial
+    finalize_api
+    initialize_api
 @end example
+@end quotation
 
-and:
+If the @code{C} calling convention is missing from package @code{API},
+then the definition file contains the mangled Ada names of the above
+entities, which in this case are:
+
+@quotation
 
 @example
-Ada.Command_Line.Argument (1) -> "'*.txt'"
+EXPORTS
+    api__count
+    api__factorial
+    api__finalize_api
+    api__initialize_api
 @end example
+@end quotation
 
-@node Mixed-Language Programming on Windows,Windows Specific Add-Ons,Disabling Command Line Argument Expansion,Microsoft Windows Topics
-@anchor{gnat_ugn/platform_specific_information id11}@anchor{1e4}@anchor{gnat_ugn/platform_specific_information mixed-language-programming-on-windows}@anchor{1e5}
-@subsection Mixed-Language Programming on Windows
-
+@node Using gnatdll,,Creating the Definition File,Creating a Spec for Ada DLLs
+@anchor{gnat_ugn/platform_specific_information using-gnatdll}@anchor{1e3}@anchor{gnat_ugn/platform_specific_information id31}@anchor{1f5}
+@subsubsection Using @code{gnatdll}
 
-Developing pure Ada applications on Windows is no different than on
-other GNAT-supported platforms. However, when developing or porting an
-application that contains a mix of Ada and C/C++, the choice of your
-Windows C/C++ development environment conditions your overall
-interoperability strategy.
 
-If you use @code{gcc} or Microsoft C to compile the non-Ada part of
-your application, there are no Windows-specific restrictions that
-affect the overall interoperability with your Ada code. If you do want
-to use the Microsoft tools for your C++ code, you have two choices:
+@geindex gnatdll
 
+@code{gnatdll} is a tool to automate the DLL build process once all the Ada
+and non-Ada sources that make up your DLL have been compiled.
+@code{gnatdll} is actually in charge of two distinct tasks: build the
+static import library for the DLL and the actual DLL. The form of the
+@code{gnatdll} command is
 
-@itemize *
+@quotation
 
-@item 
-Encapsulate your C++ code in a DLL to be linked with your Ada
-application. In this case, use the Microsoft or whatever environment to
-build the DLL and use GNAT to build your executable
-(@ref{1e6,,Using DLLs with GNAT}).
+@example
+$ gnatdll [ switches ] list-of-files [ -largs opts ]
+@end example
+@end quotation
 
-@item 
-Or you can encapsulate your Ada code in a DLL to be linked with the
-other part of your application. In this case, use GNAT to build the DLL
-(@ref{1e7,,Building DLLs with GNAT Project files}) and use the Microsoft
-or whatever environment to build your executable.
-@end itemize
+where @code{list-of-files} is a list of ALI and object files. The object
+file list must be the exact list of objects corresponding to the non-Ada
+sources whose services are to be included in the DLL. The ALI file list
+must be the exact list of ALI files for the corresponding Ada sources
+whose services are to be included in the DLL. If @code{list-of-files} is
+missing, only the static import library is generated.
 
-In addition to the description about C main in
-@ref{44,,Mixed Language Programming} section, if the C main uses a
-stand-alone library it is required on x86-windows to
-setup the SEH context. For this the C main must looks like this:
+You may specify any of the following switches to @code{gnatdll}:
 
 @quotation
 
-@example
-/* main.c */
-extern void adainit (void);
-extern void adafinal (void);
-extern void __gnat_initialize(void*);
-extern void call_to_ada (void);
+@geindex -a (gnatdll)
+@end quotation
 
-int main (int argc, char *argv[])
-@{
-  int SEH [2];
 
-  /* Initialize the SEH context */
-  __gnat_initialize (&SEH);
+@table @asis
 
-  adainit();
+@item @code{-a[@emph{address}]}
 
-  /* Then call Ada services in the stand-alone library */
+Build a non-relocatable DLL at @code{address}. If @code{address} is not
+specified the default address @code{0x11000000} will be used. By default,
+when this switch is missing, @code{gnatdll} builds relocatable DLL. We
+advise the reader to build relocatable DLL.
 
-  call_to_ada();
+@geindex -b (gnatdll)
 
-  adafinal();
-@}
-@end example
-@end quotation
+@item @code{-b @emph{address}}
 
-Note that this is not needed on x86_64-windows where the Windows
-native SEH support is used.
+Set the relocatable DLL base address. By default the address is
+@code{0x11000000}.
 
-@menu
-* Windows Calling Conventions:: 
-* Introduction to Dynamic Link Libraries (DLLs): Introduction to Dynamic Link Libraries DLLs. 
-* Using DLLs with GNAT:: 
-* Building DLLs with GNAT Project files:: 
-* Building DLLs with GNAT:: 
-* Building DLLs with gnatdll:: 
-* Ada DLLs and Finalization:: 
-* Creating a Spec for Ada DLLs:: 
-* GNAT and Windows Resources:: 
-* Using GNAT DLLs from Microsoft Visual Studio Applications:: 
-* Debugging a DLL:: 
-* Setting Stack Size from gnatlink:: 
-* Setting Heap Size from gnatlink:: 
+@geindex -bargs (gnatdll)
 
-@end menu
+@item @code{-bargs @emph{opts}}
 
-@node Windows Calling Conventions,Introduction to Dynamic Link Libraries DLLs,,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information windows-calling-conventions}@anchor{1e8}@anchor{gnat_ugn/platform_specific_information id12}@anchor{1e9}
-@subsubsection Windows Calling Conventions
+Binder options. Pass @code{opts} to the binder.
 
+@geindex -d (gnatdll)
 
-@geindex Stdcall
+@item @code{-d @emph{dllfile}}
 
-@geindex APIENTRY
+@code{dllfile} is the name of the DLL. This switch must be present for
+@code{gnatdll} to do anything. The name of the generated import library is
+obtained algorithmically from @code{dllfile} as shown in the following
+example: if @code{dllfile} is @code{xyz.dll}, the import library name is
+@code{libxyz.dll.a}. The name of the definition file to use (if not specified
+by option @code{-e}) is obtained algorithmically from @code{dllfile}
+as shown in the following example:
+if @code{dllfile} is @code{xyz.dll}, the definition
+file used is @code{xyz.def}.
 
-This section pertain only to Win32. On Win64 there is a single native
-calling convention. All convention specifiers are ignored on this
-platform.
+@geindex -e (gnatdll)
 
-When a subprogram @code{F} (caller) calls a subprogram @code{G}
-(callee), there are several ways to push @code{G}'s parameters on the
-stack and there are several possible scenarios to clean up the stack
-upon @code{G}'s return. A calling convention is an agreed upon software
-protocol whereby the responsibilities between the caller (@code{F}) and
-the callee (@code{G}) are clearly defined. Several calling conventions
-are available for Windows:
+@item @code{-e @emph{deffile}}
 
+@code{deffile} is the name of the definition file.
 
-@itemize *
+@geindex -g (gnatdll)
 
-@item 
-@code{C} (Microsoft defined)
+@item @code{-g}
 
-@item 
-@code{Stdcall} (Microsoft defined)
+Generate debugging information. This information is stored in the object
+file and copied from there to the final DLL file by the linker,
+where it can be read by the debugger. You must use the
+@code{-g} switch if you plan on using the debugger or the symbolic
+stack traceback.
 
-@item 
-@code{Win32} (GNAT specific)
+@geindex -h (gnatdll)
 
-@item 
-@code{DLL} (GNAT specific)
-@end itemize
+@item @code{-h}
 
-@menu
-* C Calling Convention:: 
-* Stdcall Calling Convention:: 
-* Win32 Calling Convention:: 
-* DLL Calling Convention:: 
+Help mode. Displays @code{gnatdll} switch usage information.
 
-@end menu
+@geindex -I (gnatdll)
 
-@node C Calling Convention,Stdcall Calling Convention,,Windows Calling Conventions
-@anchor{gnat_ugn/platform_specific_information c-calling-convention}@anchor{1ea}@anchor{gnat_ugn/platform_specific_information id13}@anchor{1eb}
-@subsubsection @code{C} Calling Convention
+@item @code{-I@emph{dir}}
 
+Direct @code{gnatdll} to search the @code{dir} directory for source and
+object files needed to build the DLL.
+(@ref{73,,Search Paths and the Run-Time Library (RTL)}).
 
-This is the default calling convention used when interfacing to C/C++
-routines compiled with either @code{gcc} or Microsoft Visual C++.
+@geindex -k (gnatdll)
 
-In the @code{C} calling convention subprogram parameters are pushed on the
-stack by the caller from right to left. The caller itself is in charge of
-cleaning up the stack after the call. In addition, the name of a routine
-with @code{C} calling convention is mangled by adding a leading underscore.
+@item @code{-k}
 
-The name to use on the Ada side when importing (or exporting) a routine
-with @code{C} calling convention is the name of the routine. For
-instance the C function:
+Removes the @code{@@@emph{nn}} suffix from the import library's exported
+names, but keeps them for the link names. You must specify this
+option if you want to use a @code{Stdcall} function in a DLL for which
+the @code{@@@emph{nn}} suffix has been removed. This is the case for most
+of the Windows NT DLL for example. This option has no effect when
+@code{-n} option is specified.
 
-@quotation
+@geindex -l (gnatdll)
 
-@example
-int get_val (long);
-@end example
-@end quotation
+@item @code{-l @emph{file}}
 
-should be imported from Ada as follows:
+The list of ALI and object files used to build the DLL are listed in
+@code{file}, instead of being given in the command line. Each line in
+@code{file} contains the name of an ALI or object file.
 
-@quotation
+@geindex -n (gnatdll)
 
-@example
-function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
-pragma Import (C, Get_Val, External_Name => "get_val");
-@end example
-@end quotation
+@item @code{-n}
 
-Note that in this particular case the @code{External_Name} parameter could
-have been omitted since, when missing, this parameter is taken to be the
-name of the Ada entity in lower case. When the @code{Link_Name} parameter
-is missing, as in the above example, this parameter is set to be the
-@code{External_Name} with a leading underscore.
+No Import. Do not create the import library.
 
-When importing a variable defined in C, you should always use the @code{C}
-calling convention unless the object containing the variable is part of a
-DLL (in which case you should use the @code{Stdcall} calling
-convention, @ref{1ec,,Stdcall Calling Convention}).
+@geindex -q (gnatdll)
 
-@node Stdcall Calling Convention,Win32 Calling Convention,C Calling Convention,Windows Calling Conventions
-@anchor{gnat_ugn/platform_specific_information stdcall-calling-convention}@anchor{1ec}@anchor{gnat_ugn/platform_specific_information id14}@anchor{1ed}
-@subsubsection @code{Stdcall} Calling Convention
+@item @code{-q}
 
+Quiet mode. Do not display unnecessary messages.
 
-This convention, which was the calling convention used for Pascal
-programs, is used by Microsoft for all the routines in the Win32 API for
-efficiency reasons. It must be used to import any routine for which this
-convention was specified.
+@geindex -v (gnatdll)
 
-In the @code{Stdcall} calling convention subprogram parameters are pushed
-on the stack by the caller from right to left. The callee (and not the
-caller) is in charge of cleaning the stack on routine exit. In addition,
-the name of a routine with @code{Stdcall} calling convention is mangled by
-adding a leading underscore (as for the @code{C} calling convention) and a
-trailing @code{@@@emph{nn}}, where @code{nn} is the overall size (in
-bytes) of the parameters passed to the routine.
+@item @code{-v}
 
-The name to use on the Ada side when importing a C routine with a
-@code{Stdcall} calling convention is the name of the C routine. The leading
-underscore and trailing @code{@@@emph{nn}} are added automatically by
-the compiler. For instance the Win32 function:
+Verbose mode. Display extra information.
 
-@quotation
+@geindex -largs (gnatdll)
 
-@example
-APIENTRY int get_val (long);
-@end example
-@end quotation
+@item @code{-largs @emph{opts}}
 
-should be imported from Ada as follows:
+Linker options. Pass @code{opts} to the linker.
+@end table
 
-@quotation
+@subsubheading @code{gnatdll} Example
 
-@example
-function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
-pragma Import (Stdcall, Get_Val);
---  On the x86 a long is 4 bytes, so the Link_Name is "_get_val@@4"
-@end example
-@end quotation
 
-As for the @code{C} calling convention, when the @code{External_Name}
-parameter is missing, it is taken to be the name of the Ada entity in lower
-case. If instead of writing the above import pragma you write:
+As an example the command to build a relocatable DLL from @code{api.adb}
+once @code{api.adb} has been compiled and @code{api.def} created is
 
 @quotation
 
 @example
-function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
-pragma Import (Stdcall, Get_Val, External_Name => "retrieve_val");
+$ gnatdll -d api.dll api.ali
 @end example
 @end quotation
 
-then the imported routine is @code{_retrieve_val@@4}. However, if instead
-of specifying the @code{External_Name} parameter you specify the
-@code{Link_Name} as in the following example:
+The above command creates two files: @code{libapi.dll.a} (the import
+library) and @code{api.dll} (the actual DLL). If you want to create
+only the DLL, just type:
 
 @quotation
 
 @example
-function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
-pragma Import (Stdcall, Get_Val, Link_Name => "retrieve_val");
+$ gnatdll -d api.dll -n api.ali
 @end example
 @end quotation
 
-then the imported routine is @code{retrieve_val}, that is, there is no
-decoration at all. No leading underscore and no Stdcall suffix
-@code{@@@emph{nn}}.
-
-This is especially important as in some special cases a DLL's entry
-point name lacks a trailing @code{@@@emph{nn}} while the exported
-name generated for a call has it.
-
-It is also possible to import variables defined in a DLL by using an
-import pragma for a variable. As an example, if a DLL contains a
-variable defined as:
+Alternatively if you want to create just the import library, type:
 
 @quotation
 
 @example
-int my_var;
+$ gnatdll -d api.dll
 @end example
 @end quotation
 
-then, to access this variable from Ada you should write:
+@subsubheading @code{gnatdll} behind the Scenes
 
-@quotation
 
-@example
-My_Var : Interfaces.C.int;
-pragma Import (Stdcall, My_Var);
-@end example
-@end quotation
+This section details the steps involved in creating a DLL. @code{gnatdll}
+does these steps for you. Unless you are interested in understanding what
+goes on behind the scenes, you should skip this section.
 
-Note that to ease building cross-platform bindings this convention
-will be handled as a @code{C} calling convention on non-Windows platforms.
+We use the previous example of a DLL containing the Ada package @code{API},
+to illustrate the steps necessary to build a DLL. The starting point is a
+set of objects that will make up the DLL and the corresponding ALI
+files. In the case of this example this means that @code{api.o} and
+@code{api.ali} are available. To build a relocatable DLL, @code{gnatdll} does
+the following:
 
-@node Win32 Calling Convention,DLL Calling Convention,Stdcall Calling Convention,Windows Calling Conventions
-@anchor{gnat_ugn/platform_specific_information win32-calling-convention}@anchor{1ee}@anchor{gnat_ugn/platform_specific_information id15}@anchor{1ef}
-@subsubsection @code{Win32} Calling Convention
 
+@itemize *
 
-This convention, which is GNAT-specific is fully equivalent to the
-@code{Stdcall} calling convention described above.
+@item 
+@code{gnatdll} builds the base file (@code{api.base}). A base file gives
+the information necessary to generate relocation information for the
+DLL.
 
-@node DLL Calling Convention,,Win32 Calling Convention,Windows Calling Conventions
-@anchor{gnat_ugn/platform_specific_information dll-calling-convention}@anchor{1f0}@anchor{gnat_ugn/platform_specific_information id16}@anchor{1f1}
-@subsubsection @code{DLL} Calling Convention
+@example
+$ gnatbind -n api
+$ gnatlink api -o api.jnk -mdll -Wl,--base-file,api.base
+@end example
 
+In addition to the base file, the @code{gnatlink} command generates an
+output file @code{api.jnk} which can be discarded. The @code{-mdll} switch
+asks @code{gnatlink} to generate the routines @code{DllMain} and
+@code{DllMainCRTStartup} that are called by the Windows loader when the DLL
+is loaded into memory.
 
-This convention, which is GNAT-specific is fully equivalent to the
-@code{Stdcall} calling convention described above.
+@item 
+@code{gnatdll} uses @code{dlltool} (see @ref{1f6,,Using dlltool}) to build the
+export table (@code{api.exp}). The export table contains the relocation
+information in a form which can be used during the final link to ensure
+that the Windows loader is able to place the DLL anywhere in memory.
 
-@node Introduction to Dynamic Link Libraries DLLs,Using DLLs with GNAT,Windows Calling Conventions,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information introduction-to-dynamic-link-libraries-dlls}@anchor{1f2}@anchor{gnat_ugn/platform_specific_information id17}@anchor{1f3}
-@subsubsection Introduction to Dynamic Link Libraries (DLLs)
+@example
+$ dlltool --dllname api.dll --def api.def --base-file api.base \\
+          --output-exp api.exp
+@end example
 
+@item 
+@code{gnatdll} builds the base file using the new export table. Note that
+@code{gnatbind} must be called once again since the binder generated file
+has been deleted during the previous call to @code{gnatlink}.
 
-@geindex DLL
+@example
+$ gnatbind -n api
+$ gnatlink api -o api.jnk api.exp -mdll
+      -Wl,--base-file,api.base
+@end example
 
-A Dynamically Linked Library (DLL) is a library that can be shared by
-several applications running under Windows. A DLL can contain any number of
-routines and variables.
+@item 
+@code{gnatdll} builds the new export table using the new base file and
+generates the DLL import library @code{libAPI.dll.a}.
 
-One advantage of DLLs is that you can change and enhance them without
-forcing all the applications that depend on them to be relinked or
-recompiled. However, you should be aware than all calls to DLL routines are
-slower since, as you will understand below, such calls are indirect.
+@example
+$ dlltool --dllname api.dll --def api.def --base-file api.base \\
+          --output-exp api.exp --output-lib libAPI.a
+@end example
 
-To illustrate the remainder of this section, suppose that an application
-wants to use the services of a DLL @code{API.dll}. To use the services
-provided by @code{API.dll} you must statically link against the DLL or
-an import library which contains a jump table with an entry for each
-routine and variable exported by the DLL. In the Microsoft world this
-import library is called @code{API.lib}. When using GNAT this import
-library is called either @code{libAPI.dll.a}, @code{libapi.dll.a},
-@code{libAPI.a} or @code{libapi.a} (names are case insensitive).
+@item 
+Finally @code{gnatdll} builds the relocatable DLL using the final export
+table.
 
-After you have linked your application with the DLL or the import library
-and you run your application, here is what happens:
+@example
+$ gnatbind -n api
+$ gnatlink api api.exp -o api.dll -mdll
+@end example
+@end itemize
+@anchor{gnat_ugn/platform_specific_information using-dlltool}@anchor{1f6}
+@subsubheading Using @code{dlltool}
 
 
-@itemize *
+@code{dlltool} is the low-level tool used by @code{gnatdll} to build
+DLLs and static import libraries. This section summarizes the most
+common @code{dlltool} switches. The form of the @code{dlltool} command
+is
 
-@item 
-Your application is loaded into memory.
+@quotation
 
-@item 
-The DLL @code{API.dll} is mapped into the address space of your
-application. This means that:
+@example
+$ dlltool [`switches`]
+@end example
+@end quotation
 
+@code{dlltool} switches include:
 
-@itemize -
+@geindex --base-file (dlltool)
 
-@item 
-The DLL will use the stack of the calling thread.
 
-@item 
-The DLL will use the virtual address space of the calling process.
+@table @asis
 
-@item 
-The DLL will allocate memory from the virtual address space of the calling
-process.
+@item @code{--base-file @emph{basefile}}
 
-@item 
-Handles (pointers) can be safely exchanged between routines in the DLL
-routines and routines in the application using the DLL.
-@end itemize
+Read the base file @code{basefile} generated by the linker. This switch
+is used to create a relocatable DLL.
+@end table
 
-@item 
-The entries in the jump table (from the import library @code{libAPI.dll.a}
-or @code{API.lib} or automatically created when linking against a DLL)
-which is part of your application are initialized with the addresses
-of the routines and variables in @code{API.dll}.
+@geindex --def (dlltool)
 
-@item 
-If present in @code{API.dll}, routines @code{DllMain} or
-@code{DllMainCRTStartup} are invoked. These routines typically contain
-the initialization code needed for the well-being of the routines and
-variables exported by the DLL.
-@end itemize
 
-There is an additional point which is worth mentioning. In the Windows
-world there are two kind of DLLs: relocatable and non-relocatable
-DLLs. Non-relocatable DLLs can only be loaded at a very specific address
-in the target application address space. If the addresses of two
-non-relocatable DLLs overlap and these happen to be used by the same
-application, a conflict will occur and the application will run
-incorrectly. Hence, when possible, it is always preferable to use and
-build relocatable DLLs. Both relocatable and non-relocatable DLLs are
-supported by GNAT. Note that the @code{-s} linker option (see GNU Linker
-User's Guide) removes the debugging symbols from the DLL but the DLL can
-still be relocated.
+@table @asis
 
-As a side note, an interesting difference between Microsoft DLLs and
-Unix shared libraries, is the fact that on most Unix systems all public
-routines are exported by default in a Unix shared library, while under
-Windows it is possible (but not required) to list exported routines in
-a definition file (see @ref{1f4,,The Definition File}).
+@item @code{--def @emph{deffile}}
 
-@node Using DLLs with GNAT,Building DLLs with GNAT Project files,Introduction to Dynamic Link Libraries DLLs,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information id18}@anchor{1f5}@anchor{gnat_ugn/platform_specific_information using-dlls-with-gnat}@anchor{1e6}
-@subsubsection Using DLLs with GNAT
+Read the definition file.
+@end table
 
+@geindex --dllname (dlltool)
 
-To use the services of a DLL, say @code{API.dll}, in your Ada application
-you must have:
 
+@table @asis
 
-@itemize *
+@item @code{--dllname @emph{name}}
 
-@item 
-The Ada spec for the routines and/or variables you want to access in
-@code{API.dll}. If not available this Ada spec must be built from the C/C++
-header files provided with the DLL.
+Gives the name of the DLL. This switch is used to embed the name of the
+DLL in the static import library generated by @code{dlltool} with switch
+@code{--output-lib}.
+@end table
 
-@item 
-The import library (@code{libAPI.dll.a} or @code{API.lib}). As previously
-mentioned an import library is a statically linked library containing the
-import table which will be filled at load time to point to the actual
-@code{API.dll} routines. Sometimes you don't have an import library for the
-DLL you want to use. The following sections will explain how to build
-one. Note that this is optional.
+@geindex -k (dlltool)
 
-@item 
-The actual DLL, @code{API.dll}.
-@end itemize
 
-Once you have all the above, to compile an Ada application that uses the
-services of @code{API.dll} and whose main subprogram is @code{My_Ada_App},
-you simply issue the command
+@table @asis
 
-@quotation
+@item @code{-k}
 
-@example
-$ gnatmake my_ada_app -largs -lAPI
-@end example
-@end quotation
+Kill @code{@@@emph{nn}} from exported names
+(@ref{1cf,,Windows Calling Conventions}
+for a discussion about @code{Stdcall}-style symbols.
+@end table
 
-The argument @code{-largs -lAPI} at the end of the @code{gnatmake} command
-tells the GNAT linker to look for an import library. The linker will
-look for a library name in this specific order:
+@geindex --help (dlltool)
 
 
-@itemize *
+@table @asis
 
-@item 
-@code{libAPI.dll.a}
+@item @code{--help}
 
-@item 
-@code{API.dll.a}
+Prints the @code{dlltool} switches with a concise description.
+@end table
 
-@item 
-@code{libAPI.a}
+@geindex --output-exp (dlltool)
 
-@item 
-@code{API.lib}
 
-@item 
-@code{libAPI.dll}
+@table @asis
 
-@item 
-@code{API.dll}
-@end itemize
+@item @code{--output-exp @emph{exportfile}}
 
-The first three are the GNU style import libraries. The third is the
-Microsoft style import libraries. The last two are the actual DLL names.
+Generate an export file @code{exportfile}. The export file contains the
+export table (list of symbols in the DLL) and is used to create the DLL.
+@end table
 
-Note that if the Ada package spec for @code{API.dll} contains the
-following pragma
+@geindex --output-lib (dlltool)
 
-@quotation
 
-@example
-pragma Linker_Options ("-lAPI");
-@end example
-@end quotation
+@table @asis
 
-you do not have to add @code{-largs -lAPI} at the end of the
-@code{gnatmake} command.
+@item @code{--output-lib @emph{libfile}}
 
-If any one of the items above is missing you will have to create it
-yourself. The following sections explain how to do so using as an
-example a fictitious DLL called @code{API.dll}.
+Generate a static import library @code{libfile}.
+@end table
 
-@menu
-* Creating an Ada Spec for the DLL Services:: 
-* Creating an Import Library:: 
+@geindex -v (dlltool)
 
-@end menu
 
-@node Creating an Ada Spec for the DLL Services,Creating an Import Library,,Using DLLs with GNAT
-@anchor{gnat_ugn/platform_specific_information creating-an-ada-spec-for-the-dll-services}@anchor{1f6}@anchor{gnat_ugn/platform_specific_information id19}@anchor{1f7}
-@subsubsection Creating an Ada Spec for the DLL Services
+@table @asis
 
+@item @code{-v}
 
-A DLL typically comes with a C/C++ header file which provides the
-definitions of the routines and variables exported by the DLL. The Ada
-equivalent of this header file is a package spec that contains definitions
-for the imported entities. If the DLL you intend to use does not come with
-an Ada spec you have to generate one such spec yourself. For example if
-the header file of @code{API.dll} is a file @code{api.h} containing the
-following two definitions:
+Verbose mode.
+@end table
 
-@quotation
+@geindex --as (dlltool)
 
-@example
-int some_var;
-int get (char *);
-@end example
-@end quotation
 
-then the equivalent Ada spec could be:
+@table @asis
 
-@quotation
+@item @code{--as @emph{assembler-name}}
 
-@example
-with Interfaces.C.Strings;
-package API is
-   use Interfaces;
+Use @code{assembler-name} as the assembler. The default is @code{as}.
+@end table
 
-   Some_Var : C.int;
-   function Get (Str : C.Strings.Chars_Ptr) return C.int;
+@node GNAT and Windows Resources,Using GNAT DLLs from Microsoft Visual Studio Applications,Creating a Spec for Ada DLLs,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information gnat-and-windows-resources}@anchor{1f7}@anchor{gnat_ugn/platform_specific_information id32}@anchor{1f8}
+@subsubsection GNAT and Windows Resources
 
-private
-   pragma Import (C, Get);
-   pragma Import (DLL, Some_Var);
-end API;
-@end example
-@end quotation
 
-@node Creating an Import Library,,Creating an Ada Spec for the DLL Services,Using DLLs with GNAT
-@anchor{gnat_ugn/platform_specific_information id20}@anchor{1f8}@anchor{gnat_ugn/platform_specific_information creating-an-import-library}@anchor{1f9}
-@subsubsection Creating an Import Library
+@geindex Resources
+@geindex windows
 
+Resources are an easy way to add Windows specific objects to your
+application. The objects that can be added as resources include:
 
-@geindex Import library
 
-If a Microsoft-style import library @code{API.lib} or a GNAT-style
-import library @code{libAPI.dll.a} or @code{libAPI.a} is available
-with @code{API.dll} you can skip this section. You can also skip this
-section if @code{API.dll} or @code{libAPI.dll} is built with GNU tools
-as in this case it is possible to link directly against the
-DLL. Otherwise read on.
+@itemize *
 
-@geindex Definition file
-@anchor{gnat_ugn/platform_specific_information the-definition-file}@anchor{1f4}
-@subsubheading The Definition File
+@item 
+menus
 
+@item 
+accelerators
 
-As previously mentioned, and unlike Unix systems, the list of symbols
-that are exported from a DLL must be provided explicitly in Windows.
-The main goal of a definition file is precisely that: list the symbols
-exported by a DLL. A definition file (usually a file with a @code{.def}
-suffix) has the following structure:
-
-@quotation
+@item 
+dialog boxes
 
-@example
-[LIBRARY `@w{`}name`@w{`}]
-[DESCRIPTION `@w{`}string`@w{`}]
-EXPORTS
-   `@w{`}symbol1`@w{`}
-   `@w{`}symbol2`@w{`}
-   ...
-@end example
-@end quotation
+@item 
+string tables
 
+@item 
+bitmaps
 
-@table @asis
+@item 
+cursors
 
-@item @emph{LIBRARY name}
+@item 
+icons
 
-This section, which is optional, gives the name of the DLL.
+@item 
+fonts
 
-@item @emph{DESCRIPTION string}
+@item 
+version information
+@end itemize
 
-This section, which is optional, gives a description string that will be
-embedded in the import library.
+For example, a version information resource can be defined as follow and
+embedded into an executable or DLL:
 
-@item @emph{EXPORTS}
+A version information resource can be used to embed information into an
+executable or a DLL. These information can be viewed using the file properties
+from the Windows Explorer. Here is an example of a version information
+resource:
 
-This section gives the list of exported symbols (procedures, functions or
-variables). For instance in the case of @code{API.dll} the @code{EXPORTS}
-section of @code{API.def} looks like:
+@quotation
 
 @example
-EXPORTS
-   some_var
-   get
+1 VERSIONINFO
+FILEVERSION     1,0,0,0
+PRODUCTVERSION  1,0,0,0
+BEGIN
+  BLOCK "StringFileInfo"
+  BEGIN
+    BLOCK "080904E4"
+    BEGIN
+      VALUE "CompanyName", "My Company Name"
+      VALUE "FileDescription", "My application"
+      VALUE "FileVersion", "1.0"
+      VALUE "InternalName", "my_app"
+      VALUE "LegalCopyright", "My Name"
+      VALUE "OriginalFilename", "my_app.exe"
+      VALUE "ProductName", "My App"
+      VALUE "ProductVersion", "1.0"
+    END
+  END
+
+  BLOCK "VarFileInfo"
+  BEGIN
+    VALUE "Translation", 0x809, 1252
+  END
+END
 @end example
-@end table
+@end quotation
 
-Note that you must specify the correct suffix (@code{@@@emph{nn}})
-(see @ref{1e8,,Windows Calling Conventions}) for a Stdcall
-calling convention function in the exported symbols list.
+The value @code{0809} (langID) is for the U.K English language and
+@code{04E4} (charsetID), which is equal to @code{1252} decimal, for
+multilingual.
 
-There can actually be other sections in a definition file, but these
-sections are not relevant to the discussion at hand.
-@anchor{gnat_ugn/platform_specific_information create-def-file-automatically}@anchor{1fa}
-@subsubheading Creating a Definition File Automatically
+This section explains how to build, compile and use resources. Note that this
+section does not cover all resource objects, for a complete description see
+the corresponding Microsoft documentation.
 
+@menu
+* Building Resources:: 
+* Compiling Resources:: 
+* Using Resources:: 
 
-You can automatically create the definition file @code{API.def}
-(see @ref{1f4,,The Definition File}) from a DLL.
-For that use the @code{dlltool} program as follows:
+@end menu
 
-@quotation
+@node Building Resources,Compiling Resources,,GNAT and Windows Resources
+@anchor{gnat_ugn/platform_specific_information building-resources}@anchor{1f9}@anchor{gnat_ugn/platform_specific_information id33}@anchor{1fa}
+@subsubsection Building Resources
 
-@example
-$ dlltool API.dll -z API.def --export-all-symbols
-@end example
 
-Note that if some routines in the DLL have the @code{Stdcall} convention
-(@ref{1e8,,Windows Calling Conventions}) with stripped @code{@@@emph{nn}}
-suffix then you'll have to edit @code{api.def} to add it, and specify
-@code{-k} to @code{gnatdll} when creating the import library.
+@geindex Resources
+@geindex building
 
-Here are some hints to find the right @code{@@@emph{nn}} suffix.
+A resource file is an ASCII file. By convention resource files have an
+@code{.rc} extension.
+The easiest way to build a resource file is to use Microsoft tools
+such as @code{imagedit.exe} to build bitmaps, icons and cursors and
+@code{dlgedit.exe} to build dialogs.
+It is always possible to build an @code{.rc} file yourself by writing a
+resource script.
 
+It is not our objective to explain how to write a resource file. A
+complete description of the resource script language can be found in the
+Microsoft documentation.
 
-@itemize -
+@node Compiling Resources,Using Resources,Building Resources,GNAT and Windows Resources
+@anchor{gnat_ugn/platform_specific_information compiling-resources}@anchor{1fb}@anchor{gnat_ugn/platform_specific_information id34}@anchor{1fc}
+@subsubsection Compiling Resources
 
-@item 
-If you have the Microsoft import library (.lib), it is possible to get
-the right symbols by using Microsoft @code{dumpbin} tool (see the
-corresponding Microsoft documentation for further details).
 
-@example
-$ dumpbin /exports api.lib
-@end example
+@geindex rc
 
-@item 
-If you have a message about a missing symbol at link time the compiler
-tells you what symbol is expected. You just have to go back to the
-definition file and add the right suffix.
-@end itemize
-@end quotation
-@anchor{gnat_ugn/platform_specific_information gnat-style-import-library}@anchor{1fb}
-@subsubheading GNAT-Style Import Library
+@geindex windres
 
+@geindex Resources
+@geindex compiling
 
-To create a static import library from @code{API.dll} with the GNAT tools
-you should create the .def file, then use @code{gnatdll} tool
-(see @ref{1fc,,Using gnatdll}) as follows:
+This section describes how to build a GNAT-compatible (COFF) object file
+containing the resources. This is done using the Resource Compiler
+@code{windres} as follows:
 
 @quotation
 
 @example
-$ gnatdll -e API.def -d API.dll
+$ windres -i myres.rc -o myres.o
 @end example
-
-@code{gnatdll} takes as input a definition file @code{API.def} and the
-name of the DLL containing the services listed in the definition file
-@code{API.dll}. The name of the static import library generated is
-computed from the name of the definition file as follows: if the
-definition file name is @code{xyz.def}, the import library name will
-be @code{libxyz.a}. Note that in the previous example option
-@code{-e} could have been removed because the name of the definition
-file (before the @code{.def} suffix) is the same as the name of the
-DLL (@ref{1fc,,Using gnatdll} for more information about @code{gnatdll}).
 @end quotation
-@anchor{gnat_ugn/platform_specific_information msvs-style-import-library}@anchor{1fd}
-@subsubheading Microsoft-Style Import Library
-
 
-A Microsoft import library is needed only if you plan to make an
-Ada DLL available to applications developed with Microsoft
-tools (@ref{1e5,,Mixed-Language Programming on Windows}).
+By default @code{windres} will run @code{gcc} to preprocess the @code{.rc}
+file. You can specify an alternate preprocessor (usually named
+@code{cpp.exe}) using the @code{windres} @code{--preprocessor}
+parameter. A list of all possible options may be obtained by entering
+the command @code{windres} @code{--help}.
 
-To create a Microsoft-style import library for @code{API.dll} you
-should create the .def file, then build the actual import library using
-Microsoft's @code{lib} utility:
+It is also possible to use the Microsoft resource compiler @code{rc.exe}
+to produce a @code{.res} file (binary resource file). See the
+corresponding Microsoft documentation for further details. In this case
+you need to use @code{windres} to translate the @code{.res} file to a
+GNAT-compatible object file as follows:
 
 @quotation
 
 @example
-$ lib -machine:IX86 -def:API.def -out:API.lib
+$ windres -i myres.res -o myres.o
 @end example
+@end quotation
 
-If you use the above command the definition file @code{API.def} must
-contain a line giving the name of the DLL:
+@node Using Resources,,Compiling Resources,GNAT and Windows Resources
+@anchor{gnat_ugn/platform_specific_information using-resources}@anchor{1fd}@anchor{gnat_ugn/platform_specific_information id35}@anchor{1fe}
+@subsubsection Using Resources
+
+
+@geindex Resources
+@geindex using
+
+To include the resource file in your program just add the
+GNAT-compatible object file for the resource(s) to the linker
+arguments. With @code{gnatmake} this is done by using the @code{-largs}
+option:
+
+@quotation
 
 @example
-LIBRARY      "API"
+$ gnatmake myprog -largs myres.o
 @end example
-
-See the Microsoft documentation for further details about the usage of
-@code{lib}.
 @end quotation
 
-@node Building DLLs with GNAT Project files,Building DLLs with GNAT,Using DLLs with GNAT,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information id21}@anchor{1fe}@anchor{gnat_ugn/platform_specific_information building-dlls-with-gnat-project-files}@anchor{1e7}
-@subsubsection Building DLLs with GNAT Project files
+@node Using GNAT DLLs from Microsoft Visual Studio Applications,Debugging a DLL,GNAT and Windows Resources,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information using-gnat-dll-from-msvs}@anchor{1ff}@anchor{gnat_ugn/platform_specific_information using-gnat-dlls-from-microsoft-visual-studio-applications}@anchor{200}
+@subsubsection Using GNAT DLLs from Microsoft Visual Studio Applications
 
 
-@geindex DLLs
-@geindex building
+@geindex Microsoft Visual Studio
+@geindex use with GNAT DLLs
 
-There is nothing specific to Windows in the build process.
-See the @emph{Library Projects} section in the @emph{GNAT Project Manager}
-chapter of the @emph{GPRbuild User's Guide}.
+This section describes a common case of mixed GNAT/Microsoft Visual Studio
+application development, where the main program is developed using MSVS, and
+is linked with a DLL developed using GNAT. Such a mixed application should
+be developed following the general guidelines outlined above; below is the
+cookbook-style sequence of steps to follow:
 
-Due to a system limitation, it is not possible under Windows to create threads
-when inside the @code{DllMain} routine which is used for auto-initialization
-of shared libraries, so it is not possible to have library level tasks in SALs.
 
-@node Building DLLs with GNAT,Building DLLs with gnatdll,Building DLLs with GNAT Project files,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information building-dlls-with-gnat}@anchor{1ff}@anchor{gnat_ugn/platform_specific_information id22}@anchor{200}
-@subsubsection Building DLLs with GNAT
+@enumerate 
 
+@item 
+First develop and build the GNAT shared library using a library project
+(let's assume the project is @code{mylib.gpr}, producing the library @code{libmylib.dll}):
+@end enumerate
 
-@geindex DLLs
-@geindex building
+@quotation
 
-This section explain how to build DLLs using the GNAT built-in DLL
-support. With the following procedure it is straight forward to build
-and use DLLs with GNAT.
+@example
+$ gprbuild -p mylib.gpr
+@end example
+@end quotation
 
 
-@itemize *
+@enumerate 2
 
 @item 
-Building object files.
-The first step is to build all objects files that are to be included
-into the DLL. This is done by using the standard @code{gnatmake} tool.
+Produce a .def file for the symbols you need to interface with, either by
+hand or automatically with possibly some manual adjustments
+(see @ref{1e1,,Creating Definition File Automatically}):
+@end enumerate
 
-@item 
-Building the DLL.
-To build the DLL you must use the @code{gcc} @code{-shared} and
-@code{-shared-libgcc} options. It is quite simple to use this method:
+@quotation
 
 @example
-$ gcc -shared -shared-libgcc -o api.dll obj1.o obj2.o ...
+$ dlltool libmylib.dll -z libmylib.def --export-all-symbols
 @end example
+@end quotation
 
-It is important to note that in this case all symbols found in the
-object files are automatically exported. It is possible to restrict
-the set of symbols to export by passing to @code{gcc} a definition
-file (see @ref{1f4,,The Definition File}).
-For example:
 
-@example
-$ gcc -shared -shared-libgcc -o api.dll api.def obj1.o obj2.o ...
-@end example
+@enumerate 3
 
-If you use a definition file you must export the elaboration procedures
-for every package that required one. Elaboration procedures are named
-using the package name followed by "_E".
+@item 
+Make sure that MSVS command-line tools are accessible on the path.
 
 @item 
-Preparing DLL to be used.
-For the DLL to be used by client programs the bodies must be hidden
-from it and the .ali set with read-only attribute. This is very important
-otherwise GNAT will recompile all packages and will not actually use
-the code in the DLL. For example:
+Create the Microsoft-style import library (see @ref{1e4,,MSVS-Style Import Library}):
+@end enumerate
+
+@quotation
 
 @example
-$ mkdir apilib
-$ copy *.ads *.ali api.dll apilib
-$ attrib +R apilib\\*.ali
+$ lib -machine:IX86 -def:libmylib.def -out:libmylib.lib
 @end example
-@end itemize
+@end quotation
 
-At this point it is possible to use the DLL by directly linking
-against it. Note that you must use the GNAT shared runtime when using
-GNAT shared libraries. This is achieved by using the @code{-shared} binder
-option.
+If you are using a 64-bit toolchain, the above becomes...
 
 @quotation
 
 @example
-$ gnatmake main -Iapilib -bargs -shared -largs -Lapilib -lAPI
+$ lib -machine:X64 -def:libmylib.def -out:libmylib.lib
 @end example
 @end quotation
 
-@node Building DLLs with gnatdll,Ada DLLs and Finalization,Building DLLs with GNAT,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information building-dlls-with-gnatdll}@anchor{201}@anchor{gnat_ugn/platform_specific_information id23}@anchor{202}
-@subsubsection Building DLLs with gnatdll
 
+@enumerate 5
 
-@geindex DLLs
-@geindex building
-
-Note that it is preferred to use GNAT Project files
-(@ref{1e7,,Building DLLs with GNAT Project files}) or the built-in GNAT
-DLL support (@ref{1ff,,Building DLLs with GNAT}) or to build DLLs.
+@item 
+Build the C main
+@end enumerate
 
-This section explains how to build DLLs containing Ada code using
-@code{gnatdll}. These DLLs will be referred to as Ada DLLs in the
-remainder of this section.
+@quotation
 
-The steps required to build an Ada DLL that is to be used by Ada as well as
-non-Ada applications are as follows:
+@example
+$ cl /O2 /MD main.c libmylib.lib
+@end example
+@end quotation
 
 
-@itemize *
+@enumerate 6
 
 @item 
-You need to mark each Ada entity exported by the DLL with a @code{C} or
-@code{Stdcall} calling convention to avoid any Ada name mangling for the
-entities exported by the DLL
-(see @ref{203,,Exporting Ada Entities}). You can
-skip this step if you plan to use the Ada DLL only from Ada applications.
+Before running the executable, make sure you have set the PATH to the DLL,
+or copy the DLL into into the directory containing the .exe.
+@end enumerate
 
-@item 
-Your Ada code must export an initialization routine which calls the routine
-@code{adainit} generated by @code{gnatbind} to perform the elaboration of
-the Ada code in the DLL (@ref{204,,Ada DLLs and Elaboration}). The initialization
-routine exported by the Ada DLL must be invoked by the clients of the DLL
-to initialize the DLL.
+@node Debugging a DLL,Setting Stack Size from gnatlink,Using GNAT DLLs from Microsoft Visual Studio Applications,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information id36}@anchor{201}@anchor{gnat_ugn/platform_specific_information debugging-a-dll}@anchor{202}
+@subsubsection Debugging a DLL
+
+
+@geindex DLL debugging
+
+Debugging a DLL is similar to debugging a standard program. But
+we have to deal with two different executable parts: the DLL and the
+program that uses it. We have the following four possibilities:
 
-@item 
-When useful, the DLL should also export a finalization routine which calls
-routine @code{adafinal} generated by @code{gnatbind} to perform the
-finalization of the Ada code in the DLL (@ref{205,,Ada DLLs and Finalization}).
-The finalization routine exported by the Ada DLL must be invoked by the
-clients of the DLL when the DLL services are no further needed.
+
+@itemize *
 
 @item 
-You must provide a spec for the services exported by the Ada DLL in each
-of the programming languages to which you plan to make the DLL available.
+The program and the DLL are built with GCC/GNAT.
 
 @item 
-You must provide a definition file listing the exported entities
-(@ref{1f4,,The Definition File}).
+The program is built with foreign tools and the DLL is built with
+GCC/GNAT.
 
 @item 
-Finally you must use @code{gnatdll} to produce the DLL and the import
-library (@ref{1fc,,Using gnatdll}).
+The program is built with GCC/GNAT and the DLL is built with
+foreign tools.
 @end itemize
 
-Note that a relocatable DLL stripped using the @code{strip}
-binutils tool will not be relocatable anymore. To build a DLL without
-debug information pass @code{-largs -s} to @code{gnatdll}. This
-restriction does not apply to a DLL built using a Library Project.
-See the @emph{Library Projects} section in the @emph{GNAT Project Manager}
-chapter of the @emph{GPRbuild User's Guide}.
-
-@c Limitations_When_Using_Ada_DLLs_from Ada:
+In this section we address only cases one and two above.
+There is no point in trying to debug
+a DLL with GNU/GDB, if there is no GDB-compatible debugging
+information in it. To do so you must use a debugger compatible with the
+tools suite used to build the DLL.
 
 @menu
-* Limitations When Using Ada DLLs from Ada:: 
-* Exporting Ada Entities:: 
-* Ada DLLs and Elaboration:: 
+* Program and DLL Both Built with GCC/GNAT:: 
+* Program Built with Foreign Tools and DLL Built with GCC/GNAT:: 
 
 @end menu
 
-@node Limitations When Using Ada DLLs from Ada,Exporting Ada Entities,,Building DLLs with gnatdll
-@anchor{gnat_ugn/platform_specific_information limitations-when-using-ada-dlls-from-ada}@anchor{206}
-@subsubsection Limitations When Using Ada DLLs from Ada
-
+@node Program and DLL Both Built with GCC/GNAT,Program Built with Foreign Tools and DLL Built with GCC/GNAT,,Debugging a DLL
+@anchor{gnat_ugn/platform_specific_information id37}@anchor{203}@anchor{gnat_ugn/platform_specific_information program-and-dll-both-built-with-gcc-gnat}@anchor{204}
+@subsubsection Program and DLL Both Built with GCC/GNAT
 
-When using Ada DLLs from Ada applications there is a limitation users
-should be aware of. Because on Windows the GNAT run-time is not in a DLL of
-its own, each Ada DLL includes a part of the GNAT run-time. Specifically,
-each Ada DLL includes the services of the GNAT run-time that are necessary
-to the Ada code inside the DLL. As a result, when an Ada program uses an
-Ada DLL there are two independent GNAT run-times: one in the Ada DLL and
-one in the main program.
 
-It is therefore not possible to exchange GNAT run-time objects between the
-Ada DLL and the main Ada program. Example of GNAT run-time objects are file
-handles (e.g., @code{Text_IO.File_Type}), tasks types, protected objects
-types, etc.
+This is the simplest case. Both the DLL and the program have @code{GDB}
+compatible debugging information. It is then possible to break anywhere in
+the process. Let's suppose here that the main procedure is named
+@code{ada_main} and that in the DLL there is an entry point named
+@code{ada_dll}.
 
-It is completely safe to exchange plain elementary, array or record types,
-Windows object handles, etc.
+The DLL (@ref{1da,,Introduction to Dynamic Link Libraries (DLLs)}) and
+program must have been built with the debugging information (see GNAT -g
+switch). Here are the step-by-step instructions for debugging it:
 
-@node Exporting Ada Entities,Ada DLLs and Elaboration,Limitations When Using Ada DLLs from Ada,Building DLLs with gnatdll
-@anchor{gnat_ugn/platform_specific_information exporting-ada-entities}@anchor{203}@anchor{gnat_ugn/platform_specific_information id24}@anchor{207}
-@subsubsection Exporting Ada Entities
 
+@itemize *
 
-@geindex Export table
+@item 
+Launch @code{GDB} on the main program.
 
-Building a DLL is a way to encapsulate a set of services usable from any
-application. As a result, the Ada entities exported by a DLL should be
-exported with the @code{C} or @code{Stdcall} calling conventions to avoid
-any Ada name mangling. As an example here is an Ada package
-@code{API}, spec and body, exporting two procedures, a function, and a
-variable:
+@example
+$ gdb -nw ada_main
+@end example
 
-@quotation
+@item 
+Start the program and stop at the beginning of the main procedure
 
 @example
-with Interfaces.C; use Interfaces;
-package API is
-   Count : C.int := 0;
-   function Factorial (Val : C.int) return C.int;
-
-   procedure Initialize_API;
-   procedure Finalize_API;
-   --  Initialization & Finalization routines. More in the next section.
-private
-   pragma Export (C, Initialize_API);
-   pragma Export (C, Finalize_API);
-   pragma Export (C, Count);
-   pragma Export (C, Factorial);
-end API;
+(gdb) start
 @end example
 
-@example
-package body API is
-   function Factorial (Val : C.int) return C.int is
-      Fact : C.int := 1;
-   begin
-      Count := Count + 1;
-      for K in 1 .. Val loop
-         Fact := Fact * K;
-      end loop;
-      return Fact;
-   end Factorial;
+This step is required to be able to set a breakpoint inside the DLL. As long
+as the program is not run, the DLL is not loaded. This has the
+consequence that the DLL debugging information is also not loaded, so it is not
+possible to set a breakpoint in the DLL.
 
-   procedure Initialize_API is
-      procedure Adainit;
-      pragma Import (C, Adainit);
-   begin
-      Adainit;
-   end Initialize_API;
+@item 
+Set a breakpoint inside the DLL
 
-   procedure Finalize_API is
-      procedure Adafinal;
-      pragma Import (C, Adafinal);
-   begin
-      Adafinal;
-   end Finalize_API;
-end API;
+@example
+(gdb) break ada_dll
+(gdb) cont
 @end example
-@end quotation
+@end itemize
 
-If the Ada DLL you are building will only be used by Ada applications
-you do not have to export Ada entities with a @code{C} or @code{Stdcall}
-convention. As an example, the previous package could be written as
-follows:
+At this stage a breakpoint is set inside the DLL. From there on
+you can use the standard approach to debug the whole program
+(@ref{14d,,Running and Debugging Ada Programs}).
 
-@quotation
+@node Program Built with Foreign Tools and DLL Built with GCC/GNAT,,Program and DLL Both Built with GCC/GNAT,Debugging a DLL
+@anchor{gnat_ugn/platform_specific_information program-built-with-foreign-tools-and-dll-built-with-gcc-gnat}@anchor{205}@anchor{gnat_ugn/platform_specific_information id38}@anchor{206}
+@subsubsection Program Built with Foreign Tools and DLL Built with GCC/GNAT
 
-@example
-package API is
-   Count : Integer := 0;
-   function Factorial (Val : Integer) return Integer;
 
-   procedure Initialize_API;
-   procedure Finalize_API;
-   --  Initialization and Finalization routines.
-end API;
-@end example
+In this case things are slightly more complex because it is not possible to
+start the main program and then break at the beginning to load the DLL and the
+associated DLL debugging information. It is not possible to break at the
+beginning of the program because there is no @code{GDB} debugging information,
+and therefore there is no direct way of getting initial control. This
+section addresses this issue by describing some methods that can be used
+to break somewhere in the DLL to debug it.
 
-@example
-package body API is
-   function Factorial (Val : Integer) return Integer is
-      Fact : Integer := 1;
-   begin
-      Count := Count + 1;
-      for K in 1 .. Val loop
-         Fact := Fact * K;
-      end loop;
-      return Fact;
-   end Factorial;
+First suppose that the main procedure is named @code{main} (this is for
+example some C code built with Microsoft Visual C) and that there is a
+DLL named @code{test.dll} containing an Ada entry point named
+@code{ada_dll}.
 
-   ...
-   --  The remainder of this package body is unchanged.
-end API;
-@end example
-@end quotation
+The DLL (see @ref{1da,,Introduction to Dynamic Link Libraries (DLLs)}) must have
+been built with debugging information (see the GNAT @code{-g} option).
 
-Note that if you do not export the Ada entities with a @code{C} or
-@code{Stdcall} convention you will have to provide the mangled Ada names
-in the definition file of the Ada DLL
-(@ref{208,,Creating the Definition File}).
+@subsubheading Debugging the DLL Directly
 
-@node Ada DLLs and Elaboration,,Exporting Ada Entities,Building DLLs with gnatdll
-@anchor{gnat_ugn/platform_specific_information ada-dlls-and-elaboration}@anchor{204}@anchor{gnat_ugn/platform_specific_information id25}@anchor{209}
-@subsubsection Ada DLLs and Elaboration
 
 
-@geindex DLLs and elaboration
+@itemize *
 
-The DLL that you are building contains your Ada code as well as all the
-routines in the Ada library that are needed by it. The first thing a
-user of your DLL must do is elaborate the Ada code
-(@ref{f,,Elaboration Order Handling in GNAT}).
+@item 
+Find out the executable starting address
 
-To achieve this you must export an initialization routine
-(@code{Initialize_API} in the previous example), which must be invoked
-before using any of the DLL services. This elaboration routine must call
-the Ada elaboration routine @code{adainit} generated by the GNAT binder
-(@ref{b4,,Binding with Non-Ada Main Programs}). See the body of
-@code{Initialize_Api} for an example. Note that the GNAT binder is
-automatically invoked during the DLL build process by the @code{gnatdll}
-tool (@ref{1fc,,Using gnatdll}).
-
-When a DLL is loaded, Windows systematically invokes a routine called
-@code{DllMain}. It would therefore be possible to call @code{adainit}
-directly from @code{DllMain} without having to provide an explicit
-initialization routine. Unfortunately, it is not possible to call
-@code{adainit} from the @code{DllMain} if your program has library level
-tasks because access to the @code{DllMain} entry point is serialized by
-the system (that is, only a single thread can execute 'through' it at a
-time), which means that the GNAT run-time will deadlock waiting for the
-newly created task to complete its initialization.
+@example
+$ objdump --file-header main.exe
+@end example
 
-@node Ada DLLs and Finalization,Creating a Spec for Ada DLLs,Building DLLs with gnatdll,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information ada-dlls-and-finalization}@anchor{205}@anchor{gnat_ugn/platform_specific_information id26}@anchor{20a}
-@subsubsection Ada DLLs and Finalization
+The starting address is reported on the last line. For example:
 
+@example
+main.exe:     file format pei-i386
+architecture: i386, flags 0x0000010a:
+EXEC_P, HAS_DEBUG, D_PAGED
+start address 0x00401010
+@end example
 
-@geindex DLLs and finalization
+@item 
+Launch the debugger on the executable.
 
-When the services of an Ada DLL are no longer needed, the client code should
-invoke the DLL finalization routine, if available. The DLL finalization
-routine is in charge of releasing all resources acquired by the DLL. In the
-case of the Ada code contained in the DLL, this is achieved by calling
-routine @code{adafinal} generated by the GNAT binder
-(@ref{b4,,Binding with Non-Ada Main Programs}).
-See the body of @code{Finalize_Api} for an
-example. As already pointed out the GNAT binder is automatically invoked
-during the DLL build process by the @code{gnatdll} tool
-(@ref{1fc,,Using gnatdll}).
+@example
+$ gdb main.exe
+@end example
 
-@node Creating a Spec for Ada DLLs,GNAT and Windows Resources,Ada DLLs and Finalization,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information id27}@anchor{20b}@anchor{gnat_ugn/platform_specific_information creating-a-spec-for-ada-dlls}@anchor{20c}
-@subsubsection Creating a Spec for Ada DLLs
+@item 
+Set a breakpoint at the starting address, and launch the program.
 
+@example
+$ (gdb) break *0x00401010
+$ (gdb) run
+@end example
 
-To use the services exported by the Ada DLL from another programming
-language (e.g., C), you have to translate the specs of the exported Ada
-entities in that language. For instance in the case of @code{API.dll},
-the corresponding C header file could look like:
+The program will stop at the given address.
 
-@quotation
+@item 
+Set a breakpoint on a DLL subroutine.
 
 @example
-extern int *_imp__count;
-#define count (*_imp__count)
-int factorial (int);
+(gdb) break ada_dll.adb:45
 @end example
-@end quotation
-
-It is important to understand that when building an Ada DLL to be used by
-other Ada applications, you need two different specs for the packages
-contained in the DLL: one for building the DLL and the other for using
-the DLL. This is because the @code{DLL} calling convention is needed to
-use a variable defined in a DLL, but when building the DLL, the variable
-must have either the @code{Ada} or @code{C} calling convention. As an
-example consider a DLL comprising the following package @code{API}:
 
-@quotation
+Or if you want to break using a symbol on the DLL, you need first to
+select the Ada language (language used by the DLL).
 
 @example
-package API is
-   Count : Integer := 0;
-   ...
-   --  Remainder of the package omitted.
-end API;
+(gdb) set language ada
+(gdb) break ada_dll
 @end example
-@end quotation
 
-After producing a DLL containing package @code{API}, the spec that
-must be used to import @code{API.Count} from Ada code outside of the
-DLL is:
-
-@quotation
+@item 
+Continue the program.
 
 @example
-package API is
-   Count : Integer;
-   pragma Import (DLL, Count);
-end API;
+(gdb) cont
 @end example
-@end quotation
 
-@menu
-* Creating the Definition File:: 
-* Using gnatdll:: 
+This will run the program until it reaches the breakpoint that has been
+set. From that point you can use the standard way to debug a program
+as described in (@ref{14d,,Running and Debugging Ada Programs}).
+@end itemize
 
-@end menu
+It is also possible to debug the DLL by attaching to a running process.
 
-@node Creating the Definition File,Using gnatdll,,Creating a Spec for Ada DLLs
-@anchor{gnat_ugn/platform_specific_information id28}@anchor{20d}@anchor{gnat_ugn/platform_specific_information creating-the-definition-file}@anchor{208}
-@subsubsection Creating the Definition File
+@subsubheading Attaching to a Running Process
 
 
-The definition file is the last file needed to build the DLL. It lists
-the exported symbols. As an example, the definition file for a DLL
-containing only package @code{API} (where all the entities are exported
-with a @code{C} calling convention) is:
+@geindex DLL debugging
+@geindex attach to process
 
-@quotation
+With @code{GDB} it is always possible to debug a running process by
+attaching to it. It is possible to debug a DLL this way. The limitation
+of this approach is that the DLL must run long enough to perform the
+attach operation. It may be useful for instance to insert a time wasting
+loop in the code of the DLL to meet this criterion.
+
+
+@itemize *
+
+@item 
+Launch the main program @code{main.exe}.
 
 @example
-EXPORTS
-    count
-    factorial
-    finalize_api
-    initialize_api
+$ main
 @end example
-@end quotation
 
-If the @code{C} calling convention is missing from package @code{API},
-then the definition file contains the mangled Ada names of the above
-entities, which in this case are:
+@item 
+Use the Windows @emph{Task Manager} to find the process ID. Let's say
+that the process PID for @code{main.exe} is 208.
 
-@quotation
+@item 
+Launch gdb.
 
 @example
-EXPORTS
-    api__count
-    api__factorial
-    api__finalize_api
-    api__initialize_api
+$ gdb
 @end example
-@end quotation
 
-@node Using gnatdll,,Creating the Definition File,Creating a Spec for Ada DLLs
-@anchor{gnat_ugn/platform_specific_information id29}@anchor{20e}@anchor{gnat_ugn/platform_specific_information using-gnatdll}@anchor{1fc}
-@subsubsection Using @code{gnatdll}
+@item 
+Attach to the running process to be debugged.
 
+@example
+(gdb) attach 208
+@end example
 
-@geindex gnatdll
+@item 
+Load the process debugging information.
 
-@code{gnatdll} is a tool to automate the DLL build process once all the Ada
-and non-Ada sources that make up your DLL have been compiled.
-@code{gnatdll} is actually in charge of two distinct tasks: build the
-static import library for the DLL and the actual DLL. The form of the
-@code{gnatdll} command is
+@example
+(gdb) symbol-file main.exe
+@end example
 
-@quotation
+@item 
+Break somewhere in the DLL.
 
 @example
-$ gnatdll [ switches ] list-of-files [ -largs opts ]
+(gdb) break ada_dll
 @end example
-@end quotation
 
-where @code{list-of-files} is a list of ALI and object files. The object
-file list must be the exact list of objects corresponding to the non-Ada
-sources whose services are to be included in the DLL. The ALI file list
-must be the exact list of ALI files for the corresponding Ada sources
-whose services are to be included in the DLL. If @code{list-of-files} is
-missing, only the static import library is generated.
+@item 
+Continue process execution.
 
-You may specify any of the following switches to @code{gnatdll}:
+@example
+(gdb) cont
+@end example
+@end itemize
 
-@quotation
+This last step will resume the process execution, and stop at
+the breakpoint we have set. From there you can use the standard
+approach to debug a program as described in
+@ref{14d,,Running and Debugging Ada Programs}.
 
-@geindex -a (gnatdll)
-@end quotation
+@node Setting Stack Size from gnatlink,Setting Heap Size from gnatlink,Debugging a DLL,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information setting-stack-size-from-gnatlink}@anchor{127}@anchor{gnat_ugn/platform_specific_information id39}@anchor{207}
+@subsubsection Setting Stack Size from @code{gnatlink}
 
 
-@table @asis
+It is possible to specify the program stack size at link time. On modern
+versions of Windows, starting with XP, this is mostly useful to set the size of
+the main stack (environment task). The other task stacks are set with pragma
+Storage_Size or with the @emph{gnatbind -d} command.
 
-@item @code{-a[@emph{address}]}
+Since older versions of Windows (2000, NT4, etc.) do not allow setting the
+reserve size of individual tasks, the link-time stack size applies to all
+tasks, and pragma Storage_Size has no effect.
+In particular, Stack Overflow checks are made against this
+link-time specified size.
 
-Build a non-relocatable DLL at @code{address}. If @code{address} is not
-specified the default address @code{0x11000000} will be used. By default,
-when this switch is missing, @code{gnatdll} builds relocatable DLL. We
-advise the reader to build relocatable DLL.
+This setting can be done with @code{gnatlink} using either of the following:
 
-@geindex -b (gnatdll)
 
-@item @code{-b @emph{address}}
+@itemize *
 
-Set the relocatable DLL base address. By default the address is
-@code{0x11000000}.
+@item 
+@code{-Xlinker} linker option
 
-@geindex -bargs (gnatdll)
+@example
+$ gnatlink hello -Xlinker --stack=0x10000,0x1000
+@end example
 
-@item @code{-bargs @emph{opts}}
+This sets the stack reserve size to 0x10000 bytes and the stack commit
+size to 0x1000 bytes.
 
-Binder options. Pass @code{opts} to the binder.
+@item 
+@code{-Wl} linker option
 
-@geindex -d (gnatdll)
+@example
+$ gnatlink hello -Wl,--stack=0x1000000
+@end example
 
-@item @code{-d @emph{dllfile}}
+This sets the stack reserve size to 0x1000000 bytes. Note that with
+@code{-Wl} option it is not possible to set the stack commit size
+because the comma is a separator for this option.
+@end itemize
 
-@code{dllfile} is the name of the DLL. This switch must be present for
-@code{gnatdll} to do anything. The name of the generated import library is
-obtained algorithmically from @code{dllfile} as shown in the following
-example: if @code{dllfile} is @code{xyz.dll}, the import library name is
-@code{libxyz.dll.a}. The name of the definition file to use (if not specified
-by option @code{-e}) is obtained algorithmically from @code{dllfile}
-as shown in the following example:
-if @code{dllfile} is @code{xyz.dll}, the definition
-file used is @code{xyz.def}.
+@node Setting Heap Size from gnatlink,,Setting Stack Size from gnatlink,Mixed-Language Programming on Windows
+@anchor{gnat_ugn/platform_specific_information setting-heap-size-from-gnatlink}@anchor{128}@anchor{gnat_ugn/platform_specific_information id40}@anchor{208}
+@subsubsection Setting Heap Size from @code{gnatlink}
 
-@geindex -e (gnatdll)
 
-@item @code{-e @emph{deffile}}
+Under Windows systems, it is possible to specify the program heap size from
+@code{gnatlink} using either of the following:
 
-@code{deffile} is the name of the definition file.
 
-@geindex -g (gnatdll)
+@itemize *
 
-@item @code{-g}
+@item 
+@code{-Xlinker} linker option
 
-Generate debugging information. This information is stored in the object
-file and copied from there to the final DLL file by the linker,
-where it can be read by the debugger. You must use the
-@code{-g} switch if you plan on using the debugger or the symbolic
-stack traceback.
-
-@geindex -h (gnatdll)
-
-@item @code{-h}
-
-Help mode. Displays @code{gnatdll} switch usage information.
-
-@geindex -I (gnatdll)
-
-@item @code{-I@emph{dir}}
-
-Direct @code{gnatdll} to search the @code{dir} directory for source and
-object files needed to build the DLL.
-(@ref{89,,Search Paths and the Run-Time Library (RTL)}).
+@example
+$ gnatlink hello -Xlinker --heap=0x10000,0x1000
+@end example
 
-@geindex -k (gnatdll)
+This sets the heap reserve size to 0x10000 bytes and the heap commit
+size to 0x1000 bytes.
 
-@item @code{-k}
+@item 
+@code{-Wl} linker option
 
-Removes the @code{@@@emph{nn}} suffix from the import library's exported
-names, but keeps them for the link names. You must specify this
-option if you want to use a @code{Stdcall} function in a DLL for which
-the @code{@@@emph{nn}} suffix has been removed. This is the case for most
-of the Windows NT DLL for example. This option has no effect when
-@code{-n} option is specified.
+@example
+$ gnatlink hello -Wl,--heap=0x1000000
+@end example
 
-@geindex -l (gnatdll)
+This sets the heap reserve size to 0x1000000 bytes. Note that with
+@code{-Wl} option it is not possible to set the heap commit size
+because the comma is a separator for this option.
+@end itemize
 
-@item @code{-l @emph{file}}
+@node Windows Specific Add-Ons,,Mixed-Language Programming on Windows,Microsoft Windows Topics
+@anchor{gnat_ugn/platform_specific_information windows-specific-add-ons}@anchor{209}@anchor{gnat_ugn/platform_specific_information win32-specific-addons}@anchor{20a}
+@subsection Windows Specific Add-Ons
 
-The list of ALI and object files used to build the DLL are listed in
-@code{file}, instead of being given in the command line. Each line in
-@code{file} contains the name of an ALI or object file.
 
-@geindex -n (gnatdll)
+This section describes the Windows specific add-ons.
 
-@item @code{-n}
+@menu
+* Win32Ada:: 
+* wPOSIX:: 
 
-No Import. Do not create the import library.
+@end menu
 
-@geindex -q (gnatdll)
+@node Win32Ada,wPOSIX,,Windows Specific Add-Ons
+@anchor{gnat_ugn/platform_specific_information win32ada}@anchor{20b}@anchor{gnat_ugn/platform_specific_information id41}@anchor{20c}
+@subsubsection Win32Ada
 
-@item @code{-q}
 
-Quiet mode. Do not display unnecessary messages.
+Win32Ada is a binding for the Microsoft Win32 API. This binding can be
+easily installed from the provided installer. To use the Win32Ada
+binding you need to use a project file, and adding a single with_clause
+will give you full access to the Win32Ada binding sources and ensure
+that the proper libraries are passed to the linker.
 
-@geindex -v (gnatdll)
+@quotation
 
-@item @code{-v}
+@example
+with "win32ada";
+project P is
+   for Sources use ...;
+end P;
+@end example
+@end quotation
 
-Verbose mode. Display extra information.
+To build the application you just need to call gprbuild for the
+application's project, here p.gpr:
 
-@geindex -largs (gnatdll)
+@quotation
 
-@item @code{-largs @emph{opts}}
+@example
+gprbuild p.gpr
+@end example
+@end quotation
 
-Linker options. Pass @code{opts} to the linker.
-@end table
+@node wPOSIX,,Win32Ada,Windows Specific Add-Ons
+@anchor{gnat_ugn/platform_specific_information id42}@anchor{20d}@anchor{gnat_ugn/platform_specific_information wposix}@anchor{20e}
+@subsubsection wPOSIX
 
-@subsubheading @code{gnatdll} Example
 
+wPOSIX is a minimal POSIX binding whose goal is to help with building
+cross-platforms applications. This binding is not complete though, as
+the Win32 API does not provide the necessary support for all POSIX APIs.
 
-As an example the command to build a relocatable DLL from @code{api.adb}
-once @code{api.adb} has been compiled and @code{api.def} created is
+To use the wPOSIX binding you need to use a project file, and adding
+a single with_clause will give you full access to the wPOSIX binding
+sources and ensure that the proper libraries are passed to the linker.
 
 @quotation
 
 @example
-$ gnatdll -d api.dll api.ali
+with "wposix";
+project P is
+   for Sources use ...;
+end P;
 @end example
 @end quotation
 
-The above command creates two files: @code{libapi.dll.a} (the import
-library) and @code{api.dll} (the actual DLL). If you want to create
-only the DLL, just type:
+To build the application you just need to call gprbuild for the
+application's project, here p.gpr:
 
 @quotation
 
 @example
-$ gnatdll -d api.dll -n api.ali
+gprbuild p.gpr
 @end example
 @end quotation
 
-Alternatively if you want to create just the import library, type:
-
-@quotation
+@node Mac OS Topics,,Microsoft Windows Topics,Platform-Specific Information
+@anchor{gnat_ugn/platform_specific_information mac-os-topics}@anchor{20f}@anchor{gnat_ugn/platform_specific_information id43}@anchor{210}
+@section Mac OS Topics
 
-@example
-$ gnatdll -d api.dll
-@end example
-@end quotation
 
-@subsubheading @code{gnatdll} behind the Scenes
+@geindex OS X
 
+This section describes topics that are specific to Apple's OS X
+platform.
 
-This section details the steps involved in creating a DLL. @code{gnatdll}
-does these steps for you. Unless you are interested in understanding what
-goes on behind the scenes, you should skip this section.
+@menu
+* Codesigning the Debugger:: 
 
-We use the previous example of a DLL containing the Ada package @code{API},
-to illustrate the steps necessary to build a DLL. The starting point is a
-set of objects that will make up the DLL and the corresponding ALI
-files. In the case of this example this means that @code{api.o} and
-@code{api.ali} are available. To build a relocatable DLL, @code{gnatdll} does
-the following:
+@end menu
 
+@node Codesigning the Debugger,,,Mac OS Topics
+@anchor{gnat_ugn/platform_specific_information codesigning-the-debugger}@anchor{211}
+@subsection Codesigning the Debugger
 
-@itemize *
 
-@item 
-@code{gnatdll} builds the base file (@code{api.base}). A base file gives
-the information necessary to generate relocation information for the
-DLL.
+The Darwin Kernel requires the debugger to have special permissions
+before it is allowed to control other processes. These permissions
+are granted by codesigning the GDB executable. Without these
+permissions, the debugger will report error messages such as:
 
 @example
-$ gnatbind -n api
-$ gnatlink api -o api.jnk -mdll -Wl,--base-file,api.base
+Starting program: /x/y/foo
+Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
+(please check gdb is codesigned - see taskgated(8))
 @end example
 
-In addition to the base file, the @code{gnatlink} command generates an
-output file @code{api.jnk} which can be discarded. The @code{-mdll} switch
-asks @code{gnatlink} to generate the routines @code{DllMain} and
-@code{DllMainCRTStartup} that are called by the Windows loader when the DLL
-is loaded into memory.
+Codesigning requires a certificate.  The following procedure explains
+how to create one:
+
+
+@itemize *
 
 @item 
-@code{gnatdll} uses @code{dlltool} (see @ref{20f,,Using dlltool}) to build the
-export table (@code{api.exp}). The export table contains the relocation
-information in a form which can be used during the final link to ensure
-that the Windows loader is able to place the DLL anywhere in memory.
+Start the Keychain Access application (in
+/Applications/Utilities/Keychain Access.app)
 
-@example
-$ dlltool --dllname api.dll --def api.def --base-file api.base \\
-          --output-exp api.exp
-@end example
+@item 
+Select the Keychain Access -> Certificate Assistant ->
+Create a Certificate... menu
 
 @item 
-@code{gnatdll} builds the base file using the new export table. Note that
-@code{gnatbind} must be called once again since the binder generated file
-has been deleted during the previous call to @code{gnatlink}.
+Then:
 
-@example
-$ gnatbind -n api
-$ gnatlink api -o api.jnk api.exp -mdll
-      -Wl,--base-file,api.base
-@end example
+
+@itemize *
 
 @item 
-@code{gnatdll} builds the new export table using the new base file and
-generates the DLL import library @code{libAPI.dll.a}.
+Choose a name for the new certificate (this procedure will use
+"gdb-cert" as an example)
 
-@example
-$ dlltool --dllname api.dll --def api.def --base-file api.base \\
-          --output-exp api.exp --output-lib libAPI.a
-@end example
+@item 
+Set "Identity Type" to "Self Signed Root"
 
 @item 
-Finally @code{gnatdll} builds the relocatable DLL using the final export
-table.
+Set "Certificate Type" to "Code Signing"
 
-@example
-$ gnatbind -n api
-$ gnatlink api api.exp -o api.dll -mdll
-@end example
+@item 
+Activate the "Let me override defaults" option
 @end itemize
-@anchor{gnat_ugn/platform_specific_information using-dlltool}@anchor{20f}
-@subsubheading Using @code{dlltool}
 
+@item 
+Click several times on "Continue" until the "Specify a Location
+For The Certificate" screen appears, then set "Keychain" to "System"
 
-@code{dlltool} is the low-level tool used by @code{gnatdll} to build
-DLLs and static import libraries. This section summarizes the most
-common @code{dlltool} switches. The form of the @code{dlltool} command
-is
+@item 
+Click on "Continue" until the certificate is created
+
+@item 
+Finally, in the view, double-click on the new certificate,
+and set "When using this certificate" to "Always Trust"
+
+@item 
+Exit the Keychain Access application and restart the computer
+(this is unfortunately required)
+@end itemize
+
+Once a certificate has been created, the debugger can be codesigned
+as follow. In a Terminal, run the following command:
 
 @quotation
 
 @example
-$ dlltool [`switches`]
+$ codesign -f -s  "gdb-cert"  <gnat_install_prefix>/bin/gdb
 @end example
 @end quotation
 
-@code{dlltool} switches include:
-
-@geindex --base-file (dlltool)
+where "gdb-cert" should be replaced by the actual certificate
+name chosen above, and <gnat_install_prefix> should be replaced by
+the location where you installed GNAT.  Also, be sure that users are
+in the Unix group @code{_developer}.
 
+@node Example of Binder Output File,Elaboration Order Handling in GNAT,Platform-Specific Information,Top
+@anchor{gnat_ugn/example_of_binder_output example-of-binder-output-file}@anchor{e}@anchor{gnat_ugn/example_of_binder_output doc}@anchor{212}@anchor{gnat_ugn/example_of_binder_output id1}@anchor{213}
+@chapter Example of Binder Output File
 
-@table @asis
 
-@item @code{--base-file @emph{basefile}}
+@geindex Binder output (example)
 
-Read the base file @code{basefile} generated by the linker. This switch
-is used to create a relocatable DLL.
-@end table
+This Appendix displays the source code for the output file
+generated by @emph{gnatbind} for a simple 'Hello World' program.
+Comments have been added for clarification purposes.
 
-@geindex --def (dlltool)
+@example
+--  The package is called Ada_Main unless this name is actually used
+--  as a unit name in the partition, in which case some other unique
+--  name is used.
 
+pragma Ada_95;
+with System;
+package ada_main is
+   pragma Warnings (Off);
 
-@table @asis
+   --  The main program saves the parameters (argument count,
+   --  argument values, environment pointer) in global variables
+   --  for later access by other units including
+   --  Ada.Command_Line.
 
-@item @code{--def @emph{deffile}}
-
-Read the definition file.
-@end table
-
-@geindex --dllname (dlltool)
-
-
-@table @asis
-
-@item @code{--dllname @emph{name}}
-
-Gives the name of the DLL. This switch is used to embed the name of the
-DLL in the static import library generated by @code{dlltool} with switch
-@code{--output-lib}.
-@end table
-
-@geindex -k (dlltool)
-
-
-@table @asis
-
-@item @code{-k}
-
-Kill @code{@@@emph{nn}} from exported names
-(@ref{1e8,,Windows Calling Conventions}
-for a discussion about @code{Stdcall}-style symbols.
-@end table
-
-@geindex --help (dlltool)
-
-
-@table @asis
-
-@item @code{--help}
-
-Prints the @code{dlltool} switches with a concise description.
-@end table
-
-@geindex --output-exp (dlltool)
-
-
-@table @asis
-
-@item @code{--output-exp @emph{exportfile}}
-
-Generate an export file @code{exportfile}. The export file contains the
-export table (list of symbols in the DLL) and is used to create the DLL.
-@end table
-
-@geindex --output-lib (dlltool)
-
-
-@table @asis
-
-@item @code{--output-lib @emph{libfile}}
-
-Generate a static import library @code{libfile}.
-@end table
-
-@geindex -v (dlltool)
-
-
-@table @asis
-
-@item @code{-v}
-
-Verbose mode.
-@end table
-
-@geindex --as (dlltool)
-
-
-@table @asis
-
-@item @code{--as @emph{assembler-name}}
-
-Use @code{assembler-name} as the assembler. The default is @code{as}.
-@end table
-
-@node GNAT and Windows Resources,Using GNAT DLLs from Microsoft Visual Studio Applications,Creating a Spec for Ada DLLs,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information gnat-and-windows-resources}@anchor{210}@anchor{gnat_ugn/platform_specific_information id30}@anchor{211}
-@subsubsection GNAT and Windows Resources
-
-
-@geindex Resources
-@geindex windows
-
-Resources are an easy way to add Windows specific objects to your
-application. The objects that can be added as resources include:
-
-
-@itemize *
-
-@item 
-menus
-
-@item 
-accelerators
-
-@item 
-dialog boxes
-
-@item 
-string tables
-
-@item 
-bitmaps
-
-@item 
-cursors
-
-@item 
-icons
-
-@item 
-fonts
-
-@item 
-version information
-@end itemize
-
-For example, a version information resource can be defined as follow and
-embedded into an executable or DLL:
-
-A version information resource can be used to embed information into an
-executable or a DLL. These information can be viewed using the file properties
-from the Windows Explorer. Here is an example of a version information
-resource:
-
-@quotation
-
-@example
-1 VERSIONINFO
-FILEVERSION     1,0,0,0
-PRODUCTVERSION  1,0,0,0
-BEGIN
-  BLOCK "StringFileInfo"
-  BEGIN
-    BLOCK "080904E4"
-    BEGIN
-      VALUE "CompanyName", "My Company Name"
-      VALUE "FileDescription", "My application"
-      VALUE "FileVersion", "1.0"
-      VALUE "InternalName", "my_app"
-      VALUE "LegalCopyright", "My Name"
-      VALUE "OriginalFilename", "my_app.exe"
-      VALUE "ProductName", "My App"
-      VALUE "ProductVersion", "1.0"
-    END
-  END
-
-  BLOCK "VarFileInfo"
-  BEGIN
-    VALUE "Translation", 0x809, 1252
-  END
-END
-@end example
-@end quotation
-
-The value @code{0809} (langID) is for the U.K English language and
-@code{04E4} (charsetID), which is equal to @code{1252} decimal, for
-multilingual.
-
-This section explains how to build, compile and use resources. Note that this
-section does not cover all resource objects, for a complete description see
-the corresponding Microsoft documentation.
+   gnat_argc : Integer;
+   gnat_argv : System.Address;
+   gnat_envp : System.Address;
 
-@menu
-* Building Resources:: 
-* Compiling Resources:: 
-* Using Resources:: 
+   --  The actual variables are stored in a library routine. This
+   --  is useful for some shared library situations, where there
+   --  are problems if variables are not in the library.
 
-@end menu
+   pragma Import (C, gnat_argc);
+   pragma Import (C, gnat_argv);
+   pragma Import (C, gnat_envp);
 
-@node Building Resources,Compiling Resources,,GNAT and Windows Resources
-@anchor{gnat_ugn/platform_specific_information building-resources}@anchor{212}@anchor{gnat_ugn/platform_specific_information id31}@anchor{213}
-@subsubsection Building Resources
+   --  The exit status is similarly an external location
 
+   gnat_exit_status : Integer;
+   pragma Import (C, gnat_exit_status);
 
-@geindex Resources
-@geindex building
+   GNAT_Version : constant String :=
+                    "GNAT Version: Pro 7.4.0w (20141119-49)" & ASCII.NUL;
+   pragma Export (C, GNAT_Version, "__gnat_version");
 
-A resource file is an ASCII file. By convention resource files have an
-@code{.rc} extension.
-The easiest way to build a resource file is to use Microsoft tools
-such as @code{imagedit.exe} to build bitmaps, icons and cursors and
-@code{dlgedit.exe} to build dialogs.
-It is always possible to build an @code{.rc} file yourself by writing a
-resource script.
+   Ada_Main_Program_Name : constant String := "_ada_hello" & ASCII.NUL;
+   pragma Export (C, Ada_Main_Program_Name, "__gnat_ada_main_program_name");
 
-It is not our objective to explain how to write a resource file. A
-complete description of the resource script language can be found in the
-Microsoft documentation.
+   --  This is the generated adainit routine that performs
+   --  initialization at the start of execution. In the case
+   --  where Ada is the main program, this main program makes
+   --  a call to adainit at program startup.
 
-@node Compiling Resources,Using Resources,Building Resources,GNAT and Windows Resources
-@anchor{gnat_ugn/platform_specific_information compiling-resources}@anchor{214}@anchor{gnat_ugn/platform_specific_information id32}@anchor{215}
-@subsubsection Compiling Resources
+   procedure adainit;
+   pragma Export (C, adainit, "adainit");
 
+   --  This is the generated adafinal routine that performs
+   --  finalization at the end of execution. In the case where
+   --  Ada is the main program, this main program makes a call
+   --  to adafinal at program termination.
 
-@geindex rc
+   procedure adafinal;
+   pragma Export (C, adafinal, "adafinal");
 
-@geindex windres
+   --  This routine is called at the start of execution. It is
+   --  a dummy routine that is used by the debugger to breakpoint
+   --  at the start of execution.
 
-@geindex Resources
-@geindex compiling
+   --  This is the actual generated main program (it would be
+   --  suppressed if the no main program switch were used). As
+   --  required by standard system conventions, this program has
+   --  the external name main.
 
-This section describes how to build a GNAT-compatible (COFF) object file
-containing the resources. This is done using the Resource Compiler
-@code{windres} as follows:
+   function main
+     (argc : Integer;
+      argv : System.Address;
+      envp : System.Address)
+      return Integer;
+   pragma Export (C, main, "main");
 
-@quotation
+   --  The following set of constants give the version
+   --  identification values for every unit in the bound
+   --  partition. This identification is computed from all
+   --  dependent semantic units, and corresponds to the
+   --  string that would be returned by use of the
+   --  Body_Version or Version attributes.
 
-@example
-$ windres -i myres.rc -o myres.o
-@end example
-@end quotation
-
-By default @code{windres} will run @code{gcc} to preprocess the @code{.rc}
-file. You can specify an alternate preprocessor (usually named
-@code{cpp.exe}) using the @code{windres} @code{--preprocessor}
-parameter. A list of all possible options may be obtained by entering
-the command @code{windres} @code{--help}.
-
-It is also possible to use the Microsoft resource compiler @code{rc.exe}
-to produce a @code{.res} file (binary resource file). See the
-corresponding Microsoft documentation for further details. In this case
-you need to use @code{windres} to translate the @code{.res} file to a
-GNAT-compatible object file as follows:
-
-@quotation
-
-@example
-$ windres -i myres.res -o myres.o
-@end example
-@end quotation
-
-@node Using Resources,,Compiling Resources,GNAT and Windows Resources
-@anchor{gnat_ugn/platform_specific_information using-resources}@anchor{216}@anchor{gnat_ugn/platform_specific_information id33}@anchor{217}
-@subsubsection Using Resources
-
-
-@geindex Resources
-@geindex using
-
-To include the resource file in your program just add the
-GNAT-compatible object file for the resource(s) to the linker
-arguments. With @code{gnatmake} this is done by using the @code{-largs}
-option:
-
-@quotation
-
-@example
-$ gnatmake myprog -largs myres.o
-@end example
-@end quotation
-
-@node Using GNAT DLLs from Microsoft Visual Studio Applications,Debugging a DLL,GNAT and Windows Resources,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information using-gnat-dll-from-msvs}@anchor{218}@anchor{gnat_ugn/platform_specific_information using-gnat-dlls-from-microsoft-visual-studio-applications}@anchor{219}
-@subsubsection Using GNAT DLLs from Microsoft Visual Studio Applications
-
-
-@geindex Microsoft Visual Studio
-@geindex use with GNAT DLLs
-
-This section describes a common case of mixed GNAT/Microsoft Visual Studio
-application development, where the main program is developed using MSVS, and
-is linked with a DLL developed using GNAT. Such a mixed application should
-be developed following the general guidelines outlined above; below is the
-cookbook-style sequence of steps to follow:
-
-
-@enumerate 
-
-@item 
-First develop and build the GNAT shared library using a library project
-(let's assume the project is @code{mylib.gpr}, producing the library @code{libmylib.dll}):
-@end enumerate
-
-@quotation
-
-@example
-$ gprbuild -p mylib.gpr
-@end example
-@end quotation
-
-
-@enumerate 2
-
-@item 
-Produce a .def file for the symbols you need to interface with, either by
-hand or automatically with possibly some manual adjustments
-(see @ref{1fa,,Creating Definition File Automatically}):
-@end enumerate
-
-@quotation
-
-@example
-$ dlltool libmylib.dll -z libmylib.def --export-all-symbols
-@end example
-@end quotation
-
-
-@enumerate 3
-
-@item 
-Make sure that MSVS command-line tools are accessible on the path.
-
-@item 
-Create the Microsoft-style import library (see @ref{1fd,,MSVS-Style Import Library}):
-@end enumerate
-
-@quotation
-
-@example
-$ lib -machine:IX86 -def:libmylib.def -out:libmylib.lib
-@end example
-@end quotation
-
-If you are using a 64-bit toolchain, the above becomes...
-
-@quotation
-
-@example
-$ lib -machine:X64 -def:libmylib.def -out:libmylib.lib
-@end example
-@end quotation
-
-
-@enumerate 5
-
-@item 
-Build the C main
-@end enumerate
-
-@quotation
-
-@example
-$ cl /O2 /MD main.c libmylib.lib
-@end example
-@end quotation
-
-
-@enumerate 6
-
-@item 
-Before running the executable, make sure you have set the PATH to the DLL,
-or copy the DLL into into the directory containing the .exe.
-@end enumerate
-
-@node Debugging a DLL,Setting Stack Size from gnatlink,Using GNAT DLLs from Microsoft Visual Studio Applications,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information id34}@anchor{21a}@anchor{gnat_ugn/platform_specific_information debugging-a-dll}@anchor{21b}
-@subsubsection Debugging a DLL
-
-
-@geindex DLL debugging
-
-Debugging a DLL is similar to debugging a standard program. But
-we have to deal with two different executable parts: the DLL and the
-program that uses it. We have the following four possibilities:
-
-
-@itemize *
-
-@item 
-The program and the DLL are built with GCC/GNAT.
-
-@item 
-The program is built with foreign tools and the DLL is built with
-GCC/GNAT.
-
-@item 
-The program is built with GCC/GNAT and the DLL is built with
-foreign tools.
-@end itemize
-
-In this section we address only cases one and two above.
-There is no point in trying to debug
-a DLL with GNU/GDB, if there is no GDB-compatible debugging
-information in it. To do so you must use a debugger compatible with the
-tools suite used to build the DLL.
-
-@menu
-* Program and DLL Both Built with GCC/GNAT:: 
-* Program Built with Foreign Tools and DLL Built with GCC/GNAT:: 
-
-@end menu
-
-@node Program and DLL Both Built with GCC/GNAT,Program Built with Foreign Tools and DLL Built with GCC/GNAT,,Debugging a DLL
-@anchor{gnat_ugn/platform_specific_information program-and-dll-both-built-with-gcc-gnat}@anchor{21c}@anchor{gnat_ugn/platform_specific_information id35}@anchor{21d}
-@subsubsection Program and DLL Both Built with GCC/GNAT
-
-
-This is the simplest case. Both the DLL and the program have @code{GDB}
-compatible debugging information. It is then possible to break anywhere in
-the process. Let's suppose here that the main procedure is named
-@code{ada_main} and that in the DLL there is an entry point named
-@code{ada_dll}.
-
-The DLL (@ref{1f2,,Introduction to Dynamic Link Libraries (DLLs)}) and
-program must have been built with the debugging information (see GNAT -g
-switch). Here are the step-by-step instructions for debugging it:
-
-
-@itemize *
-
-@item 
-Launch @code{GDB} on the main program.
-
-@example
-$ gdb -nw ada_main
-@end example
-
-@item 
-Start the program and stop at the beginning of the main procedure
-
-@example
-(gdb) start
-@end example
-
-This step is required to be able to set a breakpoint inside the DLL. As long
-as the program is not run, the DLL is not loaded. This has the
-consequence that the DLL debugging information is also not loaded, so it is not
-possible to set a breakpoint in the DLL.
-
-@item 
-Set a breakpoint inside the DLL
-
-@example
-(gdb) break ada_dll
-(gdb) cont
-@end example
-@end itemize
-
-At this stage a breakpoint is set inside the DLL. From there on
-you can use the standard approach to debug the whole program
-(@ref{24,,Running and Debugging Ada Programs}).
-
-@node Program Built with Foreign Tools and DLL Built with GCC/GNAT,,Program and DLL Both Built with GCC/GNAT,Debugging a DLL
-@anchor{gnat_ugn/platform_specific_information id36}@anchor{21e}@anchor{gnat_ugn/platform_specific_information program-built-with-foreign-tools-and-dll-built-with-gcc-gnat}@anchor{21f}
-@subsubsection Program Built with Foreign Tools and DLL Built with GCC/GNAT
-
-
-In this case things are slightly more complex because it is not possible to
-start the main program and then break at the beginning to load the DLL and the
-associated DLL debugging information. It is not possible to break at the
-beginning of the program because there is no @code{GDB} debugging information,
-and therefore there is no direct way of getting initial control. This
-section addresses this issue by describing some methods that can be used
-to break somewhere in the DLL to debug it.
-
-First suppose that the main procedure is named @code{main} (this is for
-example some C code built with Microsoft Visual C) and that there is a
-DLL named @code{test.dll} containing an Ada entry point named
-@code{ada_dll}.
-
-The DLL (see @ref{1f2,,Introduction to Dynamic Link Libraries (DLLs)}) must have
-been built with debugging information (see the GNAT @code{-g} option).
-
-@subsubheading Debugging the DLL Directly
-
-
-
-@itemize *
-
-@item 
-Find out the executable starting address
-
-@example
-$ objdump --file-header main.exe
-@end example
-
-The starting address is reported on the last line. For example:
-
-@example
-main.exe:     file format pei-i386
-architecture: i386, flags 0x0000010a:
-EXEC_P, HAS_DEBUG, D_PAGED
-start address 0x00401010
-@end example
-
-@item 
-Launch the debugger on the executable.
-
-@example
-$ gdb main.exe
-@end example
-
-@item 
-Set a breakpoint at the starting address, and launch the program.
-
-@example
-$ (gdb) break *0x00401010
-$ (gdb) run
-@end example
-
-The program will stop at the given address.
-
-@item 
-Set a breakpoint on a DLL subroutine.
-
-@example
-(gdb) break ada_dll.adb:45
-@end example
-
-Or if you want to break using a symbol on the DLL, you need first to
-select the Ada language (language used by the DLL).
-
-@example
-(gdb) set language ada
-(gdb) break ada_dll
-@end example
-
-@item 
-Continue the program.
-
-@example
-(gdb) cont
-@end example
-
-This will run the program until it reaches the breakpoint that has been
-set. From that point you can use the standard way to debug a program
-as described in (@ref{24,,Running and Debugging Ada Programs}).
-@end itemize
-
-It is also possible to debug the DLL by attaching to a running process.
-
-@subsubheading Attaching to a Running Process
-
-
-@geindex DLL debugging
-@geindex attach to process
-
-With @code{GDB} it is always possible to debug a running process by
-attaching to it. It is possible to debug a DLL this way. The limitation
-of this approach is that the DLL must run long enough to perform the
-attach operation. It may be useful for instance to insert a time wasting
-loop in the code of the DLL to meet this criterion.
-
-
-@itemize *
-
-@item 
-Launch the main program @code{main.exe}.
-
-@example
-$ main
-@end example
-
-@item 
-Use the Windows @emph{Task Manager} to find the process ID. Let's say
-that the process PID for @code{main.exe} is 208.
-
-@item 
-Launch gdb.
-
-@example
-$ gdb
-@end example
-
-@item 
-Attach to the running process to be debugged.
-
-@example
-(gdb) attach 208
-@end example
-
-@item 
-Load the process debugging information.
-
-@example
-(gdb) symbol-file main.exe
-@end example
-
-@item 
-Break somewhere in the DLL.
-
-@example
-(gdb) break ada_dll
-@end example
-
-@item 
-Continue process execution.
-
-@example
-(gdb) cont
-@end example
-@end itemize
-
-This last step will resume the process execution, and stop at
-the breakpoint we have set. From there you can use the standard
-approach to debug a program as described in
-@ref{24,,Running and Debugging Ada Programs}.
-
-@node Setting Stack Size from gnatlink,Setting Heap Size from gnatlink,Debugging a DLL,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information id37}@anchor{220}@anchor{gnat_ugn/platform_specific_information setting-stack-size-from-gnatlink}@anchor{136}
-@subsubsection Setting Stack Size from @code{gnatlink}
-
-
-It is possible to specify the program stack size at link time. On modern
-versions of Windows, starting with XP, this is mostly useful to set the size of
-the main stack (environment task). The other task stacks are set with pragma
-Storage_Size or with the @emph{gnatbind -d} command.
-
-Since older versions of Windows (2000, NT4, etc.) do not allow setting the
-reserve size of individual tasks, the link-time stack size applies to all
-tasks, and pragma Storage_Size has no effect.
-In particular, Stack Overflow checks are made against this
-link-time specified size.
-
-This setting can be done with @code{gnatlink} using either of the following:
-
-
-@itemize *
-
-@item 
-@code{-Xlinker} linker option
-
-@example
-$ gnatlink hello -Xlinker --stack=0x10000,0x1000
-@end example
-
-This sets the stack reserve size to 0x10000 bytes and the stack commit
-size to 0x1000 bytes.
-
-@item 
-@code{-Wl} linker option
-
-@example
-$ gnatlink hello -Wl,--stack=0x1000000
-@end example
-
-This sets the stack reserve size to 0x1000000 bytes. Note that with
-@code{-Wl} option it is not possible to set the stack commit size
-because the comma is a separator for this option.
-@end itemize
-
-@node Setting Heap Size from gnatlink,,Setting Stack Size from gnatlink,Mixed-Language Programming on Windows
-@anchor{gnat_ugn/platform_specific_information setting-heap-size-from-gnatlink}@anchor{137}@anchor{gnat_ugn/platform_specific_information id38}@anchor{221}
-@subsubsection Setting Heap Size from @code{gnatlink}
-
-
-Under Windows systems, it is possible to specify the program heap size from
-@code{gnatlink} using either of the following:
-
-
-@itemize *
-
-@item 
-@code{-Xlinker} linker option
-
-@example
-$ gnatlink hello -Xlinker --heap=0x10000,0x1000
-@end example
-
-This sets the heap reserve size to 0x10000 bytes and the heap commit
-size to 0x1000 bytes.
-
-@item 
-@code{-Wl} linker option
-
-@example
-$ gnatlink hello -Wl,--heap=0x1000000
-@end example
-
-This sets the heap reserve size to 0x1000000 bytes. Note that with
-@code{-Wl} option it is not possible to set the heap commit size
-because the comma is a separator for this option.
-@end itemize
-
-@node Windows Specific Add-Ons,,Mixed-Language Programming on Windows,Microsoft Windows Topics
-@anchor{gnat_ugn/platform_specific_information windows-specific-add-ons}@anchor{222}@anchor{gnat_ugn/platform_specific_information win32-specific-addons}@anchor{223}
-@subsection Windows Specific Add-Ons
-
-
-This section describes the Windows specific add-ons.
-
-@menu
-* Win32Ada:: 
-* wPOSIX:: 
-
-@end menu
-
-@node Win32Ada,wPOSIX,,Windows Specific Add-Ons
-@anchor{gnat_ugn/platform_specific_information win32ada}@anchor{224}@anchor{gnat_ugn/platform_specific_information id39}@anchor{225}
-@subsubsection Win32Ada
-
-
-Win32Ada is a binding for the Microsoft Win32 API. This binding can be
-easily installed from the provided installer. To use the Win32Ada
-binding you need to use a project file, and adding a single with_clause
-will give you full access to the Win32Ada binding sources and ensure
-that the proper libraries are passed to the linker.
-
-@quotation
-
-@example
-with "win32ada";
-project P is
-   for Sources use ...;
-end P;
-@end example
-@end quotation
-
-To build the application you just need to call gprbuild for the
-application's project, here p.gpr:
-
-@quotation
-
-@example
-gprbuild p.gpr
-@end example
-@end quotation
-
-@node wPOSIX,,Win32Ada,Windows Specific Add-Ons
-@anchor{gnat_ugn/platform_specific_information wposix}@anchor{226}@anchor{gnat_ugn/platform_specific_information id40}@anchor{227}
-@subsubsection wPOSIX
-
-
-wPOSIX is a minimal POSIX binding whose goal is to help with building
-cross-platforms applications. This binding is not complete though, as
-the Win32 API does not provide the necessary support for all POSIX APIs.
-
-To use the wPOSIX binding you need to use a project file, and adding
-a single with_clause will give you full access to the wPOSIX binding
-sources and ensure that the proper libraries are passed to the linker.
-
-@quotation
-
-@example
-with "wposix";
-project P is
-   for Sources use ...;
-end P;
-@end example
-@end quotation
-
-To build the application you just need to call gprbuild for the
-application's project, here p.gpr:
-
-@quotation
-
-@example
-gprbuild p.gpr
-@end example
-@end quotation
-
-@node Mac OS Topics,,Microsoft Windows Topics,Platform-Specific Information
-@anchor{gnat_ugn/platform_specific_information mac-os-topics}@anchor{2d}@anchor{gnat_ugn/platform_specific_information id41}@anchor{228}
-@section Mac OS Topics
-
-
-@geindex OS X
-
-This section describes topics that are specific to Apple's OS X
-platform.
-
-@menu
-* Codesigning the Debugger:: 
-
-@end menu
-
-@node Codesigning the Debugger,,,Mac OS Topics
-@anchor{gnat_ugn/platform_specific_information codesigning-the-debugger}@anchor{229}
-@subsection Codesigning the Debugger
-
-
-The Darwin Kernel requires the debugger to have special permissions
-before it is allowed to control other processes. These permissions
-are granted by codesigning the GDB executable. Without these
-permissions, the debugger will report error messages such as:
-
-@example
-Starting program: /x/y/foo
-Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
-(please check gdb is codesigned - see taskgated(8))
-@end example
-
-Codesigning requires a certificate.  The following procedure explains
-how to create one:
-
-
-@itemize *
-
-@item 
-Start the Keychain Access application (in
-/Applications/Utilities/Keychain Access.app)
-
-@item 
-Select the Keychain Access -> Certificate Assistant ->
-Create a Certificate... menu
-
-@item 
-Then:
-
-
-@itemize *
-
-@item 
-Choose a name for the new certificate (this procedure will use
-"gdb-cert" as an example)
-
-@item 
-Set "Identity Type" to "Self Signed Root"
-
-@item 
-Set "Certificate Type" to "Code Signing"
-
-@item 
-Activate the "Let me override defaults" option
-@end itemize
-
-@item 
-Click several times on "Continue" until the "Specify a Location
-For The Certificate" screen appears, then set "Keychain" to "System"
-
-@item 
-Click on "Continue" until the certificate is created
-
-@item 
-Finally, in the view, double-click on the new certificate,
-and set "When using this certificate" to "Always Trust"
-
-@item 
-Exit the Keychain Access application and restart the computer
-(this is unfortunately required)
-@end itemize
-
-Once a certificate has been created, the debugger can be codesigned
-as follow. In a Terminal, run the following command:
-
-@quotation
-
-@example
-$ codesign -f -s  "gdb-cert"  <gnat_install_prefix>/bin/gdb
-@end example
-@end quotation
-
-where "gdb-cert" should be replaced by the actual certificate
-name chosen above, and <gnat_install_prefix> should be replaced by
-the location where you installed GNAT.  Also, be sure that users are
-in the Unix group @code{_developer}.
-
-@node Example of Binder Output File,Elaboration Order Handling in GNAT,Platform-Specific Information,Top
-@anchor{gnat_ugn/example_of_binder_output example-of-binder-output-file}@anchor{e}@anchor{gnat_ugn/example_of_binder_output doc}@anchor{22a}@anchor{gnat_ugn/example_of_binder_output id1}@anchor{22b}
-@chapter Example of Binder Output File
-
-
-@geindex Binder output (example)
-
-This Appendix displays the source code for the output file
-generated by @emph{gnatbind} for a simple 'Hello World' program.
-Comments have been added for clarification purposes.
-
-@example
---  The package is called Ada_Main unless this name is actually used
---  as a unit name in the partition, in which case some other unique
---  name is used.
-
-pragma Ada_95;
-with System;
-package ada_main is
-   pragma Warnings (Off);
-
-   --  The main program saves the parameters (argument count,
-   --  argument values, environment pointer) in global variables
-   --  for later access by other units including
-   --  Ada.Command_Line.
-
-   gnat_argc : Integer;
-   gnat_argv : System.Address;
-   gnat_envp : System.Address;
-
-   --  The actual variables are stored in a library routine. This
-   --  is useful for some shared library situations, where there
-   --  are problems if variables are not in the library.
-
-   pragma Import (C, gnat_argc);
-   pragma Import (C, gnat_argv);
-   pragma Import (C, gnat_envp);
-
-   --  The exit status is similarly an external location
-
-   gnat_exit_status : Integer;
-   pragma Import (C, gnat_exit_status);
-
-   GNAT_Version : constant String :=
-                    "GNAT Version: Pro 7.4.0w (20141119-49)" & ASCII.NUL;
-   pragma Export (C, GNAT_Version, "__gnat_version");
-
-   Ada_Main_Program_Name : constant String := "_ada_hello" & ASCII.NUL;
-   pragma Export (C, Ada_Main_Program_Name, "__gnat_ada_main_program_name");
-
-   --  This is the generated adainit routine that performs
-   --  initialization at the start of execution. In the case
-   --  where Ada is the main program, this main program makes
-   --  a call to adainit at program startup.
-
-   procedure adainit;
-   pragma Export (C, adainit, "adainit");
-
-   --  This is the generated adafinal routine that performs
-   --  finalization at the end of execution. In the case where
-   --  Ada is the main program, this main program makes a call
-   --  to adafinal at program termination.
-
-   procedure adafinal;
-   pragma Export (C, adafinal, "adafinal");
-
-   --  This routine is called at the start of execution. It is
-   --  a dummy routine that is used by the debugger to breakpoint
-   --  at the start of execution.
-
-   --  This is the actual generated main program (it would be
-   --  suppressed if the no main program switch were used). As
-   --  required by standard system conventions, this program has
-   --  the external name main.
-
-   function main
-     (argc : Integer;
-      argv : System.Address;
-      envp : System.Address)
-      return Integer;
-   pragma Export (C, main, "main");
-
-   --  The following set of constants give the version
-   --  identification values for every unit in the bound
-   --  partition. This identification is computed from all
-   --  dependent semantic units, and corresponds to the
-   --  string that would be returned by use of the
-   --  Body_Version or Version attributes.
-
-   --  The following Export pragmas export the version numbers
-   --  with symbolic names ending in B (for body) or S
-   --  (for spec) so that they can be located in a link. The
-   --  information provided here is sufficient to track down
-   --  the exact versions of units used in a given build.
+   --  The following Export pragmas export the version numbers
+   --  with symbolic names ending in B (for body) or S
+   --  (for spec) so that they can be located in a link. The
+   --  information provided here is sufficient to track down
+   --  the exact versions of units used in a given build.
 
    type Version_32 is mod 2 ** 32;
    u00001 : constant Version_32 := 16#8ad6e54a#;
@@ -26535,2343 +25451,2143 @@ package ada_main is
    u00093 : constant Version_32 := 16#fe2f4b3a#;
    pragma Export (C, u00093, "system__storage_pools__subpools__finalizationS");
 
-   --  BEGIN ELABORATION ORDER
-   --  ada%s
-   --  interfaces%s
-   --  system%s
-   --  system.case_util%s
-   --  system.case_util%b
-   --  system.htable%s
-   --  system.img_bool%s
-   --  system.img_bool%b
-   --  system.img_int%s
-   --  system.img_int%b
-   --  system.io%s
-   --  system.io%b
-   --  system.parameters%s
-   --  system.parameters%b
-   --  system.crtl%s
-   --  interfaces.c_streams%s
-   --  interfaces.c_streams%b
-   --  system.standard_library%s
-   --  system.exceptions_debug%s
-   --  system.exceptions_debug%b
-   --  system.storage_elements%s
-   --  system.storage_elements%b
-   --  system.stack_checking%s
-   --  system.stack_checking%b
-   --  system.string_hash%s
-   --  system.string_hash%b
-   --  system.htable%b
-   --  system.strings%s
-   --  system.strings%b
-   --  system.os_lib%s
-   --  system.traceback_entries%s
-   --  system.traceback_entries%b
-   --  ada.exceptions%s
-   --  system.soft_links%s
-   --  system.unsigned_types%s
-   --  system.val_llu%s
-   --  system.val_util%s
-   --  system.val_util%b
-   --  system.val_llu%b
-   --  system.wch_con%s
-   --  system.wch_con%b
-   --  system.wch_cnv%s
-   --  system.wch_jis%s
-   --  system.wch_jis%b
-   --  system.wch_cnv%b
-   --  system.wch_stw%s
-   --  system.wch_stw%b
-   --  ada.exceptions.last_chance_handler%s
-   --  ada.exceptions.last_chance_handler%b
-   --  system.address_image%s
-   --  system.exception_table%s
-   --  system.exception_table%b
-   --  ada.io_exceptions%s
-   --  ada.tags%s
-   --  ada.streams%s
-   --  ada.streams%b
-   --  interfaces.c%s
-   --  system.exceptions%s
-   --  system.exceptions%b
-   --  system.exceptions.machine%s
-   --  system.finalization_root%s
-   --  system.finalization_root%b
-   --  ada.finalization%s
-   --  ada.finalization%b
-   --  system.storage_pools%s
-   --  system.storage_pools%b
-   --  system.finalization_masters%s
-   --  system.storage_pools.subpools%s
-   --  system.storage_pools.subpools.finalization%s
-   --  system.storage_pools.subpools.finalization%b
-   --  system.memory%s
-   --  system.memory%b
-   --  system.standard_library%b
-   --  system.pool_global%s
-   --  system.pool_global%b
-   --  system.file_control_block%s
-   --  system.file_io%s
-   --  system.secondary_stack%s
-   --  system.file_io%b
-   --  system.storage_pools.subpools%b
-   --  system.finalization_masters%b
-   --  interfaces.c%b
-   --  ada.tags%b
-   --  system.soft_links%b
-   --  system.os_lib%b
-   --  system.secondary_stack%b
-   --  system.address_image%b
-   --  system.traceback%s
-   --  ada.exceptions%b
-   --  system.traceback%b
-   --  ada.text_io%s
-   --  ada.text_io%b
-   --  hello%b
-   --  END ELABORATION ORDER
+   --  BEGIN ELABORATION ORDER
+   --  ada%s
+   --  interfaces%s
+   --  system%s
+   --  system.case_util%s
+   --  system.case_util%b
+   --  system.htable%s
+   --  system.img_bool%s
+   --  system.img_bool%b
+   --  system.img_int%s
+   --  system.img_int%b
+   --  system.io%s
+   --  system.io%b
+   --  system.parameters%s
+   --  system.parameters%b
+   --  system.crtl%s
+   --  interfaces.c_streams%s
+   --  interfaces.c_streams%b
+   --  system.standard_library%s
+   --  system.exceptions_debug%s
+   --  system.exceptions_debug%b
+   --  system.storage_elements%s
+   --  system.storage_elements%b
+   --  system.stack_checking%s
+   --  system.stack_checking%b
+   --  system.string_hash%s
+   --  system.string_hash%b
+   --  system.htable%b
+   --  system.strings%s
+   --  system.strings%b
+   --  system.os_lib%s
+   --  system.traceback_entries%s
+   --  system.traceback_entries%b
+   --  ada.exceptions%s
+   --  system.soft_links%s
+   --  system.unsigned_types%s
+   --  system.val_llu%s
+   --  system.val_util%s
+   --  system.val_util%b
+   --  system.val_llu%b
+   --  system.wch_con%s
+   --  system.wch_con%b
+   --  system.wch_cnv%s
+   --  system.wch_jis%s
+   --  system.wch_jis%b
+   --  system.wch_cnv%b
+   --  system.wch_stw%s
+   --  system.wch_stw%b
+   --  ada.exceptions.last_chance_handler%s
+   --  ada.exceptions.last_chance_handler%b
+   --  system.address_image%s
+   --  system.exception_table%s
+   --  system.exception_table%b
+   --  ada.io_exceptions%s
+   --  ada.tags%s
+   --  ada.streams%s
+   --  ada.streams%b
+   --  interfaces.c%s
+   --  system.exceptions%s
+   --  system.exceptions%b
+   --  system.exceptions.machine%s
+   --  system.finalization_root%s
+   --  system.finalization_root%b
+   --  ada.finalization%s
+   --  ada.finalization%b
+   --  system.storage_pools%s
+   --  system.storage_pools%b
+   --  system.finalization_masters%s
+   --  system.storage_pools.subpools%s
+   --  system.storage_pools.subpools.finalization%s
+   --  system.storage_pools.subpools.finalization%b
+   --  system.memory%s
+   --  system.memory%b
+   --  system.standard_library%b
+   --  system.pool_global%s
+   --  system.pool_global%b
+   --  system.file_control_block%s
+   --  system.file_io%s
+   --  system.secondary_stack%s
+   --  system.file_io%b
+   --  system.storage_pools.subpools%b
+   --  system.finalization_masters%b
+   --  interfaces.c%b
+   --  ada.tags%b
+   --  system.soft_links%b
+   --  system.os_lib%b
+   --  system.secondary_stack%b
+   --  system.address_image%b
+   --  system.traceback%s
+   --  ada.exceptions%b
+   --  system.traceback%b
+   --  ada.text_io%s
+   --  ada.text_io%b
+   --  hello%b
+   --  END ELABORATION ORDER
+
+end ada_main;
+@end example
+
+@example
+pragma Ada_95;
+--  The following source file name pragmas allow the generated file
+--  names to be unique for different main programs. They are needed
+--  since the package name will always be Ada_Main.
+
+pragma Source_File_Name (ada_main, Spec_File_Name => "b~hello.ads");
+pragma Source_File_Name (ada_main, Body_File_Name => "b~hello.adb");
+
+pragma Suppress (Overflow_Check);
+with Ada.Exceptions;
+
+--  Generated package body for Ada_Main starts here
+
+package body ada_main is
+   pragma Warnings (Off);
+
+   --  These values are reference counter associated to units which have
+   --  been elaborated. It is also used to avoid elaborating the
+   --  same unit twice.
+
+   E72 : Short_Integer; pragma Import (Ada, E72, "system__os_lib_E");
+   E13 : Short_Integer; pragma Import (Ada, E13, "system__soft_links_E");
+   E23 : Short_Integer; pragma Import (Ada, E23, "system__exception_table_E");
+   E46 : Short_Integer; pragma Import (Ada, E46, "ada__io_exceptions_E");
+   E48 : Short_Integer; pragma Import (Ada, E48, "ada__tags_E");
+   E45 : Short_Integer; pragma Import (Ada, E45, "ada__streams_E");
+   E70 : Short_Integer; pragma Import (Ada, E70, "interfaces__c_E");
+   E25 : Short_Integer; pragma Import (Ada, E25, "system__exceptions_E");
+   E68 : Short_Integer; pragma Import (Ada, E68, "system__finalization_root_E");
+   E66 : Short_Integer; pragma Import (Ada, E66, "ada__finalization_E");
+   E85 : Short_Integer; pragma Import (Ada, E85, "system__storage_pools_E");
+   E77 : Short_Integer; pragma Import (Ada, E77, "system__finalization_masters_E");
+   E91 : Short_Integer; pragma Import (Ada, E91, "system__storage_pools__subpools_E");
+   E87 : Short_Integer; pragma Import (Ada, E87, "system__pool_global_E");
+   E75 : Short_Integer; pragma Import (Ada, E75, "system__file_control_block_E");
+   E64 : Short_Integer; pragma Import (Ada, E64, "system__file_io_E");
+   E17 : Short_Integer; pragma Import (Ada, E17, "system__secondary_stack_E");
+   E06 : Short_Integer; pragma Import (Ada, E06, "ada__text_io_E");
+
+   Local_Priority_Specific_Dispatching : constant String := "";
+   Local_Interrupt_States : constant String := "";
+
+   Is_Elaborated : Boolean := False;
+
+   procedure finalize_library is
+   begin
+      E06 := E06 - 1;
+      declare
+         procedure F1;
+         pragma Import (Ada, F1, "ada__text_io__finalize_spec");
+      begin
+         F1;
+      end;
+      E77 := E77 - 1;
+      E91 := E91 - 1;
+      declare
+         procedure F2;
+         pragma Import (Ada, F2, "system__file_io__finalize_body");
+      begin
+         E64 := E64 - 1;
+         F2;
+      end;
+      declare
+         procedure F3;
+         pragma Import (Ada, F3, "system__file_control_block__finalize_spec");
+      begin
+         E75 := E75 - 1;
+         F3;
+      end;
+      E87 := E87 - 1;
+      declare
+         procedure F4;
+         pragma Import (Ada, F4, "system__pool_global__finalize_spec");
+      begin
+         F4;
+      end;
+      declare
+         procedure F5;
+         pragma Import (Ada, F5, "system__storage_pools__subpools__finalize_spec");
+      begin
+         F5;
+      end;
+      declare
+         procedure F6;
+         pragma Import (Ada, F6, "system__finalization_masters__finalize_spec");
+      begin
+         F6;
+      end;
+      declare
+         procedure Reraise_Library_Exception_If_Any;
+         pragma Import (Ada, Reraise_Library_Exception_If_Any, "__gnat_reraise_library_exception_if_any");
+      begin
+         Reraise_Library_Exception_If_Any;
+      end;
+   end finalize_library;
+
+   -------------
+   -- adainit --
+   -------------
+
+   procedure adainit is
+
+      Main_Priority : Integer;
+      pragma Import (C, Main_Priority, "__gl_main_priority");
+      Time_Slice_Value : Integer;
+      pragma Import (C, Time_Slice_Value, "__gl_time_slice_val");
+      WC_Encoding : Character;
+      pragma Import (C, WC_Encoding, "__gl_wc_encoding");
+      Locking_Policy : Character;
+      pragma Import (C, Locking_Policy, "__gl_locking_policy");
+      Queuing_Policy : Character;
+      pragma Import (C, Queuing_Policy, "__gl_queuing_policy");
+      Task_Dispatching_Policy : Character;
+      pragma Import (C, Task_Dispatching_Policy, "__gl_task_dispatching_policy");
+      Priority_Specific_Dispatching : System.Address;
+      pragma Import (C, Priority_Specific_Dispatching, "__gl_priority_specific_dispatching");
+      Num_Specific_Dispatching : Integer;
+      pragma Import (C, Num_Specific_Dispatching, "__gl_num_specific_dispatching");
+      Main_CPU : Integer;
+      pragma Import (C, Main_CPU, "__gl_main_cpu");
+      Interrupt_States : System.Address;
+      pragma Import (C, Interrupt_States, "__gl_interrupt_states");
+      Num_Interrupt_States : Integer;
+      pragma Import (C, Num_Interrupt_States, "__gl_num_interrupt_states");
+      Unreserve_All_Interrupts : Integer;
+      pragma Import (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
+      Detect_Blocking : Integer;
+      pragma Import (C, Detect_Blocking, "__gl_detect_blocking");
+      Default_Stack_Size : Integer;
+      pragma Import (C, Default_Stack_Size, "__gl_default_stack_size");
+      Leap_Seconds_Support : Integer;
+      pragma Import (C, Leap_Seconds_Support, "__gl_leap_seconds_support");
+
+      procedure Runtime_Initialize;
+      pragma Import (C, Runtime_Initialize, "__gnat_runtime_initialize");
+
+      Finalize_Library_Objects : No_Param_Proc;
+      pragma Import (C, Finalize_Library_Objects, "__gnat_finalize_library_objects");
+
+   --  Start of processing for adainit
+
+   begin
+
+      --  Record various information for this partition.  The values
+      --  are derived by the binder from information stored in the ali
+      --  files by the compiler.
+
+      if Is_Elaborated then
+         return;
+      end if;
+      Is_Elaborated := True;
+      Main_Priority := -1;
+      Time_Slice_Value := -1;
+      WC_Encoding := 'b';
+      Locking_Policy := ' ';
+      Queuing_Policy := ' ';
+      Task_Dispatching_Policy := ' ';
+      Priority_Specific_Dispatching :=
+        Local_Priority_Specific_Dispatching'Address;
+      Num_Specific_Dispatching := 0;
+      Main_CPU := -1;
+      Interrupt_States := Local_Interrupt_States'Address;
+      Num_Interrupt_States := 0;
+      Unreserve_All_Interrupts := 0;
+      Detect_Blocking := 0;
+      Default_Stack_Size := -1;
+      Leap_Seconds_Support := 0;
+
+      Runtime_Initialize;
+
+      Finalize_Library_Objects := finalize_library'access;
+
+      --  Now we have the elaboration calls for all units in the partition.
+      --  The Elab_Spec and Elab_Body attributes generate references to the
+      --  implicit elaboration procedures generated by the compiler for
+      --  each unit that requires elaboration. Increment a counter of
+      --  reference for each unit.
+
+      System.Soft_Links'Elab_Spec;
+      System.Exception_Table'Elab_Body;
+      E23 := E23 + 1;
+      Ada.Io_Exceptions'Elab_Spec;
+      E46 := E46 + 1;
+      Ada.Tags'Elab_Spec;
+      Ada.Streams'Elab_Spec;
+      E45 := E45 + 1;
+      Interfaces.C'Elab_Spec;
+      System.Exceptions'Elab_Spec;
+      E25 := E25 + 1;
+      System.Finalization_Root'Elab_Spec;
+      E68 := E68 + 1;
+      Ada.Finalization'Elab_Spec;
+      E66 := E66 + 1;
+      System.Storage_Pools'Elab_Spec;
+      E85 := E85 + 1;
+      System.Finalization_Masters'Elab_Spec;
+      System.Storage_Pools.Subpools'Elab_Spec;
+      System.Pool_Global'Elab_Spec;
+      E87 := E87 + 1;
+      System.File_Control_Block'Elab_Spec;
+      E75 := E75 + 1;
+      System.File_Io'Elab_Body;
+      E64 := E64 + 1;
+      E91 := E91 + 1;
+      System.Finalization_Masters'Elab_Body;
+      E77 := E77 + 1;
+      E70 := E70 + 1;
+      Ada.Tags'Elab_Body;
+      E48 := E48 + 1;
+      System.Soft_Links'Elab_Body;
+      E13 := E13 + 1;
+      System.Os_Lib'Elab_Body;
+      E72 := E72 + 1;
+      System.Secondary_Stack'Elab_Body;
+      E17 := E17 + 1;
+      Ada.Text_Io'Elab_Spec;
+      Ada.Text_Io'Elab_Body;
+      E06 := E06 + 1;
+   end adainit;
+
+   --------------
+   -- adafinal --
+   --------------
+
+   procedure adafinal is
+      procedure s_stalib_adafinal;
+      pragma Import (C, s_stalib_adafinal, "system__standard_library__adafinal");
+
+      procedure Runtime_Finalize;
+      pragma Import (C, Runtime_Finalize, "__gnat_runtime_finalize");
+
+   begin
+      if not Is_Elaborated then
+         return;
+      end if;
+      Is_Elaborated := False;
+      Runtime_Finalize;
+      s_stalib_adafinal;
+   end adafinal;
+
+   --  We get to the main program of the partition by using
+   --  pragma Import because if we try to with the unit and
+   --  call it Ada style, then not only do we waste time
+   --  recompiling it, but also, we don't really know the right
+   --  switches (e.g.@@: identifier character set) to be used
+   --  to compile it.
+
+   procedure Ada_Main_Program;
+   pragma Import (Ada, Ada_Main_Program, "_ada_hello");
+
+   ----------
+   -- main --
+   ----------
+
+   --  main is actually a function, as in the ANSI C standard,
+   --  defined to return the exit status. The three parameters
+   --  are the argument count, argument values and environment
+   --  pointer.
+
+   function main
+     (argc : Integer;
+      argv : System.Address;
+      envp : System.Address)
+      return Integer
+   is
+      --  The initialize routine performs low level system
+      --  initialization using a standard library routine which
+      --  sets up signal handling and performs any other
+      --  required setup. The routine can be found in file
+      --  a-init.c.
+
+      procedure initialize;
+      pragma Import (C, initialize, "__gnat_initialize");
+
+      --  The finalize routine performs low level system
+      --  finalization using a standard library routine. The
+      --  routine is found in file a-final.c and in the standard
+      --  distribution is a dummy routine that does nothing, so
+      --  really this is a hook for special user finalization.
+
+      procedure finalize;
+      pragma Import (C, finalize, "__gnat_finalize");
+
+      --  The following is to initialize the SEH exceptions
+
+      SEH : aliased array (1 .. 2) of Integer;
+
+      Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;
+      pragma Volatile (Ensure_Reference);
+
+   --  Start of processing for main
+
+   begin
+      --  Save global variables
+
+      gnat_argc := argc;
+      gnat_argv := argv;
+      gnat_envp := envp;
+
+      --  Call low level system initialization
+
+      Initialize (SEH'Address);
+
+      --  Call our generated Ada initialization routine
+
+      adainit;
+
+      --  Now we call the main program of the partition
+
+      Ada_Main_Program;
+
+      --  Perform Ada finalization
+
+      adafinal;
+
+      --  Perform low level system finalization
+
+      Finalize;
+
+      --  Return the proper exit status
+      return (gnat_exit_status);
+   end;
+
+--  This section is entirely comments, so it has no effect on the
+--  compilation of the Ada_Main package. It provides the list of
+--  object files and linker options, as well as some standard
+--  libraries needed for the link. The gnatlink utility parses
+--  this b~hello.adb file to read these comment lines to generate
+--  the appropriate command line arguments for the call to the
+--  system linker. The BEGIN/END lines are used for sentinels for
+--  this parsing operation.
+
+--  The exact file names will of course depend on the environment,
+--  host/target and location of files on the host system.
+
+-- BEGIN Object file/option list
+   --   ./hello.o
+   --   -L./
+   --   -L/usr/local/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/
+   --   /usr/local/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/libgnat.a
+-- END Object file/option list
 
 end ada_main;
 @end example
 
+The Ada code in the above example is exactly what is generated by the
+binder. We have added comments to more clearly indicate the function
+of each part of the generated @code{Ada_Main} package.
+
+The code is standard Ada in all respects, and can be processed by any
+tools that handle Ada. In particular, it is possible to use the debugger
+in Ada mode to debug the generated @code{Ada_Main} package. For example,
+suppose that for reasons that you do not understand, your program is crashing
+during elaboration of the body of @code{Ada.Text_IO}. To locate this bug,
+you can place a breakpoint on the call:
+
+@quotation
+
 @example
-pragma Ada_95;
---  The following source file name pragmas allow the generated file
---  names to be unique for different main programs. They are needed
---  since the package name will always be Ada_Main.
+Ada.Text_Io'Elab_Body;
+@end example
+@end quotation
 
-pragma Source_File_Name (ada_main, Spec_File_Name => "b~hello.ads");
-pragma Source_File_Name (ada_main, Body_File_Name => "b~hello.adb");
+and trace the elaboration routine for this package to find out where
+the problem might be (more usually of course you would be debugging
+elaboration code in your own application).
 
-pragma Suppress (Overflow_Check);
-with Ada.Exceptions;
+@c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit
 
---  Generated package body for Ada_Main starts here
+@node Elaboration Order Handling in GNAT,Inline Assembler,Example of Binder Output File,Top
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-order-handling-in-gnat}@anchor{f}@anchor{gnat_ugn/elaboration_order_handling_in_gnat doc}@anchor{214}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id1}@anchor{215}
+@chapter Elaboration Order Handling in GNAT
 
-package body ada_main is
-   pragma Warnings (Off);
 
-   --  These values are reference counter associated to units which have
-   --  been elaborated. It is also used to avoid elaborating the
-   --  same unit twice.
+@geindex Order of elaboration
 
-   E72 : Short_Integer; pragma Import (Ada, E72, "system__os_lib_E");
-   E13 : Short_Integer; pragma Import (Ada, E13, "system__soft_links_E");
-   E23 : Short_Integer; pragma Import (Ada, E23, "system__exception_table_E");
-   E46 : Short_Integer; pragma Import (Ada, E46, "ada__io_exceptions_E");
-   E48 : Short_Integer; pragma Import (Ada, E48, "ada__tags_E");
-   E45 : Short_Integer; pragma Import (Ada, E45, "ada__streams_E");
-   E70 : Short_Integer; pragma Import (Ada, E70, "interfaces__c_E");
-   E25 : Short_Integer; pragma Import (Ada, E25, "system__exceptions_E");
-   E68 : Short_Integer; pragma Import (Ada, E68, "system__finalization_root_E");
-   E66 : Short_Integer; pragma Import (Ada, E66, "ada__finalization_E");
-   E85 : Short_Integer; pragma Import (Ada, E85, "system__storage_pools_E");
-   E77 : Short_Integer; pragma Import (Ada, E77, "system__finalization_masters_E");
-   E91 : Short_Integer; pragma Import (Ada, E91, "system__storage_pools__subpools_E");
-   E87 : Short_Integer; pragma Import (Ada, E87, "system__pool_global_E");
-   E75 : Short_Integer; pragma Import (Ada, E75, "system__file_control_block_E");
-   E64 : Short_Integer; pragma Import (Ada, E64, "system__file_io_E");
-   E17 : Short_Integer; pragma Import (Ada, E17, "system__secondary_stack_E");
-   E06 : Short_Integer; pragma Import (Ada, E06, "ada__text_io_E");
+@geindex Elaboration control
+
+This appendix describes the handling of elaboration code in Ada and GNAT, and
+discusses how the order of elaboration of program units can be controlled in
+GNAT, either automatically or with explicit programming features.
+
+@menu
+* Elaboration Code:: 
+* Elaboration Order:: 
+* Checking the Elaboration Order:: 
+* Controlling the Elaboration Order in Ada:: 
+* Controlling the Elaboration Order in GNAT:: 
+* Mixing Elaboration Models:: 
+* ABE Diagnostics:: 
+* SPARK Diagnostics:: 
+* Elaboration Circularities:: 
+* Resolving Elaboration Circularities:: 
+* Elaboration-related Compiler Switches:: 
+* Summary of Procedures for Elaboration Control:: 
+* Inspecting the Chosen Elaboration Order:: 
+
+@end menu
+
+@node Elaboration Code,Elaboration Order,,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-code}@anchor{216}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id2}@anchor{217}
+@section Elaboration Code
+
+
+Ada defines the term @emph{execution} as the process by which a construct achieves
+its run-time effect. This process is also referred to as @strong{elaboration} for
+declarations and @emph{evaluation} for expressions.
+
+The execution model in Ada allows for certain sections of an Ada program to be
+executed prior to execution of the program itself, primarily with the intent of
+initializing data. These sections are referred to as @strong{elaboration code}.
+Elaboration code is executed as follows:
+
+
+@itemize *
+
+@item 
+All partitions of an Ada program are executed in parallel with one another,
+possibly in a separate address space, and possibly on a separate computer.
+
+@item 
+The execution of a partition involves running the environment task for that
+partition.
+
+@item 
+The environment task executes all elaboration code (if available) for all
+units within that partition. This code is said to be executed at
+@strong{elaboration time}.
+
+@item 
+The environment task executes the Ada program (if available) for that
+partition.
+@end itemize
+
+In addition to the Ada terminology, this appendix defines the following terms:
+
+
+@itemize *
+
+@item 
+@emph{Invocation}
+
+The act of calling a subprogram, instantiating a generic, or activating a
+task.
+
+@item 
+@emph{Scenario}
+
+A construct that is elaborated or invoked by elaboration code is referred to
+as an @emph{elaboration scenario} or simply a @strong{scenario}. GNAT recognizes the
+following scenarios:
+
+
+@itemize -
+
+@item 
+@code{'Access} of entries, operators, and subprograms
+
+@item 
+Activation of tasks
+
+@item 
+Calls to entries, operators, and subprograms
+
+@item 
+Instantiations of generic templates
+@end itemize
+
+@item 
+@emph{Target}
+
+A construct elaborated by a scenario is referred to as @emph{elaboration target}
+or simply @strong{target}. GNAT recognizes the following targets:
+
+
+@itemize -
+
+@item 
+For @code{'Access} of entries, operators, and subprograms, the target is the
+entry, operator, or subprogram being aliased.
+
+@item 
+For activation of tasks, the target is the task body
+
+@item 
+For calls to entries, operators, and subprograms, the target is the entry,
+operator, or subprogram being invoked.
+
+@item 
+For instantiations of generic templates, the target is the generic template
+being instantiated.
+@end itemize
+@end itemize
+
+Elaboration code may appear in two distinct contexts:
+
+
+@itemize *
+
+@item 
+@emph{Library level}
+
+A scenario appears at the library level when it is encapsulated by a package
+[body] compilation unit, ignoring any other package [body] declarations in
+between.
+
+@example
+with Server;
+package Client is
+   procedure Proc;
+
+   package Nested is
+      Val : ... := Server.Func;
+   end Nested;
+end Client;
+@end example
+
+In the example above, the call to @code{Server.Func} is an elaboration scenario
+because it appears at the library level of package @code{Client}. Note that the
+declaration of package @code{Nested} is ignored according to the definition
+given above. As a result, the call to @code{Server.Func} will be invoked when
+the spec of unit @code{Client} is elaborated.
+
+@item 
+@emph{Package body statements}
+
+A scenario appears within the statement sequence of a package body when it is
+bounded by the region starting from the @code{begin} keyword of the package body
+and ending at the @code{end} keyword of the package body.
+
+@example
+package body Client is
+   procedure Proc is
+   begin
+      ...
+   end Proc;
+begin
+   Proc;
+end Client;
+@end example
+
+In the example above, the call to @code{Proc} is an elaboration scenario because
+it appears within the statement sequence of package body @code{Client}. As a
+result, the call to @code{Proc} will be invoked when the body of @code{Client} is
+elaborated.
+@end itemize
+
+@node Elaboration Order,Checking the Elaboration Order,Elaboration Code,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-order}@anchor{218}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id3}@anchor{219}
+@section Elaboration Order
+
+
+The sequence by which the elaboration code of all units within a partition is
+executed is referred to as @strong{elaboration order}.
+
+Within a single unit, elaboration code is executed in sequential order.
+
+@quotation
+
+@example
+package body Client is
+   Result : ... := Server.Func;
+
+   procedure Proc is
+      package Inst is new Server.Gen;
+   begin
+      Inst.Eval (Result);
+   end Proc;
+begin
+   Proc;
+end Client;
+@end example
+@end quotation
+
+In the example above, the elaboration order within package body @code{Client} is
+as follows:
+
+
+@enumerate 
+
+@item 
+The object declaration of @code{Result} is elaborated.
+
+
+@itemize *
+
+@item 
+Function @code{Server.Func} is invoked.
+@end itemize
+
+@item 
+The subprogram body of @code{Proc} is elaborated.
+
+@item 
+Procedure @code{Proc} is invoked.
+
+
+@itemize *
+
+@item 
+Generic unit @code{Server.Gen} is instantiated as @code{Inst}.
+
+@item 
+Instance @code{Inst} is elaborated.
+
+@item 
+Procedure @code{Inst.Eval} is invoked.
+@end itemize
+@end enumerate
+
+The elaboration order of all units within a partition depends on the following
+factors:
+
+
+@itemize *
+
+@item 
+@emph{with}ed units
+
+@item 
+parent units
+
+@item 
+purity of units
+
+@item 
+preelaborability of units
+
+@item 
+presence of elaboration-control pragmas
 
-   Local_Priority_Specific_Dispatching : constant String := "";
-   Local_Interrupt_States : constant String := "";
+@item 
+invocations performed in elaboration code
+@end itemize
 
-   Is_Elaborated : Boolean := False;
+A program may have several elaboration orders depending on its structure.
 
-   procedure finalize_library is
+@quotation
+
+@example
+package Server is
+   function Func (Index : Integer) return Integer;
+end Server;
+@end example
+
+@example
+package body Server is
+   Results : array (1 .. 5) of Integer := (1, 2, 3, 4, 5);
+
+   function Func (Index : Integer) return Integer is
    begin
-      E06 := E06 - 1;
-      declare
-         procedure F1;
-         pragma Import (Ada, F1, "ada__text_io__finalize_spec");
-      begin
-         F1;
-      end;
-      E77 := E77 - 1;
-      E91 := E91 - 1;
-      declare
-         procedure F2;
-         pragma Import (Ada, F2, "system__file_io__finalize_body");
-      begin
-         E64 := E64 - 1;
-         F2;
-      end;
-      declare
-         procedure F3;
-         pragma Import (Ada, F3, "system__file_control_block__finalize_spec");
-      begin
-         E75 := E75 - 1;
-         F3;
-      end;
-      E87 := E87 - 1;
-      declare
-         procedure F4;
-         pragma Import (Ada, F4, "system__pool_global__finalize_spec");
-      begin
-         F4;
-      end;
-      declare
-         procedure F5;
-         pragma Import (Ada, F5, "system__storage_pools__subpools__finalize_spec");
-      begin
-         F5;
-      end;
-      declare
-         procedure F6;
-         pragma Import (Ada, F6, "system__finalization_masters__finalize_spec");
-      begin
-         F6;
-      end;
-      declare
-         procedure Reraise_Library_Exception_If_Any;
-         pragma Import (Ada, Reraise_Library_Exception_If_Any, "__gnat_reraise_library_exception_if_any");
-      begin
-         Reraise_Library_Exception_If_Any;
-      end;
-   end finalize_library;
+      return Results (Index);
+   end Func;
+end Server;
+@end example
 
-   -------------
-   -- adainit --
-   -------------
+@example
+with Server;
+package Client is
+   Val : constant Integer := Server.Func (3);
+end Client;
+@end example
 
-   procedure adainit is
+@example
+with Client;
+procedure Main is begin null; end Main;
+@end example
+@end quotation
 
-      Main_Priority : Integer;
-      pragma Import (C, Main_Priority, "__gl_main_priority");
-      Time_Slice_Value : Integer;
-      pragma Import (C, Time_Slice_Value, "__gl_time_slice_val");
-      WC_Encoding : Character;
-      pragma Import (C, WC_Encoding, "__gl_wc_encoding");
-      Locking_Policy : Character;
-      pragma Import (C, Locking_Policy, "__gl_locking_policy");
-      Queuing_Policy : Character;
-      pragma Import (C, Queuing_Policy, "__gl_queuing_policy");
-      Task_Dispatching_Policy : Character;
-      pragma Import (C, Task_Dispatching_Policy, "__gl_task_dispatching_policy");
-      Priority_Specific_Dispatching : System.Address;
-      pragma Import (C, Priority_Specific_Dispatching, "__gl_priority_specific_dispatching");
-      Num_Specific_Dispatching : Integer;
-      pragma Import (C, Num_Specific_Dispatching, "__gl_num_specific_dispatching");
-      Main_CPU : Integer;
-      pragma Import (C, Main_CPU, "__gl_main_cpu");
-      Interrupt_States : System.Address;
-      pragma Import (C, Interrupt_States, "__gl_interrupt_states");
-      Num_Interrupt_States : Integer;
-      pragma Import (C, Num_Interrupt_States, "__gl_num_interrupt_states");
-      Unreserve_All_Interrupts : Integer;
-      pragma Import (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
-      Detect_Blocking : Integer;
-      pragma Import (C, Detect_Blocking, "__gl_detect_blocking");
-      Default_Stack_Size : Integer;
-      pragma Import (C, Default_Stack_Size, "__gl_default_stack_size");
-      Leap_Seconds_Support : Integer;
-      pragma Import (C, Leap_Seconds_Support, "__gl_leap_seconds_support");
+The following elaboration order exhibits a fundamental problem referred to as
+@emph{access-before-elaboration} or simply @strong{ABE}.
 
-      procedure Runtime_Initialize;
-      pragma Import (C, Runtime_Initialize, "__gnat_runtime_initialize");
+@quotation
 
-      Finalize_Library_Objects : No_Param_Proc;
-      pragma Import (C, Finalize_Library_Objects, "__gnat_finalize_library_objects");
+@example
+spec of Server
+spec of Client
+body of Server
+body of Main
+@end example
+@end quotation
 
-   --  Start of processing for adainit
+The elaboration of @code{Server}'s spec materializes function @code{Func}, making it
+callable. The elaboration of @code{Client}'s spec elaborates the declaration of
+@code{Val}. This invokes function @code{Server.Func}, however the body of
+@code{Server.Func} has not been elaborated yet because @code{Server}'s body comes
+after @code{Client}'s spec in the elaboration order. As a result, the value of
+constant @code{Val} is now undefined.
 
-   begin
+Without any guarantees from the language, an undetected ABE problem may hinder
+proper initialization of data, which in turn may lead to undefined behavior at
+run time. To prevent such ABE problems, Ada employs dynamic checks in the same
+vein as index or null exclusion checks. A failed ABE check raises exception
+@code{Program_Error}.
 
-      --  Record various information for this partition.  The values
-      --  are derived by the binder from information stored in the ali
-      --  files by the compiler.
+The following elaboration order avoids the ABE problem and the program can be
+successfully elaborated.
 
-      if Is_Elaborated then
-         return;
-      end if;
-      Is_Elaborated := True;
-      Main_Priority := -1;
-      Time_Slice_Value := -1;
-      WC_Encoding := 'b';
-      Locking_Policy := ' ';
-      Queuing_Policy := ' ';
-      Task_Dispatching_Policy := ' ';
-      Priority_Specific_Dispatching :=
-        Local_Priority_Specific_Dispatching'Address;
-      Num_Specific_Dispatching := 0;
-      Main_CPU := -1;
-      Interrupt_States := Local_Interrupt_States'Address;
-      Num_Interrupt_States := 0;
-      Unreserve_All_Interrupts := 0;
-      Detect_Blocking := 0;
-      Default_Stack_Size := -1;
-      Leap_Seconds_Support := 0;
+@quotation
 
-      Runtime_Initialize;
+@example
+spec of Server
+body of Server
+spec of Client
+body of Main
+@end example
+@end quotation
 
-      Finalize_Library_Objects := finalize_library'access;
+Ada states that a total elaboration order must exist, but it does not define
+what this order is. A compiler is thus tasked with choosing a suitable
+elaboration order which satisfies the dependencies imposed by @emph{with} clauses,
+unit categorization, elaboration-control pragmas, and invocations performed in
+elaboration code. Ideally an order that avoids ABE problems should be chosen,
+however a compiler may not always find such an order due to complications with
+respect to control and data flow.
 
-      --  Now we have the elaboration calls for all units in the partition.
-      --  The Elab_Spec and Elab_Body attributes generate references to the
-      --  implicit elaboration procedures generated by the compiler for
-      --  each unit that requires elaboration. Increment a counter of
-      --  reference for each unit.
+@node Checking the Elaboration Order,Controlling the Elaboration Order in Ada,Elaboration Order,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat id4}@anchor{21a}@anchor{gnat_ugn/elaboration_order_handling_in_gnat checking-the-elaboration-order}@anchor{21b}
+@section Checking the Elaboration Order
 
-      System.Soft_Links'Elab_Spec;
-      System.Exception_Table'Elab_Body;
-      E23 := E23 + 1;
-      Ada.Io_Exceptions'Elab_Spec;
-      E46 := E46 + 1;
-      Ada.Tags'Elab_Spec;
-      Ada.Streams'Elab_Spec;
-      E45 := E45 + 1;
-      Interfaces.C'Elab_Spec;
-      System.Exceptions'Elab_Spec;
-      E25 := E25 + 1;
-      System.Finalization_Root'Elab_Spec;
-      E68 := E68 + 1;
-      Ada.Finalization'Elab_Spec;
-      E66 := E66 + 1;
-      System.Storage_Pools'Elab_Spec;
-      E85 := E85 + 1;
-      System.Finalization_Masters'Elab_Spec;
-      System.Storage_Pools.Subpools'Elab_Spec;
-      System.Pool_Global'Elab_Spec;
-      E87 := E87 + 1;
-      System.File_Control_Block'Elab_Spec;
-      E75 := E75 + 1;
-      System.File_Io'Elab_Body;
-      E64 := E64 + 1;
-      E91 := E91 + 1;
-      System.Finalization_Masters'Elab_Body;
-      E77 := E77 + 1;
-      E70 := E70 + 1;
-      Ada.Tags'Elab_Body;
-      E48 := E48 + 1;
-      System.Soft_Links'Elab_Body;
-      E13 := E13 + 1;
-      System.Os_Lib'Elab_Body;
-      E72 := E72 + 1;
-      System.Secondary_Stack'Elab_Body;
-      E17 := E17 + 1;
-      Ada.Text_Io'Elab_Spec;
-      Ada.Text_Io'Elab_Body;
-      E06 := E06 + 1;
-   end adainit;
 
-   --------------
-   -- adafinal --
-   --------------
+To avoid placing the entire elaboration-order burden on the programmer, Ada
+provides three lines of defense:
 
-   procedure adafinal is
-      procedure s_stalib_adafinal;
-      pragma Import (C, s_stalib_adafinal, "system__standard_library__adafinal");
 
-      procedure Runtime_Finalize;
-      pragma Import (C, Runtime_Finalize, "__gnat_runtime_finalize");
+@itemize *
 
-   begin
-      if not Is_Elaborated then
-         return;
-      end if;
-      Is_Elaborated := False;
-      Runtime_Finalize;
-      s_stalib_adafinal;
-   end adafinal;
+@item 
+@emph{Static semantics}
 
-   --  We get to the main program of the partition by using
-   --  pragma Import because if we try to with the unit and
-   --  call it Ada style, then not only do we waste time
-   --  recompiling it, but also, we don't really know the right
-   --  switches (e.g.@@: identifier character set) to be used
-   --  to compile it.
+Static semantic rules restrict the possible choice of elaboration order. For
+instance, if unit Client @emph{with}s unit Server, then the spec of Server is
+always elaborated prior to Client. The same principle applies to child units
+- the spec of a parent unit is always elaborated prior to the child unit.
 
-   procedure Ada_Main_Program;
-   pragma Import (Ada, Ada_Main_Program, "_ada_hello");
+@item 
+@emph{Dynamic semantics}
 
-   ----------
-   -- main --
-   ----------
+Dynamic checks are performed at run time, to ensure that a target is
+elaborated prior to a scenario that invokes it, thus avoiding ABE problems.
+A failed run-time check raises exception @code{Program_Error}. The following
+restrictions apply:
 
-   --  main is actually a function, as in the ANSI C standard,
-   --  defined to return the exit status. The three parameters
-   --  are the argument count, argument values and environment
-   --  pointer.
 
-   function main
-     (argc : Integer;
-      argv : System.Address;
-      envp : System.Address)
-      return Integer
-   is
-      --  The initialize routine performs low level system
-      --  initialization using a standard library routine which
-      --  sets up signal handling and performs any other
-      --  required setup. The routine can be found in file
-      --  a-init.c.
+@itemize -
 
-      procedure initialize;
-      pragma Import (C, initialize, "__gnat_initialize");
+@item 
+@emph{Restrictions on calls}
 
-      --  The finalize routine performs low level system
-      --  finalization using a standard library routine. The
-      --  routine is found in file a-final.c and in the standard
-      --  distribution is a dummy routine that does nothing, so
-      --  really this is a hook for special user finalization.
+An entry, operator, or subprogram can be called from elaboration code only
+when the corresponding body has been elaborated.
+
+@item 
+@emph{Restrictions on instantiations}
+
+A generic unit can be instantiated by elaboration code only when the
+corresponding body has been elaborated.
+
+@item 
+@emph{Restrictions on task activation}
+
+A task can be activated by elaboration code only when the body of the
+associated task type has been elaborated.
+@end itemize
+
+The restrictions above can be summarized by the following rule:
+
+@emph{If a target has a body, then this body must be elaborated prior to the
+scenario that invokes the target.}
 
-      procedure finalize;
-      pragma Import (C, finalize, "__gnat_finalize");
+@item 
+@emph{Elaboration control}
 
-      --  The following is to initialize the SEH exceptions
+Pragmas are provided for the programmer to specify the desired elaboration
+order.
+@end itemize
 
-      SEH : aliased array (1 .. 2) of Integer;
+@node Controlling the Elaboration Order in Ada,Controlling the Elaboration Order in GNAT,Checking the Elaboration Order,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat controlling-the-elaboration-order-in-ada}@anchor{21c}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id5}@anchor{21d}
+@section Controlling the Elaboration Order in Ada
 
-      Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;
-      pragma Volatile (Ensure_Reference);
 
-   --  Start of processing for main
+Ada provides several idioms and pragmas to aid the programmer with specifying
+the desired elaboration order and avoiding ABE problems altogether.
 
-   begin
-      --  Save global variables
 
-      gnat_argc := argc;
-      gnat_argv := argv;
-      gnat_envp := envp;
+@itemize *
 
-      --  Call low level system initialization
+@item 
+@emph{Packages without a body}
 
-      Initialize (SEH'Address);
+A library package which does not require a completing body does not suffer
+from ABE problems.
 
-      --  Call our generated Ada initialization routine
+@example
+package Pack is
+   generic
+      type Element is private;
+   package Containers is
+      type Element_Array is array (1 .. 10) of Element;
+   end Containers;
+end Pack;
+@end example
 
-      adainit;
+In the example above, package @code{Pack} does not require a body because it
+does not contain any constructs which require completion in a body. As a
+result, generic @code{Pack.Containers} can be instantiated without encountering
+any ABE problems.
+@end itemize
 
-      --  Now we call the main program of the partition
+@geindex pragma Pure
 
-      Ada_Main_Program;
 
-      --  Perform Ada finalization
+@itemize *
 
-      adafinal;
+@item 
+@emph{pragma Pure}
 
-      --  Perform low level system finalization
+Pragma @code{Pure} places sufficient restrictions on a unit to guarantee that no
+scenario within the unit can result in an ABE problem.
+@end itemize
 
-      Finalize;
+@geindex pragma Preelaborate
 
-      --  Return the proper exit status
-      return (gnat_exit_status);
-   end;
 
---  This section is entirely comments, so it has no effect on the
---  compilation of the Ada_Main package. It provides the list of
---  object files and linker options, as well as some standard
---  libraries needed for the link. The gnatlink utility parses
---  this b~hello.adb file to read these comment lines to generate
---  the appropriate command line arguments for the call to the
---  system linker. The BEGIN/END lines are used for sentinels for
---  this parsing operation.
+@itemize *
 
---  The exact file names will of course depend on the environment,
---  host/target and location of files on the host system.
+@item 
+@emph{pragma Preelaborate}
 
--- BEGIN Object file/option list
-   --   ./hello.o
-   --   -L./
-   --   -L/usr/local/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/
-   --   /usr/local/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/libgnat.a
--- END Object file/option list
+Pragma @code{Preelaborate} is slightly less restrictive than pragma @code{Pure},
+but still strong enough to prevent ABE problems within a unit.
+@end itemize
 
-end ada_main;
-@end example
+@geindex pragma Elaborate_Body
 
-The Ada code in the above example is exactly what is generated by the
-binder. We have added comments to more clearly indicate the function
-of each part of the generated @code{Ada_Main} package.
 
-The code is standard Ada in all respects, and can be processed by any
-tools that handle Ada. In particular, it is possible to use the debugger
-in Ada mode to debug the generated @code{Ada_Main} package. For example,
-suppose that for reasons that you do not understand, your program is crashing
-during elaboration of the body of @code{Ada.Text_IO}. To locate this bug,
-you can place a breakpoint on the call:
+@itemize *
 
-@quotation
+@item 
+@emph{pragma Elaborate_Body}
+
+Pragma @code{Elaborate_Body} requires that the body of a unit is elaborated
+immediately after its spec. This restriction guarantees that no client
+scenario can invoke a server target before the target body has been
+elaborated because the spec and body are effectively "glued" together.
 
 @example
-Ada.Text_Io'Elab_Body;
-@end example
-@end quotation
+package Server is
+   pragma Elaborate_Body;
 
-and trace the elaboration routine for this package to find out where
-the problem might be (more usually of course you would be debugging
-elaboration code in your own application).
+   function Func return Integer;
+end Server;
+@end example
 
-@c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit
+@example
+package body Server is
+   function Func return Integer is
+   begin
+      ...
+   end Func;
+end Server;
+@end example
 
-@node Elaboration Order Handling in GNAT,Inline Assembler,Example of Binder Output File,Top
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-order-handling-in-gnat}@anchor{f}@anchor{gnat_ugn/elaboration_order_handling_in_gnat doc}@anchor{22c}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id1}@anchor{22d}
-@chapter Elaboration Order Handling in GNAT
+@example
+with Server;
+package Client is
+   Val : constant Integer := Server.Func;
+end Client;
+@end example
 
+In the example above, pragma @code{Elaborate_Body} guarantees the following
+elaboration order:
 
-@geindex Order of elaboration
+@example
+spec of Server
+body of Server
+spec of Client
+@end example
 
-@geindex Elaboration control
+because the spec of @code{Server} must be elaborated prior to @code{Client} by
+virtue of the @emph{with} clause, and in addition the body of @code{Server} must be
+elaborated immediately after the spec of @code{Server}.
 
-This appendix describes the handling of elaboration code in Ada and
-in GNAT, and discusses how the order of elaboration of program units can
-be controlled in GNAT, either automatically or with explicit programming
-features.
+Removing pragma @code{Elaborate_Body} could result in the following incorrect
+elaboration order:
 
-@menu
-* Elaboration Code:: 
-* Checking the Elaboration Order:: 
-* Controlling the Elaboration Order:: 
-* Controlling Elaboration in GNAT - Internal Calls:: 
-* Controlling Elaboration in GNAT - External Calls:: 
-* Default Behavior in GNAT - Ensuring Safety:: 
-* Treatment of Pragma Elaborate:: 
-* Elaboration Issues for Library Tasks:: 
-* Mixing Elaboration Models:: 
-* What to Do If the Default Elaboration Behavior Fails:: 
-* Elaboration for Indirect Calls:: 
-* Summary of Procedures for Elaboration Control:: 
-* Other Elaboration Order Considerations:: 
-* Determining the Chosen Elaboration Order:: 
+@example
+spec of Server
+spec of Client
+body of Server
+@end example
 
-@end menu
+where @code{Client} invokes @code{Server.Func}, but the body of @code{Server.Func} has
+not been elaborated yet.
+@end itemize
 
-@node Elaboration Code,Checking the Elaboration Order,,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-code}@anchor{22e}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id2}@anchor{22f}
-@section Elaboration Code
+The pragmas outlined above allow a server unit to guarantee safe elaboration
+use by client units. Thus it is a good rule to mark units as @code{Pure} or
+@code{Preelaborate}, and if this is not possible, mark them as @code{Elaborate_Body}.
 
+There are however situations where @code{Pure}, @code{Preelaborate}, and
+@code{Elaborate_Body} are not applicable. Ada provides another set of pragmas for
+use by client units to help ensure the elaboration safety of server units they
+depend on.
 
-Ada provides rather general mechanisms for executing code at elaboration
-time, that is to say before the main program starts executing. Such code arises
-in three contexts:
+@geindex pragma Elaborate (Unit)
 
 
 @itemize *
 
 @item 
-@emph{Initializers for variables}
+@emph{pragma Elaborate (Unit)}
 
-Variables declared at the library level, in package specs or bodies, can
-require initialization that is performed at elaboration time, as in:
+Pragma @code{Elaborate} can be placed in the context clauses of a unit, after a
+@emph{with} clause. It guarantees that both the spec and body of its argument will
+be elaborated prior to the unit with the pragma. Note that other unrelated
+units may be elaborated in between the spec and the body.
 
 @example
-Sqrt_Half : Float := Sqrt (0.5);
+package Server is
+   function Func return Integer;
+end Server;
 @end example
 
-@item 
-@emph{Package initialization code}
-
-Code in a @code{begin} ... `@w{`} end`@w{`} section at the outer level of a package body is
-executed as part of the package body elaboration code.
-
-@item 
-@emph{Library level task allocators}
+@example
+package body Server is
+   function Func return Integer is
+   begin
+      ...
+   end Func;
+end Server;
+@end example
 
-Tasks that are declared using task allocators at the library level
-start executing immediately and hence can execute at elaboration time.
-@end itemize
+@example
+with Server;
+pragma Elaborate (Server);
+package Client is
+   Val : constant Integer := Server.Func;
+end Client;
+@end example
 
-Subprogram calls are possible in any of these contexts, which means that
-any arbitrary part of the program may be executed as part of the elaboration
-code. It is even possible to write a program which does all its work at
-elaboration time, with a null main program, although stylistically this
-would usually be considered an inappropriate way to structure
-a program.
+In the example above, pragma @code{Elaborate} guarantees the following
+elaboration order:
 
-An important concern arises in the context of elaboration code:
-we have to be sure that it is executed in an appropriate order. What we
-have is a series of elaboration code sections, potentially one section
-for each unit in the program. It is important that these execute
-in the correct order. Correctness here means that, taking the above
-example of the declaration of @code{Sqrt_Half},
-if some other piece of
-elaboration code references @code{Sqrt_Half},
-then it must run after the
-section of elaboration code that contains the declaration of
-@code{Sqrt_Half}.
+@example
+spec of Server
+body of Server
+spec of Client
+@end example
 
-There would never be any order of elaboration problem if we made a rule
-that whenever you @emph{with} a unit, you must elaborate both the spec and body
-of that unit before elaborating the unit doing the @emph{with}ing:
+Removing pragma @code{Elaborate} could result in the following incorrect
+elaboration order:
 
 @example
-with Unit_1;
-package Unit_2 is ...
+spec of Server
+spec of Client
+body of Server
 @end example
 
-would require that both the body and spec of @code{Unit_1} be elaborated
-before the spec of @code{Unit_2}. However, a rule like that would be far too
-restrictive. In particular, it would make it impossible to have routines
-in separate packages that were mutually recursive.
+where @code{Client} invokes @code{Server.Func}, but the body of @code{Server.Func}
+has not been elaborated yet.
+@end itemize
+
+@geindex pragma Elaborate_All (Unit)
+
+
+@itemize *
 
-You might think that a clever enough compiler could look at the actual
-elaboration code and determine an appropriate correct order of elaboration,
-but in the general case, this is not possible. Consider the following
-example.
+@item 
+@emph{pragma Elaborate_All (Unit)}
 
-In the body of @code{Unit_1}, we have a procedure @code{Func_1}
-that references
-the variable @code{Sqrt_1}, which is declared in the elaboration code
-of the body of @code{Unit_1}:
+Pragma @code{Elaborate_All} is placed in the context clauses of a unit, after
+a @emph{with} clause. It guarantees that both the spec and body of its argument
+will be elaborated prior to the unit with the pragma, as well as all units
+@emph{with}ed by the spec and body of the argument, recursively. Note that other
+unrelated units may be elaborated in between the spec and the body.
 
 @example
-Sqrt_1 : Float := Sqrt (0.1);
+package Math is
+   function Factorial (Val : Natural) return Natural;
+end Math;
 @end example
 
-The elaboration code of the body of @code{Unit_1} also contains:
+@example
+package body Math is
+   function Factorial (Val : Natural) return Natural is
+   begin
+      ...;
+   end Factorial;
+end Math;
+@end example
 
 @example
-if expression_1 = 1 then
-   Q := Unit_2.Func_2;
-end if;
+package Computer is
+   type Operation_Kind is (None, Op_Factorial);
+
+   function Compute
+     (Val : Natural;
+      Op  : Operation_Kind) return Natural;
+end Computer;
 @end example
 
-@code{Unit_2} is exactly parallel,
-it has a procedure @code{Func_2} that references
-the variable @code{Sqrt_2}, which is declared in the elaboration code of
-the body @code{Unit_2}:
+@example
+with Math;
+package body Computer is
+   function Compute
+     (Val : Natural;
+      Op  : Operation_Kind) return Natural
+   is
+      if Op = Op_Factorial then
+         return Math.Factorial (Val);
+      end if;
+
+      return 0;
+   end Compute;
+end Computer;
+@end example
 
 @example
-Sqrt_2 : Float := Sqrt (0.1);
+with Computer;
+pragma Elaborate_All (Computer);
+package Client is
+   Val : constant Natural :=
+           Computer.Compute (123, Computer.Op_Factorial);
+end Client;
 @end example
 
-The elaboration code of the body of @code{Unit_2} also contains:
+In the example above, pragma @code{Elaborate_All} can result in the following
+elaboration order:
 
 @example
-if expression_2 = 2 then
-   Q := Unit_1.Func_1;
-end if;
+spec of Math
+body of Math
+spec of Computer
+body of Computer
+spec of Client
 @end example
 
-Now the question is, which of the following orders of elaboration is
-acceptable:
+Note that there are several allowable suborders for the specs and bodies of
+@code{Math} and @code{Computer}, but the point is that these specs and bodies will
+be elaborated prior to @code{Client}.
+
+Removing pragma @code{Elaborate_All} could result in the following incorrect
+elaboration order:
 
 @example
-Spec of Unit_1
-Spec of Unit_2
-Body of Unit_1
-Body of Unit_2
+spec of Math
+spec of Computer
+body of Computer
+spec of Client
+body of Math
 @end example
 
-or
+where @code{Client} invokes @code{Computer.Compute}, which in turn invokes
+@code{Math.Factorial}, but the body of @code{Math.Factorial} has not been
+elaborated yet.
+@end itemize
 
-@example
-Spec of Unit_2
-Spec of Unit_1
-Body of Unit_2
-Body of Unit_1
-@end example
-
-If you carefully analyze the flow here, you will see that you cannot tell
-at compile time the answer to this question.
-If @code{expression_1} is not equal to 1,
-and @code{expression_2} is not equal to 2,
-then either order is acceptable, because neither of the function calls is
-executed. If both tests evaluate to true, then neither order is acceptable
-and in fact there is no correct order.
-
-If one of the two expressions is true, and the other is false, then one
-of the above orders is correct, and the other is incorrect. For example,
-if @code{expression_1} /= 1 and @code{expression_2} = 2,
-then the call to @code{Func_1}
-will occur, but not the call to @code{Func_2.}
-This means that it is essential
-to elaborate the body of @code{Unit_1} before
-the body of @code{Unit_2}, so the first
-order of elaboration is correct and the second is wrong.
-
-By making @code{expression_1} and @code{expression_2}
-depend on input data, or perhaps
-the time of day, we can make it impossible for the compiler or binder
-to figure out which of these expressions will be true, and hence it
-is impossible to guarantee a safe order of elaboration at run time.
-
-@node Checking the Elaboration Order,Controlling the Elaboration Order,Elaboration Code,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat checking-the-elaboration-order}@anchor{230}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id3}@anchor{231}
-@section Checking the Elaboration Order
+All pragmas shown above can be summarized by the following rule:
 
+@emph{If a client unit elaborates a server target directly or indirectly, then if
+the server unit requires a body and does not have pragma Pure, Preelaborate,
+or Elaborate_Body, then the client unit should have pragma Elaborate or
+Elaborate_All for the server unit.}
 
-In some languages that involve the same kind of elaboration problems,
-e.g., Java and C++, the programmer needs to take these
-ordering problems into account, and it is common to
-write a program in which an incorrect elaboration order  gives
-surprising results, because it references variables before they
-are initialized.
-Ada is designed to be a safe language, and a programmer-beware approach is
-clearly not sufficient. Consequently, the language provides three lines
-of defense:
+If the rule outlined above is not followed, then a program may fall in one of
+the following states:
 
 
 @itemize *
 
 @item 
-@emph{Standard rules}
+@emph{No elaboration order exists}
+
+In this case a compiler must diagnose the situation, and refuse to build an
+executable program.
+
+@item 
+@emph{One or more incorrect elaboration orders exist}
+
+In this case a compiler can build an executable program, but
+@code{Program_Error} will be raised when the program is run.
+
+@item 
+@emph{Several elaboration orders exist, some correct, some incorrect}
+
+In this case the programmer has not controlled the elaboration order. As a
+result, a compiler may or may not pick one of the correct orders, and the
+program may or may not raise @code{Program_Error} when it is run. This is the
+worst possible state because the program may fail on another compiler, or
+even another version of the same compiler.
+
+@item 
+@emph{One or more correct orders exist}
 
-Some standard rules restrict the possible choice of elaboration
-order. In particular, if you @emph{with} a unit, then its spec is always
-elaborated before the unit doing the @emph{with}. Similarly, a parent
-spec is always elaborated before the child spec, and finally
-a spec is always elaborated before its corresponding body.
+In this case a compiler can build an executable program, and the program is
+run successfully. This state may be guaranteed by following the outlined
+rules, or may be the result of good program architecture.
 @end itemize
 
-@geindex Elaboration checks
+Note that one additional advantage of using @code{Elaborate} and @code{Elaborate_All}
+is that the program continues to stay in the last state (one or more correct
+orders exist) even if maintenance changes the bodies of targets.
 
-@geindex Checks
-@geindex elaboration
+@node Controlling the Elaboration Order in GNAT,Mixing Elaboration Models,Controlling the Elaboration Order in Ada,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat id6}@anchor{21e}@anchor{gnat_ugn/elaboration_order_handling_in_gnat controlling-the-elaboration-order-in-gnat}@anchor{21f}
+@section Controlling the Elaboration Order in GNAT
+
+
+In addition to Ada semantics and rules synthesized from them, GNAT offers
+three elaboration models to aid the programmer with specifying the correct
+elaboration order and to diagnose elaboration problems.
+
+@geindex Dynamic elaboration model
 
 
 @itemize *
 
 @item 
-@emph{Dynamic elaboration checks}
+@emph{Dynamic elaboration model}
+
+This is the most permissive of the three elaboration models and emulates the
+behavior specified by the Ada Reference Manual. When the dynamic model is in
+effect, GNAT makes the following assumptions:
 
-Dynamic checks are made at run time, so that if some entity is accessed
-before it is elaborated (typically  by means of a subprogram call)
-then the exception (@code{Program_Error}) is raised.
+
+@itemize -
 
 @item 
-@emph{Elaboration control}
+All code within all units in a partition is considered to be elaboration
+code.
+
+@item 
+Some of the invocations in elaboration code may not take place at run time
+due to conditional execution.
+@end itemize
+
+GNAT performs extensive diagnostics on a unit-by-unit basis for all scenarios
+that invoke internal targets. In addition, GNAT generates run-time checks for
+all external targets and for all scenarios that may exhibit ABE problems.
 
-Facilities are provided for the programmer to specify the desired order
-of elaboration.
+The elaboration order is obtained by honoring all @emph{with} clauses, purity and
+preelaborability of units, and elaboration-control pragmas. The dynamic model
+attempts to take all invocations in elaboration code into account. If an
+invocation leads to a circularity, GNAT ignores the invocation based on the
+assumptions stated above. An order obtained using the dynamic model may fail
+an ABE check at run time when GNAT ignored an invocation.
+
+The dynamic model is enabled with compiler switch @code{-gnatE}.
 @end itemize
 
-Let's look at these facilities in more detail. First, the rules for
-dynamic checking. One possible rule would be simply to say that the
-exception is raised if you access a variable which has not yet been
-elaborated. The trouble with this approach is that it could require
-expensive checks on every variable reference. Instead Ada has two
-rules which are a little more restrictive, but easier to check, and
-easier to state:
+@geindex Static elaboration model
 
 
 @itemize *
 
 @item 
-@emph{Restrictions on calls}
+@emph{Static elaboration model}
+
+This is the middle ground of the three models. When the static model is in
+effect, GNAT makes the following assumptions:
+
 
-A subprogram can only be called at elaboration time if its body
-has been elaborated. The rules for elaboration given above guarantee
-that the spec of the subprogram has been elaborated before the
-call, but not the body. If this rule is violated, then the
-exception @code{Program_Error} is raised.
+@itemize -
 
 @item 
-@emph{Restrictions on instantiations}
+Only code at the library level and in package body statements within all
+units in a partition is considered to be elaboration code.
+
+@item 
+All invocations in elaboration will take place at run time, regardless of
+conditional execution.
+@end itemize
+
+GNAT performs extensive diagnostics on a unit-by-unit basis for all scenarios
+that invoke internal targets. In addition, GNAT generates run-time checks for
+all external targets and for all scenarios that may exhibit ABE problems.
 
-A generic unit can only be instantiated if the body of the generic
-unit has been elaborated. Again, the rules for elaboration given above
-guarantee that the spec of the generic unit has been elaborated
-before the instantiation, but not the body. If this rule is
-violated, then the exception @code{Program_Error} is raised.
+The elaboration order is obtained by honoring all @emph{with} clauses, purity and
+preelaborability of units, presence of elaboration-control pragmas, and all
+invocations in elaboration code. An order obtained using the static model is
+guaranteed to be ABE problem-free, excluding dispatching calls and
+access-to-subprogram types.
+
+The static model is the default model in GNAT.
 @end itemize
 
-The idea is that if the body has been elaborated, then any variables
-it references must have been elaborated; by checking for the body being
-elaborated we guarantee that none of its references causes any
-trouble. As we noted above, this is a little too restrictive, because a
-subprogram that has no non-local references in its body may in fact be safe
-to call. However, it really would be unsafe to rely on this, because
-it would mean that the caller was aware of details of the implementation
-in the body. This goes against the basic tenets of Ada.
-
-A plausible implementation can be described as follows.
-A Boolean variable is associated with each subprogram
-and each generic unit. This variable is initialized to False, and is set to
-True at the point body is elaborated. Every call or instantiation checks the
-variable, and raises @code{Program_Error} if the variable is False.
-
-Note that one might think that it would be good enough to have one Boolean
-variable for each package, but that would not deal with cases of trying
-to call a body in the same package as the call
-that has not been elaborated yet.
-Of course a compiler may be able to do enough analysis to optimize away
-some of the Boolean variables as unnecessary, and GNAT indeed
-does such optimizations, but still the easiest conceptual model is to
-think of there being one variable per subprogram.
-
-@node Controlling the Elaboration Order,Controlling Elaboration in GNAT - Internal Calls,Checking the Elaboration Order,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat id4}@anchor{232}@anchor{gnat_ugn/elaboration_order_handling_in_gnat controlling-the-elaboration-order}@anchor{233}
-@section Controlling the Elaboration Order
-
-
-In the previous section we discussed the rules in Ada which ensure
-that @code{Program_Error} is raised if an incorrect elaboration order is
-chosen. This prevents erroneous executions, but we need mechanisms to
-specify a correct execution and avoid the exception altogether.
-To achieve this, Ada provides a number of features for controlling
-the order of elaboration. We discuss these features in this section.
-
-First, there are several ways of indicating to the compiler that a given
-unit has no elaboration problems:
+@geindex SPARK elaboration model
 
 
 @itemize *
 
 @item 
-@emph{packages that do not require a body}
-
-A library package that does not require a body does not permit
-a body (this rule was introduced in Ada 95).
-Thus if we have a such a package, as in:
+@emph{SPARK elaboration model}
 
-@example
-package Definitions is
-   generic
-      type m is new integer;
-   package Subp is
-      type a is array (1 .. 10) of m;
-      type b is array (1 .. 20) of m;
-   end Subp;
-end Definitions;
-@end example
+This is the most conservative of the three models and enforces the SPARK
+rules of elaboration as defined in the SPARK Reference Manual, section 7.7.
+The SPARK model is in effect only when a scenario and a target reside in a
+region subject to @code{SPARK_Mode On}, otherwise the dynamic or static model
+is in effect.
 
-A package that @emph{with}s @code{Definitions} may safely instantiate
-@code{Definitions.Subp} because the compiler can determine that there
-definitely is no package body to worry about in this case
+The SPARK model is enabled with compiler switch @code{-gnatd.v}.
 @end itemize
 
-@geindex pragma Pure
+@geindex Legacy elaboration models
 
 
 @itemize *
 
 @item 
-@emph{pragma Pure}
+@emph{Legacy elaboration models}
+
+In addition to the three elaboration models outlined above, GNAT provides the
+following legacy models:
+
+
+@itemize -
+
+@item 
+@cite{Legacy elaboration-checking model} available in pre-18.x versions of GNAT.
+This model is enabled with compiler switch @code{-gnatH}.
 
-This pragma places sufficient restrictions on a unit to guarantee that
-no call to any subprogram in the unit can result in an
-elaboration problem. This means that the compiler does not need
-to worry about the point of elaboration of such units, and in
-particular, does not need to check any calls to any subprograms
-in this unit.
+@item 
+@cite{Legacy elaboration-order model} available in pre-20.x versions of GNAT.
+This model is enabled with binder switch @code{-H}.
+@end itemize
 @end itemize
 
-@geindex pragma Preelaborate
+@geindex Relaxed elaboration mode
+
+The dynamic, legacy, and static models can be relaxed using compiler switch
+@code{-gnatJ}, making them more permissive. Note that in this mode, GNAT
+may not diagnose certain elaboration issues or install run-time checks.
+
+@node Mixing Elaboration Models,ABE Diagnostics,Controlling the Elaboration Order in GNAT,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat mixing-elaboration-models}@anchor{220}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id7}@anchor{221}
+@section Mixing Elaboration Models
+
+
+It is possible to mix units compiled with a different elaboration model,
+however the following rules must be observed:
 
 
 @itemize *
 
 @item 
-@emph{pragma Preelaborate}
+A client unit compiled with the dynamic model can only @emph{with} a server unit
+that meets at least one of the following criteria:
 
-This pragma places slightly less stringent restrictions on a unit than
-does pragma Pure,
-but these restrictions are still sufficient to ensure that there
-are no elaboration problems with any calls to the unit.
+
+@itemize -
+
+@item 
+The server unit is compiled with the dynamic model.
+
+@item 
+The server unit is a GNAT implementation unit from the @code{Ada}, @code{GNAT},
+@code{Interfaces}, or @code{System} hierarchies.
+
+@item 
+The server unit has pragma @code{Pure} or @code{Preelaborate}.
+
+@item 
+The client unit has an explicit @code{Elaborate_All} pragma for the server
+unit.
+@end itemize
 @end itemize
 
-@geindex pragma Elaborate_Body
+These rules ensure that elaboration checks are not omitted. If the rules are
+violated, the binder emits a warning:
+
+@quotation
+
+@example
+warning: "x.ads" has dynamic elaboration checks and with's
+warning:   "y.ads" which has static elaboration checks
+@end example
+@end quotation
+
+The warnings can be suppressed by binder switch @code{-ws}.
+
+@node ABE Diagnostics,SPARK Diagnostics,Mixing Elaboration Models,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat abe-diagnostics}@anchor{222}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id8}@anchor{223}
+@section ABE Diagnostics
+
+
+GNAT performs extensive diagnostics on a unit-by-unit basis for all scenarios
+that invoke internal targets, regardless of whether the dynamic, SPARK, or
+static model is in effect.
+
+Note that GNAT emits warnings rather than hard errors whenever it encounters an
+elaboration problem. This is because the elaboration model in effect may be too
+conservative, or a particular scenario may not be invoked due conditional
+execution. The warnings can be suppressed selectively with @code{pragma Warnings
+(Off)} or globally with compiler switch @code{-gnatwL}.
+
+A @emph{guaranteed ABE} arises when the body of a target is not elaborated early
+enough, and causes @emph{all} scenarios that directly invoke the target to fail.
+
+@quotation
+
+@example
+package body Guaranteed_ABE is
+   function ABE return Integer;
+
+   Val : constant Integer := ABE;
+
+   function ABE return Integer is
+   begin
+     ...
+   end ABE;
+end Guaranteed_ABE;
+@end example
+@end quotation
+
+In the example above, the elaboration of @code{Guaranteed_ABE}'s body elaborates
+the declaration of @code{Val}. This invokes function @code{ABE}, however the body of
+@code{ABE} has not been elaborated yet. GNAT emits the following diagnostic:
+
+@quotation
+
+@example
+4.    Val : constant Integer := ABE;
+                                |
+   >>> warning: cannot call "ABE" before body seen
+   >>> warning: Program_Error will be raised at run time
+@end example
+@end quotation
+
+A @emph{conditional ABE} arises when the body of a target is not elaborated early
+enough, and causes @emph{some} scenarios that directly invoke the target to fail.
+
+@quotation
+
+@example
+ 1. package body Conditional_ABE is
+ 2.    procedure Force_Body is null;
+ 3.
+ 4.    generic
+ 5.       with function Func return Integer;
+ 6.    package Gen is
+ 7.       Val : constant Integer := Func;
+ 8.    end Gen;
+ 9.
+10.    function ABE return Integer;
+11.
+12.    function Cause_ABE return Boolean is
+13.       package Inst is new Gen (ABE);
+14.    begin
+15.       ...
+16.    end Cause_ABE;
+17.
+18.    Val : constant Boolean := Cause_ABE;
+19.
+20.    function ABE return Integer is
+21.    begin
+22.       ...
+23.    end ABE;
+24.
+25.    Safe : constant Boolean := Cause_ABE;
+26. end Conditional_ABE;
+@end example
+@end quotation
+
+In the example above, the elaboration of package body @code{Conditional_ABE}
+elaborates the declaration of @code{Val}. This invokes function @code{Cause_ABE},
+which instantiates generic unit @code{Gen} as @code{Inst}. The elaboration of
+@code{Inst} invokes function @code{ABE}, however the body of @code{ABE} has not been
+elaborated yet. GNAT emits the following diagnostic:
 
+@quotation
 
-@itemize *
+@example
+13.       package Inst is new Gen (ABE);
+          |
+    >>> warning: in instantiation at line 7
+    >>> warning: cannot call "ABE" before body seen
+    >>> warning: Program_Error may be raised at run time
+    >>> warning:   body of unit "Conditional_ABE" elaborated
+    >>> warning:   function "Cause_ABE" called at line 18
+    >>> warning:   function "ABE" called at line 7, instance at line 13
+@end example
+@end quotation
 
-@item 
-@emph{pragma Elaborate_Body}
+Note that the same ABE problem does not occur with the elaboration of
+declaration @code{Safe} because the body of function @code{ABE} has already been
+elaborated at that point.
 
-This pragma requires that the body of a unit be elaborated immediately
-after its spec. Suppose a unit @code{A} has such a pragma,
-and unit @code{B} does
-a @emph{with} of unit @code{A}. Recall that the standard rules require
-the spec of unit @code{A}
-to be elaborated before the @emph{with}ing unit; given the pragma in
-@code{A}, we also know that the body of @code{A}
-will be elaborated before @code{B}, so
-that calls to @code{A} are safe and do not need a check.
-
-Note that, unlike pragma @code{Pure} and pragma @code{Preelaborate},
-the use of @code{Elaborate_Body} does not guarantee that the program is
-free of elaboration problems, because it may not be possible
-to satisfy the requested elaboration order.
-Let's go back to the example with @code{Unit_1} and @code{Unit_2}.
-If a programmer marks @code{Unit_1} as @code{Elaborate_Body},
-and not @code{Unit_2,} then the order of
-elaboration will be:
-
-@example
-Spec of Unit_2
-Spec of Unit_1
-Body of Unit_1
-Body of Unit_2
-@end example
-
-Now that means that the call to @code{Func_1} in @code{Unit_2}
-need not be checked,
-it must be safe. But the call to @code{Func_2} in
-@code{Unit_1} may still fail if
-@code{Expression_1} is equal to 1,
-and the programmer must still take
-responsibility for this not being the case.
-
-If all units carry a pragma @code{Elaborate_Body}, then all problems are
-eliminated, except for calls entirely within a body, which are
-in any case fully under programmer control. However, using the pragma
-everywhere is not always possible.
-In particular, for our @code{Unit_1}/@cite{Unit_2} example, if
-we marked both of them as having pragma @code{Elaborate_Body}, then
-clearly there would be no possible elaboration order.
-@end itemize
+@node SPARK Diagnostics,Elaboration Circularities,ABE Diagnostics,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat spark-diagnostics}@anchor{224}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id9}@anchor{225}
+@section SPARK Diagnostics
 
-The above pragmas allow a server to guarantee safe use by clients, and
-clearly this is the preferable approach. Consequently a good rule
-is to mark units as @code{Pure} or @code{Preelaborate} if possible,
-and if this is not possible,
-mark them as @code{Elaborate_Body} if possible.
-As we have seen, there are situations where neither of these
-three pragmas can be used.
-So we also provide methods for clients to control the
-order of elaboration of the servers on which they depend:
 
-@geindex pragma Elaborate
+GNAT enforces the SPARK rules of elaboration as defined in the SPARK Reference
+Manual section 7.7 when compiler switch @code{-gnatd.v} is in effect. Note
+that GNAT emits hard errors whenever it encounters a violation of the SPARK
+rules.
 
+@quotation
 
-@itemize *
+@example
+1. with Server;
+2. package body SPARK_Diagnostics with SPARK_Mode is
+3.    Val : constant Integer := Server.Func;
+                                      |
+   >>> call to "Func" during elaboration in SPARK
+   >>> unit "SPARK_Diagnostics" requires pragma "Elaborate_All" for "Server"
+   >>>   body of unit "SPARK_Model" elaborated
+   >>>   function "Func" called at line 3
 
-@item 
-@emph{pragma Elaborate (unit)}
+4. end SPARK_Diagnostics;
+@end example
+@end quotation
 
-This pragma is placed in the context clause, after a @emph{with} clause,
-and it requires that the body of the named unit be elaborated before
-the unit in which the pragma occurs. The idea is to use this pragma
-if the current unit calls at elaboration time, directly or indirectly,
-some subprogram in the named unit.
-@end itemize
+@node Elaboration Circularities,Resolving Elaboration Circularities,SPARK Diagnostics,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat id10}@anchor{226}@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-circularities}@anchor{227}
+@section Elaboration Circularities
 
-@geindex pragma Elaborate_All
 
+An @strong{elaboration circularity} occurs whenever the elaboration of a set of
+units enters a deadlocked state, where each unit is waiting for another unit
+to be elaborated. This situation may be the result of improper use of @emph{with}
+clauses, elaboration-control pragmas, or invocations in elaboration code.
 
-@itemize *
+The following example exhibits an elaboration circularity.
 
-@item 
-@emph{pragma Elaborate_All (unit)}
+@quotation
 
-This is a stronger version of the Elaborate pragma. Consider the
-following example:
+@example
+with B; pragma Elaborate (B);
+package A is
+end A;
+@end example
 
 @example
-Unit A |withs| unit B and calls B.Func in elab code
-Unit B |withs| unit C, and B.Func calls C.Func
+package B is
+   procedure Force_Body;
+end B;
 @end example
 
-Now if we put a pragma @code{Elaborate (B)}
-in unit @code{A}, this ensures that the
-body of @code{B} is elaborated before the call, but not the
-body of @code{C}, so
-the call to @code{C.Func} could still cause @code{Program_Error} to
-be raised.
+@example
+with C;
+package body B is
+   procedure Force_Body is null;
 
-The effect of a pragma @code{Elaborate_All} is stronger, it requires
-not only that the body of the named unit be elaborated before the
-unit doing the @emph{with}, but also the bodies of all units that the
-named unit uses, following @emph{with} links transitively. For example,
-if we put a pragma @code{Elaborate_All (B)} in unit @code{A},
-then it requires not only that the body of @code{B} be elaborated before @code{A},
-but also the body of @code{C}, because @code{B} @emph{with}s @code{C}.
-@end itemize
+   Elab : constant Integer := C.Func;
+end B;
+@end example
 
-We are now in a position to give a usage rule in Ada for avoiding
-elaboration problems, at least if dynamic dispatching and access to
-subprogram values are not used. We will handle these cases separately
-later.
+@example
+package C is
+   function Func return Integer;
+end C;
+@end example
 
-The rule is simple:
+@example
+with A;
+package body C is
+   function Func return Integer is
+   begin
+      ...
+   end Func;
+end C;
+@end example
+@end quotation
 
-@emph{If a unit has elaboration code that can directly or
-indirectly make a call to a subprogram in a |withed| unit, or instantiate
-a generic package in a |withed| unit,
-then if the |withed| unit does not have
-pragma `@w{`}Pure`@w{`} or `@w{`}Preelaborate`@w{`}, then the client should have
-a pragma `@w{`}Elaborate_All`@w{`}for the |withed| unit.*}
+The binder emits the following diagnostic:
 
-By following this rule a client is
-assured that calls can be made without risk of an exception.
+@quotation
 
-For generic subprogram instantiations, the rule can be relaxed to
-require only a pragma @code{Elaborate} since elaborating the body
-of a subprogram cannot cause any transitive elaboration (we are
-not calling the subprogram in this case, just elaborating its
-declaration).
+@example
+error: Elaboration circularity detected
+info:
+info:    Reason:
+info:
+info:      unit "a (spec)" depends on its own elaboration
+info:
+info:    Circularity:
+info:
+info:      unit "a (spec)" has with clause and pragma Elaborate for unit "b (spec)"
+info:      unit "b (body)" is in the closure of pragma Elaborate
+info:      unit "b (body)" invokes a construct of unit "c (body)" at elaboration time
+info:      unit "c (body)" has with clause for unit "a (spec)"
+info:
+info:    Suggestions:
+info:
+info:      remove pragma Elaborate for unit "b (body)" in unit "a (spec)"
+info:      use the dynamic elaboration model (compiler switch -gnatE)
+@end example
+@end quotation
 
-If this rule is not followed, then a program may be in one of four
-states:
+The diagnostic consist of the following sections:
 
 
 @itemize *
 
 @item 
-@emph{No order exists}
+Reason
 
-No order of elaboration exists which follows the rules, taking into
-account any @code{Elaborate}, @code{Elaborate_All},
-or @code{Elaborate_Body} pragmas. In
-this case, an Ada compiler must diagnose the situation at bind
-time, and refuse to build an executable program.
+This section provides a short explanation describing why the set of units
+could not be ordered.
 
 @item 
-@emph{One or more orders exist, all incorrect}
+Circularity
 
-One or more acceptable elaboration orders exist, and all of them
-generate an elaboration order problem. In this case, the binder
-can build an executable program, but @code{Program_Error} will be raised
-when the program is run.
+This section enumerates the units comprising the deadlocked set, along with
+their interdependencies.
 
 @item 
-@emph{Several orders exist, some right, some incorrect}
+Suggestions
 
-One or more acceptable elaboration orders exists, and some of them
-work, and some do not. The programmer has not controlled
-the order of elaboration, so the binder may or may not pick one of
-the correct orders, and the program may or may not raise an
-exception when it is run. This is the worst case, because it means
-that the program may fail when moved to another compiler, or even
-another version of the same compiler.
+This section enumerates various tactics for eliminating the circularity.
+@end itemize
 
-@item 
-@emph{One or more orders exists, all correct}
+@node Resolving Elaboration Circularities,Elaboration-related Compiler Switches,Elaboration Circularities,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat id11}@anchor{228}@anchor{gnat_ugn/elaboration_order_handling_in_gnat resolving-elaboration-circularities}@anchor{229}
+@section Resolving Elaboration Circularities
 
-One ore more acceptable elaboration orders exist, and all of them
-work. In this case the program runs successfully. This state of
-affairs can be guaranteed by following the rule we gave above, but
-may be true even if the rule is not followed.
-@end itemize
 
-Note that one additional advantage of following our rules on the use
-of @code{Elaborate} and @code{Elaborate_All}
-is that the program continues to stay in the ideal (all orders OK) state
-even if maintenance
-changes some bodies of some units. Conversely, if a program that does
-not follow this rule happens to be safe at some point, this state of affairs
-may deteriorate silently as a result of maintenance changes.
+The most desirable option from the point of view of long-term maintenance is to
+rearrange the program so that the elaboration problems are avoided. One useful
+technique is to place the elaboration code into separate child packages.
+Another is to move some of the initialization code to explicitly invoked
+subprograms, where the program controls the order of initialization explicitly.
+Although this is the most desirable option, it may be impractical and involve
+too much modification, especially in the case of complex legacy code.
 
-You may have noticed that the above discussion did not mention
-the use of @code{Elaborate_Body}. This was a deliberate omission. If you
-@emph{with} an @code{Elaborate_Body} unit, it still may be the case that
-code in the body makes calls to some other unit, so it is still necessary
-to use @code{Elaborate_All} on such units.
+When faced with an elaboration circularity, the programmer should also consider
+the tactics given in the suggestions section of the circularity diagnostic.
+Depending on the units involved in the circularity, their @emph{with} clauses,
+purity, preelaborability, presence of elaboration-control pragmas and
+invocations at elaboration time, the binder may suggest one or more of the
+following tactics to eliminate the circularity:
 
-@node Controlling Elaboration in GNAT - Internal Calls,Controlling Elaboration in GNAT - External Calls,Controlling the Elaboration Order,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat id5}@anchor{234}@anchor{gnat_ugn/elaboration_order_handling_in_gnat controlling-elaboration-in-gnat-internal-calls}@anchor{235}
-@section Controlling Elaboration in GNAT - Internal Calls
 
+@itemize *
 
-In the case of internal calls, i.e., calls within a single package, the
-programmer has full control over the order of elaboration, and it is up
-to the programmer to elaborate declarations in an appropriate order. For
-example writing:
+@item 
+Pragma Elaborate elimination
 
 @example
-function One return Float;
+remove pragma Elaborate for unit "..." in unit "..."
+@end example
 
-Q : Float := One;
+This tactic is suggested when the binder has determined that pragma
+@code{Elaborate}:
 
-function One return Float is
-begin
-     return 1.0;
-end One;
-@end example
 
-will obviously raise @code{Program_Error} at run time, because function
-One will be called before its body is elaborated. In this case GNAT will
-generate a warning that the call will raise @code{Program_Error}:
+@itemize -
 
-@example
- 1. procedure y is
- 2.    function One return Float;
- 3.
- 4.    Q : Float := One;
-                    |
-    >>> warning: cannot call "One" before body is elaborated
-    >>> warning: Program_Error will be raised at run time
+@item 
+Prevents a set of units from being elaborated.
 
- 5.
- 6.    function One return Float is
- 7.    begin
- 8.         return 1.0;
- 9.    end One;
-10.
-11. begin
-12.    null;
-13. end;
-@end example
+@item 
+The removal of the pragma will not eliminate the semantic effects of the
+pragma. In other words, the argument of the pragma will still be elaborated
+prior to the unit containing the pragma.
+
+@item 
+The removal of the pragma will enable the successful ordering of the units.
+@end itemize
 
-Note that in this particular case, it is likely that the call is safe, because
-the function @code{One} does not access any global variables.
-Nevertheless in Ada, we do not want the validity of the check to depend on
-the contents of the body (think about the separate compilation case), so this
-is still wrong, as we discussed in the previous sections.
+The programmer should remove the pragma as advised, and rebuild the program.
 
-The error is easily corrected by rearranging the declarations so that the
-body of @code{One} appears before the declaration containing the call
-(note that in Ada 95 as well as later versions of the Ada standard,
-declarations can appear in any order, so there is no restriction that
-would prevent this reordering, and if we write:
+@item 
+Pragma Elaborate_All elimination
 
 @example
-function One return Float;
+remove pragma Elaborate_All for unit "..." in unit "..."
+@end example
 
-function One return Float is
-begin
-     return 1.0;
-end One;
+This tactic is suggested when the binder has determined that pragma
+@code{Elaborate_All}:
 
-Q : Float := One;
-@end example
 
-then all is well, no warning is generated, and no
-@code{Program_Error} exception
-will be raised.
-Things are more complicated when a chain of subprograms is executed:
+@itemize -
 
-@example
-function A return Integer;
-function B return Integer;
-function C return Integer;
+@item 
+Prevents a set of units from being elaborated.
 
-function B return Integer is begin return A; end;
-function C return Integer is begin return B; end;
+@item 
+The removal of the pragma will not eliminate the semantic effects of the
+pragma. In other words, the argument of the pragma along with its @emph{with}
+closure will still be elaborated prior to the unit containing the pragma.
 
-X : Integer := C;
+@item 
+The removal of the pragma will enable the successful ordering of the units.
+@end itemize
 
-function A return Integer is begin return 1; end;
-@end example
+The programmer should remove the pragma as advised, and rebuild the program.
 
-Now the call to @code{C}
-at elaboration time in the declaration of @code{X} is correct, because
-the body of @code{C} is already elaborated,
-and the call to @code{B} within the body of
-@code{C} is correct, but the call
-to @code{A} within the body of @code{B} is incorrect, because the body
-of @code{A} has not been elaborated, so @code{Program_Error}
-will be raised on the call to @code{A}.
-In this case GNAT will generate a
-warning that @code{Program_Error} may be
-raised at the point of the call. Let's look at the warning:
+@item 
+Pragma Elaborate_All downgrade
 
 @example
- 1. procedure x is
- 2.    function A return Integer;
- 3.    function B return Integer;
- 4.    function C return Integer;
- 5.
- 6.    function B return Integer is begin return A; end;
-                                                    |
-    >>> warning: call to "A" before body is elaborated may
-                 raise Program_Error
-    >>> warning: "B" called at line 7
-    >>> warning: "C" called at line 9
-
- 7.    function C return Integer is begin return B; end;
- 8.
- 9.    X : Integer := C;
-10.
-11.    function A return Integer is begin return 1; end;
-12.
-13. begin
-14.    null;
-15. end;
-@end example
-
-Note that the message here says 'may raise', instead of the direct case,
-where the message says 'will be raised'. That's because whether
-@code{A} is
-actually called depends in general on run-time flow of control.
-For example, if the body of @code{B} said
-
-@example
-function B return Integer is
-begin
-   if some-condition-depending-on-input-data then
-      return A;
-   else
-      return 1;
-   end if;
-end B;
+change pragma Elaborate_All for unit "..." to Elaborate in unit "..."
 @end example
 
-then we could not know until run time whether the incorrect call to A would
-actually occur, so @code{Program_Error} might
-or might not be raised. It is possible for a compiler to
-do a better job of analyzing bodies, to
-determine whether or not @code{Program_Error}
-might be raised, but it certainly
-couldn't do a perfect job (that would require solving the halting problem
-and is provably impossible), and because this is a warning anyway, it does
-not seem worth the effort to do the analysis. Cases in which it
-would be relevant are rare.
+This tactic is always suggested with the pragma @code{Elaborate_All} elimination
+tactic. It offers a different alernative of guaranteeing that the argument of
+the pragma will still be elaborated prior to the unit containing the pragma.
 
-In practice, warnings of either of the forms given
-above will usually correspond to
-real errors, and should be examined carefully and eliminated.
-In the rare case where a warning is bogus, it can be suppressed by any of
-the following methods:
+The programmer should update the pragma as advised, and rebuild the program.
 
+@item 
+Pragma Elaborate_Body elimination
 
-@itemize *
+@example
+remove pragma Elaborate_Body in unit "..."
+@end example
 
-@item 
-Compile with the @code{-gnatws} switch set
+This tactic is suggested when the binder has determined that pragma
+@code{Elaborate_Body}:
+
+
+@itemize -
 
 @item 
-Suppress @code{Elaboration_Check} for the called subprogram
+Prevents a set of units from being elaborated.
 
 @item 
-Use pragma @code{Warnings_Off} to turn warnings off for the call
+The removal of the pragma will enable the successful ordering of the units.
 @end itemize
 
-For the internal elaboration check case,
-GNAT by default generates the
-necessary run-time checks to ensure
-that @code{Program_Error} is raised if any
-call fails an elaboration check. Of course this can only happen if a
-warning has been issued as described above. The use of pragma
-@code{Suppress (Elaboration_Check)} may (but is not guaranteed to) suppress
-some of these checks, meaning that it may be possible (but is not
-guaranteed) for a program to be able to call a subprogram whose body
-is not yet elaborated, without raising a @code{Program_Error} exception.
-
-@node Controlling Elaboration in GNAT - External Calls,Default Behavior in GNAT - Ensuring Safety,Controlling Elaboration in GNAT - Internal Calls,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat id6}@anchor{236}@anchor{gnat_ugn/elaboration_order_handling_in_gnat controlling-elaboration-in-gnat-external-calls}@anchor{237}
-@section Controlling Elaboration in GNAT - External Calls
+Note that the binder cannot determine whether the pragma is required for
+other purposes, such as guaranteeing the initialization of a variable
+declared in the spec by elaboration code in the body.
 
+The programmer should remove the pragma as advised, and rebuild the program.
 
-The previous section discussed the case in which the execution of a
-particular thread of elaboration code occurred entirely within a
-single unit. This is the easy case to handle, because a programmer
-has direct and total control over the order of elaboration, and
-furthermore, checks need only be generated in cases which are rare
-and which the compiler can easily detect.
-The situation is more complex when separate compilation is taken into account.
-Consider the following:
+@item 
+Use of pragma Restrictions
 
 @example
-package Math is
-   function Sqrt (Arg : Float) return Float;
-end Math;
+use pragma Restrictions (No_Entry_Calls_In_Elaboration_Code)
+@end example
 
-package body Math is
-   function Sqrt (Arg : Float) return Float is
-   begin
-         ...
-   end Sqrt;
-end Math;
+This tactic is suggested when the binder has determined that a task
+activation at elaboration time:
 
-with Math;
-package Stuff is
-   X : Float := Math.Sqrt (0.5);
-end Stuff;
 
-with Stuff;
-procedure Main is
-begin
-   ...
-end Main;
-@end example
+@itemize -
 
-where @code{Main} is the main program. When this program is executed, the
-elaboration code must first be executed, and one of the jobs of the
-binder is to determine the order in which the units of a program are
-to be elaborated. In this case we have four units: the spec and body
-of @code{Math},
-the spec of @code{Stuff} and the body of @code{Main}).
-In what order should the four separate sections of elaboration code
-be executed?
+@item 
+Prevents a set of units from being elaborated.
+@end itemize
 
-There are some restrictions in the order of elaboration that the binder
-can choose. In particular, if unit U has a @emph{with}
-for a package @code{X}, then you
-are assured that the spec of @code{X}
-is elaborated before U , but you are
-not assured that the body of @code{X}
-is elaborated before U.
-This means that in the above case, the binder is allowed to choose the
-order:
+Note that the binder cannot determine with certainty whether the task will
+block at elaboration time.
 
-@example
-spec of Math
-spec of Stuff
-body of Math
-body of Main
-@end example
+The programmer should create a configuration file, place the pragma within,
+update the general compilation arguments, and rebuild the program.
 
-but that's not good, because now the call to @code{Math.Sqrt}
-that happens during
-the elaboration of the @code{Stuff}
-spec happens before the body of @code{Math.Sqrt} is
-elaborated, and hence causes @code{Program_Error} exception to be raised.
-At first glance, one might say that the binder is misbehaving, because
-obviously you want to elaborate the body of something you @emph{with} first, but
-that is not a general rule that can be followed in all cases. Consider
-
-@example
-package X is ...
-
-package Y is ...
-
-with X;
-package body Y is ...
-
-with Y;
-package body X is ...
-@end example
-
-This is a common arrangement, and, apart from the order of elaboration
-problems that might arise in connection with elaboration code, this works fine.
-A rule that says that you must first elaborate the body of anything you
-@emph{with} cannot work in this case:
-the body of @code{X} @emph{with}s @code{Y},
-which means you would have to
-elaborate the body of @code{Y} first, but that @emph{with}s @code{X},
-which means
-you have to elaborate the body of @code{X} first, but ... and we have a
-loop that cannot be broken.
-
-It is true that the binder can in many cases guess an order of elaboration
-that is unlikely to cause a @code{Program_Error}
-exception to be raised, and it tries to do so (in the
-above example of @code{Math/Stuff/Spec}, the GNAT binder will
-by default
-elaborate the body of @code{Math} right after its spec, so all will be well).
-
-However, a program that blindly relies on the binder to be helpful can
-get into trouble, as we discussed in the previous sections, so GNAT
-provides a number of facilities for assisting the programmer in
-developing programs that are robust with respect to elaboration order.
-
-@node Default Behavior in GNAT - Ensuring Safety,Treatment of Pragma Elaborate,Controlling Elaboration in GNAT - External Calls,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat id7}@anchor{238}@anchor{gnat_ugn/elaboration_order_handling_in_gnat default-behavior-in-gnat-ensuring-safety}@anchor{239}
-@section Default Behavior in GNAT - Ensuring Safety
-
-
-The default behavior in GNAT ensures elaboration safety. In its
-default mode GNAT implements the
-rule we previously described as the right approach. Let's restate it:
-
-@emph{If a unit has elaboration code that can directly or indirectly make a
-call to a subprogram in a |withed| unit, or instantiate a generic
-package in a |withed| unit, then if the |withed| unit
-does not have pragma `@w{`}Pure`@w{`} or `@w{`}Preelaborate`@w{`}, then the client should have an
-`@w{`}Elaborate_All`@w{`} pragma for the |withed| unit.}
-
-@emph{In the case of instantiating a generic subprogram, it is always
-sufficient to have only an `@w{`}Elaborate`@w{`} pragma for the
-|withed| unit.}
-
-By following this rule a client is assured that calls and instantiations
-can be made without risk of an exception.
-
-In this mode GNAT traces all calls that are potentially made from
-elaboration code, and puts in any missing implicit @code{Elaborate}
-and @code{Elaborate_All} pragmas.
-The advantage of this approach is that no elaboration problems
-are possible if the binder can find an elaboration order that is
-consistent with these implicit @code{Elaborate} and
-@code{Elaborate_All} pragmas. The
-disadvantage of this approach is that no such order may exist.
-
-If the binder does not generate any diagnostics, then it means that it has
-found an elaboration order that is guaranteed to be safe. However, the binder
-may still be relying on implicitly generated @code{Elaborate} and
-@code{Elaborate_All} pragmas so portability to other compilers than GNAT is not
-guaranteed.
-
-If it is important to guarantee portability, then the compilations should
-use the @code{-gnatel}
-(info messages for elaboration pragmas) switch. This will cause info messages
-to be generated indicating the missing @code{Elaborate} and
-@code{Elaborate_All} pragmas.
-Consider the following source program:
+@item 
+Use of dynamic elaboration model
 
 @example
-with k;
-package j is
-  m : integer := k.r;
-end;
+use the dynamic elaboration model (compiler switch -gnatE)
 @end example
 
-where it is clear that there
-should be a pragma @code{Elaborate_All}
-for unit @code{k}. An implicit pragma will be generated, and it is
-likely that the binder will be able to honor it. However, if you want
-to port this program to some other Ada compiler than GNAT.
-it is safer to include the pragma explicitly in the source. If this
-unit is compiled with the @code{-gnatel}
-switch, then the compiler outputs an information message:
-
-@example
-1. with k;
-2. package j is
-3.   m : integer := k.r;
-                     |
-   >>> info: call to "r" may raise Program_Error
-   >>> info: missing pragma Elaborate_All for "k"
-
-4. end;
-@end example
-
-and these messages can be used as a guide for supplying manually
-the missing pragmas. It is usually a bad idea to use this
-option during development. That's because it will tell you when
-you need to put in a pragma, but cannot tell you when it is time
-to take it out. So the use of pragma @code{Elaborate_All} may lead to
-unnecessary dependencies and even false circularities.
-
-This default mode is more restrictive than the Ada Reference
-Manual, and it is possible to construct programs which will compile
-using the dynamic model described there, but will run into a
-circularity using the safer static model we have described.
-
-Of course any Ada compiler must be able to operate in a mode
-consistent with the requirements of the Ada Reference Manual,
-and in particular must have the capability of implementing the
-standard dynamic model of elaboration with run-time checks.
-
-In GNAT, this standard mode can be achieved either by the use of
-the @code{-gnatE} switch on the compiler (@code{gcc} or
-@code{gnatmake}) command, or by the use of the configuration pragma:
-
-@example
-pragma Elaboration_Checks (DYNAMIC);
-@end example
-
-Either approach will cause the unit affected to be compiled using the
-standard dynamic run-time elaboration checks described in the Ada
-Reference Manual. The static model is generally preferable, since it
-is clearly safer to rely on compile and link time checks rather than
-run-time checks. However, in the case of legacy code, it may be
-difficult to meet the requirements of the static model. This
-issue is further discussed in
-@ref{23a,,What to Do If the Default Elaboration Behavior Fails}.
-
-Note that the static model provides a strict subset of the allowed
-behavior and programs of the Ada Reference Manual, so if you do
-adhere to the static model and no circularities exist,
-then you are assured that your program will
-work using the dynamic model, providing that you remove any
-pragma Elaborate statements from the source.
-
-@node Treatment of Pragma Elaborate,Elaboration Issues for Library Tasks,Default Behavior in GNAT - Ensuring Safety,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat treatment-of-pragma-elaborate}@anchor{23b}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id8}@anchor{23c}
-@section Treatment of Pragma Elaborate
-
-
-@geindex Pragma Elaborate
-
-The use of @code{pragma Elaborate}
-should generally be avoided in Ada 95 and Ada 2005 programs,
-since there is no guarantee that transitive calls
-will be properly handled. Indeed at one point, this pragma was placed
-in Annex J (Obsolescent Features), on the grounds that it is never useful.
-
-Now that's a bit restrictive. In practice, the case in which
-@code{pragma Elaborate} is useful is when the caller knows that there
-are no transitive calls, or that the called unit contains all necessary
-transitive @code{pragma Elaborate} statements, and legacy code often
-contains such uses.
-
-Strictly speaking the static mode in GNAT should ignore such pragmas,
-since there is no assurance at compile time that the necessary safety
-conditions are met. In practice, this would cause GNAT to be incompatible
-with correctly written Ada 83 code that had all necessary
-@code{pragma Elaborate} statements in place. Consequently, we made the
-decision that GNAT in its default mode will believe that if it encounters
-a @code{pragma Elaborate} then the programmer knows what they are doing,
-and it will trust that no elaboration errors can occur.
-
-The result of this decision is two-fold. First to be safe using the
-static mode, you should remove all @code{pragma Elaborate} statements.
-Second, when fixing circularities in existing code, you can selectively
-use @code{pragma Elaborate} statements to convince the static mode of
-GNAT that it need not generate an implicit @code{pragma Elaborate_All}
-statement.
-
-When using the static mode with @code{-gnatwl}, any use of
-@code{pragma Elaborate} will generate a warning about possible
-problems.
+This tactic is suggested when the binder has determined that an invocation at
+elaboration time:
 
-@node Elaboration Issues for Library Tasks,Mixing Elaboration Models,Treatment of Pragma Elaborate,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-issues-for-library-tasks}@anchor{23d}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id9}@anchor{23e}
-@section Elaboration Issues for Library Tasks
-
-
-@geindex Library tasks
-@geindex elaboration issues
-
-@geindex Elaboration of library tasks
-
-In this section we examine special elaboration issues that arise for
-programs that declare library level tasks.
-
-Generally the model of execution of an Ada program is that all units are
-elaborated, and then execution of the program starts. However, the
-declaration of library tasks definitely does not fit this model. The
-reason for this is that library tasks start as soon as they are declared
-(more precisely, as soon as the statement part of the enclosing package
-body is reached), that is to say before elaboration
-of the program is complete. This means that if such a task calls a
-subprogram, or an entry in another task, the callee may or may not be
-elaborated yet, and in the standard
-Reference Manual model of dynamic elaboration checks, you can even
-get timing dependent Program_Error exceptions, since there can be
-a race between the elaboration code and the task code.
-
-The static model of elaboration in GNAT seeks to avoid all such
-dynamic behavior, by being conservative, and the conservative
-approach in this particular case is to assume that all the code
-in a task body is potentially executed at elaboration time if
-a task is declared at the library level.
-
-This can definitely result in unexpected circularities. Consider
-the following example
-
-@example
-package Decls is
-  task Lib_Task is
-     entry Start;
-  end Lib_Task;
-
-  type My_Int is new Integer;
-
-  function Ident (M : My_Int) return My_Int;
-end Decls;
-
-with Utils;
-package body Decls is
-  task body Lib_Task is
-  begin
-     accept Start;
-     Utils.Put_Val (2);
-  end Lib_Task;
-
-  function Ident (M : My_Int) return My_Int is
-  begin
-     return M;
-  end Ident;
-end Decls;
-
-with Decls;
-package Utils is
-  procedure Put_Val (Arg : Decls.My_Int);
-end Utils;
-
-with Text_IO;
-package body Utils is
-  procedure Put_Val (Arg : Decls.My_Int) is
-  begin
-     Text_IO.Put_Line (Decls.My_Int'Image (Decls.Ident (Arg)));
-  end Put_Val;
-end Utils;
-
-with Decls;
-procedure Main is
-begin
-   Decls.Lib_Task.Start;
-end;
-@end example
 
-If the above example is compiled in the default static elaboration
-mode, then a circularity occurs. The circularity comes from the call
-@code{Utils.Put_Val} in the task body of @code{Decls.Lib_Task}. Since
-this call occurs in elaboration code, we need an implicit pragma
-@code{Elaborate_All} for @code{Utils}. This means that not only must
-the spec and body of @code{Utils} be elaborated before the body
-of @code{Decls}, but also the spec and body of any unit that is
-@emph{with}ed by the body of @code{Utils} must also be elaborated before
-the body of @code{Decls}. This is the transitive implication of
-pragma @code{Elaborate_All} and it makes sense, because in general
-the body of @code{Put_Val} might have a call to something in a
-@emph{with}ed unit.
+@itemize -
 
-In this case, the body of Utils (actually its spec) @emph{with}s
-@code{Decls}. Unfortunately this means that the body of @code{Decls}
-must be elaborated before itself, in case there is a call from the
-body of @code{Utils}.
+@item 
+Prevents a set of units from being elaborated.
 
-Here is the exact chain of events we are worrying about:
+@item 
+The use of the dynamic model will enable the successful ordering of the
+units.
+@end itemize
 
+The programmer has two options:
 
-@itemize *
 
-@item 
-In the body of @code{Decls} a call is made from within the body of a library
-task to a subprogram in the package @code{Utils}. Since this call may
-occur at elaboration time (given that the task is activated at elaboration
-time), we have to assume the worst, i.e., that the
-call does happen at elaboration time.
+@itemize -
 
 @item 
-This means that the body and spec of @code{Util} must be elaborated before
-the body of @code{Decls} so that this call does not cause an access before
-elaboration.
+Determine the units involved in the invocation using the detailed
+invocation information, and add compiler switch @code{-gnatE} to the
+compilation arguments of selected files only. This approach will yield
+safer elaboration orders compared to the other option because it will
+minimize the opportunities presented to the dynamic model for ignoring
+invocations.
 
 @item 
-Within the body of @code{Util}, specifically within the body of
-@code{Util.Put_Val} there may be calls to any unit @emph{with}ed
-by this package.
+Add compiler switch @code{-gnatE} to the general compilation arguments.
+@end itemize
 
 @item 
-One such @emph{with}ed package is package @code{Decls}, so there
-might be a call to a subprogram in @code{Decls} in @code{Put_Val}.
-In fact there is such a call in this example, but we would have to
-assume that there was such a call even if it were not there, since
-we are not supposed to write the body of @code{Decls} knowing what
-is in the body of @code{Utils}; certainly in the case of the
-static elaboration model, the compiler does not know what is in
-other bodies and must assume the worst.
+Use of detailed invocation information
+
+@example
+use detailed invocation information (compiler switch -gnatd_F)
+@end example
+
+This tactic is always suggested with the use of the dynamic model tactic. It
+causes the circularity section of the circularity diagnostic to describe the
+flow of elaboration code from a unit to a unit, enumerating all such paths in
+the process.
+
+The programmer should analyze this information to determine which units
+should be compiled with the dynamic model.
 
 @item 
-This means that the spec and body of @code{Decls} must also be
-elaborated before we elaborate the unit containing the call, but
-that unit is @code{Decls}! This means that the body of @code{Decls}
-must be elaborated before itself, and that's a circularity.
-@end itemize
+Forced-dependency elimination
 
-Indeed, if you add an explicit pragma @code{Elaborate_All} for @code{Utils} in
-the body of @code{Decls} you will get a true Ada Reference Manual
-circularity that makes the program illegal.
+@example
+remove the dependency of unit "..." on unit "..." from the argument of switch -f
+@end example
 
-In practice, we have found that problems with the static model of
-elaboration in existing code often arise from library tasks, so
-we must address this particular situation.
+This tactic is suggested when the binder has determined that a dependency
+present in the forced-elaboration-order file indicated by binder switch
+@code{-f}:
 
-Note that if we compile and run the program above, using the dynamic model of
-elaboration (that is to say use the @code{-gnatE} switch),
-then it compiles, binds,
-links, and runs, printing the expected result of 2. Therefore in some sense
-the circularity here is only apparent, and we need to capture
-the properties of this program that  distinguish it from other library-level
-tasks that have real elaboration problems.
 
-We have four possible answers to this question:
+@itemize -
 
+@item 
+Prevents a set of units from being elaborated.
 
-@itemize *
+@item 
+The removal of the dependency will enable the successful ordering of the
+units.
+@end itemize
+
+The programmer should edit the forced-elaboration-order file, remove the
+dependency, and rebind the program.
 
 @item 
-Use the dynamic model of elaboration.
-
-If we use the @code{-gnatE} switch, then as noted above, the program works.
-Why is this? If we examine the task body, it is apparent that the task cannot
-proceed past the
-@code{accept} statement until after elaboration has been completed, because
-the corresponding entry call comes from the main program, not earlier.
-This is why the dynamic model works here. But that's really giving
-up on a precise analysis, and we prefer to take this approach only if we cannot
-solve the
-problem in any other manner. So let us examine two ways to reorganize
-the program to avoid the potential elaboration problem.
-
-@item 
-Split library tasks into separate packages.
-
-Write separate packages, so that library tasks are isolated from
-other declarations as much as possible. Let us look at a variation on
-the above program.
-
-@example
-package Decls1 is
-  task Lib_Task is
-     entry Start;
-  end Lib_Task;
-end Decls1;
-
-with Utils;
-package body Decls1 is
-  task body Lib_Task is
-  begin
-     accept Start;
-     Utils.Put_Val (2);
-  end Lib_Task;
-end Decls1;
-
-package Decls2 is
-  type My_Int is new Integer;
-  function Ident (M : My_Int) return My_Int;
-end Decls2;
-
-with Utils;
-package body Decls2 is
-  function Ident (M : My_Int) return My_Int is
-  begin
-     return M;
-  end Ident;
-end Decls2;
-
-with Decls2;
-package Utils is
-  procedure Put_Val (Arg : Decls2.My_Int);
-end Utils;
-
-with Text_IO;
-package body Utils is
-  procedure Put_Val (Arg : Decls2.My_Int) is
-  begin
-     Text_IO.Put_Line (Decls2.My_Int'Image (Decls2.Ident (Arg)));
-  end Put_Val;
-end Utils;
-
-with Decls1;
-procedure Main is
-begin
-   Decls1.Lib_Task.Start;
-end;
+All forced-dependency elimination
+
+@example
+remove switch -f
 @end example
 
-All we have done is to split @code{Decls} into two packages, one
-containing the library task, and one containing everything else. Now
-there is no cycle, and the program compiles, binds, links and executes
-using the default static model of elaboration.
+This tactic is suggested in case editing the forced-elaboration-order file is
+not an option.
 
-@item 
-Declare separate task types.
+The programmer should remove binder switch @code{-f} from the binder
+arguments, and rebind.
 
-A significant part of the problem arises because of the use of the
-single task declaration form. This means that the elaboration of
-the task type, and the elaboration of the task itself (i.e., the
-creation of the task) happen at the same time. A good rule
-of style in Ada is to always create explicit task types. By
-following the additional step of placing task objects in separate
-packages from the task type declaration, many elaboration problems
-are avoided. Here is another modified example of the example program:
+@item 
+Multiple-circularities diagnostic
 
 @example
-package Decls is
-  task type Lib_Task_Type is
-     entry Start;
-  end Lib_Task_Type;
+diagnose all circularities (binder switch -d_C)
+@end example
 
-  type My_Int is new Integer;
+By default, the binder will diagnose only the highest-precedence circularity.
+If the program contains multiple circularities, the binder will suggest the
+use of binder switch @code{-d_C} in order to obtain the diagnostics of all
+circularities.
 
-  function Ident (M : My_Int) return My_Int;
-end Decls;
+The programmer should add binder switch @code{-d_C} to the binder
+arguments, and rebind.
+@end itemize
 
-with Utils;
-package body Decls is
-  task body Lib_Task_Type is
-  begin
-     accept Start;
-     Utils.Put_Val (2);
-  end Lib_Task_Type;
+If none of the tactics suggested by the binder eliminate the elaboration
+circularity, the programmer should consider using one of the legacy elaboration
+models, in the following order:
 
-  function Ident (M : My_Int) return My_Int is
-  begin
-     return M;
-  end Ident;
-end Decls;
 
-with Decls;
-package Utils is
-  procedure Put_Val (Arg : Decls.My_Int);
-end Utils;
+@itemize *
 
-with Text_IO;
-package body Utils is
-  procedure Put_Val (Arg : Decls.My_Int) is
-  begin
-     Text_IO.Put_Line (Decls.My_Int'Image (Decls.Ident (Arg)));
-  end Put_Val;
-end Utils;
+@item 
+Use the pre-20.x legacy elaboration-order model, with binder switch
+@code{-H}.
 
-with Decls;
-package Declst is
-   Lib_Task : Decls.Lib_Task_Type;
-end Declst;
+@item 
+Use both pre-18.x and pre-20.x legacy elaboration models, with compiler
+switch @code{-gnatH} and binder switch @code{-H}.
 
-with Declst;
-procedure Main is
-begin
-   Declst.Lib_Task.Start;
-end;
-@end example
+@item 
+Use the relaxed static-elaboration model, with compiler switches
+@code{-gnatH} @code{-gnatJ} and binder switch @code{-H}.
 
-What we have done here is to replace the @code{task} declaration in
-package @code{Decls} with a @code{task type} declaration. Then we
-introduce a separate package @code{Declst} to contain the actual
-task object. This separates the elaboration issues for
-the @code{task type}
-declaration, which causes no trouble, from the elaboration issues
-of the task object, which is also unproblematic, since it is now independent
-of the elaboration of  @code{Utils}.
-This separation of concerns also corresponds to
-a generally sound engineering principle of separating declarations
-from instances. This version of the program also compiles, binds, links,
-and executes, generating the expected output.
+@item 
+Use the relaxed dynamic-elaboration model, with compiler switches
+@code{-gnatH} @code{-gnatJ} @code{-gnatE} and binder switch
+@code{-H}.
 @end itemize
 
-@geindex No_Entry_Calls_In_Elaboration_Code restriction
+@node Elaboration-related Compiler Switches,Summary of Procedures for Elaboration Control,Resolving Elaboration Circularities,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat id12}@anchor{22a}@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-related-compiler-switches}@anchor{22b}
+@section Elaboration-related Compiler Switches
 
 
-@itemize *
+GNAT has several switches that affect the elaboration model and consequently
+the elaboration order chosen by the binder.
 
-@item 
-Use No_Entry_Calls_In_Elaboration_Code restriction.
+@geindex -gnatE (gnat)
 
-The previous two approaches described how a program can be restructured
-to avoid the special problems caused by library task bodies. in practice,
-however, such restructuring may be difficult to apply to existing legacy code,
-so we must consider solutions that do not require massive rewriting.
 
-Let us consider more carefully why our original sample program works
-under the dynamic model of elaboration. The reason is that the code
-in the task body blocks immediately on the @code{accept}
-statement. Now of course there is nothing to prohibit elaboration
-code from making entry calls (for example from another library level task),
-so we cannot tell in isolation that
-the task will not execute the accept statement  during elaboration.
+@table @asis
 
-However, in practice it is very unusual to see elaboration code
-make any entry calls, and the pattern of tasks starting
-at elaboration time and then immediately blocking on @code{accept} or
-@code{select} statements is very common. What this means is that
-the compiler is being too pessimistic when it analyzes the
-whole package body as though it might be executed at elaboration
-time.
+@item @code{-gnatE}
 
-If we know that the elaboration code contains no entry calls, (a very safe
-assumption most of the time, that could almost be made the default
-behavior), then we can compile all units of the program under control
-of the following configuration pragma:
+Dynamic elaboration checking mode enabled
 
-@example
-pragma Restrictions (No_Entry_Calls_In_Elaboration_Code);
-@end example
+When this switch is in effect, GNAT activates the dynamic model.
+@end table
 
-This pragma can be placed in the @code{gnat.adc} file in the usual
-manner. If we take our original unmodified program and compile it
-in the presence of a @code{gnat.adc} containing the above pragma,
-then once again, we can compile, bind, link, and execute, obtaining
-the expected result. In the presence of this pragma, the compiler does
-not trace calls in a task body, that appear after the first @code{accept}
-or @code{select} statement, and therefore does not report a potential
-circularity in the original program.
+@geindex -gnatel (gnat)
 
-The compiler will check to the extent it can that the above
-restriction is not violated, but it is not always possible to do a
-complete check at compile time, so it is important to use this
-pragma only if the stated restriction is in fact met, that is to say
-no task receives an entry call before elaboration of all units is completed.
-@end itemize
 
-@node Mixing Elaboration Models,What to Do If the Default Elaboration Behavior Fails,Elaboration Issues for Library Tasks,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat id10}@anchor{23f}@anchor{gnat_ugn/elaboration_order_handling_in_gnat mixing-elaboration-models}@anchor{240}
-@section Mixing Elaboration Models
+@table @asis
 
+@item @code{-gnatel}
 
-So far, we have assumed that the entire program is either compiled
-using the dynamic model or static model, ensuring consistency. It
-is possible to mix the two models, but rules have to be followed
-if this mixing is done to ensure that elaboration checks are not
-omitted.
+Turn on info messages on generated Elaborate[_All] pragmas
 
-The basic rule is that
-@strong{a unit compiled with the static model cannot
-be |withed| by a unit compiled with the dynamic model}.
-The reason for this is that in the static model, a unit assumes that
-its clients guarantee to use (the equivalent of) pragma
-@code{Elaborate_All} so that no elaboration checks are required
-in inner subprograms, and this assumption is violated if the
-client is compiled with dynamic checks.
+This switch is only applicable to the pre-20.x legacy elaboration models.
+The post-20.x elaboration model no longer relies on implicitly generated
+@code{Elaborate} and @code{Elaborate_All} pragmas to order units.
 
-The precise rule is as follows. A unit that is compiled with dynamic
-checks can only @emph{with} a unit that meets at least one of the
-following criteria:
+When this switch is in effect, GNAT will emit the following supplementary
+information depending on the elaboration model in effect.
 
 
-@itemize *
+@itemize -
 
 @item 
-The @emph{with}ed unit is itself compiled with dynamic elaboration
-checks (that is with the @code{-gnatE} switch.
+@emph{Dynamic model}
 
-@item 
-The @emph{with}ed unit is an internal GNAT implementation unit from
-the System, Interfaces, Ada, or GNAT hierarchies.
+GNAT will indicate missing @code{Elaborate} and @code{Elaborate_All} pragmas for
+all library-level scenarios within the partition.
 
 @item 
-The @emph{with}ed unit has pragma Preelaborate or pragma Pure.
+@emph{Static model}
+
+GNAT will indicate all scenarios invoked during elaboration. In addition,
+it will provide detailed traceback when an implicit @code{Elaborate} or
+@code{Elaborate_All} pragma is generated.
 
 @item 
-The @emph{with}ing unit (that is the client) has an explicit pragma
-@code{Elaborate_All} for the @emph{with}ed unit.
-@end itemize
+@emph{SPARK model}
 
-If this rule is violated, that is if a unit with dynamic elaboration
-checks @emph{with}s a unit that does not meet one of the above four
-criteria, then the binder (@code{gnatbind}) will issue a warning
-similar to that in the following example:
+GNAT will indicate how an elaboration requirement is met by the context of
+a unit. This diagnostic requires compiler switch @code{-gnatd.v}.
 
 @example
-warning: "x.ads" has dynamic elaboration checks and with's
-warning:   "y.ads" which has static elaboration checks
+1. with Server; pragma Elaborate_All (Server);
+2. package Client with SPARK_Mode is
+3.    Val : constant Integer := Server.Func;
+                                      |
+   >>> info: call to "Func" during elaboration in SPARK
+   >>> info: "Elaborate_All" requirement for unit "Server" met by pragma at line 1
+
+4. end Client;
 @end example
+@end itemize
+@end table
 
-These warnings indicate that the rule has been violated, and that as a result
-elaboration checks may be missed in the resulting executable file.
-This warning may be suppressed using the @code{-ws} binder switch
-in the usual manner.
+@geindex -gnatH (gnat)
 
-One useful application of this mixing rule is in the case of a subsystem
-which does not itself @emph{with} units from the remainder of the
-application. In this case, the entire subsystem can be compiled with
-dynamic checks to resolve a circularity in the subsystem, while
-allowing the main application that uses this subsystem to be compiled
-using the more reliable default static model.
 
-@node What to Do If the Default Elaboration Behavior Fails,Elaboration for Indirect Calls,Mixing Elaboration Models,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat id11}@anchor{241}@anchor{gnat_ugn/elaboration_order_handling_in_gnat what-to-do-if-the-default-elaboration-behavior-fails}@anchor{23a}
-@section What to Do If the Default Elaboration Behavior Fails
+@table @asis
 
+@item @code{-gnatH}
 
-If the binder cannot find an acceptable order, it outputs detailed
-diagnostics. For example:
+Legacy elaboration checking mode enabled
 
-@example
-error: elaboration circularity detected
-info:   "proc (body)" must be elaborated before "pack (body)"
-info:     reason: Elaborate_All probably needed in unit "pack (body)"
-info:     recompile "pack (body)" with -gnatel
-info:                             for full details
-info:       "proc (body)"
-info:         is needed by its spec:
-info:       "proc (spec)"
-info:         which is withed by:
-info:       "pack (body)"
-info:  "pack (body)" must be elaborated before "proc (body)"
-info:     reason: pragma Elaborate in unit "proc (body)"
-@end example
+When this switch is in effect, GNAT will utilize the pre-18.x elaboration
+model.
+@end table
 
-In this case we have a cycle that the binder cannot break. On the one
-hand, there is an explicit pragma Elaborate in @code{proc} for
-@code{pack}. This means that the body of @code{pack} must be elaborated
-before the body of @code{proc}. On the other hand, there is elaboration
-code in @code{pack} that calls a subprogram in @code{proc}. This means
-that for maximum safety, there should really be a pragma
-Elaborate_All in @code{pack} for @code{proc} which would require that
-the body of @code{proc} be elaborated before the body of
-@code{pack}. Clearly both requirements cannot be satisfied.
-Faced with a circularity of this kind, you have three different options.
+@geindex -gnatJ (gnat)
 
 
-@itemize *
+@table @asis
 
-@item 
-@emph{Fix the program}
+@item @code{-gnatJ}
 
-The most desirable option from the point of view of long-term maintenance
-is to rearrange the program so that the elaboration problems are avoided.
-One useful technique is to place the elaboration code into separate
-child packages. Another is to move some of the initialization code to
-explicitly called subprograms, where the program controls the order
-of initialization explicitly. Although this is the most desirable option,
-it may be impractical and involve too much modification, especially in
-the case of complex legacy code.
+Relaxed elaboration checking mode enabled
 
-@item 
-@emph{Perform dynamic checks}
+When this switch is in effect, GNAT will not process certain scenarios,
+resulting in a more permissive elaboration model. Note that this may
+eliminate some diagnostics and run-time checks.
+@end table
 
-If the compilations are done using the @code{-gnatE}
-(dynamic elaboration check) switch, then GNAT behaves in a quite different
-manner. Dynamic checks are generated for all calls that could possibly result
-in raising an exception. With this switch, the compiler does not generate
-implicit @code{Elaborate} or @code{Elaborate_All} pragmas. The behavior then is
-exactly as specified in the @cite{Ada Reference Manual}.
-The binder will generate
-an executable program that may or may not raise @code{Program_Error}, and then
-it is the programmer's job to ensure that it does not raise an exception. Note
-that it is important to compile all units with the switch, it cannot be used
-selectively.
+@geindex -gnatw.f (gnat)
 
-@item 
-@emph{Suppress checks}
 
-The drawback of dynamic checks is that they generate a
-significant overhead at run time, both in space and time. If you
-are absolutely sure that your program cannot raise any elaboration
-exceptions, and you still want to use the dynamic elaboration model,
-then you can use the configuration pragma
-@code{Suppress (Elaboration_Check)} to suppress all such checks. For
-example this pragma could be placed in the @code{gnat.adc} file.
+@table @asis
 
-@item 
-@emph{Suppress checks selectively}
+@item @code{-gnatw.f}
 
-When you know that certain calls or instantiations in elaboration code cannot
-possibly lead to an elaboration error, and the binder nevertheless complains
-about implicit @code{Elaborate} and @code{Elaborate_All} pragmas that lead to
-elaboration circularities, it is possible to remove those warnings locally and
-obtain a program that will bind. Clearly this can be unsafe, and it is the
-responsibility of the programmer to make sure that the resulting program has no
-elaboration anomalies. The pragma @code{Suppress (Elaboration_Check)} can be
-used with different granularity to suppress warnings and break elaboration
-circularities:
+Turn on warnings for suspicious Subp'Access
 
+When this switch is in effect, GNAT will treat @code{'Access} of an entry,
+operator, or subprogram as a potential call to the target and issue warnings:
 
-@itemize *
+@example
+ 1. package body Attribute_Call is
+ 2.    function Func return Integer;
+ 3.    type Func_Ptr is access function return Integer;
+ 4.
+ 5.    Ptr : constant Func_Ptr := Func'Access;
+                                      |
+    >>> warning: "Access" attribute of "Func" before body seen
+    >>> warning: possible Program_Error on later references
+    >>> warning:   body of unit "Attribute_Call" elaborated
+    >>> warning:   "Access" of "Func" taken at line 5
 
-@item 
-Place the pragma that names the called subprogram in the declarative part
-that contains the call.
+ 6.
+ 7.    function Func return Integer is
+ 8.    begin
+ 9.       ...
+10.    end Func;
+11. end Attribute_Call;
+@end example
 
-@item 
-Place the pragma in the declarative part, without naming an entity. This
-disables warnings on all calls in the corresponding  declarative region.
+In the example above, the elaboration of declaration @code{Ptr} is assigned
+@code{Func'Access} before the body of @code{Func} has been elaborated.
+@end table
 
-@item 
-Place the pragma in the package spec that declares the called subprogram,
-and name the subprogram. This disables warnings on all elaboration calls to
-that subprogram.
+@geindex -gnatwl (gnat)
 
-@item 
-Place the pragma in the package spec that declares the called subprogram,
-without naming any entity. This disables warnings on all elaboration calls to
-all subprograms declared in this spec.
 
-@item 
-Use Pragma Elaborate.
+@table @asis
 
-As previously described in section @ref{23b,,Treatment of Pragma Elaborate},
-GNAT in static mode assumes that a @code{pragma} Elaborate indicates correctly
-that no elaboration checks are required on calls to the designated unit.
-There may be cases in which the caller knows that no transitive calls
-can occur, so that a @code{pragma Elaborate} will be sufficient in a
-case where @code{pragma Elaborate_All} would cause a circularity.
-@end itemize
+@item @code{-gnatwl}
 
-These five cases are listed in order of decreasing safety, and therefore
-require increasing programmer care in their application. Consider the
-following program:
+Turn on warnings for elaboration problems
 
-@example
-package Pack1 is
-  function F1 return Integer;
-  X1 : Integer;
-end Pack1;
+When this switch is in effect, GNAT emits diagnostics in the form of warnings
+concerning various elaboration problems. The warnings are enabled by default.
+The switch is provided in case all warnings are suppressed, but elaboration
+warnings are still desired.
 
-package Pack2 is
-  function F2 return Integer;
-  function Pure (x : integer) return integer;
-  --  pragma Suppress (Elaboration_Check, On => Pure);  -- (3)
-  --  pragma Suppress (Elaboration_Check);              -- (4)
-end Pack2;
+@item @code{-gnatwL}
 
-with Pack2;
-package body Pack1 is
-  function F1 return Integer is
-  begin
-    return 100;
-  end F1;
-  Val : integer := Pack2.Pure (11);    --  Elab. call (1)
-begin
-  declare
-    --  pragma Suppress(Elaboration_Check, Pack2.F2);   -- (1)
-    --  pragma Suppress(Elaboration_Check);             -- (2)
-  begin
-    X1 := Pack2.F2 + 1;                --  Elab. call (2)
-  end;
-end Pack1;
+Turn off warnings for elaboration problems
 
-with Pack1;
-package body Pack2 is
-  function F2 return Integer is
-  begin
-     return Pack1.F1;
-  end F2;
-  function Pure (x : integer) return integer is
-  begin
-     return x ** 3 - 3 * x;
-  end;
-end Pack2;
+When this switch is in effect, GNAT no longer emits any diagnostics in the
+form of warnings. Selective suppression of elaboration problems is possible
+using @code{pragma Warnings (Off)}.
 
-with Pack1, Ada.Text_IO;
-procedure Proc3 is
-begin
-  Ada.Text_IO.Put_Line(Pack1.X1'Img); -- 101
-end Proc3;
-@end example
-
-In the absence of any pragmas, an attempt to bind this program produces
-the following diagnostics:
-
-@example
-error: elaboration circularity detected
-info:    "pack1 (body)" must be elaborated before "pack1 (body)"
-info:       reason: Elaborate_All probably needed in unit "pack1 (body)"
-info:       recompile "pack1 (body)" with -gnatel for full details
-info:          "pack1 (body)"
-info:             must be elaborated along with its spec:
-info:          "pack1 (spec)"
-info:             which is withed by:
-info:          "pack2 (body)"
-info:             which must be elaborated along with its spec:
-info:          "pack2 (spec)"
-info:             which is withed by:
-info:          "pack1 (body)"
-@end example
-
-The sources of the circularity are the two calls to @code{Pack2.Pure} and
-@code{Pack2.F2} in the body of @code{Pack1}. We can see that the call to
-F2 is safe, even though F2 calls F1, because the call appears after the
-elaboration of the body of F1. Therefore the pragma (1) is safe, and will
-remove the warning on the call. It is also possible to use pragma (2)
-because there are no other potentially unsafe calls in the block.
-
-The call to @code{Pure} is safe because this function does not depend on the
-state of @code{Pack2}. Therefore any call to this function is safe, and it
-is correct to place pragma (3) in the corresponding package spec.
-
-Finally, we could place pragma (4) in the spec of @code{Pack2} to disable
-warnings on all calls to functions declared therein. Note that this is not
-necessarily safe, and requires more detailed examination of the subprogram
-bodies involved. In particular, a call to @code{F2} requires that @code{F1}
-be already elaborated.
-@end itemize
+@example
+ 1. package body Selective_Suppression is
+ 2.    function ABE return Integer;
+ 3.
+ 4.    Val_1 : constant Integer := ABE;
+                                   |
+    >>> warning: cannot call "ABE" before body seen
+    >>> warning: Program_Error will be raised at run time
 
-It is hard to generalize on which of these four approaches should be
-taken. Obviously if it is possible to fix the program so that the default
-treatment works, this is preferable, but this may not always be practical.
-It is certainly simple enough to use @code{-gnatE}
-but the danger in this case is that, even if the GNAT binder
-finds a correct elaboration order, it may not always do so,
-and certainly a binder from another Ada compiler might not. A
-combination of testing and analysis (for which the
-information messages generated with the @code{-gnatel}
-switch can be useful) must be used to ensure that the program is free
-of errors. One switch that is useful in this testing is the
-@code{-p} (pessimistic elaboration order) switch for @code{gnatbind}.
-Normally the binder tries to find an order that has the best chance
-of avoiding elaboration problems. However, if this switch is used, the binder
-plays a devil's advocate role, and tries to choose the order that
-has the best chance of failing. If your program works even with this
-switch, then it has a better chance of being error free, but this is still
-not a guarantee.
-
-For an example of this approach in action, consider the C-tests (executable
-tests) from the ACATS suite. If these are compiled and run with the default
-treatment, then all but one of them succeed without generating any error
-diagnostics from the binder. However, there is one test that fails, and
-this is not surprising, because the whole point of this test is to ensure
-that the compiler can handle cases where it is impossible to determine
-a correct order statically, and it checks that an exception is indeed
-raised at run time.
-
-This one test must be compiled and run using the @code{-gnatE}
-switch, and then it passes. Alternatively, the entire suite can
-be run using this switch. It is never wrong to run with the dynamic
-elaboration switch if your code is correct, and we assume that the
-C-tests are indeed correct (it is less efficient, but efficiency is
-not a factor in running the ACATS tests.)
-
-@node Elaboration for Indirect Calls,Summary of Procedures for Elaboration Control,What to Do If the Default Elaboration Behavior Fails,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat id12}@anchor{242}@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-for-indirect-calls}@anchor{243}
-@section Elaboration for Indirect Calls
-
-
-@geindex Dispatching calls
-
-@geindex Indirect calls
-
-In rare cases, the static elaboration model fails to prevent
-dispatching calls to not-yet-elaborated subprograms. In such cases, we
-fall back to run-time checks; premature calls to any primitive
-operation of a tagged type before the body of the operation has been
-elaborated will raise @code{Program_Error}.
-
-Access-to-subprogram types, however, are handled conservatively in many
-cases. This was not true in earlier versions of the compiler; you can use
-the @code{-gnatd.U} debug switch to revert to the old behavior if the new
-conservative behavior causes elaboration cycles. Here, 'conservative' means
-that if you do @code{P'Access} during elaboration, the compiler will normally
-assume that you might call @code{P} indirectly during elaboration, so it adds an
-implicit @code{pragma Elaborate_All} on the library unit containing @code{P}. The
-@code{-gnatd.U} switch is safe if you know there are no such calls. If the
-program worked before, it will continue to work with @code{-gnatd.U}. But beware
-that code modifications such as adding an indirect call can cause erroneous
-behavior in the presence of @code{-gnatd.U}.
-
-These implicit Elaborate_All pragmas are not added in all cases, because
-they cause elaboration cycles in certain common code patterns. If you want
-even more conservative handling of P'Access, you can use the @code{-gnatd.o}
-switch.
+ 5.
+ 6.    pragma Warnings (Off);
+ 7.    Val_2 : constant Integer := ABE;
+ 8.    pragma Warnings (On);
+ 9.
+10.    function ABE return Integer is
+11.    begin
+12.       ...
+13.    end ABE;
+14. end Selective_Suppression;
+@end example
 
-See @code{debug.adb} for documentation on the @code{-gnatd...} debug switches.
+Note that suppressing elaboration warnings does not eliminate run-time
+checks. The example above will still fail at run time with an ABE.
+@end table
 
-@node Summary of Procedures for Elaboration Control,Other Elaboration Order Considerations,Elaboration for Indirect Calls,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat id13}@anchor{244}@anchor{gnat_ugn/elaboration_order_handling_in_gnat summary-of-procedures-for-elaboration-control}@anchor{245}
+@node Summary of Procedures for Elaboration Control,Inspecting the Chosen Elaboration Order,Elaboration-related Compiler Switches,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat id13}@anchor{22c}@anchor{gnat_ugn/elaboration_order_handling_in_gnat summary-of-procedures-for-elaboration-control}@anchor{22d}
 @section Summary of Procedures for Elaboration Control
 
 
-@geindex Elaboration control
-
-First, compile your program with the default options, using none of
-the special elaboration-control switches. If the binder successfully
-binds your program, then you can be confident that, apart from issues
-raised by the use of access-to-subprogram types and dynamic dispatching,
-the program is free of elaboration errors. If it is important that the
-program be portable to other compilers than GNAT, then use the
-@code{-gnatel}
-switch to generate messages about missing @code{Elaborate} or
-@code{Elaborate_All} pragmas, and supply the missing pragmas.
-
-If the program fails to bind using the default static elaboration
-handling, then you can fix the program to eliminate the binder
-message, or recompile the entire program with the
-@code{-gnatE} switch to generate dynamic elaboration checks,
-and, if you are sure there really are no elaboration problems,
-use a global pragma @code{Suppress (Elaboration_Check)}.
-
-@node Other Elaboration Order Considerations,Determining the Chosen Elaboration Order,Summary of Procedures for Elaboration Control,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat id14}@anchor{246}@anchor{gnat_ugn/elaboration_order_handling_in_gnat other-elaboration-order-considerations}@anchor{247}
-@section Other Elaboration Order Considerations
-
-
-This section has been entirely concerned with the issue of finding a valid
-elaboration order, as defined by the Ada Reference Manual. In a case
-where several elaboration orders are valid, the task is to find one
-of the possible valid elaboration orders (and the static model in GNAT
-will ensure that this is achieved).
-
-The purpose of the elaboration rules in the Ada Reference Manual is to
-make sure that no entity is accessed before it has been elaborated. For
-a subprogram, this means that the spec and body must have been elaborated
-before the subprogram is called. For an object, this means that the object
-must have been elaborated before its value is read or written. A violation
-of either of these two requirements is an access before elaboration order,
-and this section has been all about avoiding such errors.
-
-In the case where more than one order of elaboration is possible, in the
-sense that access before elaboration errors are avoided, then any one of
-the orders is 'correct' in the sense that it meets the requirements of
-the Ada Reference Manual, and no such error occurs.
-
-However, it may be the case for a given program, that there are
-constraints on the order of elaboration that come not from consideration
-of avoiding elaboration errors, but rather from extra-lingual logic
-requirements. Consider this example:
-
-@example
-with Init_Constants;
-package Constants is
-   X : Integer := 0;
-   Y : Integer := 0;
-end Constants;
-
-package Init_Constants is
-   procedure P; --* require a body*
-end Init_Constants;
-
-with Constants;
-package body Init_Constants is
-   procedure P is begin null; end;
-begin
-   Constants.X := 3;
-   Constants.Y := 4;
-end Init_Constants;
-
-with Constants;
-package Calc is
-   Z : Integer := Constants.X + Constants.Y;
-end Calc;
-
-with Calc;
-with Text_IO; use Text_IO;
-procedure Main is
-begin
-   Put_Line (Calc.Z'Img);
-end Main;
-@end example
+A programmer should first compile the program with the default options, using
+none of the binder or compiler switches. If the binder succeeds in finding an
+elaboration order, then apart from possible cases involing dispatching calls
+and access-to-subprogram types, the program is free of elaboration errors.
 
-In this example, there is more than one valid order of elaboration. For
-example both the following are correct orders:
+If it is important for the program to be portable to compilers other than GNAT,
+then the programmer should use compiler switch @code{-gnatel} and consider
+the messages about missing or implicitly created @code{Elaborate} and
+@code{Elaborate_All} pragmas.
 
-@example
-Init_Constants spec
-Constants spec
-Calc spec
-Init_Constants body
-Main body
-@end example
+If the binder reports an elaboration circularity, the programmer has several
+options:
 
-and
 
-@example
-Init_Constants spec
-Constants spec
-Init_Constants body
-Calc spec
-Main body
-@end example
+@itemize *
 
-There is no language rule to prefer one or the other, both are correct
-from an order of elaboration point of view. But the programmatic effects
-of the two orders are very different. In the first, the elaboration routine
-of @code{Calc} initializes @code{Z} to zero, and then the main program
-runs with this value of zero. But in the second order, the elaboration
-routine of @code{Calc} runs after the body of Init_Constants has set
-@code{X} and @code{Y} and thus @code{Z} is set to 7 before @code{Main} runs.
+@item 
+Ensure that elaboration warnings are enabled. This will allow the static
+model to output trace information of elaboration issues. The trace
+information could shed light on previously unforeseen dependencies, as well
+as their origins. Elaboration warnings are enabled with compiler switch
+@code{-gnatwl}.
 
-One could perhaps by applying pretty clever non-artificial intelligence
-to the situation guess that it is more likely that the second order of
-elaboration is the one desired, but there is no formal linguistic reason
-to prefer one over the other. In fact in this particular case, GNAT will
-prefer the second order, because of the rule that bodies are elaborated
-as soon as possible, but it's just luck that this is what was wanted
-(if indeed the second order was preferred).
+@item 
+Cosider the tactics given in the suggestions section of the circularity
+diagnostic.
 
-If the program cares about the order of elaboration routines in a case like
-this, it is important to specify the order required. In this particular
-case, that could have been achieved by adding to the spec of Calc:
+@item 
+If none of the steps outlined above resolve the circularity, use a more
+permissive elaboration model, in the following order:
 
-@example
-pragma Elaborate_All (Constants);
-@end example
 
-which requires that the body (if any) and spec of @code{Constants},
-as well as the body and spec of any unit @emph{with}ed by
-@code{Constants} be elaborated before @code{Calc} is elaborated.
+@itemize -
 
-Clearly no automatic method can always guess which alternative you require,
-and if you are working with legacy code that had constraints of this kind
-which were not properly specified by adding @code{Elaborate} or
-@code{Elaborate_All} pragmas, then indeed it is possible that two different
-compilers can choose different orders.
+@item 
+Use the pre-20.x legacy elaboration-order model, with binder switch
+@code{-H}.
 
-However, GNAT does attempt to diagnose the common situation where there
-are uninitialized variables in the visible part of a package spec, and the
-corresponding package body has an elaboration block that directly or
-indirectly initializes one or more of these variables. This is the situation
-in which a pragma Elaborate_Body is usually desirable, and GNAT will generate
-a warning that suggests this addition if it detects this situation.
+@item 
+Use both pre-18.x and pre-20.x legacy elaboration models, with compiler
+switch @code{-gnatH} and binder switch @code{-H}.
 
-The @code{gnatbind` :switch:`-p` switch may be useful in smoking
-out problems. This switch causes bodies to be elaborated as late as possible
-instead of as early as possible. In the example above, it would have forced
-the choice of the first elaboration order. If you get different results
-when using this switch, and particularly if one set of results is right,
-and one is wrong as far as you are concerned, it shows that you have some
-missing `@w{`}Elaborate} pragmas. For the example above, we have the
-following output:
+@item 
+Use the relaxed static elaboration model, with compiler switches
+@code{-gnatH} @code{-gnatJ} and binder switch @code{-H}.
 
-@example
-$ gnatmake -f -q main
-$ main
- 7
-$ gnatmake -f -q main -bargs -p
-$ main
- 0
-@end example
+@item 
+Use the relaxed dynamic elaboration model, with compiler switches
+@code{-gnatH} @code{-gnatJ} @code{-gnatE} and binder switch
+@code{-H}.
+@end itemize
+@end itemize
 
-It is of course quite unlikely that both these results are correct, so
-it is up to you in a case like this to investigate the source of the
-difference, by looking at the two elaboration orders that are chosen,
-and figuring out which is correct, and then adding the necessary
-@code{Elaborate} or @code{Elaborate_All} pragmas to ensure the desired order.
+@node Inspecting the Chosen Elaboration Order,,Summary of Procedures for Elaboration Control,Elaboration Order Handling in GNAT
+@anchor{gnat_ugn/elaboration_order_handling_in_gnat id14}@anchor{22e}@anchor{gnat_ugn/elaboration_order_handling_in_gnat inspecting-the-chosen-elaboration-order}@anchor{22f}
+@section Inspecting the Chosen Elaboration Order
 
-@node Determining the Chosen Elaboration Order,,Other Elaboration Order Considerations,Elaboration Order Handling in GNAT
-@anchor{gnat_ugn/elaboration_order_handling_in_gnat determining-the-chosen-elaboration-order}@anchor{248}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id15}@anchor{249}
-@section Determining the Chosen Elaboration Order
 
+To see the elaboration order chosen by the binder, inspect the contents of file
+@cite{b~xxx.adb}. On certain targets, this file appears as @cite{b_xxx.adb}. The
+elaboration order appears as a sequence of calls to @code{Elab_Body} and
+@code{Elab_Spec}, interspersed with assignments to @cite{Exxx} which indicates that a
+particular unit is elaborated. For example:
 
-To see the elaboration order that the binder chooses, you can look at
-the last part of the file:@cite{b~xxx.adb} binder output file. Here is an example:
+@quotation
 
 @example
 System.Soft_Links'Elab_Body;
@@ -28908,15 +27624,12 @@ Ada.Text_Io'Elab_Spec;
 Ada.Text_Io'Elab_Body;
 E07 := True;
 @end example
+@end quotation
 
-Here Elab_Spec elaborates the spec
-and Elab_Body elaborates the body. The assignments to the @code{E@emph{xx}} flags
-flag that the corresponding body is now elaborated.
+Note also binder switch @code{-l}, which outputs the chosen elaboration
+order and provides a more readable form of the above:
 
-You can also ask the binder to generate a more
-readable list of the elaboration order using the
-@code{-l} switch when invoking the binder. Here is
-an example of the output generated by this switch:
+@quotation
 
 @example
 ada (spec)
@@ -29004,9 +27717,10 @@ ada.text_io (body)
 text_io (spec)
 gdbstr (body)
 @end example
+@end quotation
 
 @node Inline Assembler,GNU Free Documentation License,Elaboration Order Handling in GNAT,Top
-@anchor{gnat_ugn/inline_assembler inline-assembler}@anchor{10}@anchor{gnat_ugn/inline_assembler doc}@anchor{24a}@anchor{gnat_ugn/inline_assembler id1}@anchor{24b}
+@anchor{gnat_ugn/inline_assembler inline-assembler}@anchor{10}@anchor{gnat_ugn/inline_assembler doc}@anchor{230}@anchor{gnat_ugn/inline_assembler id1}@anchor{231}
 @chapter Inline Assembler
 
 
@@ -29065,7 +27779,7 @@ and with assembly language programming.
 @end menu
 
 @node Basic Assembler Syntax,A Simple Example of Inline Assembler,,Inline Assembler
-@anchor{gnat_ugn/inline_assembler id2}@anchor{24c}@anchor{gnat_ugn/inline_assembler basic-assembler-syntax}@anchor{24d}
+@anchor{gnat_ugn/inline_assembler id2}@anchor{232}@anchor{gnat_ugn/inline_assembler basic-assembler-syntax}@anchor{233}
 @section Basic Assembler Syntax
 
 
@@ -29181,7 +27895,7 @@ Intel: Destination first; for example @code{mov eax, 4}@w{ }
 
 
 @node A Simple Example of Inline Assembler,Output Variables in Inline Assembler,Basic Assembler Syntax,Inline Assembler
-@anchor{gnat_ugn/inline_assembler a-simple-example-of-inline-assembler}@anchor{24e}@anchor{gnat_ugn/inline_assembler id3}@anchor{24f}
+@anchor{gnat_ugn/inline_assembler a-simple-example-of-inline-assembler}@anchor{234}@anchor{gnat_ugn/inline_assembler id3}@anchor{235}
 @section A Simple Example of Inline Assembler
 
 
@@ -29330,7 +28044,7 @@ If there are no errors, @code{as} will generate an object file
 @code{nothing.out}.
 
 @node Output Variables in Inline Assembler,Input Variables in Inline Assembler,A Simple Example of Inline Assembler,Inline Assembler
-@anchor{gnat_ugn/inline_assembler id4}@anchor{250}@anchor{gnat_ugn/inline_assembler output-variables-in-inline-assembler}@anchor{251}
+@anchor{gnat_ugn/inline_assembler id4}@anchor{236}@anchor{gnat_ugn/inline_assembler output-variables-in-inline-assembler}@anchor{237}
 @section Output Variables in Inline Assembler
 
 
@@ -29697,7 +28411,7 @@ end Get_Flags_3;
 @end quotation
 
 @node Input Variables in Inline Assembler,Inlining Inline Assembler Code,Output Variables in Inline Assembler,Inline Assembler
-@anchor{gnat_ugn/inline_assembler id5}@anchor{252}@anchor{gnat_ugn/inline_assembler input-variables-in-inline-assembler}@anchor{253}
+@anchor{gnat_ugn/inline_assembler id5}@anchor{238}@anchor{gnat_ugn/inline_assembler input-variables-in-inline-assembler}@anchor{239}
 @section Input Variables in Inline Assembler
 
 
@@ -29786,7 +28500,7 @@ _increment__incr.1:
 @end quotation
 
 @node Inlining Inline Assembler Code,Other Asm Functionality,Input Variables in Inline Assembler,Inline Assembler
-@anchor{gnat_ugn/inline_assembler id6}@anchor{254}@anchor{gnat_ugn/inline_assembler inlining-inline-assembler-code}@anchor{255}
+@anchor{gnat_ugn/inline_assembler id6}@anchor{23a}@anchor{gnat_ugn/inline_assembler inlining-inline-assembler-code}@anchor{23b}
 @section Inlining Inline Assembler Code
 
 
@@ -29857,7 +28571,7 @@ movl %esi,%eax
 thus saving the overhead of stack frame setup and an out-of-line call.
 
 @node Other Asm Functionality,,Inlining Inline Assembler Code,Inline Assembler
-@anchor{gnat_ugn/inline_assembler other-asm-functionality}@anchor{256}@anchor{gnat_ugn/inline_assembler id7}@anchor{257}
+@anchor{gnat_ugn/inline_assembler other-asm-functionality}@anchor{23c}@anchor{gnat_ugn/inline_assembler id7}@anchor{23d}
 @section Other @code{Asm} Functionality
 
 
@@ -29872,7 +28586,7 @@ and @code{Volatile}, which inhibits unwanted optimizations.
 @end menu
 
 @node The Clobber Parameter,The Volatile Parameter,,Other Asm Functionality
-@anchor{gnat_ugn/inline_assembler the-clobber-parameter}@anchor{258}@anchor{gnat_ugn/inline_assembler id8}@anchor{259}
+@anchor{gnat_ugn/inline_assembler the-clobber-parameter}@anchor{23e}@anchor{gnat_ugn/inline_assembler id8}@anchor{23f}
 @subsection The @code{Clobber} Parameter
 
 
@@ -29936,7 +28650,7 @@ Use 'register' name @code{memory} if you changed a memory location
 @end itemize
 
 @node The Volatile Parameter,,The Clobber Parameter,Other Asm Functionality
-@anchor{gnat_ugn/inline_assembler the-volatile-parameter}@anchor{25a}@anchor{gnat_ugn/inline_assembler id9}@anchor{25b}
+@anchor{gnat_ugn/inline_assembler the-volatile-parameter}@anchor{240}@anchor{gnat_ugn/inline_assembler id9}@anchor{241}
 @subsection The @code{Volatile} Parameter
 
 
@@ -29972,7 +28686,7 @@ to @code{True} only if the compiler's optimizations have created
 problems.
 
 @node GNU Free Documentation License,Index,Inline Assembler,Top
-@anchor{share/gnu_free_documentation_license gnu-fdl}@anchor{1}@anchor{share/gnu_free_documentation_license doc}@anchor{25c}@anchor{share/gnu_free_documentation_license gnu-free-documentation-license}@anchor{25d}
+@anchor{share/gnu_free_documentation_license gnu-fdl}@anchor{1}@anchor{share/gnu_free_documentation_license doc}@anchor{242}@anchor{share/gnu_free_documentation_license gnu-free-documentation-license}@anchor{243}
 @chapter GNU Free Documentation License
 
 
@@ -30460,8 +29174,8 @@ to permit their use in free software.
 
 @printindex ge
 
-@anchor{de}@w{                              }
 @anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{                              }
+@anchor{cf}@w{                              }
 
 @c %**end of body
 @bye