Noticed with valgrind. Suppose a foreign thread calls Ada code. This results in Register_Foreign_Thread being called, which creates an ATCB. At the end of this routine, Enter_Task is called. Enter_Task is defined in s-taprop-linux.adb on linux. It contains this code that causes Task_Alternate_Stack to be registered as the signal stack:
if Use_Alternate_Stack then declare Stack : aliased stack_t; Result : Interfaces.C.int; begin Stack.ss_sp := Self_ID.Common.Task_Alternate_Stack; Stack.ss_size := Alternate_Stack_Size; Stack.ss_flags := 0; Result := sigaltstack (Stack'Access, null); pragma Assert (Result = 0); end; end if; But where was Task_Alternate_Stack initialized? Answer: it wasn't. Normally it would be initialized in Task_Wrapper, but of course Task_Wrapper is not called for foreign threads. Using a random uninitialized address for the signal stack results in much unpleasantness if the signal stack is ever used. -- Summary: Foreign thread results in Task_Alternate_Stack being used unitialized on linux Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: baldrick at gcc dot gnu dot org GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43993