diff mbox

[Ada] Always consider Linker_Options from package System

Message ID 20160620122554.GA141666@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 20, 2016, 12:25 p.m. UTC
On full runtimes, this was always the case.  On restricted one, force system
to be in the closer of the program.
No test for full runtimes (as no behaviour change).

Tested on x86_64-pc-linux-gnu, committed on trunk

2016-06-20  Tristan Gingold  <gingold@adacore.com>

	* make.adb (Check_Standard_Library): Consider system.ads
	if s-stalib.adb is not available.
	* gnatbind.adb (Add_Artificial_ALI_File): New procedure extracted from
	gnatbind.
diff mbox

Patch

Index: make.adb
===================================================================
--- make.adb	(revision 237595)
+++ make.adb	(working copy)
@@ -84,8 +84,11 @@ 
    --  Make control characters visible
 
    Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
-   --  Every program depends on this package, that must then be checked,
-   --  especially when -f and -a are used.
+   System_Package_Spec_Name : constant String := "system.ads";
+   --  Every program depends on one of these packages: usually the first one,
+   --  or if Supress_Standard_Library is true on the second one. The dependency
+   --  is not always explicit and considering it is important when -f and -a
+   --  are used.
 
    type Sigint_Handler is access procedure;
    pragma Convention (C, Sigint_Handler);
@@ -2701,39 +2704,43 @@ 
       begin
          Need_To_Check_Standard_Library := False;
 
+         Name_Len := 0;
+
          if not Targparm.Suppress_Standard_Library_On_Target then
-            declare
-               Sfile  : File_Name_Type;
-               Add_It : Boolean := True;
+            Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
+         else
+            Add_Str_To_Name_Buffer (System_Package_Spec_Name);
+         end if;
 
-            begin
-               Name_Len := 0;
-               Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
-               Sfile := Name_Enter;
+         declare
+            Sfile  : File_Name_Type;
+            Add_It : Boolean := True;
 
-               --  If we have a special runtime, we add the standard
-               --  library only if we can find it.
+         begin
+            Sfile := Name_Enter;
 
-               if RTS_Switch then
-                  Add_It := Full_Source_Name (Sfile) /= No_File;
-               end if;
+            --  If we have a special runtime, we add the standard library only
+            --  if we can find it.
 
-               if Add_It then
-                  if not Queue.Insert
-                           ((Format  => Format_Gnatmake,
-                             File    => Sfile,
-                             Unit    => No_Unit_Name,
-                             Project => No_Project,
-                             Index   => 0,
-                             Sid     => No_Source))
-                  then
-                     if Is_In_Obsoleted (Sfile) then
-                        Executable_Obsolete := True;
-                     end if;
+            if RTS_Switch then
+               Add_It := Full_Source_Name (Sfile) /= No_File;
+            end if;
+
+            if Add_It then
+               if not Queue.Insert
+                        ((Format  => Format_Gnatmake,
+                          File    => Sfile,
+                          Unit    => No_Unit_Name,
+                          Project => No_Project,
+                          Index   => 0,
+                          Sid     => No_Source))
+               then
+                  if Is_In_Obsoleted (Sfile) then
+                     Executable_Obsolete := True;
                   end if;
                end if;
-            end;
-         end if;
+            end if;
+         end;
       end Check_Standard_Library;
 
       -----------------------------------
Index: gnatbind.adb
===================================================================
--- gnatbind.adb	(revision 237595)
+++ gnatbind.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2015, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2016, 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- --
@@ -89,6 +89,9 @@ 
    --  Table to record the sources in the closure, to avoid duplications. Used
    --  only with switch -R.
 
+   procedure Add_Artificial_ALI_File (Name : String);
+   --  Artificially add ALI file Name in the closure.
+
    function Gnatbind_Supports_Auto_Init return Boolean;
    --  Indicates if automatic initialization of elaboration procedure
    --  through the constructor mechanism is possible on the platform.
@@ -113,6 +116,30 @@ 
    function Is_Cross_Compiler return Boolean;
    --  Returns True iff this is a cross-compiler
 
+   -----------------------------
+   -- Add_Artificial_ALI_File --
+   -----------------------------
+
+   procedure Add_Artificial_ALI_File (Name : String) is
+      Id : ALI_Id;
+      pragma Warnings (Off, Id);
+   begin
+      Name_Len := Name'Length;
+      Name_Buffer (1 .. Name_Len) := Name;
+      Std_Lib_File := Name_Find;
+      Text := Read_Library_Info (Std_Lib_File, True);
+
+      Id :=
+        Scan_ALI
+          (F             => Std_Lib_File,
+           T             => Text,
+           Ignore_ED     => False,
+           Err           => False,
+           Ignore_Errors => Debug_Flag_I);
+
+      Free (Text);
+   end Add_Artificial_ALI_File;
+
    ---------------------------------
    -- Gnatbind_Supports_Auto_Init --
    ---------------------------------
@@ -740,29 +767,15 @@ 
 
       --  Add System.Standard_Library to list to ensure that these files are
       --  included in the bind, even if not directly referenced from Ada code
-      --  This is suppressed if the appropriate targparm switch is set.
+      --  This is suppressed if the appropriate targparm switch is set. Be sure
+      --  in any case that System is in the closure, as it may contains linker
+      --  options. Note that it will be automatically added if s-stalib is
+      --  added.
 
       if not Suppress_Standard_Library_On_Target then
-         Name_Buffer (1 .. 12) := "s-stalib.ali";
-         Name_Len := 12;
-         Std_Lib_File := Name_Find;
-         Text := Read_Library_Info (Std_Lib_File, True);
-
-         declare
-            Id : ALI_Id;
-            pragma Warnings (Off, Id);
-
-         begin
-            Id :=
-              Scan_ALI
-                (F             => Std_Lib_File,
-                 T             => Text,
-                 Ignore_ED     => False,
-                 Err           => False,
-                 Ignore_Errors => Debug_Flag_I);
-         end;
-
-         Free (Text);
+         Add_Artificial_ALI_File ("s-stalib.ali");
+      else
+         Add_Artificial_ALI_File ("system.ali");
       end if;
 
       --  Load ALIs for all dependent units