From: Piotr Trojanek <troja...@adacore.com> 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. Tested on x86_64-pc-linux-gnu, committed on master. --- 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 ec57cd23731..52063c8067f 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; -- 2.43.0