]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Allow file mapping for System's spec
authorRonan Desplanques <desplanques@adacore.com>
Thu, 24 Oct 2024 12:56:15 +0000 (14:56 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 12 Nov 2024 13:00:52 +0000 (14:00 +0100)
Before this patch, it was never allowed to use pragma Source_File_Name
for the spec of System, allegedly because Targparm.Get_Target_Parameters
is called before configuration pragmas are processed. Using a mapping
file was allowed but did not work correctly.

This patch makes mapping files loading happen before the call to
Get_Target_Parameters so mapping file can set the file name of System.
Also, pragma Source_File_Name is allowed if it confirms a mapping that
was previously given in a mapping file, to accommodate GPRbuild that
uses both pragmas and mapping files.

gcc/ada/ChangeLog:

* frontend.adb (Frontend): Move call to Fmap.Initialize ...
* gnat1drv.adb (Gnat1drv): ... here. Look up Fmap when loading System.
* par-prag.adb (Prag): Allow pragma Source_File_Name for System when
it confirms an existing mapping.

gcc/ada/frontend.adb
gcc/ada/gnat1drv.adb
gcc/ada/par-prag.adb

index ece0e728e4a658b384845f89c151dba6ad0e9a54..ea0c7b12b4a0942f2818f3095f727a63cf74d79a 100644 (file)
@@ -286,13 +286,6 @@ begin
 
       Save_Config_Cunit_Boolean_Restrictions;
 
-      --  If there was a -gnatem switch, initialize the mappings of unit names
-      --  to file names and of file names to path names from the mapping file.
-
-      if Mapping_File_Name /= null then
-         Fmap.Initialize (Mapping_File_Name.all);
-      end if;
-
       --  Adjust Optimize_Alignment mode from debug switches if necessary
 
       if Debug_Flag_Dot_SS then
index b532aefcaaa904aefe70c4ea60c1daf489ce51d9..acc649122804f791e4c8555f9c82dc795b3db82b 100644 (file)
@@ -1034,6 +1034,13 @@ begin
       Sem_Eval.Initialize;
       Sem_Type.Init_Interp_Tables;
 
+      --  If there was a -gnatem switch, initialize the mappings of unit names
+      --  to file names and of file names to path names from the mapping file.
+
+      if Mapping_File_Name /= null then
+         Fmap.Initialize (Mapping_File_Name.all);
+      end if;
+
       --  Capture compilation date and time
 
       Opt.Compilation_Time := System.OS_Lib.Current_Time_String;
@@ -1051,9 +1058,12 @@ begin
             N : File_Name_Type;
 
          begin
-            Name_Buffer (1 .. 10) := "system.ads";
-            Name_Len := 10;
-            N := Name_Find;
+            N := Fmap.Mapped_File_Name (Name_To_Unit_Name (Name_System));
+
+            if N = No_File then
+               N := Name_Find ("system.ads");
+            end if;
+
             S := Load_Source_File (N);
 
             --  Failed to read system.ads, fatal error
index 1a2a7b6b77bea7a23959fd1f91653df4a5a8053d..8ea94a3f9bd3452adb7e8ac640fadd49e8facf4b 100644 (file)
@@ -29,6 +29,7 @@
 --  which require recognition and either partial or complete processing
 --  during parsing, and this unit performs this required processing.
 
+with Fmap;
 with Fname.UF; use Fname.UF;
 with Osint;    use Osint;
 with Rident;   use Rident;
@@ -754,15 +755,6 @@ begin
                   and then
                  Nkind (Selector_Name (Expr1)) = N_Identifier)
             then
-               if Nkind (Expr1) = N_Identifier
-                 and then Chars (Expr1) = Name_System
-               then
-                  Error_Msg_N
-                    ("pragma Source_File_Name may not be used for System",
-                     Arg1);
-                  return Error;
-               end if;
-
                --  Process index argument if present
 
                if Arg_Count = 3 then
@@ -793,6 +785,26 @@ begin
 
                Check_Arg_Is_String_Literal (Arg2);
 
+               if Nkind (Expr1) = N_Identifier
+                 and then Chars (Expr1) = Name_System
+               then
+                  --  We allow pragma Source_File_Name on System if it confirms
+                  --  a mapping that already exists in Fmap. The goal is to
+                  --  accommodate GPRbuild, which uses both a map file and
+                  --  a pragma, while at the same time preventing users from
+                  --  using just a pragma. Using just a pragma is a problem
+                  --  because those are not registered yet when
+                  --  Get_Target_Parameters is called.
+                  if Fmap.Mapped_File_Name (Name_To_Unit_Name (Name_System))
+                    /= Get_Fname (Arg2)
+                  then
+                     Error_Msg_N
+                       ("pragma Source_File_Name may not be used for System",
+                        Arg1);
+                     return Error;
+                  end if;
+               end if;
+
                if Chars (Arg2) = Name_Spec_File_Name then
                   Set_File_Name
                     (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);