https://gcc.gnu.org/g:f4649a8901b2ebd6bd87451c8b758022600bf281
commit r15-8987-gf4649a8901b2ebd6bd87451c8b758022600bf281 Author: Eric Botcazou <ebotca...@adacore.com> Date: Thu Mar 27 20:29:51 2025 +0100 Ada: Fix too late initialization of tasking runtime with standalone library The Tasking_Runtime_Initialize routine installs the tasking version of the RTS_Lock manipulation routines and thus needs to be called very early before the elaboration of all the Ada units of the program, including those of the runtime itself. This is guaranteed by the binder when the tasking runtime is explicitly dragged into the link. However, for a standalone dynamic library that does not depend on the tasking runtime and is auto-initialized, no such guarantee holds, even though the library might be later dragged into a link that contains the tasking runtime. This change causes the routine to be called even earlier, in particular at load time when a (standalone) dynamic library is involved in the link, so as to meet the requirements. It will cause the routine to be called twice if the main subprogram is generated by the binder, but this is harmless since the routine is idempotent. ada/ * libgnarl/s-tasini.adb (Tasking_Runtime_Initialize): Add pragma Linker_Constructor for the procedure. Diff: --- gcc/ada/libgnarl/s-tasini.adb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/ada/libgnarl/s-tasini.adb b/gcc/ada/libgnarl/s-tasini.adb index 144ac7c1c4e8..ae0826590c86 100644 --- a/gcc/ada/libgnarl/s-tasini.adb +++ b/gcc/ada/libgnarl/s-tasini.adb @@ -115,11 +115,13 @@ package body System.Tasking.Initialization is procedure Tasking_Runtime_Initialize; pragma Export (Ada, Tasking_Runtime_Initialize, "__gnat_tasking_runtime_initialize"); + pragma Linker_Constructor (Tasking_Runtime_Initialize); -- This procedure starts the initialization of the GNARL. It installs the - -- tasking versions of the RTS_Lock manipulation routines. It is called + -- tasking version of the RTS_Lock manipulation routines. It is called -- very early before the elaboration of all the Ada units of the program, -- including those of the runtime, because this elaboration may require - -- the initialization of RTS_Lock objects. + -- the initialization of RTS_Lock objects, which means that it must only + -- contain code to which pragma Restrictions (No_Elaboration_Code) applies. -------------------------- -- Change_Base_Priority --