]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix ALI elaboration flags for ghost compilation units
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 22 May 2025 14:46:17 +0000 (16:46 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 1 Jul 2025 08:29:44 +0000 (10:29 +0200)
When GNAT was compiling a ghost unit, the ALI file wrongly suggested that this
unit includes elaboration code, which caused linking errors to non-existing
elaboration counters. This was because elaboration code is only detected in
Gigi, which is skipped for ignored ghost units, because we don't generate
object code for them

gcc/ada/ChangeLog:

* gnat1drv.adb (Gnat1drv): Do minimal decoration of the spec and body
of an ignored ghost compilation unit.

gcc/ada/gnat1drv.adb

index ec57cd23731ee8de4c290e955af92fe63068ebef..52063c8067f747304bec8e0d704f3ec79c752d91 100644 (file)
@@ -1352,7 +1352,15 @@ begin
             --  Exit the gnat driver with success, otherwise external builders
             --  such as gnatmake and gprbuild will treat the compilation of an
             --  ignored Ghost unit as a failure. Be sure we produce an empty
-            --  object file for the unit.
+            --  object file for the unit, while indicating for the ALI file
+            --  generation that neither spec or body has elaboration code
+            --  (which in ordinary compilation is indicated in Gigi).
+
+            Set_Has_No_Elaboration_Code (Main_Unit_Node);
+
+            if Present (Library_Unit (Main_Unit_Node)) then
+               Set_Has_No_Elaboration_Code (Library_Unit (Main_Unit_Node));
+            end if;
 
             Ecode := E_Success;
             Back_End.Gen_Or_Update_Object_File;