In this patch, we enable calls to the binder and linker in gnatmake in CodePeer mode, to help support e.g. detection of global uninitialized variables or e.g. environment task race conditions.
Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-04 Arnaud Charlet <char...@adacore.com> * make.adb (Do_Codepeer_Globalize_Step): Removed. Use CodePeer_Mode instead. (CodePeer_Mode_String): New. (Linking_Phase, Binding_Phase): Call gnatlink with -P switch in CodePeer mode. (Scan_Make_Arg): Do not disable binding/linking phase in CodePeer mode. * bindgen.adb (Gen_Elab_Calls_Ada): Ignore subprograms in CodePeer mode, since no useful elaboration subprogram is needed by CodePeer. * gnatlink.adb (Gnatlink): Add support for -P switch (CodePeer mode). In this mode, compile binder file with -gnatC and do stop after this step.
Index: make.adb =================================================================== --- make.adb (revision 177365) +++ make.adb (working copy) @@ -386,11 +386,9 @@ -- with the switches -c, -b and -l. These flags are reset to True for -- each invocation of procedure Gnatmake. - Do_Codepeer_Globalize_Step : Boolean := False; - -- Flag to indicate whether the CodePeer globalizer should be called - Shared_String : aliased String := "-shared"; Force_Elab_Flags_String : aliased String := "-F"; + CodePeer_Mode_String : aliased String := "-P"; No_Shared_Switch : aliased Argument_List := (1 .. 0 => null); Shared_Switch : aliased Argument_List := (1 => Shared_String'Access); @@ -2927,7 +2925,7 @@ then -- If we compile with -gnatC, enable CodePeer globalize step - Do_Codepeer_Globalize_Step := True; + CodePeer_Mode := True; end if; end loop; @@ -2968,7 +2966,7 @@ declare Str : String renames Args (Arg_Index).all; begin - if Do_Codepeer_Globalize_Step + if CodePeer_Mode and then Str'Length > 2 and then Str (Str'First .. Str'First + 1) = "-m" then @@ -4399,7 +4397,13 @@ end; end if; - -- Add switch -M to gnatlink if buider switch --create-map-file + if CodePeer_Mode then + Linker_Switches.Increment_Last; + Linker_Switches.Table (Linker_Switches.Last) := + new String'(CodePeer_Mode_String); + end if; + + -- Add switch -M to gnatlink if builder switch --create-map-file -- has been specified. if Map_File /= null then @@ -4560,6 +4564,11 @@ Args (Last_Arg) := Force_Elab_Flags_String'Access; end if; + if CodePeer_Mode then + Last_Arg := Last_Arg + 1; + Args (Last_Arg) := CodePeer_Mode_String'Access; + end if; + if Main_Project /= No_Project then -- Put all the source directories in ADA_INCLUDE_PATH, @@ -6313,10 +6322,9 @@ end if; end loop Multiple_Main_Loop; - if Do_Codepeer_Globalize_Step then + if CodePeer_Mode then declare Success : Boolean := False; - begin Globalize (Success); @@ -7962,10 +7970,15 @@ Add_Switch (Argv, Compiler, And_Save => And_Save); Operating_Mode := Check_Semantics; Check_Object_Consistency := False; - Compile_Only := True; - Do_Bind_Step := False; - Do_Link_Step := False; + if not CodePeer_Mode + and then (Argv'Last < 7 or else Argv (7) /= 'C') + then + Compile_Only := True; + Do_Bind_Step := False; + Do_Link_Step := False; + end if; + elsif Argv (2 .. Argv'Last) = "nostdlib" then -- Pass -nstdlib to gnatbind and gnatlink Index: bindgen.adb =================================================================== --- bindgen.adb (revision 177365) +++ bindgen.adb (working copy) @@ -1423,7 +1423,10 @@ -- The uname_E increment is skipped if this is a separate spec, -- since it will be done when we process the body. - else + -- Ignore subprograms in CodePeer mode, since no useful + -- elaboration subprogram is needed by CodePeer. + + elsif U.Unit_Kind /= 's' or else not CodePeer_Mode then if Force_Checking_Of_Elaboration_Flags or Interface_Library_Unit or not Bind_Main_Program Index: gnatlink.adb =================================================================== --- gnatlink.adb (revision 177274) +++ gnatlink.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1996-2010, Free Software Foundation, Inc. -- +-- Copyright (C) 1996-2011, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -479,6 +479,9 @@ (Argument (Next_Arg), Only_If_No_Suffix => True)); + when 'P' => + Opt.CodePeer_Mode := True; + when 'R' => Opt.Run_Path_Option := False; @@ -1441,12 +1444,13 @@ Write_Eol; Write_Line (" mainprog.ali the ALI file of the main program"); Write_Eol; - Write_Line (" -f force object file list to be generated"); + Write_Line (" -f Force object file list to be generated"); Write_Line (" -g Compile binder source file with debug information"); Write_Line (" -n Do not compile the binder source file"); + Write_Line (" -P Process files for use by CodePeer"); Write_Line (" -R Do not use a run_path_option"); - Write_Line (" -v verbose mode"); - Write_Line (" -v -v very verbose mode"); + Write_Line (" -v Verbose mode"); + Write_Line (" -v -v Very verbose mode"); Write_Eol; Write_Line (" -o nam Use 'nam' as the name of the executable"); Write_Line (" -b target Compile the binder source to run on target"); @@ -1675,6 +1679,8 @@ -- because bindgen uses brackets encoding for all upper -- half and wide characters in identifier names. + -- In addition, in CodePeer mode compile with -gnatC + if Ada_Bind_File then Binder_Options_From_ALI.Increment_Last; Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) := @@ -1685,6 +1691,12 @@ Binder_Options_From_ALI.Increment_Last; Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) := new String'("-gnatiw"); + + if Opt.CodePeer_Mode then + Binder_Options_From_ALI.Increment_Last; + Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) := + new String'("-gnatC"); + end if; end if; -- Locate all the necessary programs and verify required files are present @@ -1888,6 +1900,13 @@ end Bind_Step; end if; + -- In CodePeer mode, there's nothing left to do after the binder file has + -- been compiled. + + if Opt.CodePeer_Mode then + return; + end if; + -- Now, actually link the program -- Skip this step for now on JVM since the Java interpreter will do