1.. _Example_of_Binder_Output_File: 2 3***************************** 4Example of Binder Output File 5***************************** 6 7.. index:: Binder output (example) 8 9This Appendix displays the source code for the output file 10generated by *gnatbind* for a simple 'Hello World' program. 11Comments have been added for clarification purposes. 12 13 14.. code-block:: ada 15 16 -- The package is called Ada_Main unless this name is actually used 17 -- as a unit name in the partition, in which case some other unique 18 -- name is used. 19 20 pragma Ada_95; 21 with System; 22 package ada_main is 23 pragma Warnings (Off); 24 25 -- The main program saves the parameters (argument count, 26 -- argument values, environment pointer) in global variables 27 -- for later access by other units including 28 -- Ada.Command_Line. 29 30 gnat_argc : Integer; 31 gnat_argv : System.Address; 32 gnat_envp : System.Address; 33 34 -- The actual variables are stored in a library routine. This 35 -- is useful for some shared library situations, where there 36 -- are problems if variables are not in the library. 37 38 pragma Import (C, gnat_argc); 39 pragma Import (C, gnat_argv); 40 pragma Import (C, gnat_envp); 41 42 -- The exit status is similarly an external location 43 44 gnat_exit_status : Integer; 45 pragma Import (C, gnat_exit_status); 46 47 GNAT_Version : constant String := 48 "GNAT Version: Pro 7.4.0w (20141119-49)" & ASCII.NUL; 49 pragma Export (C, GNAT_Version, "__gnat_version"); 50 51 Ada_Main_Program_Name : constant String := "_ada_hello" & ASCII.NUL; 52 pragma Export (C, Ada_Main_Program_Name, "__gnat_ada_main_program_name"); 53 54 -- This is the generated adainit routine that performs 55 -- initialization at the start of execution. In the case 56 -- where Ada is the main program, this main program makes 57 -- a call to adainit at program startup. 58 59 procedure adainit; 60 pragma Export (C, adainit, "adainit"); 61 62 -- This is the generated adafinal routine that performs 63 -- finalization at the end of execution. In the case where 64 -- Ada is the main program, this main program makes a call 65 -- to adafinal at program termination. 66 67 procedure adafinal; 68 pragma Export (C, adafinal, "adafinal"); 69 70 -- This routine is called at the start of execution. It is 71 -- a dummy routine that is used by the debugger to breakpoint 72 -- at the start of execution. 73 74 -- This is the actual generated main program (it would be 75 -- suppressed if the no main program switch were used). As 76 -- required by standard system conventions, this program has 77 -- the external name main. 78 79 function main 80 (argc : Integer; 81 argv : System.Address; 82 envp : System.Address) 83 return Integer; 84 pragma Export (C, main, "main"); 85 86 -- The following set of constants give the version 87 -- identification values for every unit in the bound 88 -- partition. This identification is computed from all 89 -- dependent semantic units, and corresponds to the 90 -- string that would be returned by use of the 91 -- Body_Version or Version attributes. 92 93 -- The following Export pragmas export the version numbers 94 -- with symbolic names ending in B (for body) or S 95 -- (for spec) so that they can be located in a link. The 96 -- information provided here is sufficient to track down 97 -- the exact versions of units used in a given build. 98 99 type Version_32 is mod 2 ** 32; 100 u00001 : constant Version_32 := 16#8ad6e54a#; 101 pragma Export (C, u00001, "helloB"); 102 u00002 : constant Version_32 := 16#fbff4c67#; 103 pragma Export (C, u00002, "system__standard_libraryB"); 104 u00003 : constant Version_32 := 16#1ec6fd90#; 105 pragma Export (C, u00003, "system__standard_libraryS"); 106 u00004 : constant Version_32 := 16#3ffc8e18#; 107 pragma Export (C, u00004, "adaS"); 108 u00005 : constant Version_32 := 16#28f088c2#; 109 pragma Export (C, u00005, "ada__text_ioB"); 110 u00006 : constant Version_32 := 16#f372c8ac#; 111 pragma Export (C, u00006, "ada__text_ioS"); 112 u00007 : constant Version_32 := 16#2c143749#; 113 pragma Export (C, u00007, "ada__exceptionsB"); 114 u00008 : constant Version_32 := 16#f4f0cce8#; 115 pragma Export (C, u00008, "ada__exceptionsS"); 116 u00009 : constant Version_32 := 16#a46739c0#; 117 pragma Export (C, u00009, "ada__exceptions__last_chance_handlerB"); 118 u00010 : constant Version_32 := 16#3aac8c92#; 119 pragma Export (C, u00010, "ada__exceptions__last_chance_handlerS"); 120 u00011 : constant Version_32 := 16#1d274481#; 121 pragma Export (C, u00011, "systemS"); 122 u00012 : constant Version_32 := 16#a207fefe#; 123 pragma Export (C, u00012, "system__soft_linksB"); 124 u00013 : constant Version_32 := 16#467d9556#; 125 pragma Export (C, u00013, "system__soft_linksS"); 126 u00014 : constant Version_32 := 16#b01dad17#; 127 pragma Export (C, u00014, "system__parametersB"); 128 u00015 : constant Version_32 := 16#630d49fe#; 129 pragma Export (C, u00015, "system__parametersS"); 130 u00016 : constant Version_32 := 16#b19b6653#; 131 pragma Export (C, u00016, "system__secondary_stackB"); 132 u00017 : constant Version_32 := 16#b6468be8#; 133 pragma Export (C, u00017, "system__secondary_stackS"); 134 u00018 : constant Version_32 := 16#39a03df9#; 135 pragma Export (C, u00018, "system__storage_elementsB"); 136 u00019 : constant Version_32 := 16#30e40e85#; 137 pragma Export (C, u00019, "system__storage_elementsS"); 138 u00020 : constant Version_32 := 16#41837d1e#; 139 pragma Export (C, u00020, "system__stack_checkingB"); 140 u00021 : constant Version_32 := 16#93982f69#; 141 pragma Export (C, u00021, "system__stack_checkingS"); 142 u00022 : constant Version_32 := 16#393398c1#; 143 pragma Export (C, u00022, "system__exception_tableB"); 144 u00023 : constant Version_32 := 16#b33e2294#; 145 pragma Export (C, u00023, "system__exception_tableS"); 146 u00024 : constant Version_32 := 16#ce4af020#; 147 pragma Export (C, u00024, "system__exceptionsB"); 148 u00025 : constant Version_32 := 16#75442977#; 149 pragma Export (C, u00025, "system__exceptionsS"); 150 u00026 : constant Version_32 := 16#37d758f1#; 151 pragma Export (C, u00026, "system__exceptions__machineS"); 152 u00027 : constant Version_32 := 16#b895431d#; 153 pragma Export (C, u00027, "system__exceptions_debugB"); 154 u00028 : constant Version_32 := 16#aec55d3f#; 155 pragma Export (C, u00028, "system__exceptions_debugS"); 156 u00029 : constant Version_32 := 16#570325c8#; 157 pragma Export (C, u00029, "system__img_intB"); 158 u00030 : constant Version_32 := 16#1ffca443#; 159 pragma Export (C, u00030, "system__img_intS"); 160 u00031 : constant Version_32 := 16#b98c3e16#; 161 pragma Export (C, u00031, "system__tracebackB"); 162 u00032 : constant Version_32 := 16#831a9d5a#; 163 pragma Export (C, u00032, "system__tracebackS"); 164 u00033 : constant Version_32 := 16#9ed49525#; 165 pragma Export (C, u00033, "system__traceback_entriesB"); 166 u00034 : constant Version_32 := 16#1d7cb2f1#; 167 pragma Export (C, u00034, "system__traceback_entriesS"); 168 u00035 : constant Version_32 := 16#8c33a517#; 169 pragma Export (C, u00035, "system__wch_conB"); 170 u00036 : constant Version_32 := 16#065a6653#; 171 pragma Export (C, u00036, "system__wch_conS"); 172 u00037 : constant Version_32 := 16#9721e840#; 173 pragma Export (C, u00037, "system__wch_stwB"); 174 u00038 : constant Version_32 := 16#2b4b4a52#; 175 pragma Export (C, u00038, "system__wch_stwS"); 176 u00039 : constant Version_32 := 16#92b797cb#; 177 pragma Export (C, u00039, "system__wch_cnvB"); 178 u00040 : constant Version_32 := 16#09eddca0#; 179 pragma Export (C, u00040, "system__wch_cnvS"); 180 u00041 : constant Version_32 := 16#6033a23f#; 181 pragma Export (C, u00041, "interfacesS"); 182 u00042 : constant Version_32 := 16#ece6fdb6#; 183 pragma Export (C, u00042, "system__wch_jisB"); 184 u00043 : constant Version_32 := 16#899dc581#; 185 pragma Export (C, u00043, "system__wch_jisS"); 186 u00044 : constant Version_32 := 16#10558b11#; 187 pragma Export (C, u00044, "ada__streamsB"); 188 u00045 : constant Version_32 := 16#2e6701ab#; 189 pragma Export (C, u00045, "ada__streamsS"); 190 u00046 : constant Version_32 := 16#db5c917c#; 191 pragma Export (C, u00046, "ada__io_exceptionsS"); 192 u00047 : constant Version_32 := 16#12c8cd7d#; 193 pragma Export (C, u00047, "ada__tagsB"); 194 u00048 : constant Version_32 := 16#ce72c228#; 195 pragma Export (C, u00048, "ada__tagsS"); 196 u00049 : constant Version_32 := 16#c3335bfd#; 197 pragma Export (C, u00049, "system__htableB"); 198 u00050 : constant Version_32 := 16#99e5f76b#; 199 pragma Export (C, u00050, "system__htableS"); 200 u00051 : constant Version_32 := 16#089f5cd0#; 201 pragma Export (C, u00051, "system__string_hashB"); 202 u00052 : constant Version_32 := 16#3bbb9c15#; 203 pragma Export (C, u00052, "system__string_hashS"); 204 u00053 : constant Version_32 := 16#807fe041#; 205 pragma Export (C, u00053, "system__unsigned_typesS"); 206 u00054 : constant Version_32 := 16#d27be59e#; 207 pragma Export (C, u00054, "system__val_lluB"); 208 u00055 : constant Version_32 := 16#fa8db733#; 209 pragma Export (C, u00055, "system__val_lluS"); 210 u00056 : constant Version_32 := 16#27b600b2#; 211 pragma Export (C, u00056, "system__val_utilB"); 212 u00057 : constant Version_32 := 16#b187f27f#; 213 pragma Export (C, u00057, "system__val_utilS"); 214 u00058 : constant Version_32 := 16#d1060688#; 215 pragma Export (C, u00058, "system__case_utilB"); 216 u00059 : constant Version_32 := 16#392e2d56#; 217 pragma Export (C, u00059, "system__case_utilS"); 218 u00060 : constant Version_32 := 16#84a27f0d#; 219 pragma Export (C, u00060, "interfaces__c_streamsB"); 220 u00061 : constant Version_32 := 16#8bb5f2c0#; 221 pragma Export (C, u00061, "interfaces__c_streamsS"); 222 u00062 : constant Version_32 := 16#6db6928f#; 223 pragma Export (C, u00062, "system__crtlS"); 224 u00063 : constant Version_32 := 16#4e6a342b#; 225 pragma Export (C, u00063, "system__file_ioB"); 226 u00064 : constant Version_32 := 16#ba56a5e4#; 227 pragma Export (C, u00064, "system__file_ioS"); 228 u00065 : constant Version_32 := 16#b7ab275c#; 229 pragma Export (C, u00065, "ada__finalizationB"); 230 u00066 : constant Version_32 := 16#19f764ca#; 231 pragma Export (C, u00066, "ada__finalizationS"); 232 u00067 : constant Version_32 := 16#95817ed8#; 233 pragma Export (C, u00067, "system__finalization_rootB"); 234 u00068 : constant Version_32 := 16#52d53711#; 235 pragma Export (C, u00068, "system__finalization_rootS"); 236 u00069 : constant Version_32 := 16#769e25e6#; 237 pragma Export (C, u00069, "interfaces__cB"); 238 u00070 : constant Version_32 := 16#4a38bedb#; 239 pragma Export (C, u00070, "interfaces__cS"); 240 u00071 : constant Version_32 := 16#07e6ee66#; 241 pragma Export (C, u00071, "system__os_libB"); 242 u00072 : constant Version_32 := 16#d7b69782#; 243 pragma Export (C, u00072, "system__os_libS"); 244 u00073 : constant Version_32 := 16#1a817b8e#; 245 pragma Export (C, u00073, "system__stringsB"); 246 u00074 : constant Version_32 := 16#639855e7#; 247 pragma Export (C, u00074, "system__stringsS"); 248 u00075 : constant Version_32 := 16#e0b8de29#; 249 pragma Export (C, u00075, "system__file_control_blockS"); 250 u00076 : constant Version_32 := 16#b5b2aca1#; 251 pragma Export (C, u00076, "system__finalization_mastersB"); 252 u00077 : constant Version_32 := 16#69316dc1#; 253 pragma Export (C, u00077, "system__finalization_mastersS"); 254 u00078 : constant Version_32 := 16#57a37a42#; 255 pragma Export (C, u00078, "system__address_imageB"); 256 u00079 : constant Version_32 := 16#bccbd9bb#; 257 pragma Export (C, u00079, "system__address_imageS"); 258 u00080 : constant Version_32 := 16#7268f812#; 259 pragma Export (C, u00080, "system__img_boolB"); 260 u00081 : constant Version_32 := 16#e8fe356a#; 261 pragma Export (C, u00081, "system__img_boolS"); 262 u00082 : constant Version_32 := 16#d7aac20c#; 263 pragma Export (C, u00082, "system__ioB"); 264 u00083 : constant Version_32 := 16#8365b3ce#; 265 pragma Export (C, u00083, "system__ioS"); 266 u00084 : constant Version_32 := 16#6d4d969a#; 267 pragma Export (C, u00084, "system__storage_poolsB"); 268 u00085 : constant Version_32 := 16#e87cc305#; 269 pragma Export (C, u00085, "system__storage_poolsS"); 270 u00086 : constant Version_32 := 16#e34550ca#; 271 pragma Export (C, u00086, "system__pool_globalB"); 272 u00087 : constant Version_32 := 16#c88d2d16#; 273 pragma Export (C, u00087, "system__pool_globalS"); 274 u00088 : constant Version_32 := 16#9d39c675#; 275 pragma Export (C, u00088, "system__memoryB"); 276 u00089 : constant Version_32 := 16#445a22b5#; 277 pragma Export (C, u00089, "system__memoryS"); 278 u00090 : constant Version_32 := 16#6a859064#; 279 pragma Export (C, u00090, "system__storage_pools__subpoolsB"); 280 u00091 : constant Version_32 := 16#e3b008dc#; 281 pragma Export (C, u00091, "system__storage_pools__subpoolsS"); 282 u00092 : constant Version_32 := 16#63f11652#; 283 pragma Export (C, u00092, "system__storage_pools__subpools__finalizationB"); 284 u00093 : constant Version_32 := 16#fe2f4b3a#; 285 pragma Export (C, u00093, "system__storage_pools__subpools__finalizationS"); 286 287 -- BEGIN ELABORATION ORDER 288 -- ada%s 289 -- interfaces%s 290 -- system%s 291 -- system.case_util%s 292 -- system.case_util%b 293 -- system.htable%s 294 -- system.img_bool%s 295 -- system.img_bool%b 296 -- system.img_int%s 297 -- system.img_int%b 298 -- system.io%s 299 -- system.io%b 300 -- system.parameters%s 301 -- system.parameters%b 302 -- system.crtl%s 303 -- interfaces.c_streams%s 304 -- interfaces.c_streams%b 305 -- system.standard_library%s 306 -- system.exceptions_debug%s 307 -- system.exceptions_debug%b 308 -- system.storage_elements%s 309 -- system.storage_elements%b 310 -- system.stack_checking%s 311 -- system.stack_checking%b 312 -- system.string_hash%s 313 -- system.string_hash%b 314 -- system.htable%b 315 -- system.strings%s 316 -- system.strings%b 317 -- system.os_lib%s 318 -- system.traceback_entries%s 319 -- system.traceback_entries%b 320 -- ada.exceptions%s 321 -- system.soft_links%s 322 -- system.unsigned_types%s 323 -- system.val_llu%s 324 -- system.val_util%s 325 -- system.val_util%b 326 -- system.val_llu%b 327 -- system.wch_con%s 328 -- system.wch_con%b 329 -- system.wch_cnv%s 330 -- system.wch_jis%s 331 -- system.wch_jis%b 332 -- system.wch_cnv%b 333 -- system.wch_stw%s 334 -- system.wch_stw%b 335 -- ada.exceptions.last_chance_handler%s 336 -- ada.exceptions.last_chance_handler%b 337 -- system.address_image%s 338 -- system.exception_table%s 339 -- system.exception_table%b 340 -- ada.io_exceptions%s 341 -- ada.tags%s 342 -- ada.streams%s 343 -- ada.streams%b 344 -- interfaces.c%s 345 -- system.exceptions%s 346 -- system.exceptions%b 347 -- system.exceptions.machine%s 348 -- system.finalization_root%s 349 -- system.finalization_root%b 350 -- ada.finalization%s 351 -- ada.finalization%b 352 -- system.storage_pools%s 353 -- system.storage_pools%b 354 -- system.finalization_masters%s 355 -- system.storage_pools.subpools%s 356 -- system.storage_pools.subpools.finalization%s 357 -- system.storage_pools.subpools.finalization%b 358 -- system.memory%s 359 -- system.memory%b 360 -- system.standard_library%b 361 -- system.pool_global%s 362 -- system.pool_global%b 363 -- system.file_control_block%s 364 -- system.file_io%s 365 -- system.secondary_stack%s 366 -- system.file_io%b 367 -- system.storage_pools.subpools%b 368 -- system.finalization_masters%b 369 -- interfaces.c%b 370 -- ada.tags%b 371 -- system.soft_links%b 372 -- system.os_lib%b 373 -- system.secondary_stack%b 374 -- system.address_image%b 375 -- system.traceback%s 376 -- ada.exceptions%b 377 -- system.traceback%b 378 -- ada.text_io%s 379 -- ada.text_io%b 380 -- hello%b 381 -- END ELABORATION ORDER 382 383 end ada_main; 384 385.. code-block:: ada 386 387 pragma Ada_95; 388 -- The following source file name pragmas allow the generated file 389 -- names to be unique for different main programs. They are needed 390 -- since the package name will always be Ada_Main. 391 392 pragma Source_File_Name (ada_main, Spec_File_Name => "b~hello.ads"); 393 pragma Source_File_Name (ada_main, Body_File_Name => "b~hello.adb"); 394 395 pragma Suppress (Overflow_Check); 396 with Ada.Exceptions; 397 398 -- Generated package body for Ada_Main starts here 399 400 package body ada_main is 401 pragma Warnings (Off); 402 403 -- These values are reference counter associated to units which have 404 -- been elaborated. It is also used to avoid elaborating the 405 -- same unit twice. 406 407 E72 : Short_Integer; pragma Import (Ada, E72, "system__os_lib_E"); 408 E13 : Short_Integer; pragma Import (Ada, E13, "system__soft_links_E"); 409 E23 : Short_Integer; pragma Import (Ada, E23, "system__exception_table_E"); 410 E46 : Short_Integer; pragma Import (Ada, E46, "ada__io_exceptions_E"); 411 E48 : Short_Integer; pragma Import (Ada, E48, "ada__tags_E"); 412 E45 : Short_Integer; pragma Import (Ada, E45, "ada__streams_E"); 413 E70 : Short_Integer; pragma Import (Ada, E70, "interfaces__c_E"); 414 E25 : Short_Integer; pragma Import (Ada, E25, "system__exceptions_E"); 415 E68 : Short_Integer; pragma Import (Ada, E68, "system__finalization_root_E"); 416 E66 : Short_Integer; pragma Import (Ada, E66, "ada__finalization_E"); 417 E85 : Short_Integer; pragma Import (Ada, E85, "system__storage_pools_E"); 418 E77 : Short_Integer; pragma Import (Ada, E77, "system__finalization_masters_E"); 419 E91 : Short_Integer; pragma Import (Ada, E91, "system__storage_pools__subpools_E"); 420 E87 : Short_Integer; pragma Import (Ada, E87, "system__pool_global_E"); 421 E75 : Short_Integer; pragma Import (Ada, E75, "system__file_control_block_E"); 422 E64 : Short_Integer; pragma Import (Ada, E64, "system__file_io_E"); 423 E17 : Short_Integer; pragma Import (Ada, E17, "system__secondary_stack_E"); 424 E06 : Short_Integer; pragma Import (Ada, E06, "ada__text_io_E"); 425 426 Local_Priority_Specific_Dispatching : constant String := ""; 427 Local_Interrupt_States : constant String := ""; 428 429 Is_Elaborated : Boolean := False; 430 431 procedure finalize_library is 432 begin 433 E06 := E06 - 1; 434 declare 435 procedure F1; 436 pragma Import (Ada, F1, "ada__text_io__finalize_spec"); 437 begin 438 F1; 439 end; 440 E77 := E77 - 1; 441 E91 := E91 - 1; 442 declare 443 procedure F2; 444 pragma Import (Ada, F2, "system__file_io__finalize_body"); 445 begin 446 E64 := E64 - 1; 447 F2; 448 end; 449 declare 450 procedure F3; 451 pragma Import (Ada, F3, "system__file_control_block__finalize_spec"); 452 begin 453 E75 := E75 - 1; 454 F3; 455 end; 456 E87 := E87 - 1; 457 declare 458 procedure F4; 459 pragma Import (Ada, F4, "system__pool_global__finalize_spec"); 460 begin 461 F4; 462 end; 463 declare 464 procedure F5; 465 pragma Import (Ada, F5, "system__storage_pools__subpools__finalize_spec"); 466 begin 467 F5; 468 end; 469 declare 470 procedure F6; 471 pragma Import (Ada, F6, "system__finalization_masters__finalize_spec"); 472 begin 473 F6; 474 end; 475 declare 476 procedure Reraise_Library_Exception_If_Any; 477 pragma Import (Ada, Reraise_Library_Exception_If_Any, "__gnat_reraise_library_exception_if_any"); 478 begin 479 Reraise_Library_Exception_If_Any; 480 end; 481 end finalize_library; 482 483 ------------- 484 -- adainit -- 485 ------------- 486 487 procedure adainit is 488 489 Main_Priority : Integer; 490 pragma Import (C, Main_Priority, "__gl_main_priority"); 491 Time_Slice_Value : Integer; 492 pragma Import (C, Time_Slice_Value, "__gl_time_slice_val"); 493 WC_Encoding : Character; 494 pragma Import (C, WC_Encoding, "__gl_wc_encoding"); 495 Locking_Policy : Character; 496 pragma Import (C, Locking_Policy, "__gl_locking_policy"); 497 Queuing_Policy : Character; 498 pragma Import (C, Queuing_Policy, "__gl_queuing_policy"); 499 Task_Dispatching_Policy : Character; 500 pragma Import (C, Task_Dispatching_Policy, "__gl_task_dispatching_policy"); 501 Priority_Specific_Dispatching : System.Address; 502 pragma Import (C, Priority_Specific_Dispatching, "__gl_priority_specific_dispatching"); 503 Num_Specific_Dispatching : Integer; 504 pragma Import (C, Num_Specific_Dispatching, "__gl_num_specific_dispatching"); 505 Main_CPU : Integer; 506 pragma Import (C, Main_CPU, "__gl_main_cpu"); 507 Interrupt_States : System.Address; 508 pragma Import (C, Interrupt_States, "__gl_interrupt_states"); 509 Num_Interrupt_States : Integer; 510 pragma Import (C, Num_Interrupt_States, "__gl_num_interrupt_states"); 511 Unreserve_All_Interrupts : Integer; 512 pragma Import (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts"); 513 Detect_Blocking : Integer; 514 pragma Import (C, Detect_Blocking, "__gl_detect_blocking"); 515 Default_Stack_Size : Integer; 516 pragma Import (C, Default_Stack_Size, "__gl_default_stack_size"); 517 Leap_Seconds_Support : Integer; 518 pragma Import (C, Leap_Seconds_Support, "__gl_leap_seconds_support"); 519 520 procedure Runtime_Initialize; 521 pragma Import (C, Runtime_Initialize, "__gnat_runtime_initialize"); 522 523 Finalize_Library_Objects : No_Param_Proc; 524 pragma Import (C, Finalize_Library_Objects, "__gnat_finalize_library_objects"); 525 526 -- Start of processing for adainit 527 528 begin 529 530 -- Record various information for this partition. The values 531 -- are derived by the binder from information stored in the ali 532 -- files by the compiler. 533 534 if Is_Elaborated then 535 return; 536 end if; 537 Is_Elaborated := True; 538 Main_Priority := -1; 539 Time_Slice_Value := -1; 540 WC_Encoding := 'b'; 541 Locking_Policy := ' '; 542 Queuing_Policy := ' '; 543 Task_Dispatching_Policy := ' '; 544 Priority_Specific_Dispatching := 545 Local_Priority_Specific_Dispatching'Address; 546 Num_Specific_Dispatching := 0; 547 Main_CPU := -1; 548 Interrupt_States := Local_Interrupt_States'Address; 549 Num_Interrupt_States := 0; 550 Unreserve_All_Interrupts := 0; 551 Detect_Blocking := 0; 552 Default_Stack_Size := -1; 553 Leap_Seconds_Support := 0; 554 555 Runtime_Initialize; 556 557 Finalize_Library_Objects := finalize_library'access; 558 559 -- Now we have the elaboration calls for all units in the partition. 560 -- The Elab_Spec and Elab_Body attributes generate references to the 561 -- implicit elaboration procedures generated by the compiler for 562 -- each unit that requires elaboration. Increment a counter of 563 -- reference for each unit. 564 565 System.Soft_Links'Elab_Spec; 566 System.Exception_Table'Elab_Body; 567 E23 := E23 + 1; 568 Ada.Io_Exceptions'Elab_Spec; 569 E46 := E46 + 1; 570 Ada.Tags'Elab_Spec; 571 Ada.Streams'Elab_Spec; 572 E45 := E45 + 1; 573 Interfaces.C'Elab_Spec; 574 System.Exceptions'Elab_Spec; 575 E25 := E25 + 1; 576 System.Finalization_Root'Elab_Spec; 577 E68 := E68 + 1; 578 Ada.Finalization'Elab_Spec; 579 E66 := E66 + 1; 580 System.Storage_Pools'Elab_Spec; 581 E85 := E85 + 1; 582 System.Finalization_Masters'Elab_Spec; 583 System.Storage_Pools.Subpools'Elab_Spec; 584 System.Pool_Global'Elab_Spec; 585 E87 := E87 + 1; 586 System.File_Control_Block'Elab_Spec; 587 E75 := E75 + 1; 588 System.File_Io'Elab_Body; 589 E64 := E64 + 1; 590 E91 := E91 + 1; 591 System.Finalization_Masters'Elab_Body; 592 E77 := E77 + 1; 593 E70 := E70 + 1; 594 Ada.Tags'Elab_Body; 595 E48 := E48 + 1; 596 System.Soft_Links'Elab_Body; 597 E13 := E13 + 1; 598 System.Os_Lib'Elab_Body; 599 E72 := E72 + 1; 600 System.Secondary_Stack'Elab_Body; 601 E17 := E17 + 1; 602 Ada.Text_Io'Elab_Spec; 603 Ada.Text_Io'Elab_Body; 604 E06 := E06 + 1; 605 end adainit; 606 607 -------------- 608 -- adafinal -- 609 -------------- 610 611 procedure adafinal is 612 procedure s_stalib_adafinal; 613 pragma Import (C, s_stalib_adafinal, "system__standard_library__adafinal"); 614 615 procedure Runtime_Finalize; 616 pragma Import (C, Runtime_Finalize, "__gnat_runtime_finalize"); 617 618 begin 619 if not Is_Elaborated then 620 return; 621 end if; 622 Is_Elaborated := False; 623 Runtime_Finalize; 624 s_stalib_adafinal; 625 end adafinal; 626 627 -- We get to the main program of the partition by using 628 -- pragma Import because if we try to with the unit and 629 -- call it Ada style, then not only do we waste time 630 -- recompiling it, but also, we don't really know the right 631 -- switches (e.g.@: identifier character set) to be used 632 -- to compile it. 633 634 procedure Ada_Main_Program; 635 pragma Import (Ada, Ada_Main_Program, "_ada_hello"); 636 637 ---------- 638 -- main -- 639 ---------- 640 641 -- main is actually a function, as in the ANSI C standard, 642 -- defined to return the exit status. The three parameters 643 -- are the argument count, argument values and environment 644 -- pointer. 645 646 function main 647 (argc : Integer; 648 argv : System.Address; 649 envp : System.Address) 650 return Integer 651 is 652 -- The initialize routine performs low level system 653 -- initialization using a standard library routine which 654 -- sets up signal handling and performs any other 655 -- required setup. The routine can be found in file 656 -- a-init.c. 657 658 procedure initialize; 659 pragma Import (C, initialize, "__gnat_initialize"); 660 661 -- The finalize routine performs low level system 662 -- finalization using a standard library routine. The 663 -- routine is found in file a-final.c and in the standard 664 -- distribution is a dummy routine that does nothing, so 665 -- really this is a hook for special user finalization. 666 667 procedure finalize; 668 pragma Import (C, finalize, "__gnat_finalize"); 669 670 -- The following is to initialize the SEH exceptions 671 672 SEH : aliased array (1 .. 2) of Integer; 673 674 Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address; 675 pragma Volatile (Ensure_Reference); 676 677 -- Start of processing for main 678 679 begin 680 -- Save global variables 681 682 gnat_argc := argc; 683 gnat_argv := argv; 684 gnat_envp := envp; 685 686 -- Call low level system initialization 687 688 Initialize (SEH'Address); 689 690 -- Call our generated Ada initialization routine 691 692 adainit; 693 694 -- Now we call the main program of the partition 695 696 Ada_Main_Program; 697 698 -- Perform Ada finalization 699 700 adafinal; 701 702 -- Perform low level system finalization 703 704 Finalize; 705 706 -- Return the proper exit status 707 return (gnat_exit_status); 708 end; 709 710 -- This section is entirely comments, so it has no effect on the 711 -- compilation of the Ada_Main package. It provides the list of 712 -- object files and linker options, as well as some standard 713 -- libraries needed for the link. The gnatlink utility parses 714 -- this b~hello.adb file to read these comment lines to generate 715 -- the appropriate command line arguments for the call to the 716 -- system linker. The BEGIN/END lines are used for sentinels for 717 -- this parsing operation. 718 719 -- The exact file names will of course depend on the environment, 720 -- host/target and location of files on the host system. 721 722 -- BEGIN Object file/option list 723 -- ./hello.o 724 -- -L./ 725 -- -L/usr/local/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/ 726 -- /usr/local/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/libgnat.a 727 -- END Object file/option list 728 729 end ada_main; 730 731 732The Ada code in the above example is exactly what is generated by the 733binder. We have added comments to more clearly indicate the function 734of each part of the generated ``Ada_Main`` package. 735 736The code is standard Ada in all respects, and can be processed by any 737tools that handle Ada. In particular, it is possible to use the debugger 738in Ada mode to debug the generated ``Ada_Main`` package. For example, 739suppose that for reasons that you do not understand, your program is crashing 740during elaboration of the body of ``Ada.Text_IO``. To locate this bug, 741you can place a breakpoint on the call: 742 743 .. code-block:: ada 744 745 Ada.Text_Io'Elab_Body; 746 747and trace the elaboration routine for this package to find out where 748the problem might be (more usually of course you would be debugging 749elaboration code in your own application). 750