https://gcc.gnu.org/g:176e9d801490511675772182b7d2b04b2a658ca4

commit r16-1882-g176e9d801490511675772182b7d2b04b2a658ca4
Author: Piotr Trojanek <troja...@adacore.com>
Date:   Thu May 22 16:46:17 2025 +0200

    ada: Fix ALI elaboration flags for ghost compilation units
    
    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.

Diff:
---
 gcc/ada/gnat1drv.adb | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gnat1drv.adb b/gcc/ada/gnat1drv.adb
index ec57cd23731e..52063c8067f7 100644
--- a/gcc/ada/gnat1drv.adb
+++ b/gcc/ada/gnat1drv.adb
@@ -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;

Reply via email to